Coverage fixups.
[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 -D_FORTIFY_SOURCE=2 -fstack-protector-all $(CFLAGS) -g
12 LIBS=$(shell pkg-config --libs libedit)
13 INC+=$(shell pkg-config --cflags libedit)
14
15 # LLVM/Clang on macOS seems to need -ledit flag for linking
16 UNAME_S := $(shell uname -s)
17 ifeq ($(UNAME_S),Darwin)
18     LIBS += -ledit
19 endif
20
21 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
22 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
23 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py templates/*.tpl
24
25 .c.o:
26         $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
27
28 advent: $(OBJS) dungeon.o
29         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
30
31 main.o:         advent.h dungeon.h
32
33 init.o:         advent.h dungeon.h
34
35 actions.o:      advent.h dungeon.h
36
37 score.o:        advent.h dungeon.h
38
39 misc.o:         advent.h dungeon.h
40
41 cheat.o:        advent.h dungeon.h
42
43 saveresume.o:   advent.h dungeon.h
44
45 dungeon.o:      dungeon.c dungeon.h
46         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
47
48 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
49         ./make_dungeon.py
50
51 clean:
52         rm -f *.o advent cheat *.html *.gcno *.gcda
53         rm -f dungeon.c dungeon.h
54         rm -f README advent.6 MANIFEST *.tar.gz
55         rm -f *~
56         rm -f .*~
57         rm -rf coverage advent.info
58         cd tests; $(MAKE) --quiet clean
59
60
61 cheat: $(CHEAT_OBJS) dungeon.o
62         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
63
64 check: advent cheat
65         cd tests; $(MAKE) --quiet
66
67 # After this, run your browser ob coverage/open-adventure/index.html
68 # to see coverage results.
69 coverage: debug
70         cd tests; $(MAKE) coverage --quiet
71
72 .SUFFIXES: .adoc .html .6
73
74 # Requires asciidoc and xsltproc/docbook stylesheets.
75 .adoc.6:
76         a2x --doctype manpage --format manpage $<
77 .adoc.html:
78         asciidoc $<
79 .adoc:
80         asciidoc $<
81
82 html: advent.html history.html hints.html
83
84 # README.adoc exists because that filename is magic on GitLab.
85 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
86 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
87
88 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
89 # This is a requirement for testing dist in GitLab's CI pipeline
90 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
91         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
92         @(ln -s . advent-$(VERS))
93         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
94         @(rm advent-$(VERS))
95
96 indent:
97         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
98
99 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
100         shipper version=$(VERS) | sh -e -x
101
102 refresh: advent.html notes.html history.html
103         shipper -N -w version=$(VERS) | sh -e -x
104
105 dist: advent-$(VERS).tar.gz
106
107 linty: CCFLAGS += -W
108 linty: CCFLAGS += -Wall
109 linty: CCFLAGS += -Wextra
110 linty: CCGLAGS += -Wpedantic
111 linty: CCFLAGS += -Wundef
112 linty: CCFLAGS += -Wstrict-prototypes
113 linty: CCFLAGS += -Wmissing-prototypes
114 linty: CCFLAGS += -Wmissing-declarations
115 linty: CCFLAGS += -Wshadow
116 linty: CCFLAGS += -Wnull-dereference
117 linty: CCFLAGS += -Wjump-misses-init
118 linty: CCFLAGS += -Wfloat-equal
119 linty: CCFLAGS += -Wcast-align
120 linty: CCFLAGS += -Wwrite-strings
121 linty: CCFLAGS += -Waggregate-return
122 linty: CCFLAGS += -Wcast-qual
123 linty: CCFLAGS += -Wswitch-enum
124 linty: CCFLAGS += -Wwrite-strings
125 linty: CCFLAGS += -Wunreachable-code
126 linty: CCFLAGS += -Winit-self
127 linty: CCFLAGS += -Wpointer-arith
128 linty: advent cheat
129
130 debug: CCFLAGS += -O0
131 debug: CCFLAGS += --coverage
132 debug: CCFLAGS += -ggdb
133 debug: CCFLAGS += -U_FORTIFY_SOURCE
134 debug: CCFLAGS += -fsanitize=address
135 debug: CCFLAGS += -fsanitize=undefined
136 debug: linty
137
138 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
139 cppcheck:
140         cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]