1 # Makefile for the open-source release of adventure 2.5
3 # SPDX-FileCopyrightText: (C) Eric S. Raymond <esr@thyrsus.com>
4 # SPDX-License-Identifier: BSD-2-Clause
6 # To build with save/resume disabled, pass CFLAGS="-DADVENT_NOSAVE"
7 # To build with auto-save/resume enabled, pass CFLAGS="-DADVENT_AUTOSAVE"
9 VERS=$(shell sed -n <NEWS.adoc '/^[0-9]/s/:.*//p' | head -1)
11 .PHONY: debug indent release refresh dist linty html clean
12 .PHONY: check coverage
15 CCFLAGS+=-std=c99 -Wall -Wextra -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all $(CFLAGS) -g $(EXTRA)
16 LIBS=$(shell pkg-config --libs libedit)
17 INC+=$(shell pkg-config --cflags libedit)
19 # LLVM/Clang on macOS seems to need -ledit flag for linking
20 UNAME_S := $(shell uname -s)
21 ifeq ($(UNAME_S),Darwin)
25 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
26 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
27 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py templates/*.tpl
30 $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
32 advent: $(OBJS) dungeon.o
33 $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
35 main.o: advent.h dungeon.h
37 init.o: advent.h dungeon.h
39 actions.o: advent.h dungeon.h
41 score.o: advent.h dungeon.h
43 misc.o: advent.h dungeon.h
45 cheat.o: advent.h dungeon.h
47 saveresume.o: advent.h dungeon.h
49 dungeon.o: dungeon.c dungeon.h
50 $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
52 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
56 rm -f *.o advent cheat *.html *.gcno *.gcda
57 rm -f dungeon.c dungeon.h
58 rm -f README advent.6 MANIFEST *.tar.gz
61 rm -rf coverage advent.info
62 cd tests; $(MAKE) --quiet clean
65 cheat: $(CHEAT_OBJS) dungeon.o
66 $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
68 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
70 @-cppcheck -I. --quiet --template gcc -UPROP_SET_SEEN --enable=all $(CSUPPRESSIONS) *.[ch]
73 @-pylint --score=n *.py */*.py
75 check: advent cheat pylint cppcheck
76 cd tests; $(MAKE) --quiet
79 @clang-format --style="{IndentWidth: 8, UseTab: ForIndentation}" -i $$(find . -name "*.[ch]")
82 # Requires gcov, lcov, libasan6, and libubsan1
83 # The last two are Ubuntu names, might vary on other distributions.
84 # After this, run your browser on coverage/open-adventure/index.html
85 # to see coverage results. Browse coverage/adventure.yaml.html
86 # to see symbol coverage over the YAML file.
88 cd tests; $(MAKE) coverage --quiet
90 # Note: to suppress the footers with timestamps being generated in HTML,
91 # we use "-a nofooter".
92 # To debug asciidoc problems, you may need to run "xmllint --nonet --noout --valid"
93 # on the intermediate XML that throws an error.
94 .SUFFIXES: .html .adoc .6
97 asciidoctor -D. -a nofooter -b manpage $<
99 asciidoctor -D. -a nofooter -a webfonts! $<
101 html: advent.html history.html hints.html
103 # README.adoc exists because that filename is magic on GitLab.
104 DOCS=COPYING NEWS.adoc README.adoc advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
105 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
107 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
108 # This is a requirement for testing dist in GitLab's CI pipeline
109 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
110 @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
111 @(ln -s . advent-$(VERS))
112 (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
115 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
116 shipper version=$(VERS) | sh -e -x
118 refresh: advent.html notes.html history.html
119 shipper -N -w version=$(VERS) | sh -e -x
121 dist: advent-$(VERS).tar.gz
124 linty: CCFLAGS += -Wall
125 linty: CCFLAGS += -Wextra
126 linty: CCGLAGS += -Wpedantic
127 linty: CCFLAGS += -Wundef
128 linty: CCFLAGS += -Wstrict-prototypes
129 linty: CCFLAGS += -Wmissing-prototypes
130 linty: CCFLAGS += -Wmissing-declarations
131 linty: CCFLAGS += -Wshadow
132 linty: CCFLAGS += -Wnull-dereference
133 linty: CCFLAGS += -Wjump-misses-init
134 linty: CCFLAGS += -Wfloat-equal
135 linty: CCFLAGS += -Wcast-align
136 linty: CCFLAGS += -Wwrite-strings
137 linty: CCFLAGS += -Waggregate-return
138 linty: CCFLAGS += -Wcast-qual
139 linty: CCFLAGS += -Wswitch-enum
140 linty: CCFLAGS += -Wwrite-strings
141 linty: CCFLAGS += -Wunreachable-code
142 linty: CCFLAGS += -Winit-self
143 linty: CCFLAGS += -Wpointer-arith
146 # These seem to be more modern options for enabling coverage testing.
147 # Documenting them here in case a future version bump disables --coverage.
148 #debug: CCFLAGS += -ftest-coverage
149 #debug: CCFLAGS += -fprofile-arcs
151 debug: CCFLAGS += -O0
152 debug: CCFLAGS += --coverage
153 debug: CCFLAGS += -ggdb
154 debug: CCFLAGS += -U_FORTIFY_SOURCE
155 debug: CCFLAGS += -fsanitize=address
156 debug: CCFLAGS += -fsanitize=undefined