e9c0de38748c06354386d324043636b3d04772a7
[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:         linenoise-gitmodule 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:        linenoise-gitmodule 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-gitmodule: 
70         test -s linenoise/linenoise.h || { echo "\nlinenoise not present. Try: \n\n\tgit submodule update --recursive --remote --init\n"; exit 1; }
71
72 linenoise.o:    linenoise-gitmodule linenoise/linenoise.h
73         $(CC) -c linenoise/linenoise.c
74
75 linenoise-dbg:  linenoise-gitmodule linenoise/linenoise.h
76         $(CC) $(CCFLAGS) -c linenoise/linenoise.c
77
78 clean:
79         rm -f *.o advent cheat *.html *.gcno *.gcda
80         rm -f dungeon.c dungeon.h
81         rm -f README advent.6 MANIFEST *.tar.gz
82         rm -f *~
83         rm -f .*~
84         rm -rf coverage advent.info
85         cd tests; $(MAKE) --quiet clean
86
87
88 cheat: $(CHEAT_OBJS) linenoise.o dungeon.o 
89         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) linenoise.o dungeon.o $(LDFLAGS) $(LIBS)
90
91 check: advent cheat
92         cd tests; $(MAKE) --quiet
93
94 coverage: debug cheat
95         cd tests; $(MAKE) coverage --quiet
96
97 .SUFFIXES: .adoc .html .6
98
99 # Requires asciidoc and xsltproc/docbook stylesheets.
100 .adoc.6:
101         a2x --doctype manpage --format manpage $<
102 .adoc.html:
103         asciidoc $<
104 .adoc:
105         asciidoc $<
106
107 html: advent.html history.html hints.html
108
109 # README.adoc exists because that filename is magic on GitLab.
110 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6
111 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
112
113 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
114 # This is a requirement for testing dist in GitLab's CI pipeline
115 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
116         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
117         @(ln -s . advent-$(VERS))
118         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
119         @(rm advent-$(VERS))
120
121 indent:
122         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
123
124 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
125         shipper version=$(VERS) | sh -e -x
126
127 refresh: advent.html notes.html history.html
128         shipper -N -w version=$(VERS) | sh -e -x
129
130 dist: advent-$(VERS).tar.gz
131
132 linty: CCFLAGS += -W
133 linty: CCFLAGS += -Wall
134 linty: CCFLAGS += -Wextra
135 linty: CCFLAGS += -Wundef
136 linty: CCFLAGS += -Wstrict-prototypes
137 linty: CCFLAGS += -Wmissing-prototypes
138 linty: CCFLAGS += -Wmissing-declarations
139 linty: CCFLAGS += -Wshadow
140 linty: CCFLAGS += -Wfloat-equal
141 linty: CCFLAGS += -Wcast-align
142 linty: CCFLAGS += -Wwrite-strings
143 linty: CCFLAGS += -Waggregate-return
144 linty: CCFLAGS += -Wcast-qual
145 linty: CCFLAGS += -Wswitch-enum
146 linty: CCFLAGS += -Wwrite-strings
147 linty: CCFLAGS += -Wunreachable-code
148 linty: CCFLAGS += -Winit-self
149 linty: CCFLAGS += -Wpointer-arith
150 linty: advent
151
152 debug: CCFLAGS += -O0 --coverage -ggdb
153 debug: linty
154 debug: cheat
155
156 debug-ln: linenoise-dbg debug