Document changes, upload to unstable.
[tfortune.git] / Makefile
1 # SPDX-License-Identifier: GPL-3.0-only
2
3 .SUFFIXES:
4 MAKEFLAGS += -Rr
5 .ONESHELL:
6 .SHELLFLAGS := -ec
7
8 RM := rm -f
9 MKDIR_P := mkdir -p
10 CHMOD := chmod
11 GZIP := gzip -nf9
12
13 ifeq ("$(origin CC)", "default")
14         CC := cc
15 endif
16 ifeq ("$(origin V)", "command line")
17         SAY =
18 else
19         SAY = @echo '$(strip $(1))'
20 endif
21
22 PACKAGE := tfortune
23 SLOGAN := fortune cookies with tags
24 AUTHOR := Andre Noll
25 EMAIL := maan@tuebingen.mpg.de
26 COPYRIGHT_YEAR := 2019
27 PACKAGE_HOMEPAGE := http://people.tuebingen.mpg.de/maan/$(PACKAGE)/
28 CLONE_URL := git://git.tuebingen.mpg.de/$(PACKAGE)/
29 GITWEB_URL := http://git.tuebingen.mpg.de/$(PACKAGE).git
30 LICENSE := GNU GPL version 3
31 LICENSE_URL := https://www.gnu.org/licenses/gpl-3.0-standalone.html
32 HOME_URL := http://people.tuebingen.mpg.de/maan/
33
34 define DESCRIPTION1 :=
35         Like fortune(6), tfortune is a Unix command line utility which prints
36         a random epigram. Epigrams are stored as plain text files, but they
37         must be annotated with tags to make full use of the features which
38         tfortune offers over other implementations.
39 endef
40
41 define DESCRIPTION2 :=
42         Tfortune has a built-in matching language for epigrams. User-supplied
43         tag expressions define subsets of admissible epigrams. If a tag
44         expression is given, epigrams are picked from the admissible subset
45         only.
46 endef
47
48 define DESCRIPTION3 :=
49         Besides printing random epigrams, tfortune supports a number of other
50         subcommands which help to maintain epigrams and tag expressions. There
51         are subcommands for listing and for editing the input files, and for
52         printing statistics about epigrams, expressions and tags. A subcommand
53         that enables bash command line completion is also included.
54 endef
55 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
56 GIT_VERSION := $(shell ./version-gen.sh $(PACKAGE) version.c)
57 cc_version := $(shell $(CC) --version | head -n 1)
58 build_date := $(shell date)
59 uname_rs := $(shell uname -rs)
60
61 exe := tfortune
62 man := tfortune.6.gz
63 epigrams := epigrams/en.tfortunes
64 all: $(man) $(exe)
65 man build-indep: $(man)
66 exe build-arch: $(exe)
67
68 deps := txp.bison.d txp.flex.d ast.d tfortune.d util.d txp.flex.d \
69         tfortune.lsg.d version.d linhash.d
70
71 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
72 -include $(deps)
73 -include config.mak
74 endif
75
76 config.h.in: configure.ac
77         $(call SAY, AH $<)
78         autoheader -f
79 config.mak config.h: config.status config.mak.in config.h.in
80         $(call SAY, CS $@)
81         ./config.status -q
82         test -f config.h && touch config.h
83 config.status: configure.sh
84         $(call SAY, CFG)
85         if test -x config.status; then \
86                 ./config.status --recheck; \
87         else \
88                 ./configure.sh --no-create; \
89         fi
90 configure.sh: configure.ac
91         $(call SAY, AC $<)
92         autoconf configure.ac > $@
93         $(CHMOD) 755 $@
94
95 .PRECIOUS: %.flex.c %.bison.c %.bison.h %.lsg.h %.lsg.c %.lsg.h
96
97 # created by version-gen.sh
98 version.c:
99
100 index.html tfortune.suite: %: %.m4
101         $(call SAY, M4 $<)
102         $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
103                 -D "DATADIR=$(datadir)" \
104                 -D "PACKAGE=$(PACKAGE)" \
105                 -D "SLOGAN=$(SLOGAN)" \
106                 -D "EMAIL=$(EMAIL)" \
107                 -D "PACKAGE_URL=$(PACKAGE_URL)" \
108                 -D "PACKAGE_HOMEPAGE=$(PACKAGE_HOMEPAGE)" \
109                 -D "CLONE_URL=$(CLONE_URL)" \
110                 -D "GITWEB_URL=$(GITWEB_URL)" \
111                 -D "HOME_URL=$(HOME_URL)" \
112                 -D "LICENSE=$(LICENSE)" \
113                 -D "LICENSE_URL=$(LICENSE_URL)" \
114                 -D "DESCRIPTION1=$(DESCRIPTION1)" \
115                 -D "DESCRIPTION2=$(DESCRIPTION2)" \
116                 -D "DESCRIPTION3=$(DESCRIPTION3)" $< > $@
117 %.lsg.c: %.suite
118         $(call SAY, LSGC $<)
119         $(LOPSUBGEN) --gen-c < $<
120
121 %.lsg.h: %.suite
122         $(call SAY, LSGH $<)
123         $(LOPSUBGEN) --gen-header < $<
124
125 %.6.gz: %.suite version.c
126         $(call SAY, LSGM $<)
127         $(LOPSUBGEN) --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
128         $(GZIP) ${@:.gz=}
129
130 %.flex.c: %.lex
131         $(call SAY, FLEX $<)
132         $(FLEX) -o $@ $<
133
134 %.bison.c %.bison.h: %.y
135         $(call SAY, BISON $<)
136         $(BISON) --defines=$(notdir $(<:.y=.bison.h)) \
137                 --output=$(notdir $(<:.y=.bison.c)) $<
138
139 TF_CPPFLAGS += -Wunused-macros
140 TF_CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
141 TF_CPPFLAGS += -DPACKAGE='"$(PACKAGE)"'
142 TF_CPPFLAGS += -DAUTHOR='"$(AUTHOR)"'
143 TF_CPPFLAGS += -DEMAIL='"$(EMAIL)"'
144 TF_CPPFLAGS += -DPACKAGE_HOMEPAGE='"$(PACKAGE_HOMEPAGE)"'
145 TF_CPPFLAGS += -DCLONE_URL='"$(CLONE_URL)"'
146 TF_CPPFLAGS += -DGITWEB_URL='"$(GITWEB_URL)"'
147 TF_CPPFLAGS += -DHOME_URL='"$(HOME_URL)"'
148 TF_CPPFLAGS += -DGET_VERSION='$(PACKAGE)_version'
149 TF_CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
150 TF_CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
151 TF_CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
152 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
153 TF_CPPFLAGS += -DLICENSE='"$(LICENSE)"'
154 TF_CPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
155 TF_CPPFLAGS += -DDATADIR='"$(datadir)"'
156 TF_CPPFLAGS += -I/usr/local/include
157
158 TF_CFLAGS += -g
159 TF_CFLAGS += -O2
160 TF_CFLAGS += -Wall
161 TF_CFLAGS += -Wundef -W -Wuninitialized
162 TF_CFLAGS += -Wchar-subscripts
163 TF_CFLAGS += -Werror-implicit-function-declaration
164 TF_CFLAGS += -Wmissing-noreturn
165 TF_CFLAGS += -Wbad-function-cast
166 TF_CFLAGS += -Wredundant-decls
167 TF_CFLAGS += -Wdeclaration-after-statement
168 TF_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
169 #TF_CFLAGS += -fsanitize=address
170
171 %.flex.o: TF_CFLAGS += -Wno-all -Wno-sign-compare -Wno-unused-parameter
172 %.flex.o %.bison.o: TF_CPPFLAGS += -Wno-unused-macros
173
174 %.o: %.c tfortune.lsg.h txp.bison.h
175         $(call SAY, CC $<)
176         $(CC) \
177                 -o $@ -c -MMD -MF $(*F).d \
178                 -MT $@ $(TF_CPPFLAGS) $(CPPFLAGS) $(TF_CFLAGS) $(CFLAGS) $<
179
180 TF_LDFLAGS = -llopsub
181 #TF_LDFLAGS += -fsanitize=address
182
183 tfortune: $(deps:.d=.o)
184         $(call SAY, LD $@)
185         $(CC) $^ -o $@ $(TF_LDFLAGS) $(LDFLAGS)
186
187 .PHONY: all mostlyclean clean distclan maintainer-clean install \
188         install-strip README exe build-arch man build-indep
189
190 mostlyclean:
191         $(RM) $(exe) *.o *.d
192 clean: mostlyclean
193         $(RM) *.lsg.* *.flex.* *.bison.* $(man) *.suite
194 distclean: clean
195         $(RM) config.mak config.status config.log config.h config.h.in \
196                 version.c configure.sh
197         $(RM) -r autom4te.cache
198 maintainer-clean:
199         git clean -dfqx > /dev/null 2>&1
200
201 mandir := $(datarootdir)/man/man6
202 epidir := $(datadir)/tfortunes/epigrams
203 INSTALL ?= install
204 INSTALL_PROGRAM ?= $(INSTALL) -m 755
205 INSTALL_DATA ?= $(INSTALL) -m 644
206 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
207         strip_option := -s
208 endif
209
210 install install-strip: all
211         $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir) $(DESTDIR)$(epidir)
212         $(INSTALL_PROGRAM) $(strip_option) $(exe) $(DESTDIR)$(bindir)
213         $(INSTALL_DATA) $(man) $(DESTDIR)$(mandir)
214         $(INSTALL_DATA) $(epigrams) $(DESTDIR)$(epidir)
215
216 define README :=
217 tfortune - $(SLOGAN)
218
219 $(DESCRIPTION1)
220
221 $(DESCRIPTION2)
222
223 $(DESCRIPTION3)
224
225 Resources
226 ~~~~~~~~~
227 |       web page: $(PACKAGE_HOMEPAGE)
228 |       git clone URL: $(CLONE_URL)
229 |       gitweb: $(GITWEB_URL)
230 |       author's home page: $(HOME_URL)
231 |       Send feedback to: $(AUTHOR) <$(EMAIL)>
232
233 Documentation
234 ~~~~~~~~~~~~~
235 See tfortune.suite. Or build the man page with \"make man\"
236 and run \"man -l $(man)\".
237
238 Dependencies
239 ~~~~~~~~~~~~
240 This package requires m4, autoconf, gnu make, flex, bison, gcc or
241 clang, and lopsub. The configure script checks if all required
242 dependencies are installed and prints a meaningful error message if
243 one of them is missing.
244
245 Building
246 ~~~~~~~~
247 Run \"make\" to build tfortune with the default settings. Run
248 \"./configure -h\" to list configuration options.
249
250 Installation
251 ~~~~~~~~~~~~
252 Run \"sudo make install\" to install to /usr/local. To install to
253 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
254 first.
255 endef
256
257 README:
258         @printf '%s\n' "$(README)"