-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
51 lines (33 loc) · 1.11 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
# Author: Dominik Harmim <[email protected]>
VPATH = $(PROJ)
CC = gcc
CFLAGS = -Wall -std=c99 -pedantic
PROJ = c016
EXECUTABLE = $(PROJ)-test
SRCS = $(PROJ)/*.c
OBJS = $(shell $(CC) $(CFLAGS) -MM $(SRCS) | grep ':' | cut -d ':' -f1 | tr '\n' ' ')
TEST_OUTPUT = test.output
.PHONY: all
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJS)
.PHONY: test
test: $(EXECUTABLE)
./$(EXECUTABLE) > $(TEST_OUTPUT)
- diff -u $(TEST_OUTPUT) $(PROJ)/$(PROJ)-test.output
.PHONY: clean
clean:
rm -rf *.o *.out *.dSYM/ $(EXECUTABLE) $(TEST_OUTPUT) $(DEPDIR)
# #################### Auto-Dependency Generation #####################
DEPDIR := .d
$(shell mkdir -p $(DEPDIR) > /dev/null)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
%.o: %.c
%.o: %.c $(DEPDIR)/%.d
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(POSTCOMPILE)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
include $(wildcard $(patsubst %, $(DEPDIR)/%.d, $(basename $(SRCS))))
# #####################################################################