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