Improve Makefile recipe for coverage testing.
[open-adventure.git] / Makefile
1 # Makefile for the open-source release of adventure 2.5
2
3 # To build with save/resume disabled, pass CFLAGS="-DADVENT_NOSAVE"
4 # To build with auto-save/resume enabled, pass CFLAGS="-D ADVENT_AUTOSAVE"
5
6 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
7
8 .PHONY: debug indent release refresh dist linty html clean
9 .PHONY: check coverage
10
11 CC?=gcc
12 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all $(CFLAGS) -g
13 LIBS=$(shell pkg-config --libs libedit)
14 INC+=$(shell pkg-config --cflags libedit)
15
16 # LLVM/Clang on macOS seems to need -ledit flag for linking
17 UNAME_S := $(shell uname -s)
18 ifeq ($(UNAME_S),Darwin)
19     LIBS += -ledit
20 endif
21
22 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
23 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
24 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py templates/*.tpl
25
26 .c.o:
27         $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
28
29 advent: $(OBJS) dungeon.o
30         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
31
32 main.o:         advent.h dungeon.h
33
34 init.o:         advent.h dungeon.h
35
36 actions.o:      advent.h dungeon.h
37
38 score.o:        advent.h dungeon.h
39
40 misc.o:         advent.h dungeon.h
41
42 cheat.o:        advent.h dungeon.h
43
44 saveresume.o:   advent.h dungeon.h
45
46 dungeon.o:      dungeon.c dungeon.h
47         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
48
49 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
50         ./make_dungeon.py
51
52 clean:
53         rm -f *.o advent cheat *.html *.gcno *.gcda
54         rm -f dungeon.c dungeon.h
55         rm -f README advent.6 MANIFEST *.tar.gz
56         rm -f *~
57         rm -f .*~
58         rm -rf coverage advent.info
59         cd tests; $(MAKE) --quiet clean
60
61
62 cheat: $(CHEAT_OBJS) dungeon.o
63         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
64
65 check: advent cheat
66         cd tests; $(MAKE) --quiet
67
68 # Requires gcov, lcov, libasan6, and libubsan1
69 # The last two are Ubuntu names, might vary onb other distributions.
70 # After this, run your browser on coverage/open-adventure/index.html
71 # to see coverage results. Browse coverage/adventure.yaml.html
72 # to see symbol coverage over the YAML file.
73 coverage: clean debug
74         cd tests; $(MAKE) coverage --quiet
75
76 .SUFFIXES: .adoc .html .6
77
78 # Requires asciidoc and xsltproc/docbook stylesheets.
79 .adoc.6:
80         a2x --doctype manpage --format manpage $<
81 .adoc.html:
82         asciidoc $<
83 .adoc:
84         asciidoc $<
85
86 html: advent.html history.html hints.html
87
88 # README.adoc exists because that filename is magic on GitLab.
89 DOCS=COPYING NEWS README.adoc advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
90 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
91
92 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
93 # This is a requirement for testing dist in GitLab's CI pipeline
94 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
95         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
96         @(ln -s . advent-$(VERS))
97         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
98         @(rm advent-$(VERS))
99
100 indent:
101         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
102
103 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
104         shipper version=$(VERS) | sh -e -x
105
106 refresh: advent.html notes.html history.html
107         shipper -N -w version=$(VERS) | sh -e -x
108
109 dist: advent-$(VERS).tar.gz
110
111 linty: CCFLAGS += -W
112 linty: CCFLAGS += -Wall
113 linty: CCFLAGS += -Wextra
114 linty: CCGLAGS += -Wpedantic
115 linty: CCFLAGS += -Wundef
116 linty: CCFLAGS += -Wstrict-prototypes
117 linty: CCFLAGS += -Wmissing-prototypes
118 linty: CCFLAGS += -Wmissing-declarations
119 linty: CCFLAGS += -Wshadow
120 linty: CCFLAGS += -Wnull-dereference
121 linty: CCFLAGS += -Wjump-misses-init
122 linty: CCFLAGS += -Wfloat-equal
123 linty: CCFLAGS += -Wcast-align
124 linty: CCFLAGS += -Wwrite-strings
125 linty: CCFLAGS += -Waggregate-return
126 linty: CCFLAGS += -Wcast-qual
127 linty: CCFLAGS += -Wswitch-enum
128 linty: CCFLAGS += -Wwrite-strings
129 linty: CCFLAGS += -Wunreachable-code
130 linty: CCFLAGS += -Winit-self
131 linty: CCFLAGS += -Wpointer-arith
132 linty: advent cheat
133
134 # These seem to be more modeern options for enabling coverage testing.
135 # Documenting them here in case a future version bump disables --coverage.
136 #debug: CCFLAGS += -ftest-coverage
137 #debug: CCFLAGS += -fprofile-arcs
138
139 debug: CCFLAGS += -O0
140 debug: CCFLAGS += --coverage
141 debug: CCFLAGS += -ggdb
142 debug: CCFLAGS += -U_FORTIFY_SOURCE
143 debug: CCFLAGS += -fsanitize=address
144 debug: CCFLAGS += -fsanitize=undefined
145 debug: linty
146
147 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
148 cppcheck:
149         cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]
150
151 pylint:
152         @pylint --score=n *.py */*.py