Reissue 1.18 - same code, corrected metadata.
[open-adventure.git] / Makefile
1 # Makefile for the open-source release of adventure 2.5
2
3 # SPDX-FileCopyrightText: (C) Eric S. Raymond <esr@thyrsus.com>
4 # SPDX-License-Identifier: BSD-2-Clause
5
6 # To build with save/resume disabled, pass CFLAGS="-DADVENT_NOSAVE"
7 # To build with auto-save/resume enabled, pass CFLAGS="-DADVENT_AUTOSAVE"
8
9 VERS=$(shell sed -n <NEWS.adoc '/^[0-9]/s/:.*//p' | head -1)
10
11 .PHONY: debug indent release refresh dist linty html clean
12 .PHONY: check coverage
13
14 CC?=gcc
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)
18
19 # LLVM/Clang on macOS seems to need -ledit flag for linking
20 UNAME_S := $(shell uname -s)
21 ifeq ($(UNAME_S),Darwin)
22     LIBS += -ledit
23 endif
24
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
28
29 .c.o:
30         $(CC) $(CCFLAGS) $(INC) $(DBX) -c $<
31
32 advent: $(OBJS) dungeon.o
33         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
34
35 main.o:         advent.h dungeon.h
36
37 init.o:         advent.h dungeon.h
38
39 actions.o:      advent.h dungeon.h
40
41 score.o:        advent.h dungeon.h
42
43 misc.o:         advent.h dungeon.h
44
45 cheat.o:        advent.h dungeon.h
46
47 saveresume.o:   advent.h dungeon.h
48
49 dungeon.o:      dungeon.c dungeon.h
50         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
51
52 dungeon.c dungeon.h: make_dungeon.py adventure.yaml advent.h templates/*.tpl
53         ./make_dungeon.py
54
55 clean:
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
59         rm -f *~
60         rm -f .*~
61         rm -rf coverage advent.info
62         cd tests; $(MAKE) --quiet clean
63
64
65 cheat: $(CHEAT_OBJS) dungeon.o
66         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
67
68 CSUPPRESSIONS = --suppress=missingIncludeSystem --suppress=invalidscanf
69 cppcheck:
70         @-cppcheck -I. --quiet --template gcc -UPROP_SET_SEEN --enable=all $(CSUPPRESSIONS) *.[ch]
71
72 pylint:
73         @-pylint --score=n *.py */*.py
74
75 check: advent cheat pylint cppcheck
76         cd tests; $(MAKE) --quiet
77
78 reflow:
79         @clang-format --style="{IndentWidth: 8, UseTab: ForIndentation}" -i $$(find . -name "*.[ch]")
80         @black --quiet *.py
81
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.
87 coverage: clean debug
88         cd tests; $(MAKE) coverage --quiet
89
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
95
96 .adoc.6:
97         asciidoctor -D. -a nofooter -b manpage $<
98 .adoc.html:
99         asciidoctor -D. -a nofooter -a webfonts! $<
100
101 html: advent.html history.html hints.html
102
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
106
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)
113         @(rm advent-$(VERS))
114
115 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
116         shipper version=$(VERS) | sh -e -x
117
118 refresh: advent.html notes.html history.html
119         shipper -N -w version=$(VERS) | sh -e -x
120
121 dist: advent-$(VERS).tar.gz
122
123 linty: CCFLAGS += -W
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
144 linty: advent cheat
145
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
150
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
157 debug: linty
158