-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
131 lines (114 loc) · 6.7 KB
/
Makefile
File metadata and controls
131 lines (114 loc) · 6.7 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
130
131
.PHONY: default release debug help help-es help-en doc test check clean
default: release
all: release debug
HELP != case $$LANG in es*) echo help-es;; *) echo help-en;; esac
help: $(HELP)
help-es:
@echo "Objetivos disponibles:"
@echo "release: compilación optimizada, comprobaciones desactivadas, NDEBUG definido."
@echo " → bin/cedro*"
@echo "debug: compilación para diagnóstico, comprobaciones activadas."
@echo " → bin/cedro*-debug"
@echo "static: lo mismo que release, sólo que con enlace estático."
@echo " → bin/cedro*-static"
@echo "doc: construye la documentación con Doxygen https://www.doxygen.org"
@echo " → doc/api/index.html"
@echo "test: construye tanto release como debug, y dispara la batería de pruebas."
@echo "check: aplica varias herramientas de análisis estático:"
@echo " sparse: https://sparse.docs.kernel.org/"
@echo " valgrind: https://valgrind.org/"
@echo " gcc -fanalyzer:"
@echo " https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html"
@echo "clean: elimina el directorio bin/, y limpia también dentro de doc/."
help-en:
@echo "Available targets:"
@echo "release: optimized build, assertions disabled, NDEBUG defined."
@echo " → bin/cedro*"
@echo "debug: debugging build, assertions enabled."
@echo " → bin/cedro*-debug"
@echo "static: same as release, only statically linked."
@echo " → bin/cedro*-static"
@echo "doc: build documentation with Doxygen https://www.doxygen.org"
@echo " → doc/api/index.html"
@echo "test: build both release and debug, then run test suite."
@echo "check: apply several static analysis tools:"
@echo " sparse: https://sparse.docs.kernel.org/"
@echo " valgrind: https://valgrind.org/"
@echo " gcc -fanalyzer:"
@echo " https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html"
@echo "clean: remove bin/ directory, and clean also inside doc/."
NAME=cedro
# Strict compilation flags, use during development:
CFLAGS=-g -fshort-enums -std=c99 -fmax-errors=4 -pedantic-errors -Wall -Werror -Wno-unused-function -Wno-unused-const-variable -Wsign-conversion -Wsign-compare
# miniz has many implicit sign conversions, after removing some it works on
# some manchines but it is not enough in others, so better ignore it:
CFLAGS_MINIZ=-g -fshort-enums -std=c99 -fmax-errors=4 -pedantic-errors -Wall -Werror -Wno-unused-function -Wno-unused-const-variable
# Loose compilation flags, use for releases:
CFLAGS=-g -std=c99
CFLAGS_MINIZ=-g -std=c99
# -DNDEBUG mutes the unused-variable warnings/errors.
OPTIMIZATION=-O -DNDEBUG
VALGRIND_CHECK=valgrind --error-exitcode=123 --leak-check=yes
TEST_ARGUMENTS=src/$(NAME)cc.c
debug: bin/$(NAME)-debug bin/$(NAME)cc-debug bin/$(NAME)-new-debug
release: bin/$(NAME) bin/$(NAME)cc bin/$(NAME)-new
static: bin/$(NAME)-static bin/$(NAME)cc-static bin/$(NAME)-new-static
bin/$(NAME)-debug: src/cedro.c src/*.c src/*.h src/macros/*.h Makefile
@mkdir -p bin
$(CC) $(CFLAGS) -o $@ $<
bin/$(NAME): src/cedro.c src/*.c src/*.h src/macros/*.h Makefile
@mkdir -p bin
$(CC) $(CFLAGS) -o $@ $< $(OPTIMIZATION)
bin/$(NAME)cc-debug: src/cedrocc.c Makefile bin/$(NAME)-debug
@mkdir -p bin
bin/$(NAME)-debug --insert-line-directives $< | $(CC) $(CFLAGS) -I src -x c - -o $@
bin/$(NAME)cc: src/cedrocc.c Makefile bin/$(NAME)
@mkdir -p bin
bin/$(NAME) --insert-line-directives $< | $(CC) $(CFLAGS) -I src -x c - -o $@ $(OPTIMIZATION)
bin/$(NAME)-new-debug: src/cedro-new.c template.zip Makefile bin/$(NAME)cc-debug
@mkdir -p bin
bin/$(NAME)cc-debug $< -I src $(CFLAGS_MINIZ) -o $@
bin/$(NAME)-new: src/cedro-new.c template.zip Makefile bin/$(NAME)cc
@mkdir -p bin
bin/$(NAME)cc $< -I src $(CFLAGS_MINIZ) -o $@ $(OPTIMIZATION)
bin/$(NAME)-static: src/cedro.c src/*.c src/*.h src/macros/*.h Makefile
@mkdir -p bin
$(CC) $(CFLAGS) -static -o $@ $< $(OPTIMIZATION)
bin/$(NAME)cc-static: src/cedrocc.c Makefile bin/$(NAME)
@mkdir -p bin
bin/$(NAME) --insert-line-directives $< | $(CC) $(CFLAGS) -static -I src -x c - -o $@ $(OPTIMIZATION)
bin/$(NAME)-new-static: src/cedro-new.c template.zip Makefile bin/$(NAME)cc
@mkdir -p bin
bin/$(NAME)cc -static $< -I src $(CFLAGS_MINIZ) -o $@ $(OPTIMIZATION)
bin/%: src/%.c Makefile bin/$(NAME)cc
@mkdir -p bin
bin/$(NAME)cc $< -I src $(CFLAGS_MINIZ) -o $@ $(OPTIMIZATION)
%.zip: % %/* %/*/* bin/zip-template
bin/zip-template $@ $<
doc:
$(MAKE) -C doc
test: src/$(NAME)-test.c test/* bin/$(NAME) bin/$(NAME)-debug
@$(CC) $(CFLAGS) -o bin/$@ $<
@bin/$@
@for f in test/*.c; do echo -n "$${f} ... "; OPTS=""; if [ -z "$${f##*-line-directives*}" ]; then OPTS="--insert-line-directives $${OPTS}"; fi; if [ -z "$${f##*-embed-as-string*}" ]; then OPTS="--embed-as-string=80 $${OPTS}"; fi; ERROR=$$(bin/$(NAME) $${OPTS} "$${f}" | bin/$(NAME) - $${OPTS} --validate="test/reference/$${f##test/}" 2>&1); if [ "$$ERROR" ]; then echo "ERROR"; echo "$${ERROR}"; exit 7; else echo -n "OK"; fi; if which valgrind >/dev/null; then CMD="$(VALGRIND_CHECK) --quiet bin/$(NAME) $${OPTS} $${f}"; if $$CMD </dev/null >/dev/null; then echo ", valgrind OK"; else echo ", valgrind ERROR"; echo Run check with: "$(VALGRIND_CHECK) bin/$(NAME) $${OPTS} $${f}"; fi; else echo ""; fi; done
# gcc -fanalyzer needs at least GCC 11. GCC 10 gives false positives.
# https://valgrind.org/
# https://sparse.docs.kernel.org/en/latest/
# http://cppcheck.sourceforge.net/ https://github.com/danmar/cppcheck
check: bin/$(NAME)
# The sed filter is to avoid “warning: directive in macro's argument list”.
$(CPP) src/$(NAME).c | sed 's/^\(\s*\)# /\1\/\/ # /' >bin/$(NAME).i
@if which sparse >/dev/null; then echo 'Checking with sparse...'; sparse -Wall bin/$(NAME).i; else echo 'sparse not installed.'; fi
@if which valgrind >/dev/null; then echo 'Checking with Valgrind...'; valgrind --leak-check=yes bin/$(NAME) src/$(NAME)cc.c >/dev/null; else echo 'valgrind not installed.'; fi
@echo
@echo 'Omitted because Clang 12 gives several false positives:'
@echo "if which clang >/dev/null; then echo 'Checking with Clang...'; clang --analyze src/$(NAME).c; else echo 'clang not installed.'; fi"
@echo
@echo 'GCC should be version 11.2 or later because older releases such as 10.2 produce false positives on Cedro.'
@if which gcc >/dev/null; then echo 'Checking with gcc '`gcc -dumpversion`'...'; gcc -fanalyzer -c -o /dev/null -std=c99 src/$(NAME).c; fi
@echo
@echo 'Omitted because it has become way too slow (around 25 minutes):'
@echo "@if which cppcheck >/dev/null; then echo 'Checking with Cpphheck...'; cppcheck src/$(NAME).c --std=c99 --report-progress --enable=performance,portability; else echo 'cppcheck not installed.'; fi"
clean:
rm -rf bin
if [ -e doc ]; then $(MAKE) -C doc clean; fi