]> git.tuebingen.mpg.de Git - tfortune.git/blob - Makefile
d9f31971cec099d2cb16721a490cd927b728ec8d
[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 all: $(man) $(exe)
64 man build-indep: $(man)
65 exe build-arch: $(exe)
66
67 deps := txp.bison.d txp.flex.d ast.d tfortune.d util.d txp.flex.d \
68         tfortune.lsg.d version.d linhash.d
69
70 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
71 -include $(deps)
72 -include config.mak
73 endif
74
75 config.h.in: configure.ac
76         $(call SAY, AH $<)
77         autoheader -f
78 config.mak config.h: config.status config.mak.in config.h.in
79         $(call SAY, CS $@)
80         ./config.status -q
81         test -f config.h && touch config.h
82 config.status: configure.sh
83         $(call SAY, CFG)
84         if test -x config.status; then \
85                 ./config.status --recheck; \
86         else \
87                 ./configure.sh --no-create; \
88         fi
89 configure.sh: configure.ac
90         $(call SAY, AC $<)
91         autoconf configure.ac > $@
92         $(CHMOD) 755 $@
93
94 .PRECIOUS: %.flex.c %.bison.c %.bison.h %.lsg.h %.lsg.c %.lsg.h
95
96 # created by version-gen.sh
97 version.c:
98
99 index.html tfortune.suite: %: %.m4
100         $(call SAY, M4 $<)
101         $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
102                 -D "DATADIR=$(datadir)" \
103                 -D "PACKAGE=$(PACKAGE)" \
104                 -D "SLOGAN=$(SLOGAN)" \
105                 -D "EMAIL=$(EMAIL)" \
106                 -D "PACKAGE_URL=$(PACKAGE_URL)" \
107                 -D "PACKAGE_HOMEPAGE=$(PACKAGE_HOMEPAGE)" \
108                 -D "CLONE_URL=$(CLONE_URL)" \
109                 -D "GITWEB_URL=$(GITWEB_URL)" \
110                 -D "HOME_URL=$(HOME_URL)" \
111                 -D "LICENSE=$(LICENSE)" \
112                 -D "LICENSE_URL=$(LICENSE_URL)" \
113                 -D "DESCRIPTION1=$(DESCRIPTION1)" \
114                 -D "DESCRIPTION2=$(DESCRIPTION2)" \
115                 -D "DESCRIPTION3=$(DESCRIPTION3)" $< > $@
116 %.lsg.c: %.suite
117         $(call SAY, LSGC $<)
118         $(LOPSUBGEN) --gen-c < $<
119
120 %.lsg.h: %.suite
121         $(call SAY, LSGH $<)
122         $(LOPSUBGEN) --gen-header < $<
123
124 %.6.gz: %.suite version.c
125         $(call SAY, LSGM $<)
126         $(LOPSUBGEN) --gen-man=${@:.gz=} --version-string $(GIT_VERSION) < $<
127         $(GZIP) ${@:.gz=}
128
129 %.flex.c: %.lex
130         $(call SAY, FLEX $<)
131         $(FLEX) -o $@ $<
132
133 %.bison.c %.bison.h: %.y
134         $(call SAY, BISON $<)
135         $(BISON) --defines=$(notdir $(<:.y=.bison.h)) \
136                 --output=$(notdir $(<:.y=.bison.c)) $<
137
138 TF_CPPFLAGS += -Wunused-macros
139 TF_CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
140 TF_CPPFLAGS += -DPACKAGE='"$(PACKAGE)"'
141 TF_CPPFLAGS += -DAUTHOR='"$(AUTHOR)"'
142 TF_CPPFLAGS += -DEMAIL='"$(EMAIL)"'
143 TF_CPPFLAGS += -DPACKAGE_HOMEPAGE='"$(PACKAGE_HOMEPAGE)"'
144 TF_CPPFLAGS += -DCLONE_URL='"$(CLONE_URL)"'
145 TF_CPPFLAGS += -DGITWEB_URL='"$(GITWEB_URL)"'
146 TF_CPPFLAGS += -DHOME_URL='"$(HOME_URL)"'
147 TF_CPPFLAGS += -DGET_VERSION='$(PACKAGE)_version'
148 TF_CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
149 TF_CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
150 TF_CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
151 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
152 TF_CPPFLAGS += -DLICENSE='"$(LICENSE)"'
153 TF_CPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
154 TF_CPPFLAGS += -DDATADIR='"$(datadir)"'
155 TF_CPPFLAGS += -I/usr/local/include
156
157 TF_CFLAGS += -g
158 TF_CFLAGS += -O2
159 TF_CFLAGS += -Wall
160 TF_CFLAGS += -Wundef -W -Wuninitialized
161 TF_CFLAGS += -Wchar-subscripts
162 TF_CFLAGS += -Werror-implicit-function-declaration
163 TF_CFLAGS += -Wmissing-noreturn
164 TF_CFLAGS += -Wbad-function-cast
165 TF_CFLAGS += -Wredundant-decls
166 TF_CFLAGS += -Wdeclaration-after-statement
167 TF_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
168 #TF_CFLAGS += -fsanitize=address
169
170 %.flex.o: TF_CFLAGS += -Wno-all -Wno-sign-compare -Wno-unused-parameter
171 %.flex.o %.bison.o: TF_CPPFLAGS += -Wno-unused-macros
172
173 %.o: %.c tfortune.lsg.h txp.bison.h
174         $(call SAY, CC $<)
175         $(CC) \
176                 -o $@ -c -MMD -MF $(*F).d \
177                 -MT $@ $(TF_CPPFLAGS) $(CPPFLAGS) $(TF_CFLAGS) $(CFLAGS) $<
178
179 TF_LDFLAGS = -llopsub
180 #TF_LDFLAGS += -fsanitize=address
181
182 tfortune: $(deps:.d=.o)
183         $(call SAY, LD $@)
184         $(CC) $^ -o $@ $(TF_LDFLAGS) $(LDFLAGS)
185
186 .PHONY: all mostlyclean clean distclan maintainer-clean install \
187         install-strip README exe build-arch man build-indep
188
189 mostlyclean:
190         $(RM) $(exe) *.o *.d
191 clean: mostlyclean
192         $(RM) *.lsg.* *.flex.* *.bison.* $(man) *.suite
193 distclean: clean
194         $(RM) config.mak config.status config.log config.h config.h.in \
195                 version.c configure.sh
196         $(RM) -r autom4te.cache
197 maintainer-clean:
198         git clean -dfqx > /dev/null 2>&1
199
200 mandir := $(datarootdir)/man/man6
201 INSTALL ?= install
202 INSTALL_PROGRAM ?= $(INSTALL) -m 755
203 INSTALL_DATA ?= $(INSTALL) -m 644
204 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
205         strip_option := -s
206 endif
207
208 install install-strip: all
209         $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
210         $(INSTALL_PROGRAM) $(strip_option) $(exe) $(DESTDIR)$(bindir)
211         $(INSTALL_DATA) $(man) $(DESTDIR)$(mandir)
212
213 define README :=
214 tfortune - $(SLOGAN)
215
216 $(DESCRIPTION1)
217
218 $(DESCRIPTION2)
219
220 $(DESCRIPTION3)
221
222 Resources
223 ~~~~~~~~~
224 |       web page: $(PACKAGE_HOMEPAGE)
225 |       git clone URL: $(CLONE_URL)
226 |       gitweb: $(GITWEB_URL)
227 |       author's home page: $(HOME_URL)
228 |       Send feedback to: $(AUTHOR) <$(EMAIL)>
229
230 Documentation
231 ~~~~~~~~~~~~~
232 See tfortune.suite. Or build the man page with \"make man\"
233 and run \"man -l $(man)\".
234
235 Dependencies
236 ~~~~~~~~~~~~
237 This package requires m4, autoconf, gnu make, flex, bison, gcc or
238 clang, and lopsub. The configure script checks if all required
239 dependencies are installed and prints a meaningful error message if
240 one of them is missing.
241
242 Building
243 ~~~~~~~~
244 Run \"make\" to build tfortune with the default settings. Run
245 \"./configure -h\" to list configuration options.
246
247 Installation
248 ~~~~~~~~~~~~
249 Run \"sudo make install\" to install to /usr/local. To install to
250 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
251 first.
252 endef
253
254 README:
255         @printf '%s\n' "$(README)"