source: trunk/m4/yat_am_macros.m4 @ 1476

Last change on this file since 1476 was 1463, checked in by Peter Johansson, 9 years ago

set svncopyright:ignore property

  • Property svn:eol-style set to native
File size: 8.6 KB
Line 
1## $Id: yat_am_macros.m4 2680 2012-01-09 02:28:59Z peter $
2
3# serial 9 (yat 0.9)
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#
45# Create shell script move-if-change at autoconf time and AC_SUBST
46# MOVE_IF_CHANGE
47AC_DEFUN([YAT_PROG_MOVE_IF_CHANGE],
48[
49m4_define([yat_MOVE_IF_CHANGE], m4_default([$1], [move-if-change]))
50AC_SUBST([MOVE_IF_CHANGE], ['${SHELL} $(top_srcdir)/yat_MOVE_IF_CHANGE'])
51AX_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
56usage="[$]0: usage: [$]0 SOURCE DEST"
57
58test [$]# = 2 || { echo $usage >&2 && exit 1; }
59
60if test -r "[$]2" && cmp -s "[$]1" "[$]2"; then
61  rm -f "[$]1"
62else
63  mv -f "[$]1" "[$]2"
64fi
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#
84AC_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            ])
97dnl create dummy file in 'svn export'
98m4_syscmd([test -d .svn || test -r ]yat_svn_revision_FILE[ || \
99           echo "exported" > ]yat_svn_revision_FILE[])
100dnl write top of am file
101_YAT_AM_TOP(YAT_AM_FILE)
102
103dnl write rules to create .revision
104_YAT_AC_APPEND_TO_FILE(YAT_AM_FILE,
105EXTRA_DIST += $(srcdir)/yat_svn_revision_FILE
106if HAVE_SVN_WC
107YAT_SVN_REVISION_FORCE:
108$(srcdir)/yat_svn_revision_FILE: YAT_SVN_REVISION_FORCE
109  @$(SVNVERSION) $(srcdir) > [$][@]-t \
110  && $(MOVE_IF_CHANGE) [$][@]-t [$][@]
111endif
112)
113dnl end AX_AC_APPEND_TO_FILE
114m4_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#
136AC_DEFUN([YAT_REVISION_HEADER],
137[
138AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE])
139m4_pushdef([yat_AM_FILE], [m4_default([$1], [svn_revision_header.am])])
140m4_define([yat_HEADER_FILE], [m4_default([$2], [svn_revision.h])])
141m4_pushdef([yat_REVISION_DEFINE], [m4_default([$3], [SVN_REVISION])])
142m4_pushdef([yat_INPUT_FILE], [m4_default([$4], [.revision])])
143
144dnl create svn_revision.h.in
145AX_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])
151m4_syscmd([sh ]yat_MOVE_IF_CHANGE[ ]yat_HEADER_FILE[.in-t ]yat_HEADER_FILE[.in])
152dnl write make rule for svn_revision.h
153_YAT_AM_TOP(yat_AM_FILE)
154_YAT_AC_APPEND_TO_FILE(yat_AM_FILE,
155EXTRA_DIST += $(srcdir)/]yat_HEADER_FILE[.in
156DISTCLEANFILES += $(builddir)/]yat_HEADER_FILE[
157BUILT_SOURCES += $(builddir)/]yat_HEADER_FILE[
158$(builddir)/]yat_HEADER_FILE[: $(srcdir)/yat_HEADER_FILE.in $(srcdir)/]yat_INPUT_FILE[
159  revision=$$(cat $(srcdir)/]yat_INPUT_FILE[) \
160  && sed "s|@]yat_REVISION_DEFINE[@|$$revision|g" < $(srcdir)/]yat_HEADER_FILE.in[ \
161  > [$][@]-t && mv [$][@]-t [$][@]
162)
163m4_popdef([yat_AM_FILE])
164m4_popdef([yat_REVISION_DEFINE])
165m4_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#
183AC_DEFUN([YAT_SVN_RELEASE_YEAR],
184[
185AC_REQUIRE([YAT_HAVE_SVN_WC])
186AC_REQUIRE([_YAT_PROG_SVNVERSION])
187AC_REQUIRE([YAT_PROG_MOVE_IF_CHANGE])
188m4_pushdef([YAT_am_file], [m4_default([$1], [svn_release_year.am])])
189m4_pushdef([YAT_release_year], [m4_default([$2], [.release_year])])
190# .release_year is generated during make so in order to avoid bootstrap problem
191test -r $srcdir/YAT_release_year || date -u "+%Y" > $srcdir/YAT_release_year
192# propagate RELEASE_YEAR from file .release_year
193RELEASE_YEAR=`cat "$srcdir/YAT_release_year"`
194AC_SUBST([RELEASE_YEAR])
195AC_DEFINE_UNQUOTED([RELEASE_YEAR], ["$RELEASE_YEAR"],
196                   [Define year package was last modified])
197dnl generate make rule for .release_year
198_YAT_AM_TOP(YAT_am_file)
199_YAT_AC_APPEND_TO_FILE(YAT_am_file,
200EXTRA_DIST += $(srcdir)/YAT_release_year
201CONFIG_STATUS_DEPENDENCIES += $(srcdir)/YAT_release_year
202RELEASE_YEAR_FORCE:
203if HAVE_SVN_WC
204$(srcdir)/YAT_release_year: RELEASE_YEAR_FORCE
205  @if $(SVNVERSION) $(srcdir) | grep 'M' > /dev/null; then \
206     date -u "+%%Y" > [$][@]-t \
207     && $(MOVE_IF_CHANGE) [$][@]-t [$][@]; \
208  fi
209endif
210)
211m4_popdef([YAT_am_file])
212m4_popdef([YAT_release_year])
213]) # YAT_SVN_RELEASE_YEAR
214
215
216### Private Macros ###
217
218# _YAT_AM_TOP(FILE)
219#
220# Write the header of a Automake snippet with the copyright noticed
221# decalared in top of this file.
222AC_DEFUN([_YAT_AM_TOP],
223[
224AC_PREREQ([2.62])
225AX_AC_PRINT_TO_FILE([$1],dnl
226[# ]$1[ generated automatically by GNU Autoconf
227]yat_am_macros_copyright[
228# stub rule to work around bug in Automake
229\$(top_srcdir)/]$1[:
230
231])
232]) # _YAT_AM_TOP
233
234
235# wrapper around AX_AC_APPEND_TO_FILE to avoid usage of variables
236# defined in AX_FILE_ESCAPES
237AC_DEFUN([_YAT_AC_APPEND_TO_FILE],
238[
239AX_AC_APPEND_TO_FILE([$1],
240m4_bpatsubsts([$2], [\$], [${AX_DOLLAR}],
241                    [\\], [${AX_BS}],
242                    [\"], [${AX_DQ}]))
243])
244
245
246# _YAT_PROG_SVNVERSION
247#
248# Wrapper around AC_PATH_PROG to allow using it as argument to
249# AC_REQUIRE
250AC_DEFUN([_YAT_PROG_SVNVERSION],
251[
252AC_PATH_PROG([SVNVERSION], [svnversion], [false])
253])
Note: See TracBrowser for help on using the repository browser.