1 # SPDX-License-Identifier: GPL-2.0
11 ifeq ("$(origin CC)", "default")
14 ifeq ("$(origin V)", "command line")
17 SAY = @echo '$(strip $(1))'
20 COPYRIGHT_YEAR := 2018
21 LOGLEVELS := LL_DEBUG,LL_INFO,LL_NOTICE,LL_WARNING,LL_ERROR,LL_CRIT,LL_EMERG
22 GIT_VERSION := $(shell ./version-gen.sh)
23 cc_version := $(shell $(CC) --version | head -n 1)
24 build_date := $(shell date)
25 uname_rs := $(shell uname -rs)
27 all := tfortune tfortune.1
30 deps := txp.bison.d txp.flex.d ast.d tfortune.d util.d txp.flex.d \
31 tfortune.lsg.d version.d
33 ifeq ($(findstring clean, $(MAKECMDGOALS)),)
38 .PRECIOUS: %.flex.c %.bison.c %.bison.h %.lsg.h %.lsg.c %.lsg.h
40 # created by version-gen.sh
45 $(LOPSUBGEN) --gen-c < $<
49 $(LOPSUBGEN) --gen-header < $<
53 $(LOPSUBGEN) --gen-man=$@ --version-string $(GIT_VERSION) < $<
59 %.bison.c %.bison.h: %.y
61 $(BISON) --defines=$(notdir $(<:.y=.bison.h)) \
62 --output=$(notdir $(<:.y=.bison.c)) $<
64 TF_CPPFLAGS += -DCOPYRIGHT_YEAR='"$(COPYRIGHT_YEAR)"'
65 TF_CPPFLAGS += -DLOGLEVELS='$(LOGLEVELS)'
66 TF_CPPFLAGS += -DBUILD_DATE='"$(build_date)"'
67 TF_CPPFLAGS += -DCC_VERSION='"$(cc_version)"'
68 TF_CPPFLAGS += -DUNAME_RS='"$(uname_rs)"'
69 TF_CPPFLAGS += -I/usr/local/include
74 TF_CFLAGS += -Wundef -W -Wuninitialized
75 TF_CFLAGS += -Wchar-subscripts
76 TF_CFLAGS += -Werror-implicit-function-declaration
77 TF_CFLAGS += -Wmissing-noreturn
78 TF_CFLAGS += -Wbad-function-cast
79 TF_CFLAGS += -Wredundant-decls
80 TF_CFLAGS += -Wdeclaration-after-statement
81 TF_CFLAGS += -Wformat -Wformat-security -Wmissing-format-attribute
83 %.flex.o: TF_CFLAGS += -Wno-all
85 %.o: %.c tfortune.lsg.h txp.bison.h
88 -o $@ -c -MMD -MF $(*F).d \
89 -MT $@ $(TF_CPPFLAGS) $(CPPFLAGS) $(TF_CFLAGS) $(CFLAGS) $<
92 tfortune: $(deps:.d=.o)
94 $(CC) $^ -o $@ $(TF_LDFLAGS) $(LDFLAGS)
96 .PHONY: all mostlyclean clean install install-strip
99 $(RM) tfortune *.o *.d
101 $(RM) *.lsg.* *.flex.* *.bison.* *.1 version.c
103 $(RM) config.mak config.status config.log config.h configure config.h.in
104 $(RM) -r autom4te.cache
105 maintainer-clean: distclean
106 git clean -dfqx > /dev/null 2>&1
108 mandir := $(datarootdir)/man/man1
110 INSTALL_PROGRAM ?= $(INSTALL) -m 755
111 INSTALL_DATA ?= $(INSTALL) -m 644
112 ifneq ($(findstring strip, $(MAKECMDGOALS)),)
116 install install-strip: all
117 $(MKDIR_P) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)
118 $(INSTALL_PROGRAM) $(strip_option) tfortune $(DESTDIR)$(bindir)
119 $(INSTALL_DATA) tfortune.1 $(DESTDIR)$(mandir)