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