Initial commit.
[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 AUTHOR := Andre Noll
22 COPYRIGHT_YEAR := 2018
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
27
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.
33 endef
34
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
39 only.
40 endef
41
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.
48 endef
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)
54
55 all := tfortune tfortune.1
56 all: $(all)
57
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
60
61 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
62 -include $(deps)
63 include config.mak
64 endif
65
66 config.h.in: configure.ac
67 $(call SAY, AH $<)
68 autoheader -f
69 config.mak config.h: config.status config.mak.in config.h.in
70 $(call SAY, CS $@)
71 ./config.status -q
72 test -f config.h && touch config.h
73 config.status: configure.sh
74 $(call SAY, CFG)
75 if test -x config.status; then \
76 ./config.status --recheck; \
77 else \
78 ./configure.sh --no-create; \
79 fi
80 configure.sh: configure.ac
81 $(call SAY, AC $<)
82 autoconf configure.ac > $@
83 $(CHMOD) 755 $@
84
85 .PRECIOUS: %.flex.c %.bison.c %.bison.h %.lsg.h %.lsg.c %.lsg.h
86
87 # created by version-gen.sh
88 version.c:
89
90 index.html tfortune.suite: %: %.m4
91 $(call SAY, 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)" $< > $@
102 %.lsg.c: %.suite
103 $(call SAY, LSGC $<)
104 $(LOPSUBGEN) --gen-c < $<
105
106 %.lsg.h: %.suite
107 $(call SAY, LSGH $<)
108 $(LOPSUBGEN) --gen-header < $<
109
110 %.1: %.suite version.c
111 $(call SAY, LSGM $<)
112 $(LOPSUBGEN) --gen-man=$@ --version-string $(GIT_VERSION) < $<
113
114 %.flex.c: %.lex
115 $(call SAY, FLEX $<)
116 $(FLEX) -o $@ $<
117
118 %.bison.c %.bison.h: %.y
119 $(call SAY, BISON $<)
120 $(BISON) --defines=$(notdir $(<:.y=.bison.h)) \
121 --output=$(notdir $(<:.y=.bison.c)) $<
122
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
133
134 TF_CFLAGS += -g
135 TF_CFLAGS += -O2
136 TF_CFLAGS += -Wall
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
146
147 %.flex.o: TF_CFLAGS += -Wno-all -Wno-sign-compare -Wno-unused-parameter
148 %.flex.o %.bison.o: TF_CPPFLAGS += -Wno-unused-macros
149
150 %.o: %.c tfortune.lsg.h txp.bison.h
151 $(call SAY, CC $<)
152 $(CC) \
153 -o $@ -c -MMD -MF $(*F).d \
154 -MT $@ $(TF_CPPFLAGS) $(CPPFLAGS) $(TF_CFLAGS) $(CFLAGS) $<
155
156 TF_LDFLAGS = -llopsub
157 #TF_LDFLAGS += -fsanitize=address
158
159 tfortune: $(deps:.d=.o)
160 $(call SAY, LD $@)
161 $(CC) $^ -o $@ $(TF_LDFLAGS) $(LDFLAGS)
162
163 .PHONY: all mostlyclean clean distclan maintainer-clean install \
164 install-strip README
165
166 mostlyclean:
167 $(RM) tfortune *.o *.d
168 clean: mostlyclean
169 $(RM) *.lsg.* *.flex.* *.bison.* *.1 *.suite
170 distclean: clean
171 $(RM) config.mak config.status config.log config.h config.h.in version.c
172 $(RM) -r autom4te.cache
173 maintainer-clean:
174 git clean -dfqx > /dev/null 2>&1
175
176 mandir := $(datarootdir)/man/man1
177 INSTALL ?= install
178 INSTALL_PROGRAM ?= $(INSTALL) -m 755
179 INSTALL_DATA ?= $(INSTALL) -m 644
180 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
181 strip_option := -s
182 endif
183
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)
188
189 define README :=
190 tfortune - fortune cookies with tags
191 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192 $(DESCRIPTION1)
193
194 $(DESCRIPTION2)
195
196 $(DESCRIPTION3)
197
198 Resources
199 ~~~~~~~~~
200 | git clone URL: $(CLONE_URL)
201 | web page: $(PACKAGE_URL)
202 | email: $(AUTHOR) <$(PACKAGE_BUGREPORT)>
203
204 Documentation
205 ~~~~~~~~~~~~~
206 See tfortune.suite. Or build the man page with \"make tfortune.1\"
207 and run \"man -l tfortune.1\".
208
209 Dependencies
210 ~~~~~~~~~~~~
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.
215
216 Building
217 ~~~~~~~~
218 Run \"make\" to build tfortune with the default settings. Run
219 \"./configure -h\" to list configuration options.
220
221 Installation
222 ~~~~~~~~~~~~
223 Run \"sudo make install\" to install to /usr/local. To install to
224 /somewhere/else, run \"./configure --prefix /somewhere/else && make\"
225 first.
226 endef
227
228 README:
229 @printf '%s\n' "$(README)"