Move most build instructions into INSTALL.adoc.
[open-adventure.git] / Makefile
1 # Makefile for the open-source release of adventure 2.5
2
3 # To build with save/resume disabled, pass CCFLAGS="-D ADVENT_NOSAVE"
4
5 VERS=$(shell sed -n <NEWS '/^[0-9]/s/:.*//p' | head -1)
6
7 .PHONY: debug indent release refresh dist linty html clean
8 .PHONY: check coverage
9
10 CC?=gcc
11 CCFLAGS+=-std=c99 -D_DEFAULT_SOURCE -DVERSION=\"$(VERS)\" -Wpedantic -O2
12 LIBS=-ledit
13 UNAME_S := $(shell uname -s)
14 ifeq ($(UNAME_S),Linux)
15         LIBS+=-lrt
16 endif
17
18 OBJS=main.o init.o actions.o score.o misc.o saveresume.o
19 CHEAT_OBJS=cheat.o init.o actions.o score.o misc.o saveresume.o
20 SOURCES=$(OBJS:.o=.c) advent.h adventure.yaml Makefile control make_dungeon.py
21
22 .c.o:
23         $(CC) $(CCFLAGS) $(DBX) -c $<
24
25 advent: $(OBJS) dungeon.o
26         $(CC) $(CCFLAGS) $(DBX) -o advent $(OBJS) dungeon.o $(LDFLAGS) $(LIBS)
27
28 main.o:         advent.h dungeon.h
29
30 init.o:         advent.h dungeon.h
31
32 actions.o:      advent.h dungeon.h
33
34 score.o:        advent.h dungeon.h
35
36 misc.o:         advent.h dungeon.h
37
38 cheat.o:        advent.h dungeon.h
39
40 saveresume.o:   advent.h dungeon.h
41
42 dungeon.o:      dungeon.c dungeon.h
43         $(CC) $(CCFLAGS) $(DBX) -c dungeon.c
44
45 dungeon.c dungeon.h: make_dungeon.py adventure.yaml
46         python3 make_dungeon.py
47
48 clean:
49         rm -f *.o advent cheat *.html *.gcno *.gcda
50         rm -f dungeon.c dungeon.h
51         rm -f README advent.6 MANIFEST *.tar.gz
52         rm -f *~
53         rm -f .*~
54         rm -rf coverage advent.info
55         cd tests; $(MAKE) --quiet clean
56
57
58 cheat: $(CHEAT_OBJS) dungeon.o
59         $(CC) $(CCFLAGS) $(DBX) -o cheat $(CHEAT_OBJS) dungeon.o $(LDFLAGS) $(LIBS)
60
61 check: advent cheat
62         cd tests; $(MAKE) --quiet
63
64 coverage: debug cheat
65         cd tests; $(MAKE) coverage --quiet
66
67 .SUFFIXES: .adoc .html .6
68
69 # Requires asciidoc and xsltproc/docbook stylesheets.
70 .adoc.6:
71         a2x --doctype manpage --format manpage $<
72 .adoc.html:
73         asciidoc $<
74 .adoc:
75         asciidoc $<
76
77 html: advent.html history.html hints.html
78
79 # README.adoc exists because that filename is magic on GitLab.
80 DOCS=COPYING NEWS README.adoc TODO advent.adoc history.adoc notes.adoc hints.adoc advent.6
81 TESTFILES=tests/*.log tests/*.chk tests/README tests/decheck tests/Makefile
82
83 # Can't use GNU tar's --transform, needs to build under Alpine Linux.
84 # This is a requirement for testing dist in GitLab's CI pipeline
85 advent-$(VERS).tar.gz: $(SOURCES) $(DOCS)
86         @find $(SOURCES) $(DOCS) $(TESTFILES) -print | sed s:^:advent-$(VERS)/: >MANIFEST
87         @(ln -s . advent-$(VERS))
88         (tar -T MANIFEST -czvf advent-$(VERS).tar.gz)
89         @(rm advent-$(VERS))
90
91 indent:
92         astyle -n -A3 --pad-header --min-conditional-indent=1 --pad-oper *.c
93
94 release: advent-$(VERS).tar.gz advent.html history.html hints.html notes.html
95         shipper version=$(VERS) | sh -e -x
96
97 refresh: advent.html notes.html history.html
98         shipper -N -w version=$(VERS) | sh -e -x
99
100 dist: advent-$(VERS).tar.gz
101
102 linty: CCFLAGS += -W
103 linty: CCFLAGS += -Wall
104 linty: CCFLAGS += -Wextra
105 linty: CCFLAGS += -Wundef
106 linty: CCFLAGS += -Wstrict-prototypes
107 linty: CCFLAGS += -Wmissing-prototypes
108 linty: CCFLAGS += -Wmissing-declarations
109 linty: CCFLAGS += -Wshadow
110 linty: CCFLAGS += -Wfloat-equal
111 linty: CCFLAGS += -Wcast-align
112 linty: CCFLAGS += -Wwrite-strings
113 linty: CCFLAGS += -Waggregate-return
114 linty: CCFLAGS += -Wcast-qual
115 linty: CCFLAGS += -Wswitch-enum
116 linty: CCFLAGS += -Wwrite-strings
117 linty: CCFLAGS += -Wunreachable-code
118 linty: CCFLAGS += -Winit-self
119 linty: CCFLAGS += -Wpointer-arith
120 linty: advent
121
122 debug: CCFLAGS += -O0 --coverage -ggdb
123 debug: linty
124 debug: cheat
125