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