-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
129 lines (86 loc) · 2.69 KB
/
makefile
File metadata and controls
129 lines (86 loc) · 2.69 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# make release : generate a release build
# make debug : generate a debug build
# toolchain:
CC := gcc
LD := gcc
# opt levels:
OPT_DBG := 0
OPT_REL := 2
# output:
BIN := proxy_server
# output dirs:
BUILDDIR := build
BUILDDIR_RELEASEDIR := $(BUILDDIR)/release
BUILDDIR_DEBUGDIR := $(BUILDDIR)/debug
# srcs:
SRCDIR := ./
SRC_C := $(shell find $(SRCDIR)/ -type d \( -path ./tests \) -prune -false -o -name '*.c')
# objs:
OBJS := ${SRC_C:.c=.o}
# toolchain flags:
CCFLAGS_DEBUG := -O$(OPT_DBG) \
-std=gnu23 \
-Wall \
-Wextra \
-Wpadded \
-pedantic \
-pedantic-errors \
-pipe \
-pthread \
-lrt \
-g3
CCFLAGS_RELEASE := -O$(OPT_REL) \
-std=gnu23 \
-Wall \
-Wextra \
-Wpadded \
-pedantic \
-pedantic-errors \
-pipe \
-pthread \
-lrt
LDFLAGS_DEBUG := -O$(OPT_DBG)
LDFLAGS_RELEASE := -O$(OPT_REL)
# eval later in setvars_* recipes:
BUILD_OUTPUT_DIR :=
CCFLAGS :=
LDFLAGS :=
# START:
all:
@printf "\nUsage:\n"
@printf "\nmake release : generate a release build\n"
@printf "\nmake debug : generate a debug build\n"
# the main build routines:
debug : dirs_debug setvars_debug compile_and_link
@printf "\nOUTPUT: ./$(BUILD_OUTPUT_DIR)/$(BIN)\n"
@printf "\nDEBUG: DONE!\n\n"
release : dirs_release setvars_release compile_and_link
@printf "\nOUTPUT: ./$(BUILD_OUTPUT_DIR)/$(BIN)\n"
@printf "\nRELEASE: DONE!\n\n"
# make build dirs:
dirs_debug:
@mkdir -p $(BUILDDIR)
@mkdir -p $(BUILDDIR_DEBUGDIR)
dirs_release:
@mkdir -p $(BUILDDIR)
@mkdir -p $(BUILDDIR_RELEASEDIR)
# set build vars:
setvars_debug:
$(eval CCFLAGS = $(CCFLAGS_DEBUG))
$(eval LDFLAGS = $(LDFLAGS_DEBUG))
$(eval BUILD_OUTPUT_DIR = $(BUILDDIR_DEBUGDIR))
setvars_release:
$(eval CCFLAGS = $(CCFLAGS_RELEASE))
$(eval LDFLAGS = $(LDFLAGS_RELEASE))
$(eval BUILD_OUTPUT_DIR = $(BUILDDIR_RELEASEDIR))
# invoke the .c compiling template and link the bin:
compile_and_link : $(OBJS)
@printf "LINK: "
$(LD) $(LDFLAGS) $^ -o $(BUILD_OUTPUT_DIR)/$(BIN)
# compile .c:
%.o : %.c
@printf "COMPILE: "
$(CC) $(CCFLAGS) -c $< -o $@
# clean:
clean:
rm -rf $(BUILDDIR) $(shell find ./ -type f -name '*.o')