1 # SPDX-License-Identifier: GPL-3.0-only
12 ifeq ("$(origin CC)", "default")
15 ifeq ("$(origin V)", "command line")
18 SAY = @echo '$(strip $(1))'
22 COPYRIGHT_YEAR := 2019
23 CLONE_URL := git://git.tuebingen.mpg.de/tfortune
24 GITWEB_URL := http://git.tuebingen.mpg.de/tfortune.git
25 LICENSE := GNU GPL version 3
26 LICENSE_URL := https://www.gnu.org/licenses/gpl-3.0-standalone.html
28 define DESCRIPTION1 :=
29 Like fortune(1), tfortune is a Unix command line utility which prints
30 a random epigram. Epigrams are stored as plain text files, but they
31 must be annotated with tags to make full use of the features which
32 tfortune offers over other implementations.
35 define DESCRIPTION2 :=
36 Tfortune has a built-in matching language for epigrams. User-supplied
37 tag expressions define subsets of admissible epigrams. If a tag
38 expression is given, epigrams are picked from the admissible subset
42 define DESCRIPTION3 :=
43 Besides printing random epigrams, tfortune supports a number of other
44 subcommands which help to maintain epigrams and tag expressions. There
45 are subcommands for listing and for editing the input files, and for
46 printing statistics about epigrams, expressions and tags. A subcommand
47 that enables bash command line completion is also included.
49 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
50 GIT_VERSION := $(shell ./version-gen.sh)
51 cc_version := $(shell $(CC) --version | head -n 1)
52 build_date := $(shell date)
53 uname_rs := $(shell uname -rs)
55 all := tfortune tfortune.1
58 deps := txp.bison.d txp.flex.d ast.d tfortune.d util.d txp.flex.d \
59 tfortune.lsg.d version.d linhash.d
61 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
66 config.h.in: configure.ac
69 config.mak config.h: config.status config.mak.in config.h.in
72 test -f config.h && touch config.h
73 config.status: configure.sh
75 if test -x config.status; then \
76 ./config.status --recheck; \
78 ./configure.sh --no-create; \
80 configure.sh: configure.ac
82 autoconf configure.ac > $@
85 .PRECIOUS: %.flex.c %.bison.c %.bison.h %.lsg.h %.lsg.c %.lsg.h
87 # created by version-gen.sh
90 index.html tfortune.suite: %: %.m4
92 $(M4) -D "AUTHOR=$(AUTHOR)" -D "COPYRIGHT_YEAR=$(COPYRIGHT_YEAR)" \
93 -D "PACKAGE_BUGREPORT=$(PACKAGE_BUGREPORT)" \
94 -D "PACKAGE_URL=$(PACKAGE_URL)" \
95 -D "CLONE_URL=$(CLONE_URL)" \
96 -D "GITWEB_URL=$(GITWEB_URL)" \
97 -D "LICENSE=$(LICENSE)" \
98 -D "LICENSE_URL=$(LICENSE_URL)" \
99 -D "DESCRIPTION1=$(DESCRIPTION1)" \
100 -D "DESCRIPTION2=$(DESCRIPTION2)" \
101 -D "DESCRIPTION3=$(DESCRIPTION3)" $< > $@
104 $(LOPSUBGEN) --gen-c < $<
108 $(LOPSUBGEN) --gen-header < $<
110 %.1: %.suite version.c
112 $(LOPSUBGEN) --gen-man=$@ --version-string $(GIT_VERSION) < $<
118 %.bison.c %.bison.h: %.y
119 $(call SAY, BISON $<)
120 $(BISON) --defines=$(notdir $(<:.y=.bison.h)) \
121 --output=$(notdir $(<:.y=.bison.c)) $<
123 TF_CPPFLAGS += -Wunused-macros
124 TF_CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
125 TF_CPPFLAGS += -DAUTHOR='"$(AUTHOR)"'
126 TF_CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
127 TF_CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
128 TF_CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
129 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
130 TF_CPPFLAGS += -DLICENSE='"$(LICENSE)"'
131 TF_CPPFLAGS += -DLICENSE_URL='"$(LICENSE_URL)"'
132 TF_CPPFLAGS += -I/usr/local/include
137 TF_CFLAGS += -Wundef -W -Wuninitialized
138 TF_CFLAGS += -Wchar-subscripts
139 TF_CFLAGS += -Werror-implicit-function-declaration
140 TF_CFLAGS += -Wmissing-noreturn
141 TF_CFLAGS += -Wbad-function-cast
142 TF_CFLAGS += -Wredundant-decls
143 TF_CFLAGS += -Wdeclaration-after-statement
144 TF_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
145 #TF_CFLAGS += -fsanitize=address
147 %.flex.o: TF_CFLAGS += -Wno-all -Wno-sign-compare -Wno-unused-parameter
148 %.flex.o %.bison.o: TF_CPPFLAGS += -Wno-unused-macros
150 %.o: %.c tfortune.lsg.h txp.bison.h
153 -o $@ -c -MMD -MF $(*F).d \
154 -MT $@ $(TF_CPPFLAGS) $(CPPFLAGS) $(TF_CFLAGS) $(CFLAGS) $<
156 TF_LDFLAGS = -llopsub
157 #TF_LDFLAGS += -fsanitize=address
159 tfortune: $(deps:.d=.o)
161 $(CC) $^ -o $@ $(TF_LDFLAGS) $(LDFLAGS)
163 .PHONY: all mostlyclean clean distclan maintainer-clean install \
167 $(RM) tfortune *.o *.d
169 $(RM) *.lsg.* *.flex.* *.bison.* *.1 *.suite
171 $(RM) config.mak config.status config.log config.h config.h.in version.c
172 $(RM) -r autom4te.cache
174 git clean -dfqx > /dev/null 2>&1
176 mandir := $(datarootdir)/man/man1
178 INSTALL_PROGRAM ?= $(INSTALL) -m 755
179 INSTALL_DATA ?= $(INSTALL) -m 644
180 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
184 install install-strip: all
185 $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
186 $(INSTALL_PROGRAM) $(strip_option) tfortune $(DESTDIR)$(bindir)
187 $(INSTALL_DATA) tfortune.1 $(DESTDIR)$(mandir)
190 tfortune - fortune cookies with tags
191 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200 | git clone URL: $(CLONE_URL)
201 | web page: $(PACKAGE_URL)
202 | email: $(AUTHOR) <$(PACKAGE_BUGREPORT)>
206 See tfortune.suite. Or build the man page with \"make tfortune.1\"
207 and run \"man -l tfortune.1\".
211 This package requires m4, autoconf, gnu make, flex, bison, gcc or
212 clang, and lopsub. The configure script checks if all required
213 dependencies are installed and prints a meaningful error message if
214 one of them is missing.
218 Run \"make\" to build tfortune with the default settings. Run
219 \"./configure -h\" to list configuration options.
223 Run \"sudo make install\" to install to /usr/local. To install to
224 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
229 @printf '%s\n' "$(README)"