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