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 # After this, run your browser on coverage/open-adventure/index.html
69 # to see coverage results. Browse coverage/adventure.yaml.html
70 # to see symbol coverage over the YAML file.
72 cd tests; $(MAKE) coverage --quiet
74 .SUFFIXES: .adoc .html .6
76 # Requires asciidoc and xsltproc/docbook stylesheets.
78 a2x --doctype manpage --format manpage $<
84 html: advent.html history.html hints.html
86 # README.adoc exists because that filename is magic on GitLab.
87 DOCS=COPYING NEWS README.adoc advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
88 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
90 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
91 # This is a requirement for testing dist in GitLab's CI pipeline
92 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
93 @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
94 @(ln -s . advent-$(VERS))
95 (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
99 astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
101 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
102 shipper version=$(VERS) | sh -e -x
104 refresh: advent.html notes.html history.html
105 shipper -N -w version=$(VERS) | sh -e -x
107 dist: advent-$(VERS).tar.gz
110 linty: CCFLAGS += -Wall
111 linty: CCFLAGS += -Wextra
112 linty: CCGLAGS += -Wpedantic
113 linty: CCFLAGS += -Wundef
114 linty: CCFLAGS += -Wstrict-prototypes
115 linty: CCFLAGS += -Wmissing-prototypes
116 linty: CCFLAGS += -Wmissing-declarations
117 linty: CCFLAGS += -Wshadow
118 linty: CCFLAGS += -Wnull-dereference
119 linty: CCFLAGS += -Wjump-misses-init
120 linty: CCFLAGS += -Wfloat-equal
121 linty: CCFLAGS += -Wcast-align
122 linty: CCFLAGS += -Wwrite-strings
123 linty: CCFLAGS += -Waggregate-return
124 linty: CCFLAGS += -Wcast-qual
125 linty: CCFLAGS += -Wswitch-enum
126 linty: CCFLAGS += -Wwrite-strings
127 linty: CCFLAGS += -Wunreachable-code
128 linty: CCFLAGS += -Winit-self
129 linty: CCFLAGS += -Wpointer-arith
132 debug: CCFLAGS += -O0
133 debug: CCFLAGS += --coverage
134 debug: CCFLAGS += -ggdb
135 debug: CCFLAGS += -U_FORTIFY_SOURCE
136 debug: CCFLAGS += -fsanitize=address
137 debug: CCFLAGS += -fsanitize=undefined
140 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
142 cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]
145 @pylint --score=n *.py */*.py