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 -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)
69 cd tests; $(MAKE) --quiet
72 @clang-format --style="{IndentWidth: 8, UseTab: ForIndentation}" -i $$(find . -name "*.[ch]")
74 # Requires gcov, lcov, libasan6, and libubsan1
75 # The last two are Ubuntu names, might vary on other distributions.
76 # After this, run your browser on coverage/open-adventure/index.html
77 # to see coverage results. Browse coverage/adventure.yaml.html
78 # to see symbol coverage over the YAML file.
80 cd tests; $(MAKE) coverage --quiet
82 .SUFFIXES: .adoc .html .6
84 # Requires asciidoc and xsltproc/docbook stylesheets.
86 a2x --doctype manpage --format manpage $<
92 html: advent.html history.html hints.html
94 # README.adoc exists because that filename is magic on GitLab.
95 DOCS=COPYING NEWS.adoc README.adoc advent.adoc history.adoc notes.adoc hints.adoc advent.6 INSTALL.adoc
96 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
98 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
99 # This is a requirement for testing dist in GitLab's CI pipeline
100 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
101 @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
102 @(ln -s . advent-$(VERS))
103 (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
107 astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
109 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
110 shipper version=$(VERS) | sh -e -x
112 refresh: advent.html notes.html history.html
113 shipper -N -w version=$(VERS) | sh -e -x
115 dist: advent-$(VERS).tar.gz
118 linty: CCFLAGS += -Wall
119 linty: CCFLAGS += -Wextra
120 linty: CCGLAGS += -Wpedantic
121 linty: CCFLAGS += -Wundef
122 linty: CCFLAGS += -Wstrict-prototypes
123 linty: CCFLAGS += -Wmissing-prototypes
124 linty: CCFLAGS += -Wmissing-declarations
125 linty: CCFLAGS += -Wshadow
126 linty: CCFLAGS += -Wnull-dereference
127 linty: CCFLAGS += -Wjump-misses-init
128 linty: CCFLAGS += -Wfloat-equal
129 linty: CCFLAGS += -Wcast-align
130 linty: CCFLAGS += -Wwrite-strings
131 linty: CCFLAGS += -Waggregate-return
132 linty: CCFLAGS += -Wcast-qual
133 linty: CCFLAGS += -Wswitch-enum
134 linty: CCFLAGS += -Wwrite-strings
135 linty: CCFLAGS += -Wunreachable-code
136 linty: CCFLAGS += -Winit-self
137 linty: CCFLAGS += -Wpointer-arith
140 # These seem to be more modern options for enabling coverage testing.
141 # Documenting them here in case a future version bump disables --coverage.
142 #debug: CCFLAGS += -ftest-coverage
143 #debug: CCFLAGS += -fprofile-arcs
145 debug: CCFLAGS += -O0
146 debug: CCFLAGS += --coverage
147 debug: CCFLAGS += -ggdb
148 debug: CCFLAGS += -U_FORTIFY_SOURCE
149 debug: CCFLAGS += -fsanitize=address
150 debug: CCFLAGS += -fsanitize=undefined
153 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
155 cppcheck -I. --template gcc --enable=all $(CSUPPRESSIONS) *.[ch]
158 @pylint --score=n *.py */*.py