-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (48 loc) · 1.15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Variables
CC = gcc
CFLAGS = -Wall -O0 -std=c11 -DDEBUG -g
ODUMP = objdump
ODFLAGS = -d
OBJCOPY = objcopy
OBJFLAGS = -O binary
MKDIRARGS = --parents
# Directories
OBJDIR := obj
TGTDIR := target
SRCDIR := src
TSTDIR := tests
# Target name
target = vk
# Sources
sources := $(wildcard $(SRCDIR)/*.c $(SRCDIR)/*/*.c)
# Objects list
objects = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(sources))
# Tests
tests := $(wildcard $(TSTDIR)/*.c)
# Tests list
tests_list := $(patsubst $(TSTDIR)/%.c,$(OBJDIR)/%.exe,$(tests))
# Includes
includes := $(wildcard $(SRCDIR)/*.h $(SRCDIR)/*/*.h)
all: test run | test
# Run rules.
run: $(TGTDIR)/$(target)
@echo "success"
$(TGTDIR)/$(target) : $(objects)
$(CC) $(CFLAGS) $^ -o $@
$@
# Test rules.
# TODO:: get the recipe to fail on failed test.
test: $(tests_list)
@$(foreach f,$^,./$(f);)
$(OBJDIR)/%.exe: $(TSTDIR)/%.c $(objects)
$(CC) $(CFLAGS) -o $@ $< $(filter-out $(@D)/main.o,$(objects))
# Shared build rules.
$(OBJDIR)/%.o: $(SRCDIR)/%.c | folders
@mkdir $(MKDIRARGS) $(@D)
@$(CC) $(CFLAGS) -c -o $@ $<
folders:
@mkdir $(MKDIRARGS) $(OBJDIR)
@mkdir $(MKDIRARGS) $(TGTDIR)
.PHONY: clean
clean:
rm -rf $(OBJDIR) $(TGTDIR)