forked from spartalab/tap-b
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
108 lines (79 loc) · 2.48 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
PROJECT = tap
SRCDIR = src
OBJDIR = obj
BINDIR = bin
DEPDIR = .depend
INCLUDEDIR = include
$(shell mkdir -p $(DEPDIR) > /dev/null)
$(shell mkdir -p $(OBJDIR))
$(shell mkdir -p $(BINDIR))
INCLUDEFLAG = -I $(INCLUDEDIR)
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(INCLUDEDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
RM = rm -f
CC = gcc
CFLAGS = -pthread -Wall $(INCLUDEFLAG) $(DEPFLAGS)
CFLAGS += -Wextra -Wwrite-strings -Wno-parentheses -Winline
CFLAGS += -Wpedantic -Warray-bounds
DEBUGFLAGS = -g -O0
RELEASEFLAGS = -O3
PROFILEFLAGS = -pg $(DEBUGFLAGS)
LINKER = gcc
LFLAGS = -Wall -pthread -lm $(INCLUDEFLAG)
MACFLAGS = -Wall -lm $(INCLUDEFLAG)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
# ------- all target: build the main project ------
.PHONY: all
all: $(BINDIR)/$(PROJECT)
$(BINDIR)/$(PROJECT): $(OBJECTS)
$(LINKER) $^ $(LFLAGS) -o $@
# ------- parallel target: build the main project ------
.PHONY: parallel
parallel: CFLAGS += $(RELEASEFLAGS) -DPARALLELISM=1
parallel: $(BINDIR)/$(PROJECT)
# ------- parallel debug: build the main project ------
.PHONY: parallel-d
parallel-d: CFLAGS += -DPARALLELISM=1 -g
parallel-d: $(BINDIR)/$(PROJECT)
# ------- nctcog: build the main project ------
.PHONY: nctcog
nctcog: CFLAGS += $(RELEASEFLAGS) -DNCTCOG_ENABLED=1
nctcog: $(BINDIR)/$(PROJECT)
# ------- nctcog-par: build the main project ------
.PHONY: nctcog-par
nctcog-par: CFLAGS += $(RELEASEFLAGS) -DPARALLELISM=1 -DNCTCOG_ENABLED=1
nctcog-par: $(BINDIR)/$(PROJECT)
# ---------- release target: extra optimization ----
.PHONY: release
release: CFLAGS += $(RELEASEFLAGS)
release: $(BINDIR)/$(PROJECT)
# ---------- debug target---------------------------
.PHONY: debug
debug: CFLAGS += $(DEBUGFLAGS)
debug: $(BINDIR)/$(PROJECT)
# ---------- profile target-------------------------
.PHONY: debug
profile: CFLAGS += $(PROFILEFLAGS)
profile: $(BINDIR)/$(PROJECT)
# ---------- compile objects
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(DEPDIR)/%.d
$(CC) $(CFLAGS) -c $< $(INCLUDEFLAG) -o $@
$(POSTCOMPILE)
$(OBJDIR)/%.o: $(TESTDIR)/%.c
$(CC) $(CFLAGS_TEST) -c $< $(INCLUDEFLAG_TEST) -o $@
$(POSTCOMPILE)
# ---------- clean/clear
.PHONY: clean clear
clean clear:
@$(RM) -r .depend
@$(RM) $(OBJECTS)
.PHONY: remove
remove: clean
@$(RM) $(BINDIR)/$(PROJECT)
.DELETE_ON_ERROR:
# -------- dependency tracking
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))