clone url: git://git.m455.casa/mth
Makefile
1 | # usage: |
2 | # make check: checks for compliance, errors, bad practices, memory leaks |
3 | # make: builds the damn thing |
4 | # |
5 | # for my reference/in case i decide to use this: -D_POSIX_C_SOURCE=200112 |
6 |
|
7 | SOURCE_FILE = main.c |
8 | BIN_FILE = a.out |
9 |
|
10 | # flags that are compatible between gcc and clang |
11 | # CFLAGS = -std=c89 -pedantic-errors -Wall -Wextra |
12 |
|
13 | build: |
14 | $(CC) -std=c89 -static $(SOURCE_FILE) -o $(BIN_FILE) |
15 |
|
16 | check: cppcheck splint clangtidy gccfanalyzer gccstrictflags valgrind |
17 |
|
18 | clean: |
19 | @rm $(BIN_FILE) |
20 |
|
21 | cppcheck: |
22 | @echo "== cppcheck ======================" |
23 | @cppcheck $(SOURCE_FILE) |
24 | @echo "done!" |
25 | @echo "" |
26 |
|
27 | # -nullret: suppress returns of NULL |
28 | splint: |
29 | @echo "== splint ========================" |
30 | @splint -nullret $(SOURCE_FILE) |
31 | @echo "" |
32 |
|
33 | # the `--` here suppresses the noisy database errors from clang-tidy |
34 | clangtidy: |
35 | @echo "== clang-tidy ====================" |
36 | @clang-tidy $(SOURCE_FILE) --warnings-as-errors=* -extra-arg=-std=c89 -- $(SOURCE_FILE) |
37 | @echo "done!" |
38 | @echo "" |
39 |
|
40 | # no clue if i should keep this separate from the gcc flags below since it's |
41 | # static analysis lol |
42 | gccfanalyzer: |
43 | @echo "== gcc -fanalyzer ====================" |
44 | @gcc -std=c89 -Wall -Wextra -pedantic-errors -fanalyzer $(SOURCE_FILE) |
45 | @echo "done!" |
46 | @echo "" |
47 | @rm $(BIN_FILE) |
48 |
|
49 | # use gcc-only flags here as yet another check |
50 | gccstrictflags: |
51 | @echo "== checking strict compliance ====================" |
52 | @gcc -std=c89 \ |
53 | -Wall \ |
54 | -Wextra \ |
55 | -pedantic-errors \ |
56 | -Wstrict-prototypes \ |
57 | -Wold-style-definition \ |
58 | -Wmissing-prototypes \ |
59 | -Wmissing-declarations \ |
60 | -Wdeclaration-after-statement \ |
61 | -Wconversion \ |
62 | -Wunused-function \ |
63 | -Wunused-macros \ |
64 | -Wunused-parameter \ |
65 | -Wunused-value \ |
66 | -Wunused-variable $(SOURCE_FILE) -o $(BIN_FILE) |
67 | @echo "done!" |
68 | @echo "" |
69 | @rm $(BIN_FILE) |
70 |
|
71 | valgrind: |
72 | @echo "== valgrind ======================" |
73 | @$(CC) -g $(SOURCE_FILE) -o $(BIN_FILE) |
74 | @valgrind -s --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(BIN_FILE) |
75 | @rm $(BIN_FILE) |
76 |
|