43f1f9514caa1c1286ec093cbb47e5147d92d307
[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 .PHONY: check coverage
31
32 CC?=gcc
33 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -Wpedantic -O2
34 LIBS=
35 UNAME_S := $(shell uname -s)
36 ifeq ($(UNAME_S),Linux)
37         LIBS=-lrt
38 endif
39
40 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
41 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
42 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control linenoise/linenoise.[ch] make_dungeon.py
43
44 .c.o:
45         $(CC) $(CCFLAGS) $(DBX) -c $<
46
47 advent: $(OBJS) linenoise.o dungeon.o
48         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o linenoise.o $(LDFLAGS) $(LIBS)
49
50 main.o:         advent.h dungeon.h linenoise.o
51
52 init.o:         advent.h dungeon.h
53
54 actions.o:      advent.h dungeon.h
55
56 score.o:        advent.h dungeon.h
57
58 misc.o:         advent.h dungeon.h
59
60 cheat.o:        advent.h dungeon.h linenoise.o
61
62 saveresume.o:   advent.h dungeon.h
63
64 dungeon.o:      dungeon.c dungeon.h
65         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
66
67 dungeon.c dungeon.h: make_dungeon.py adventure.yaml
68         python3 make_dungeon.py
69
70 linenoise.o: linenoise/linenoise.h
71         @test -s linenoise/linenoise.h || { echo -e "linenoise not present. Try:\n\
72                 git submodule update --recursive --remote --init"; exit 1; }
73         $(CC) -c linenoise/linenoise.c
74
75 linenoise-dbg: linenoise/linenoise.h
76         @test -s linenoise/linenoise.h || { echo -e "linenoise not present. Try:\n\
77                 git submodule update --recursive --remote --init"; exit 1; }
78         $(CC) $(CCFLAGS) -c linenoise/linenoise.c
79
80 clean:
81         rm -f *.o advent cheat *.html *.gcno *.gcda
82         rm -f dungeon.c dungeon.h
83         rm -f README advent.6 MANIFEST *.tar.gz
84         rm -f *~
85         rm -f .*~
86         rm -rf coverage advent.info
87         cd tests; $(MAKE) --quiet clean
88
89
90 cheat: $(CHEAT_OBJS) linenoise.o dungeon.o 
91         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) linenoise.o dungeon.o $(LDFLAGS) $(LIBS)
92
93 check: advent cheat
94         cd tests; $(MAKE) --quiet
95
96 coverage: debug cheat
97         cd tests; $(MAKE) coverage --quiet
98
99 .SUFFIXES: .adoc .html .6
100
101 # Requires asciidoc and xsltproc/docbook stylesheets.
102 .adoc.6:
103         a2x --doctype manpage --format manpage $<
104 .adoc.html:
105         asciidoc $<
106 .adoc:
107         asciidoc $<
108
109 html: advent.html history.html hints.html
110
111 # README.adoc exists because that filename is magic on GitLab.
112 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6
113 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
114
115 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
116 # This is a requirement for testing dist in GitLab's CI pipeline
117 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
118         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
119         @(ln -s . advent-$(VERS))
120         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
121         @(rm advent-$(VERS))
122
123 indent:
124         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
125
126 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
127         shipper version=$(VERS) | sh -e -x
128
129 refresh: advent.html notes.html history.html
130         shipper -N -w version=$(VERS) | sh -e -x
131
132 dist: advent-$(VERS).tar.gz
133
134 linty: CCFLAGS += -W
135 linty: CCFLAGS += -Wall
136 linty: CCFLAGS += -Wextra
137 linty: CCFLAGS += -Wundef
138 linty: CCFLAGS += -Wstrict-prototypes
139 linty: CCFLAGS += -Wmissing-prototypes
140 linty: CCFLAGS += -Wmissing-declarations
141 linty: CCFLAGS += -Wshadow
142 linty: CCFLAGS += -Wfloat-equal
143 linty: CCFLAGS += -Wcast-align
144 linty: CCFLAGS += -Wwrite-strings
145 linty: CCFLAGS += -Waggregate-return
146 linty: CCFLAGS += -Wcast-qual
147 linty: CCFLAGS += -Wswitch-enum
148 linty: CCFLAGS += -Wwrite-strings
149 linty: CCFLAGS += -Wunreachable-code
150 linty: CCFLAGS += -Winit-self
151 linty: CCFLAGS += -Wpointer-arith
152 linty: advent
153
154 debug: CCFLAGS += -O0 --coverage -ggdb
155 debug: linty
156 debug: cheat
157
158 debug-ln: linenoise-dbg debug