1 | ## $Id: yat_am_macros.m4 4323 2023-02-22 23:08:13Z peter $ |
---|
2 | |
---|
3 | # serial 16 (yat 0.21) |
---|
4 | |
---|
5 | m4_define([yat_am_macros_copyright], [ |
---|
6 | # |
---|
7 | # Copyright (C) 2011, 2012, 2019 Peter Johansson |
---|
8 | # |
---|
9 | # This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
10 | # |
---|
11 | # The yat library is free software; you can redistribute it and/or |
---|
12 | # modify it under the terms of the GNU General Public License as |
---|
13 | # published by the Free Software Foundation; either version 3 of the |
---|
14 | # License, or (at your option) any later version. |
---|
15 | # |
---|
16 | # The yat library is distributed in the hope that it will be useful, |
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | # General Public License for more details. |
---|
20 | # |
---|
21 | # You should have received a copy of the GNU General Public License |
---|
22 | # along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | # |
---|
24 | ]) |
---|
25 | |
---|
26 | # YAT_HAVE_SVN_WC |
---|
27 | # |
---|
28 | # Test if we are building from a subversion repository and sets shell |
---|
29 | # variable `have_svn_wc' to `yes' or `no'. Macro calls |
---|
30 | # AC_SUBST([have_svn_wc]) and defines an Automake Conditional |
---|
31 | # HAVE_SVN_WC. |
---|
32 | # |
---|
33 | AC_DEFUN([YAT_HAVE_SVN_WC], |
---|
34 | [ |
---|
35 | AC_MSG_CHECKING([if building from subversion wc]) |
---|
36 | AS_IF([test -d $srcdir/.svn], [have_svn_wc=yes], [have_svn_wc=no]) |
---|
37 | AM_CONDITIONAL([HAVE_SVN_WC], [test "x$have_svn_wc" = "xyes"]) |
---|
38 | AC_SUBST([have_svn_wc]) |
---|
39 | AC_MSG_RESULT([$have_svn_wc]) |
---|
40 | ]) # YAT_HAVE_SVN_WC |
---|
41 | |
---|
42 | |
---|
43 | # YAT_PROG_MOVE_IF_CHANGE |
---|
44 | # |
---|
45 | # Create shell script move-if-change at autoconf time and AC_SUBST |
---|
46 | # MOVE_IF_CHANGE |
---|
47 | AC_DEFUN([YAT_PROG_MOVE_IF_CHANGE], |
---|
48 | [ |
---|
49 | m4_define([yat_MOVE_IF_CHANGE], m4_default([$1], [move-if-change])) |
---|
50 | AC_SUBST([MOVE_IF_CHANGE], ['${SHELL} $(top_srcdir)/yat_MOVE_IF_CHANGE']) |
---|
51 | AX_AC_PRINT_TO_FILE(yat_MOVE_IF_CHANGE, [#!/bin/sh]) |
---|
52 | _YAT_AC_APPEND_TO_FILE(yat_MOVE_IF_CHANGE,[ |
---|
53 | # Like mv ]$[1 ]$[2, but if the files are the same, just delete ]$[1. |
---|
54 | # Status is zero if successful, nonzero otherwise. |
---|
55 | |
---|
56 | usage="[$]0: usage: [$]0 SOURCE DEST" |
---|
57 | |
---|
58 | test [$]# = 2 || { echo $usage >&2 && exit 1; } |
---|
59 | |
---|
60 | if test -r "[$]2" && cmp -s "[$]1" "[$]2"; then |
---|
61 | rm -f "[$]1" |
---|
62 | else |
---|
63 | mv -f "[$]1" "[$]2" |
---|
64 | fi |
---|
65 | ]) |
---|
66 | ]) # YAT_PROG_MOVE_IF_CHANGE |
---|
67 | |
---|
68 | |
---|
69 | # YAT_SVN_REVISION([AM_FILE = svn_revison.am], [REVISION_FILE = .revision]) |
---|
70 | # |
---|
71 | # Create a file, AM_FILE, at Autoconf time that should be included in |
---|
72 | # your top Makefile.am. The file creates make rules for creation of a |
---|
73 | # file REVISION_FILE that will contain the current revision of the |
---|
74 | # subversion wc. We use `svnversion' to generate the revision number, |
---|
75 | # so `svnversion' (included in Apache Subversion) must be available |
---|
76 | # when building in a subversion wc. When building in the tarball there |
---|
77 | # is no need to re-generate `.revision' as the file is included in the |
---|
78 | # distribution and the revision number is hopefully constant in a |
---|
79 | # tarball release. |
---|
80 | # |
---|
81 | # You need to declare Automake variable in your Makefile.am |
---|
82 | # 'EXTRA_DIST = ' |
---|
83 | # |
---|
84 | AC_DEFUN([YAT_SVN_REVISION], |
---|
85 | [ |
---|
86 | AC_REQUIRE([YAT_HAVE_SVN_WC]) |
---|
87 | AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE]) |
---|
88 | AC_REQUIRE([_YAT_PROG_SVNVERSION]) |
---|
89 | m4_pushdef([YAT_AM_FILE], [m4_default([$1], [svn_revision.am])]) |
---|
90 | m4_pushdef([yat_svn_revision_FILE], m4_default([$2], [.revision])) |
---|
91 | AS_VAR_IF([have_svn_wc], [yes], [ |
---|
92 | AS_VAR_IF([SVNVERSION], [false], [ |
---|
93 | AC_MSG_ERROR([could not find svnversion, which is |
---|
94 | required when building from a subversion working copy]) |
---|
95 | ]) |
---|
96 | ]) |
---|
97 | dnl create dummy file in 'svn export' |
---|
98 | m4_syscmd([test -d .svn || test -r ]yat_svn_revision_FILE[ || \ |
---|
99 | echo "exported" > ]yat_svn_revision_FILE[]) |
---|
100 | dnl write top of am file |
---|
101 | _YAT_AM_TOP(YAT_AM_FILE) |
---|
102 | |
---|
103 | dnl write rules to create .revision |
---|
104 | _YAT_AC_APPEND_TO_FILE(YAT_AM_FILE, |
---|
105 | EXTRA_DIST += $(srcdir)/yat_svn_revision_FILE |
---|
106 | if HAVE_SVN_WC |
---|
107 | YAT_SVN_REVISION_FORCE: |
---|
108 | $(srcdir)/yat_svn_revision_FILE: YAT_SVN_REVISION_FORCE |
---|
109 | $(AM_V_at)$(SVNVERSION) $(srcdir) > [$][@]-t \ |
---|
110 | && $(MOVE_IF_CHANGE) [$][@]-t [$][@] |
---|
111 | endif |
---|
112 | ) |
---|
113 | dnl end AX_AC_APPEND_TO_FILE |
---|
114 | m4_popdef([YAT_AM_FILE]) |
---|
115 | ]) # YAT_SVN_REVISION |
---|
116 | |
---|
117 | |
---|
118 | # YAT_REVISION_HEADER([AM_FILE = svn_revision_header.am], |
---|
119 | # [HEADER = svn_revision.h], |
---|
120 | # [DEFINE = SVN_REVISION], |
---|
121 | # [REVISION = .revision]) |
---|
122 | # |
---|
123 | # Create make rules for creation of a C header file, which defines the |
---|
124 | # current revision as DEFINE. The make rule is generated in file, |
---|
125 | # AM_FILE, that should be included in your Makefile.am. The C header |
---|
126 | # file, HEADER, in two steps. First, at Autoconf time HEADER.in is |
---|
127 | # created. Then at Make time HEADER is created from files HEADER.in |
---|
128 | # and REVISION. The latter file is supposed to contain the current |
---|
129 | # revision and a convenient way to generate this file is to the use |
---|
130 | # macro YAT_SVN_REVISION. You need to declare the following variables |
---|
131 | # in your Makefile.am: |
---|
132 | # BUILT_SOURCES = |
---|
133 | # DISTCLEANFILES = |
---|
134 | # EXTRA_DIST = |
---|
135 | # |
---|
136 | AC_DEFUN([YAT_REVISION_HEADER], |
---|
137 | [ |
---|
138 | AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE]) |
---|
139 | m4_pushdef([yat_AM_FILE], [m4_default([$1], [svn_revision_header.am])]) |
---|
140 | m4_define([yat_HEADER_FILE], [m4_default([$2], [svn_revision.h])]) |
---|
141 | m4_pushdef([yat_REVISION_DEFINE], [m4_default([$3], [SVN_REVISION])]) |
---|
142 | m4_pushdef([yat_INPUT_FILE], [m4_default([$4], [.revision])]) |
---|
143 | |
---|
144 | dnl create svn_revision.h.in |
---|
145 | AX_AC_PRINT_TO_FILE([]yat_HEADER_FILE[.in-t],[ |
---|
146 | /* created by $0 */ |
---|
147 | #ifndef ]yat_REVISION_DEFINE[ |
---|
148 | #define ]yat_REVISION_DEFINE[ \"@]yat_REVISION_DEFINE[@\" |
---|
149 | #endif |
---|
150 | ]) |
---|
151 | m4_syscmd([sh ]yat_MOVE_IF_CHANGE[ ]yat_HEADER_FILE[.in-t ]yat_HEADER_FILE[.in]) |
---|
152 | dnl write make rule for svn_revision.h |
---|
153 | _YAT_AM_TOP(yat_AM_FILE) |
---|
154 | _YAT_AC_APPEND_TO_FILE(yat_AM_FILE, |
---|
155 | EXTRA_DIST += $(srcdir)/]yat_HEADER_FILE[.in |
---|
156 | DISTCLEANFILES += $(builddir)/]yat_HEADER_FILE[ |
---|
157 | BUILT_SOURCES += $(builddir)/]yat_HEADER_FILE[ |
---|
158 | $(builddir)/]yat_HEADER_FILE[: $(srcdir)/yat_HEADER_FILE.in $(srcdir)/]yat_INPUT_FILE[ |
---|
159 | $(AM_V_at)revision=$$(cat $(srcdir)/]yat_INPUT_FILE[) \ |
---|
160 | && sed "s|@]yat_REVISION_DEFINE[@|$$revision|g" < $(srcdir)/]yat_HEADER_FILE.in[ \ |
---|
161 | > [$][@]-t && mv [$][@]-t [$][@] |
---|
162 | ) |
---|
163 | m4_popdef([yat_AM_FILE]) |
---|
164 | m4_popdef([yat_REVISION_DEFINE]) |
---|
165 | m4_popdef([yat_INPUT_FILE]) |
---|
166 | ]) # YAT_REVISION_HEADER |
---|
167 | |
---|
168 | |
---|
169 | # YAT_SVN_RELEASE_YEAR([AM_FILE = svn_release_year.am],[OUTPUT = .release_year]) |
---|
170 | # |
---|
171 | # Create file, AM_FILE, with make rules for creation of a file, |
---|
172 | # OUTPUT, that holds the year the package was last modified. The rule |
---|
173 | # is only active when building in subversion wc and the wc is modified |
---|
174 | # compared to the repository. The value of OUTPUT is AC_SUBSTed and |
---|
175 | # AC_DEFINEed and OUTPUT added to CONFIG_STATUS_DEPENDENCIES which |
---|
176 | # means ./configure will be re-run when OUTPUT is updated. Typically |
---|
177 | # it is a good idea to check in OUTPUT in repository because then |
---|
178 | # OUTPUT will get expected value also in 'svn export' case. You need |
---|
179 | # to declare the following variables in Makefile.am: |
---|
180 | # CONFIG_STATUS_DEPENDENCIES = |
---|
181 | # EXTRA_DIST = |
---|
182 | # |
---|
183 | AC_DEFUN([YAT_SVN_RELEASE_YEAR], |
---|
184 | [ |
---|
185 | AC_REQUIRE([YAT_HAVE_SVN_WC]) |
---|
186 | AC_REQUIRE([_YAT_PROG_SVNVERSION]) |
---|
187 | AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE]) |
---|
188 | m4_pushdef([YAT_am_file], [m4_default([$1], [svn_release_year.am])]) |
---|
189 | m4_pushdef([YAT_release_year], [m4_default([$2], [.release_year])]) |
---|
190 | # .release_year is generated during make so in order to avoid bootstrap problem |
---|
191 | test -r $srcdir/YAT_release_year || date -u "+%Y" > $srcdir/YAT_release_year |
---|
192 | # propagate RELEASE_YEAR from file .release_year |
---|
193 | RELEASE_YEAR=`cat "$srcdir/YAT_release_year"` |
---|
194 | AC_SUBST([RELEASE_YEAR]) |
---|
195 | AC_DEFINE_UNQUOTED([RELEASE_YEAR], ["$RELEASE_YEAR"], |
---|
196 | [Define year package was last modified]) |
---|
197 | dnl generate make rule for .release_year |
---|
198 | _YAT_AM_TOP(YAT_am_file) |
---|
199 | _YAT_AC_APPEND_TO_FILE(YAT_am_file, |
---|
200 | EXTRA_DIST += $(srcdir)/YAT_release_year |
---|
201 | CONFIG_STATUS_DEPENDENCIES += $(srcdir)/YAT_release_year |
---|
202 | RELEASE_YEAR_FORCE: |
---|
203 | if HAVE_SVN_WC |
---|
204 | $(srcdir)/YAT_release_year: RELEASE_YEAR_FORCE |
---|
205 | $(AM_V_at)if $(SVNVERSION) $(srcdir) | grep 'M' > /dev/null; then \ |
---|
206 | date -u "+%Y" > [$][@]-t \ |
---|
207 | && $(MOVE_IF_CHANGE) [$][@]-t [$][@]; \ |
---|
208 | fi |
---|
209 | endif |
---|
210 | ) |
---|
211 | m4_popdef([YAT_am_file]) |
---|
212 | m4_popdef([YAT_release_year]) |
---|
213 | ]) # YAT_SVN_RELEASE_YEAR |
---|
214 | |
---|
215 | |
---|
216 | # YAT_SVN_TIMESTAMP([AM_FILE = svn_timestamp.am]) |
---|
217 | # |
---|
218 | # Create a file, AM_FILE, at Autoconf time that should be included in |
---|
219 | # your top Makefile.am. The file contains rules for creation of a file |
---|
220 | # '.timestamp' and associated '.svn_timestamp', |
---|
221 | # '$(srcdir)/.svn_export_timestamp' and '$(srcdir)/.tarball_timestamp' |
---|
222 | # depending on whether building from subversion working-copy, |
---|
223 | # subversion export, or a tarball, respectively. The macro inherits |
---|
224 | # the same requirements from YAT_SVN_REVISION and in addition the |
---|
225 | # Makefile.am needs to define Automake variable |
---|
226 | # yat_am_dist_hooks = |
---|
227 | # and let the dist hook depend on this variable |
---|
228 | # dist-hook: $(yat_am_dist_hooks) |
---|
229 | AC_DEFUN([YAT_SVN_TIMESTAMP], |
---|
230 | [ |
---|
231 | AC_REQUIRE([YAT_HAVE_SVN_WC]) |
---|
232 | AC_REQUIRE([YAT_SVN_REVISION]) |
---|
233 | AC_REQUIRE([_YAT_PROG_SVN]) |
---|
234 | m4_pushdef([YAT_AM_FILE], [m4_default([$1], [svn_timestamp.am])]) |
---|
235 | |
---|
236 | dnl create dummy file in 'svn export' |
---|
237 | m4_syscmd([test -d .svn || test -r .tarball_timestamp \ |
---|
238 | || test -e .svn_export_timestamp \ |
---|
239 | || date +%s > .svn_export_timestamp]) |
---|
240 | |
---|
241 | AC_MSG_CHECKING([if .tarball_timestamp exists]) |
---|
242 | have_tarball_timestamp=no |
---|
243 | test -e $srcdir/.tarball_timestamp && have_tarball_timestamp=yes |
---|
244 | AC_MSG_RESULT([$have_tarball_timestamp]) |
---|
245 | |
---|
246 | AC_MSG_CHECKING([if .svn_export_timestamp exists]) |
---|
247 | have_svn_export_timestamp=no |
---|
248 | test -e $srcdir/.svn_export_timestamp && have_svn_export_timestamp=yes |
---|
249 | AC_MSG_RESULT([$have_svn_export_timestamp]) |
---|
250 | |
---|
251 | AS_IF([test x"$have_svn_wc" = x"yes"], [ |
---|
252 | yat_timestamp_source=.svn_timestamp |
---|
253 | ], [test x"$have_svn_export_timestamp" = x"yes"], [ |
---|
254 | yat_timestamp_source='$(srcdir)/.svn_export_timestamp' |
---|
255 | ], [test x"$have_tarball_timestamp" = x"yes"], [ |
---|
256 | yat_timestamp_source='$(srcdir)/.tarball_timestamp' |
---|
257 | ], [ |
---|
258 | AC_MSG_ERROR([cannot find required file; |
---|
259 | both .tarball_timestamp and .svn_export_timestamp are missing]) |
---|
260 | ]) |
---|
261 | AC_SUBST([yat_timestamp_source]) |
---|
262 | |
---|
263 | dnl write rules to create .timestamp |
---|
264 | _YAT_AM_TOP(YAT_AM_FILE) |
---|
265 | |
---|
266 | _YAT_AC_APPEND_TO_FILE(YAT_AM_FILE, |
---|
267 | ## The .timestamp reflects the last change to the svn repo, i.e., it |
---|
268 | ## changes via 'svn update' or 'svn commit', which is a subset of when |
---|
269 | ## .revision changes and only need to update the .timestamp when |
---|
270 | ## .revision has changed. |
---|
271 | if HAVE_SVN_WC |
---|
272 | .svn_timestamp: $(srcdir)/.revision |
---|
273 | $(AM_V_at)date=$($(SVN) info $(scrdir) --show-item last-changed-date --no-newline); \ |
---|
274 | date +%s --date="$$date" > [$][@] |
---|
275 | DISTCLEANFILES += .svn_timestamp |
---|
276 | endif |
---|
277 | |
---|
278 | .timestamp: $(yat_timestamp_source) |
---|
279 | $(AM_V_at)cp $(yat_timestamp_source) [$][@] |
---|
280 | |
---|
281 | CLEANFILES += .timestamp |
---|
282 | |
---|
283 | yat_am_dist_hooks += yat_dist_tarball_timestamp |
---|
284 | |
---|
285 | if HAVE_SVN_WC |
---|
286 | yat_dist_tarball_timestamp: .timestamp |
---|
287 | $(AM_V_at)cp .timestamp $(distdir)/.tarball_timestamp |
---|
288 | else |
---|
289 | # in case some does a dist from a non-wc, use 'now' as timestamp |
---|
290 | # (rather than timestamp file in builddir, which reflects the date of |
---|
291 | # the previous release) |
---|
292 | yat_dist_tarball_timestamp: |
---|
293 | date +%s > $(distdir)/.tarball_timestamp |
---|
294 | endif |
---|
295 | |
---|
296 | ) dnl end of writing automake segment |
---|
297 | |
---|
298 | |
---|
299 | ]) # YAT_SVN_TIMESTAMP |
---|
300 | |
---|
301 | |
---|
302 | ### Private Macros ### |
---|
303 | |
---|
304 | # _YAT_AM_TOP(FILE) |
---|
305 | # |
---|
306 | # Write the header of a Automake snippet with the copyright noticed |
---|
307 | # decalared in top of this file. |
---|
308 | AC_DEFUN([_YAT_AM_TOP], |
---|
309 | [ |
---|
310 | AC_PREREQ([2.62]) |
---|
311 | AX_AC_PRINT_TO_FILE([$1],dnl |
---|
312 | [# ]$1[ generated automatically by GNU Autoconf |
---|
313 | ]yat_am_macros_copyright[ |
---|
314 | # stub rule to work around bug in Automake 1.11 |
---|
315 | \$(top_srcdir)/]$1[: |
---|
316 | |
---|
317 | ]) |
---|
318 | ]) # _YAT_AM_TOP |
---|
319 | |
---|
320 | |
---|
321 | # wrapper around AX_AC_APPEND_TO_FILE to avoid usage of variables |
---|
322 | # defined in AX_FILE_ESCAPES |
---|
323 | AC_DEFUN([_YAT_AC_APPEND_TO_FILE], |
---|
324 | [ |
---|
325 | AX_AC_APPEND_TO_FILE([$1], |
---|
326 | m4_bpatsubsts([$2], [\$], [${AX_DOLLAR}], |
---|
327 | [\\], [\\\\], |
---|
328 | [\"], [${AX_DQ}])) |
---|
329 | |
---|
330 | ]) |
---|
331 | |
---|
332 | |
---|
333 | # _YAT_PROG_SVN |
---|
334 | # |
---|
335 | # Wrapper around AC_CHECK_PROG to allow using it as argument to |
---|
336 | # AC_REQUIRE |
---|
337 | AC_DEFUN([_YAT_PROG_SVN], |
---|
338 | [ |
---|
339 | AC_CHECK_PROG([SVN], [svn], [svn], [false]) |
---|
340 | ]) |
---|
341 | |
---|
342 | |
---|
343 | # _YAT_PROG_SVNVERSION |
---|
344 | # |
---|
345 | # Wrapper around AC_CHECK_PROG to allow using it as argument to |
---|
346 | # AC_REQUIRE |
---|
347 | AC_DEFUN([_YAT_PROG_SVNVERSION], |
---|
348 | [ |
---|
349 | AC_CHECK_PROG([SVNVERSION], [svnversion], [svnversion], [false]) |
---|
350 | ]) |
---|