Major cleanups. Pre-process loop back in main loop, pre-processing abstracted into...
[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
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     CCFLAGS += -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 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 coverage: debug
68         cd tests; $(MAKE) coverage --quiet
69
70 .SUFFIXES: .adoc .html .6
71
72 # Requires asciidoc and xsltproc/docbook stylesheets.
73 .adoc.6:
74         a2x --doctype manpage --format manpage $<
75 .adoc.html:
76         asciidoc $<
77 .adoc:
78         asciidoc $<
79
80 html: advent.html history.html hints.html
81
82 # README.adoc exists because that filename is magic on GitLab.
83 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
84 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
85
86 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
87 # This is a requirement for testing dist in GitLab's CI pipeline
88 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
89         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
90         @(ln -s . advent-$(VERS))
91         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
92         @(rm advent-$(VERS))
93
94 indent:
95         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
96
97 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
98         shipper version=$(VERS) | sh -e -x
99
100 refresh: advent.html notes.html history.html
101         shipper -N -w version=$(VERS) | sh -e -x
102
103 dist: advent-$(VERS).tar.gz
104
105 linty: CCFLAGS += -W
106 linty: CCFLAGS += -Wall
107 linty: CCFLAGS += -Wextra
108 linty: CCGLAGS += -Wpedantic
109 linty: CCFLAGS += -Wundef
110 linty: CCFLAGS += -Wstrict-prototypes
111 linty: CCFLAGS += -Wmissing-prototypes
112 linty: CCFLAGS += -Wmissing-declarations
113 linty: CCFLAGS += -Wshadow
114 linty: CCFLAGS += -Wnull-dereference
115 linty: CCFLAGS += -Wjump-misses-init
116 linty: CCFLAGS += -Wfloat-equal
117 linty: CCFLAGS += -Wcast-align
118 linty: CCFLAGS += -Wwrite-strings
119 linty: CCFLAGS += -Waggregate-return
120 linty: CCFLAGS += -Wcast-qual
121 linty: CCFLAGS += -Wswitch-enum
122 linty: CCFLAGS += -Wwrite-strings
123 linty: CCFLAGS += -Wunreachable-code
124 linty: CCFLAGS += -Winit-self
125 linty: CCFLAGS += -Wpointer-arith
126 linty: advent cheat
127
128 debug: CCFLAGS += -O0
129 debug: CCFLAGS += --coverage
130 debug: CCFLAGS += -ggdb
131 debug: CCFLAGS += -U_FORTIFY_SOURCE
132 debug: CCFLAGS += -fsanitize=address
133 debug: CCFLAGS += -fsanitize=undefined
134 debug: linty
135
136 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
137 cppcheck:
138         cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]