1 # Makefile for the open-source release of adventure 2.5
3 # To build with save/resume disabled, pass CFLAGS="-DADVENT_NOSAVE"
4 # To build with auto-save/resume enabled, pass CFLAGS="-D ADVENT_AUTOSAVE"
6 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
8 .PHONY: debug indent release refresh dist linty html clean
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)
16 # LLVM/Clang on macOS seems to need -ledit flag for linking
17 UNAME_S := $(shell uname -s)
18 ifeq ($(UNAME_S),Darwin)
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
27 $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
29 advent: $(OBJS) dungeon.o
30 $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
32 main.o: advent.h dungeon.h
34 init.o: advent.h dungeon.h
36 actions.o: advent.h dungeon.h
38 score.o: advent.h dungeon.h
40 misc.o: advent.h dungeon.h
42 cheat.o: advent.h dungeon.h
44 saveresume.o: advent.h dungeon.h
46 dungeon.o: dungeon.c dungeon.h
47 $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
49 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
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
58 rm -rf coverage advent.info
59 cd tests; $(MAKE) --quiet clean
62 cheat: $(CHEAT_OBJS) dungeon.o
63 $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
66 cd tests; $(MAKE) --quiet
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.
74 cd tests; $(MAKE) coverage --quiet
76 .SUFFIXES: .adoc .html .6
78 # Requires asciidoc and xsltproc/docbook stylesheets.
80 a2x --doctype manpage --format manpage $<
86 html: advent.html history.html hints.html
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
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)
101 astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
103 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
104 shipper version=$(VERS) | sh -e -x
106 refresh: advent.html notes.html history.html
107 shipper -N -w version=$(VERS) | sh -e -x
109 dist: advent-$(VERS).tar.gz
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
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
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
147 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
149 cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]
152 @pylint --score=n *.py */*.py