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