]> git.draconx.ca Git - cdecl99.git/blob - Makefile.am
cdecl99: Optimize print_version a bit.
[cdecl99.git] / Makefile.am
1 # Copyright © 2011-2013, 2019-2023 Nick Bowler
2 #
3 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
4 # This is free software: you are free to do what the fuck you want to.
5 # There is NO WARRANTY, to the extent permitted by law.
6
7 ACLOCAL_AMFLAGS = -I m4 -I common/m4
8
9 # For Gnulib
10 MOSTLYCLEANFILES =
11 EXTRA_LTLIBRARIES =
12 EXTRA_PROGRAMS =
13
14 AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \
15         -I$(top_builddir)/lib -I$(top_srcdir)/lib \
16         -I$(DX_BASEDIR)/src -I$(top_builddir)/t \
17         -DBISON_LOCALEDIR=\"$(BISON_LOCALEDIR)\" \
18         -DLOCALEDIR=\"$(localedir)\"
19
20 MAINTAINERCLEANFILES = src/scan.c src/scan.h src/scan.stamp \
21                        src/parse.c src/parse.h src/parse.stamp
22
23 DISTCLEANFILES =
24
25 CLEANFILES = $(EXTRA_LTLIBRARIES) $(EXTRA_LIBRARIES)
26
27 EXTRA_DIST = bootstrap $(DX_BASEDIR)/scripts/fix-gnulib.pl m4/gnulib-cache.m4 \
28              src/types.lst src/parse.y src/parse.stamp src/scan.l \
29              src/scan.stamp COPYING.WTFPL2 README.md INSTALL
30
31 dist_man_MANS = doc/cdecl99.1 doc/libcdecl.3
32
33 noinst_HEADERS = conf_pre.h conf_post.h common/src/help.h common/src/tap.h \
34                  common/src/xtra.h src/cdecl.h src/scan.h src/parse.h \
35                  src/version.h t/declgen.h t/test.h
36
37 noinst_DATA = $(MOFILES)
38
39 nodist_include_HEADERS = src/config/cdecl.h
40 src/config/cdecl.h: config.h src/cdecl.h $(DX_BASEDIR)/scripts/bake-config.awk
41         $(AM_V_at) $(AWK) -f $(DX_BASEDIR)/scripts/bake-config.awk \
42           config.h $(srcdir)/src/cdecl.h >$@-t
43         $(AM_V_at) mv -f $@-t $@
44 EXTRA_DIST += $(DX_BASEDIR)/scripts/bake-config.awk
45 CLEANFILES += src/config/cdecl.h
46
47 # Hack to get Automake to emit a dirstamp rule, and use it in src/config/cdecl.h.
48 src/config/cdecl.h: src/config/$(am__dirstamp)
49 EXTRA_PROGRAMS += src/config/gl-dirstamp
50 src_config_gl_dirstamp_SOURCES =
51
52 shared_gl_objects = $(gnulib_symfiles:.glsym=.lo)
53 static_gl_objects = $(gnulib_extra_objects:.lo=.@OBJEXT@)
54
55 lib_LTLIBRARIES = libcdecl.la
56 libcdecl_la_LDFLAGS = -export-symbols-regex '^cdecl_([[:lower:]]|_gl_)' \
57                       -no-undefined -version-info 1:0:0
58 libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/output.c \
59                       src/explain.c src/declare.c src/error.c src/normalize.c \
60                       src/keywords.c src/cdecl-internal.h src/errmsg.h
61 libcdecl_la_LIBADD = $(shared_gl_objects) $(LTLIBINTL) $(LIBTHREAD)
62 EXTRA_libcdecl_la_DEPENDENCIES = $(shared_gl_objects)
63 $(libcdecl_la_OBJECTS): $(gnulib_headers)
64
65 EXTRA_LIBRARIES = libgnu.a
66 libgnu_a_SOURCES =
67 libgnu_a_SHORTNAME = s
68 libgnu_a_CFLAGS = $(AM_CFLAGS)
69 libgnu_a_LIBADD = $(static_gl_objects)
70 EXTRA_libgnu_a_SOURCES = $(libgnu_la_SOURCES) $(EXTRA_libgnu_la_SOURCES)
71
72 EXTRA_libgnu_a_DEPENDENCIES = $(static_gl_objects)
73 dummy $(static_gl_objects): $(gnulib_headers)
74
75 bin_PROGRAMS = cdecl99
76 cdecl99_SOURCES = common/src/help.c src/commands.c src/cdecl99.h
77 EXTRA_cdecl99_DEPENDENCIES = $(libmain_a_OBJECTS) $(libexec_a_OBJECTS)
78 cdecl99_LDADD = $(EXTRA_cdecl99_DEPENDENCIES) libcdecl.la libgnu.a \
79                 $(LTLIBINTL) $(LTLIBREADLINE)
80 $(cdecl99_OBJECTS): $(gnulib_headers)
81
82 if USE_NLS
83 cdecl99_SOURCES += common/src/copysym.c common/src/copysym.h
84 endif
85
86 EXTRA_LIBRARIES += libexec.a
87 libexec_a_SOURCES = src/execute.c src/commands.h
88 $(libexec_a_OBJECTS): $(gnulib_headers)
89 $(libexec_a_OBJECTS): src/commands.h src/cmdlist.h
90
91 EXTRA_LIBRARIES += libmain.a
92 libmain_a_SOURCES = src/cdecl99.c src/options.h
93 $(libmain_a_OBJECTS): $(gnulib_headers)
94 $(libmain_a_OBJECTS): src/options.h
95
96 check_PROGRAMS = t/crossparse t/normalize t/randomdecl t/rng-test
97 check_LIBRARIES = libtest.a
98 libtest_a_SOURCES = t/testlib.c t/rng.c common/src/help.c common/src/tap.c
99 $(libtest_a_OBJECTS): $(gnulib_headers)
100
101 TEST_LIBS = libtest.a libcdecl.la libgnu.a $(LDEXP_LIBM)
102
103 t_randomdecl_SOURCES = t/randomdecl.c t/declgen.c
104 t_randomdecl_LDADD = $(TEST_LIBS)
105 $(t_randomdecl_OBJECTS): $(gnulib_headers)
106
107 t_crossparse_LDADD = $(TEST_LIBS)
108 $(t_crossparse_OBJECTS): $(gnulib_headers)
109
110 t_normalize_LDADD = src/normalize.lo $(TEST_LIBS)
111 $(t_normalize_OBJECTS): $(gnulib_headers)
112
113 t_rng_test_LDADD = $(TEST_LIBS)
114 $(t_rng_test_OBJECTS): $(gnulib_headers)
115 EXTRA_DIST += t/xos256p.c
116
117 check_PROGRAMS += t/rendertest
118 t_rendertest_LDADD = $(TEST_LIBS)
119 $(t_rendertest_OBJECTS): $(gnulib_headers)
120
121 src/error.lo: src/errmsg.h
122 src/keywords.lo: src/parse.h
123 src/output.lo: src/parse.h src/specstr.h
124 src/parse-decl.lo: src/scan.h src/parse.h src/typemap.h src/errmsg.h
125 src/parse.lo: src/scan.h src/errmsg.h
126 src/scan.lo: src/parse.h src/errmsg.h
127 t/declgen.$(OBJEXT): t/typegen.h
128 t/cdeclerr.$(OBJEXT): src/errmsg.h
129
130 check_PROGRAMS += t/cdeclerr
131 t_cdeclerr_SOURCES = common/src/tap.c t/cdeclerr.c
132 EXTRA_t_cdeclerr_DEPENDENCIES = src/error.lo src/output.lo $(shared_gl_objects)
133 t_cdeclerr_LDADD = $(EXTRA_t_cdeclerr_DEPENDENCIES) $(LIBTHREAD)
134 $(t_cdeclerr_OBJECTS): $(gnulib_headers)
135
136 # Supporting rules for gettext.
137 include $(top_srcdir)/common/snippet/gettext.mk
138
139 EXTRA_DIST += po/$(PACKAGE).pot
140 MAINTAINERCLEANFILES += po/$(PACKAGE).pot
141
142 XGETTEXT_OPTS = -D $(builddir) -D $(srcdir) --from-code=utf-8 \
143         --add-comments=TRANSLATORS: --foreign-user \
144         --package-name=$(PACKAGE) --package-version=$(PACKAGE_VERSION) \
145         --msgid-bugs-address=$(PACKAGE_BUGREPORT) \
146         --keyword=_ --keyword=N_ --keyword=PN_:1c,2
147
148 po/$(PACKAGE).pot: $(SOURCES)
149         $(AM_V_GEN) $(MKDIR_P) po
150         $(AM_V_at) $(XGETTEXT) $(XGETTEXT_OPTS) -o $@.tmp $(SOURCES)
151         $(AM_V_at) mv -f $@.tmp $@
152
153 # These are required to prevent the builtin lex/yacc rules from
154 # superseding ours...
155 src/scan.c src/scan.h: src/scan.stamp
156 src/parse.c src/parse.h: src/parse.stamp
157
158 # The flex/bison rules refrain from updating unchanged headers for the
159 # convenience of developers, but the headers must be distributed with
160 # up-to-date timestamps, otherwise make will try to update them in a fresh
161 # VPATH build.
162 dist-hook: update-headers
163 update-headers: unfuck-distdir
164         touch -c '$(distdir)/src/scan.h'
165         touch -c '$(distdir)/src/parse.h'
166 .PHONY: update-headers
167
168 # When running "make dist" in a VPATH build with a read-only srcdir, Automake
169 # will produce a distribution with all files read-only.  Moreover, the files
170 # are read-only in distdir when the dist hooks are run.  This hook will
171 # manually fix up the permissions.  All dist hooks that modify files in distdir
172 # should list unfuck-distdir as a prerequisite.
173 dist-hook: unfuck-distdir
174 unfuck-distdir:
175         find '$(distdir)' -type f -exec chmod u+w {} +
176 .PHONY: unfuck-distdir
177
178 GITLOG_FLAGS = --format='%s%n%n%b%n'
179
180 dist-hook: generate-changelog
181 generate-changelog: unfuck-distdir
182         -: "$${GIT_DIR=$(top_srcdir)/.git}"; \
183           export GIT_DIR; test -d "$$GIT_DIR" || exit 0; \
184           $(top_srcdir)/gitlog-to-changelog $(GITLOG_FLAGS) \
185             >'$(distdir)/ChangeLog.gen' && \
186           mv -f '$(distdir)/ChangeLog.gen' '$(distdir)/ChangeLog'
187         rm -f '$(distdir)/ChangeLog.gen'
188 .PHONY: generate-changelog
189
190 GENERIC_V   = $(GENERIC_V_@AM_V@)
191 GENERIC_V_  = $(GENERIC_V_@AM_DEFAULT_V@)
192 GENERIC_V_0 = @printf '%2.0s%$(DX_ALIGN_V)s %s\n'
193
194 TEST_DISTRIBUTION = false
195 TEST_DISTRIBUTION_OR_ERROR = if $(TEST_DISTRIBUTION); \
196   then echo 'Proceeding anyway...'; \
197   else echo 'Run $(MAKE) TEST_DISTRIBUTION=true to ignore this failure.'; \
198        false; \
199   fi
200
201 distcheck-hook:
202         $(GENERIC_V) : 'CHECK   ' ChangeLog; \
203           $(AWK) '/^Stub/ { print FILENAME ":" NR ":", $$0; exit 1 }' \
204             $(distdir)/ChangeLog || { \
205               echo 'ERROR: *** Packaged ChangeLog was not properly generated from git log.'; \
206               echo '       *** The source version was used instead, but this appears to'; \
207               echo '       *** be the stub from a git checkout.  The "git" and "perl"'; \
208               echo '       *** programs are required for ChangeLog generation to work.'; \
209               $(TEST_DISTRIBUTION_OR_ERROR); } >&2
210         $(GENERIC_V) : 'CHECK   ' NEWS; \
211           $(AWK) 'NR == 1 && $$NF != "$(PACKAGE_VERSION):" \
212             { print FILENAME ":" NR ":", $$0; exit 1}' \
213             $(distdir)/NEWS || { \
214               echo 'ERROR: *** First line of NEWS should match the package version'; \
215               echo '       *** $(PACKAGE_VERSION), but that does not appear to be the case.'; \
216               echo '       *** Remember to update NEWS before preparing a release.'; \
217               $(TEST_DISTRIBUTION_OR_ERROR); } >&2
218
219 OPTFILES = src/options.opt
220 .opt.h:
221         $(AM_V_GEN) $(AWK) -f $(DX_BASEDIR)/scripts/gen-options.awk $< >$@.tmp
222         $(AM_V_at) mv -f $@.tmp $@
223 $(OPTFILES:.opt=.h): $(DX_BASEDIR)/scripts/gen-options.awk
224 MAINTAINERCLEANFILES += $(OPTFILES:.opt=.h)
225 EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-options.awk $(OPTFILES)
226
227 STRFILES = src/commands.str src/errmsg.str
228 .str.h:
229         $(AM_V_GEN) $(AWK) -f $(DX_BASEDIR)/scripts/gen-strtab.awk $< >$@.tmp
230         $(AM_V_at) mv -f $@.tmp $@
231 $(STRFILES:.str=.h): $(DX_BASEDIR)/scripts/gen-strtab.awk
232 MAINTAINERCLEANFILES += $(STRFILES:.str=.h)
233 EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-strtab.awk $(STRFILES)
234
235 src/cmdlist.h: src/gen-cmdlist.awk src/execute.c
236         $(AM_V_GEN) if test -f '$(builddir)/src/execute.c'; \
237           then f='$(builddir)/src/execute.c'; \
238           else f='$(srcdir)/src/execute.c'; \
239           fi; $(AWK) -f $(srcdir)/src/gen-cmdlist.awk "$$f" >$@.tmp
240         $(AM_V_at) mv -f $@.tmp $@
241 DISTCLEANFILES += src/cmdlist.h
242 EXTRA_DIST += src/gen-cmdlist.awk
243
244 src/specstr.h: src/gen-specstr.awk src/cdecl.h
245         $(AM_V_GEN) $(AWK) -f $(srcdir)/src/gen-specstr.awk \
246                               $(srcdir)/src/cdecl.h >$@.tmp
247         $(AM_V_at) mv -f $@.tmp $@
248 DISTCLEANFILES += src/specstr.h
249 EXTRA_DIST += src/gen-specstr.awk
250
251 src/typemap.h: src/gen-typemap.awk src/types.lst
252         $(AM_V_GEN) $(AWK) -f $(srcdir)/src/gen-typemap.awk \
253                               $(srcdir)/src/types.lst >$@.tmp
254         $(AM_V_at) mv -f $@.tmp $@
255 DISTCLEANFILES += src/typemap.h
256 EXTRA_DIST += src/gen-typemap.awk
257
258 t/typegen.h: t/gen-typegen.awk src/types.lst
259         $(AM_V_GEN) $(AWK) -f $(srcdir)/t/gen-typegen.awk \
260                               $(srcdir)/src/types.lst >$@.tmp
261         $(AM_V_at) mv -f $@.tmp $@
262 DISTCLEANFILES += t/typegen.h
263 EXTRA_DIST += t/gen-typegen.awk
264
265 # Supporting rules for bison/flex.
266
267 BISON_V   = $(BISON_V_@AM_V@)
268 BISON_V_  = $(BISON_V_@AM_DEFAULT_V@)
269 BISON_V_0 = @printf '  %$(DX_ALIGN_V)s %s\n' 'BISON   ' $<;
270
271 FLEX_V   = $(FLEX_V_@AM_V@)
272 FLEX_V_  = $(FLEX_V_@AM_DEFAULT_V@)
273 FLEX_V_0 = @printf '  %$(DX_ALIGN_V)s %s\n' 'FLEX    ' $<;
274
275 DEV_TOOL_ERROR = { \
276   echo "ERROR: *** $$tool is missing on your system."; \
277   echo "       *** Because of this, I cannot compile $$toolsrc, but"; \
278   echo "       *** (perhaps because you modified it) the sources appear out"; \
279   echo "       *** of date.  If $$tool is installed but was not detected by"; \
280   echo "       *** configure, consired setting $$toolvar and re-running configure."; \
281   echo "       *** See config.log for more details."; } >&2; false
282
283 DO_BISON = $(BISON) $(BISON_COMPAT) $(BISONFLAGS)
284
285 .y.c: ;
286 .y.stamp:
287 if !HAVE_BISON
288         $(BISON_V)tool=bison toolvar=BISON toolsrc=$<; $(DEV_TOOL_ERROR)
289 endif
290         $(BISON_V) : >$@.tmp
291         $(AM_V_at) $(DO_BISON) -o $*.c.tmp --defines=$*.h.tmp $<
292         $(AM_V_at) $(AWK) -f $(srcdir)/src/fix-yytname.awk $*.c.tmp >$*.c.t2
293         $(AM_V_at) mv -f $*.c.t2 $*.c
294         $(AM_V_at) cmp $*.h.tmp $*.h >/dev/null 2>&1 || mv -f $*.h.tmp $*.h
295         $(AM_V_at) rm -f $*.c.tmp $*.h.tmp
296         $(AM_V_at) mv -f $@.tmp $@
297 src/parse.stamp: $(srcdir)/src/fix-yytname.awk
298 EXTRA_DIST += src/fix-yytname.awk
299
300 .l.c: ;
301 .l.stamp:
302 if !HAVE_FLEX
303         $(FLEX_V)tool=flex toolvar=FLEX toolsrc=$<; $(DEV_TOOL_ERROR)
304 endif
305         $(AM_V_at) touch $@.tmp
306         $(FLEX_V) $(FLEX) -o $*.c --header-file=$*.h.tmp $(FLEXFLAGS) $<
307         $(AM_V_at) if cmp $*.h.tmp $*.h >/dev/null 2>&1; then \
308                 rm -f $*.h.tmp; \
309         else \
310                 mv -f $*.h.tmp $*.h; \
311         fi
312         $(AM_V_at) mv -f $@.tmp $@
313
314 .stamp.c:
315         @if test -f $@; then :; else \
316                 rm -f $<; \
317                 $(MAKE) $(AM_MAKEFLAGS) $<; \
318         fi
319
320 .stamp.h:
321         @if test -f $@; then :; else \
322                 rm -f $<; \
323                 $(MAKE) $(AM_MAKEFLAGS) $<; \
324         fi
325
326 GPERF     = gperf
327 V_GPERF   = $(V_GPERF_@AM_V@)
328 V_GPERF_  = $(V_GPERF_@AM_DEFAULT_V@)
329 V_GPERF_0 = @printf '  %$(DX_ALIGN_V)s %s\n' 'GPERF   ' $@;
330
331 GPERFFILES = src/execute.gperf src/keywords.gperf
332 .gperf.c:
333         $(V_GPERF) $(GPERF) $< >$@.tmp
334         $(AM_V_at) $(AWK) -f $(srcdir)/src/gperf-wordwrap.awk $@.tmp >$@.t2
335         $(AM_V_at) mv $@.t2 $@
336         $(AM_V_at) rm -f $@.tmp
337 MAINTAINERCLEANFILES += $(GPERFFILES:.gperf=.c)
338 EXTRA_DIST += $(GPERFFILES) src/gperf-wordwrap.awk
339 $(GPERFFILES:.gperf=.c): $(srcdir)/src/gperf-wordwrap.awk
340
341 atlocal: config.status
342         $(AM_V_GEN) $(AWK) </dev/null >$@.tmp \
343           'BEGIN{ for (i = 1; i < ARGC; i++) print ": \"$${" ARGV[i] "}\""; }' \
344           'AWK=$(AWK)' 'EXEEXT=$(EXEEXT)' 'check_PROGRAMS=$(check_PROGRAMS)'
345         $(AM_V_at) mv -f $@.tmp $@
346 check_DATA = atlocal
347 CLEANFILES += atlocal
348
349 # Note: to reliably test linking against the installed library we directly
350 # refer to the just-installed .la file, rather than more typical library flags
351 # (-Lfoo -lfoo).  Otherwise libtool can pick up libcdecl.la from the current
352 # working directory which defeats the point of an install check.
353 EXTRA_PROGRAMS += t/installcheck
354 t_installcheck_CPPFLAGS = -I$(DESTDIR)$(includedir)
355 t_installcheck_LDADD = $(DESTDIR)$(libdir)/libcdecl.la
356 t_installcheck_CFLAGS =
357 t_installcheck_SHORTNAME = x
358
359 installcheck-local:
360         rm -f t/installcheck$(EXEEXT) $(t_installcheck_OBJECTS)
361         $(MAKE) $(AM_MAKEFLAGS) t/installcheck$(EXEEXT)
362         t/installcheck$(EXEEXT) | diff - $(srcdir)/t/installcheck.exp
363 .PHONY: installcheck-local
364 EXTRA_DIST += t/installcheck.c t/installcheck.exp
365 CLEANFILES += t/installcheck$(EXEEXT)
366
367 include $(top_srcdir)/lib/gnulib.mk
368 include $(top_srcdir)/common/snippet/glconfig.mk
369 include $(top_srcdir)/common/snippet/autotest.mk