1 # Makefile for the open-source release of adventure 2.5
3 # To build with save/resume disabled, pass CCFLAGS="-D ADVENT_NOSAVE"
5 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
7 .PHONY: debug indent release refresh dist linty html clean
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)
15 # LLVM/Clang on macOS seems to need -ledit flag for linking
16 UNAME_S := $(shell uname -s)
17 ifeq ($(UNAME_S),Darwin)
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
26 $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
28 advent: $(OBJS) dungeon.o
29 $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
31 main.o: advent.h dungeon.h
33 init.o: advent.h dungeon.h
35 actions.o: advent.h dungeon.h
37 score.o: advent.h dungeon.h
39 misc.o: advent.h dungeon.h
41 cheat.o: advent.h dungeon.h
43 saveresume.o: advent.h dungeon.h
45 dungeon.o: dungeon.c dungeon.h
46 $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
48 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
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
57 rm -rf coverage advent.info
58 cd tests; $(MAKE) --quiet clean
61 cheat: $(CHEAT_OBJS) dungeon.o
62 $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
65 cd tests; $(MAKE) --quiet
68 cd tests; $(MAKE) coverage --quiet
70 .SUFFIXES: .adoc .html .6
72 # Requires asciidoc and xsltproc/docbook stylesheets.
74 a2x --doctype manpage --format manpage $<
80 html: advent.html history.html hints.html
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
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)
95 astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
97 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
98 shipper version=$(VERS) | sh -e -x
100 refresh: advent.html notes.html history.html
101 shipper -N -w version=$(VERS) | sh -e -x
103 dist: advent-$(VERS).tar.gz
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
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
136 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
138 cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]