Implement and document %V escape so version only needs to be set once.
[open-adventure.git] / Makefile
1 # Makefile for the open-source release of adventure 2.5
2
3 # Note: If you're building from the repository rather than the source tarball,
4 # do this to get the linenoise library where you can use it:
5 #
6 # git submodule update --recursive --remote --init
7 #
8 # Therafter, you can update it like this:
9 #
10 # git submodule update --recursive --remote
11 #
12 # but this should seldom be necessary as that library is pretty stable.
13 #
14 # You will also need Python 3 YAML.  Under Debian or ubuntu:
15 #
16 # apt-get install python3-yaml
17 #
18 # If you have pip installed,
19 #
20 # pip3 install PyYAML
21 #
22 # If you are using MacPorts on OS X:
23 # port install py3{5,6}-yaml as appropriate for your Python 3 version.
24 #
25 # To build with save/resume disabled, pass CCFLAGS="-D ADVENT_NOSAVE"
26
27 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
28
29 .PHONY: debug indent release refresh dist linty html clean
30
31 CC?=gcc
32 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -Wpedantic -O2
33 LIBS=
34 UNAME_S := $(shell uname -s)
35 ifeq ($(UNAME_S),Linux)
36         LIBS=-lrt
37 endif
38
39 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
40 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
41 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control linenoise/linenoise.[ch] make_dungeon.py
42
43 .c.o:
44         $(CC) $(CCFLAGS) $(DBX) -c $<
45
46 advent: $(OBJS) linenoise.o dungeon.o
47         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o linenoise.o $(LDFLAGS) $(LIBS)
48
49 main.o:         advent.h dungeon.h
50
51 init.o:         advent.h dungeon.h
52
53 actions.o:      advent.h dungeon.h
54
55 score.o:        advent.h dungeon.h
56
57 misc.o:         advent.h dungeon.h
58
59 cheat.o:        advent.h dungeon.h
60
61 saveresume.o:   advent.h dungeon.h
62
63 dungeon.o:      dungeon.c dungeon.h
64         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
65
66 dungeon.c dungeon.h: make_dungeon.py adventure.yaml
67         python3 make_dungeon.py
68
69 linenoise.o:    linenoise/linenoise.h
70         $(CC) -c linenoise/linenoise.c
71
72 linenoise-dbg:  linenoise/linenoise.h
73         $(CC) $(CCFLAGS) -c linenoise/linenoise.c
74
75 clean:
76         rm -f *.o advent cheat *.html *.gcno *.gcda
77         rm -f dungeon.c dungeon.h
78         rm -f README advent.6 MANIFEST *.tar.gz
79         rm -f *~
80         rm -f .*~
81         rm -rf coverage advent.info
82         cd tests; $(MAKE) --quiet clean
83
84
85 cheat: $(CHEAT_OBJS) linenoise.o dungeon.o 
86         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) linenoise.o dungeon.o $(LDFLAGS) $(LIBS)
87
88 check: advent cheat
89         cd tests; $(MAKE) --quiet
90
91 coverage: debug cheat
92         cd tests; $(MAKE) coverage --quiet
93
94 .SUFFIXES: .adoc .html .6
95
96 # Requires asciidoc and xsltproc/docbook stylesheets.
97 .adoc.6:
98         a2x --doctype manpage --format manpage $<
99 .adoc.html:
100         asciidoc $<
101 .adoc:
102         asciidoc $<
103
104 html: advent.html history.html hints.html
105
106 # README.adoc exists because that filename is magic on GitLab.
107 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6
108 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
109
110 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
111 # This is a requirement for testing dist in GitLab's CI pipeline
112 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
113         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
114         @(ln -s . advent-$(VERS))
115         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
116         @(rm advent-$(VERS))
117
118 indent:
119         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
120
121 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
122         shipper version=$(VERS) | sh -e -x
123
124 refresh: advent.html notes.html history.html
125         shipper -N -w version=$(VERS) | sh -e -x
126
127 dist: advent-$(VERS).tar.gz
128
129 linty: CCFLAGS += -W
130 linty: CCFLAGS += -Wall
131 linty: CCFLAGS += -Wextra
132 linty: CCFLAGS += -Wundef
133 linty: CCFLAGS += -Wstrict-prototypes
134 linty: CCFLAGS += -Wmissing-prototypes
135 linty: CCFLAGS += -Wmissing-declarations
136 linty: CCFLAGS += -Wshadow
137 linty: CCFLAGS += -Wfloat-equal
138 linty: CCFLAGS += -Wcast-align
139 linty: CCFLAGS += -Wwrite-strings
140 linty: CCFLAGS += -Waggregate-return
141 linty: CCFLAGS += -Wcast-qual
142 linty: CCFLAGS += -Wswitch-enum
143 linty: CCFLAGS += -Wwrite-strings
144 linty: CCFLAGS += -Wunreachable-code
145 linty: CCFLAGS += -Winit-self
146 linty: CCFLAGS += -Wpointer-arith
147 linty: advent
148
149 debug: CCFLAGS += -O0 --coverage -ggdb
150 debug: linty
151 debug: cheat
152
153 debug-ln: linenoise-dbg debug