source: trunk/m4/yat_am_macros.m4 @ 1339

Last change on this file since 1339 was 1339, checked in by Peter Johansson, 12 years ago

use Id expansion from yat repository

  • Property svn:eol-style set to native
File size: 8.2 KB
Line 
1## $Id: yat_am_macros.m4 2425 2011-02-12 23:54:53Z peter $
2
3# serial 1 (yat 0.8)
4
5m4_define([yat_am_macros_copyright], [
6#
7#   Copyright (C) 2011 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#
33AC_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#
45AC_DEFUN([YAT_PROG_MOVE_IF_CHANGE],
46[
47m4_pushdef([yat_OUT], m4_default([$1], [move-if-change]))
48AC_SUBST([MOVE_IF_CHANGE], ['${SHELL} $(top_srcdir)/yat_OUT'])
49AX_AC_PRINT_TO_FILE(yat_OUT, [#!/bin/sh])
50_YAT_AC_APPEND_TO_FILE(yat_OUT,[
51# Like mv $1 $2, but if the files are the same, just delete $1.
52# Status is zero if successful, nonzero otherwise.
53
54usage="[$]0: usage: [$]0 SOURCE DEST"
55
56test [$]# = 2 || { echo $usage >&2 && exit 1; }
57
58if test -r "[$]2" && cmp -s "[$]1" "[$]2"; then
59  rm -f "[$]1"
60else
61  mv -f "[$]1" "[$]2"
62fi
63])
64m4_popdef([yat_OUT])
65]) # YAT_PROG_MOVE_IF_CHANGE
66
67
68# YAT_SVN_REVISION([AM_FILE = svn_revison.am], [REVISION_FILE = .revision])
69#
70# Create a file, AM_FILE, at Autoconf time that should be included in
71# your top Makefile.am. The file creates make rules for creation of a
72# file REVISION_FILE that will contain the current revision of the
73# subversion wc. We use `svnversion' to generate the revision number,
74# so `svnversion' (included in Apache Subversion) must be available
75# when building in a subversion wc. When building in the tarball there
76# is no need to re-generate `.revision' as the file is included in the
77# distribution and the revision number is hopefully constant in a
78# tarball release.
79#
80# You need to declare Automake variable in your Makefile.am
81#   'EXTRA_DIST = '
82#
83AC_DEFUN([YAT_SVN_REVISION],
84[
85  AC_REQUIRE([YAT_HAVE_SVN_WC])
86  AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE])
87  AC_REQUIRE([_YAT_PROG_SVNVERSION])
88  m4_pushdef([YAT_AM_FILE], [m4_default([$1], [svn_revision.am])])
89  m4_pushdef([yat_svn_revision_FILE], m4_default([$2], [.revision]))
90  AS_VAR_IF([have_svn_wc], [yes], [
91             AS_VAR_IF([SVNVERSION], [false], [
92                        AC_MSG_ERROR([could not find svnversion, which is
93                         required when building from a subversion working copy])
94                       ])
95            ])
96dnl create dummy file in 'svn export'
97m4_syscmd([test -d .svn || test -r ]yat_svn_revision_FILE[ || \
98           echo "exported" > ]yat_svn_revision_FILE[])
99dnl write top of am file
100_YAT_AM_TOP(YAT_AM_FILE)
101
102dnl write rules to create .revision
103_YAT_AC_APPEND_TO_FILE(YAT_AM_FILE,
104EXTRA_DIST += yat_svn_revision_FILE
105if HAVE_SVN_WC
106YAT_SVN_REVISION_FORCE:
107$(srcdir)/yat_svn_revision_FILE: YAT_SVN_REVISION_FORCE
108  @$(SVNVERSION) $(srcdir) > [$][@]-t \
109  && $(MOVE_IF_CHANGE) [$][@]-t [$][@]
110endif
111)
112dnl end AX_AC_APPEND_TO_FILE
113m4_popdef([YAT_AM_FILE])
114]) # YAT_SVN_RELEASE
115
116
117# YAT_REVISION_HEADER([AM_FILE = svn_revision_header.am],
118#                     [HEADER = svn_revision.h],
119#                     [DEFINE = SVN_REVISION],
120#                     [REVISION = .revision])
121#
122# Create make rules for creation of a C header file, which defines the
123# current revision as DEFINE. The make rule is generated in file,
124# AM_FILE, that should be included in your Makefile.am. The C header
125# file, HEADER, in two steps. First, at Autoconf time HEADER.in is
126# created. Then at Make time HEADER is created from files HEADER.in
127# and REVISION. The latter file is supposed to contain the current
128# revision and a convenient way to generate this file is to the use
129# macro YAT_SVN_REVISION.  You need to define the following variables
130# in your Makefile.am:
131#   BUILT_SOURCES =
132#   DISTCLEANFILES =
133#   EXTRA_DIST =
134#
135AC_DEFUN([YAT_REVISION_HEADER],
136[
137m4_pushdef([yat_AM_FILE], [m4_default([$1], [svn_revision_header.am])])
138m4_define([yat_HEADER_FILE], [m4_default([$2], [svn_revision.h])])
139m4_pushdef([yat_REVISION_DEFINE], [m4_default([$1], [SVN_REVISION])])
140m4_pushdef([yat_INPUT_FILE], [m4_default([$3], [.revision])])
141
142dnl create svn_revision.h.in
143AX_AC_PRINT_TO_FILE([]yat_HEADER_FILE[.in],[
144/* created by $0 */
145#ifndef ]yat_REVISION_DEFINE[
146#define ]yat_REVISION_DEFINE[ \"@]yat_REVISION_DEFINE[@\"
147#endif
148])
149dnl write make rule for svn_revision.h
150_YAT_AM_TOP(yat_AM_FILE)
151_YAT_AC_APPEND_TO_FILE(yat_AM_FILE,
152EXTRA_DIST += $(srcdir)/]yat_HEADER_FILE[.in
153DISTCLEANFILES += $(builddir)/]yat_HEADER_FILE[
154BUILT_SOURCES += $(builddir)/]yat_HEADER_FILE[
155$(builddir)/]yat_HEADER_FILE[: $(srcdir)/yat_HEADER_FILE.in $(srcdir)/]yat_INPUT_FILE[
156  revision=$$(cat $(srcdir)/]yat_INPUT_FILE[) \
157  && sed "s|@]yat_REVISION_DEFINE[@|$$revision|g" < $(srcdir)/]yat_HEADER_FILE.in[ \
158  > [$][@]-t && mv [$][@]-t [$][@]
159)
160m4_popdef([yat_AM_FILE])
161m4_popdef([yat_REVISION_DEFINE])
162m4_popdef([yat_INPUT_FILE])
163]) # YAT_REVISION_HEADER
164
165
166# YAT_SVN_RELEASE_YEAR([AM_FILE = svn_releas_year.am], [OUTPUT = .release_year])
167#
168# Create file, AM_FILE, with make rules for creation of a file,
169# OUTPUT, that holds the year the package was last modified. The rule
170# is only active when building in subversion wc and the wc is modified
171# compared to the repository. The value of OUTPUT is AC_SUBSTed and
172# AC_DEFINEed and OUTPUT added to CONFIG_STATUS_DEPENDENCIES which
173# means ./configure will be re-run when OUTPUT is updated. Typically
174# it is a good idea to check in OUTPUT in repository because then
175# OUTPUT will get expected value also in 'svn export' case. You need
176# to defined the following variables in Makefile.am:
177#   CONFIG_STATUS_DEPENDENCIES =
178#   EXTRA_DIST =
179#
180AC_DEFUN([YAT_SVN_RELEASE_YEAR],
181[
182AC_REQUIRE([YAT_HAVE_SVN_WC])
183AC_REQUIRE([_YAT_PROG_SVNVERSION])
184AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE])
185# .release_year is generated during make so in order to avoid bootstrap problem
186test -r $srcdir/.release_year || date -u "+%Y" > $srcdir/.release_year
187# propagate RELEASE_YEAR from file .release_year
188RELEASE_YEAR=`cat $srcdir/.release_year`
189AC_SUBST([RELEASE_YEAR])
190AC_DEFINE_UNQUOTED([RELEASE_YEAR], ["$RELEASE_YEAR"],
191                   [Define year package was last modified])
192dnl generate make rule for .release_year
193_YAT_AM_TOP([svn_release_year.am])
194_YAT_AC_APPEND_TO_FILE([svn_release_year.am],
195EXTRA_DIST += .release_year
196CONFIG_STATUS_DEPENDENCIES += $(srcdir)/.release_year
197RELEASE_YEAR_FORCE:
198if HAVE_SVN_WC
199$(srcdir)/.release_year: RELEASE_YEAR_FORCE
200  @if $(SVNVERSION) $(srcdir) | grep 'M' > /dev/null; then \
201     date -u "+%%Y" > [$][@]-t \
202     && $(MOVE_IF_CHANGE) [$][@]-t [$][@]; \
203  fi
204endif
205)
206]) # YAT_SVN_RELEASE_YEAR
207
208
209### Pricae Macros ###
210
211# _YAT_AM_TOP(FILE)
212#
213# Write the header of a Automake snippet with the copyright noticed
214# decalared in top of this file.
215AC_DEFUN([_YAT_AM_TOP],
216[
217AC_PREREQ([2.62])
218AX_AC_PRINT_TO_FILE([$1],dnl
219[# ]$1[ generated automatically by GNU Autoconf
220]yat_am_macros_copyright[
221# stub rule to work around bug in Automake
222\$(top_srcdir)/]$1[:
223
224])
225]) # _YAT_AM_TOP
226
227
228# wrapper around AX_AC_APPEND_TO_FILE to avoid usage of variables
229# defined in AX_FILE_ESCAPES
230AC_DEFUN([_YAT_AC_APPEND_TO_FILE],
231[
232AX_AC_APPEND_TO_FILE([$1],
233m4_bpatsubsts([$2], [\$], [${AX_DOLLAR}],
234                    [\\], [${AX_BS}],
235                    [\"], [${AX_DQ}]))
236])
237
238
239# _YAT_PROG_SVNVERSION
240#
241# Wrapper around AC_PATH_PROG to allow using it as argument to
242# AC_REQUIRE
243AC_DEFUN([_YAT_PROG_SVNVERSION],
244[
245AC_PATH_PROG([SVNVERSION], [svnversion], [false])
246])
Note: See TracBrowser for help on using the repository browser.