forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_many.makefile
More file actions
53 lines (44 loc) · 1.06 KB
/
c_many.makefile
File metadata and controls
53 lines (44 loc) · 1.06 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
.POSIX:
-include params.makefile
O ?= 0
STD ?= c11
CCC ?= gcc -DIMPLEMENTATION_SIGNAL -DUNDEFINED_BEHAVIOUR -ggdb3 -pedantic-errors -std=$(STD) -O$(O) -Wextra -Wno-ignored-qualifiers -Wno-sign-compare -Wno-unused-variable -Wno-unused-label -Wno-unused-but-set-variable
IN_EXT ?= .c
LIBS ?= -lm
OUT_EXT ?= .out
RUN ?= main
TEST ?= test
TMP_EXT ?= .tmp
INS := $(wildcard *$(IN_EXT))
OUTS_NOEXT := $(basename $(INS))
OUTS := $(addsuffix $(OUT_EXT), $(OUTS_NOEXT))
.PHONY: all clean run
all: $(OUTS)
%$(OUT_EXT): %$(IN_EXT)
$(CCC) -o '$@' '$<' $(LIBS)
clean:
rm -f *'$(OUT_EXT)' *'$(TMP_EXT)'
run: all
./'$(RUN)$(OUT_EXT)'
# If a `test` script exists, use it.
# Otherwise, run a default test script which checks if all programs exit 0.
test: all
@\
if [ -x $(TEST) ]; then\
./$(TEST) '$(OUT_EXT)';\
else\
fail=false;\
for t in *"$(OUT_EXT)"; do\
if ! ./"$$t"; then\
fail=true;\
break;\
fi;\
done;\
if $$fail; then\
echo "ASSERT FAILED: $$t";\
exit 1;\
else\
echo 'ALL TESTS PASSED';\
exit 0;\
fi;\
fi;\