Two coverage imprivenents, one by recognizing dead code.
[open-adventure.git] / Makefile
1 # Makefile for the open-source release of adventure 2.5
2
3 # To build with save/resume disabled, pass CCFLAGS="-D ADVENT_NOSAVE"
4
5 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
6
7 .PHONY: debug indent release refresh dist linty html clean
8 .PHONY: check coverage
9
10 CC?=gcc
11 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -O2
12 LIBS=$(shell pkg-config --libs libedit)
13 INC+=$(shell pkg-config --cflags libedit)
14
15 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
16 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
17 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py
18
19 .c.o:
20         $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
21
22 advent: $(OBJS) dungeon.o
23         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
24
25 main.o:         advent.h dungeon.h
26
27 init.o:         advent.h dungeon.h
28
29 actions.o:      advent.h dungeon.h
30
31 score.o:        advent.h dungeon.h
32
33 misc.o:         advent.h dungeon.h
34
35 cheat.o:        advent.h dungeon.h
36
37 saveresume.o:   advent.h dungeon.h
38
39 dungeon.o:      dungeon.c dungeon.h
40         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
41
42 dungeon.c dungeon.h: make_dungeon.py adventure.yaml
43         ./make_dungeon.py
44
45 clean:
46         rm -f *.o advent cheat *.html *.gcno *.gcda
47         rm -f dungeon.c dungeon.h
48         rm -f README advent.6 MANIFEST *.tar.gz
49         rm -f *~
50         rm -f .*~
51         rm -rf coverage advent.info
52         cd tests; $(MAKE) --quiet clean
53
54
55 cheat: $(CHEAT_OBJS) dungeon.o
56         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
57
58 check: advent cheat
59         cd tests; $(MAKE) --quiet
60
61 coverage: debug cheat
62         cd tests; $(MAKE) coverage --quiet
63
64 .SUFFIXES: .adoc .html .6
65
66 # Requires asciidoc and xsltproc/docbook stylesheets.
67 .adoc.6:
68         a2x --doctype manpage --format manpage $<
69 .adoc.html:
70         asciidoc $<
71 .adoc:
72         asciidoc $<
73
74 html: advent.html history.html hints.html
75
76 # README.adoc exists because that filename is magic on GitLab.
77 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6
78 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
79
80 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
81 # This is a requirement for testing dist in GitLab's CI pipeline
82 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
83         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
84         @(ln -s . advent-$(VERS))
85         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
86         @(rm advent-$(VERS))
87
88 indent:
89         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
90
91 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
92         shipper version=$(VERS) | sh -e -x
93
94 refresh: advent.html notes.html history.html
95         shipper -N -w version=$(VERS) | sh -e -x
96
97 dist: advent-$(VERS).tar.gz
98
99 linty: CCFLAGS += -W
100 linty: CCFLAGS += -Wall
101 linty: CCFLAGS += -Wextra
102 linty: CCGLAGS += -Wpedantic
103 linty: CCFLAGS += -Wundef
104 linty: CCFLAGS += -Wstrict-prototypes
105 linty: CCFLAGS += -Wmissing-prototypes
106 linty: CCFLAGS += -Wmissing-declarations
107 linty: CCFLAGS += -Wshadow
108 linty: CCFLAGS += -Wfloat-equal
109 linty: CCFLAGS += -Wcast-align
110 linty: CCFLAGS += -Wwrite-strings
111 linty: CCFLAGS += -Waggregate-return
112 linty: CCFLAGS += -Wcast-qual
113 linty: CCFLAGS += -Wswitch-enum
114 linty: CCFLAGS += -Wwrite-strings
115 linty: CCFLAGS += -Wunreachable-code
116 linty: CCFLAGS += -Winit-self
117 linty: CCFLAGS += -Wpointer-arith
118 linty: advent
119
120 debug: CCFLAGS += -O0 --coverage -ggdb
121 debug: linty
122 debug: cheat
123
124 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
125 cppcheck:
126         cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]