Add make target for coverage
[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         cd tests; $(MAKE) --quiet clean
89
90
91 cheat: $(CHEAT_OBJS) linenoise.o newdb.o 
92         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) linenoise.o newdb.o $(LDFLAGS) $(LIBS)
93
94 check: advent cheat
95         cd tests; $(MAKE) --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 coverage: debug check
157         lcov -t "advent" -o advent.info -c -d .
158         genhtml -o coverage/ advent.info
159