add packaging
[platform/upstream/gettext.git] / m4 / init-package-version.m4
1 # init-package-version.m4 serial 2 (gettext-0.18)
2 dnl Copyright (C) 1992-2009 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License.  As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
8
9 # Make it possible to pass version numbers extracted from a file in
10 # $(srcdir) to autoconf.
11 #
12 # Autoconf insists on passing the package name and version number to
13 # every generated .h file and every Makefile. This was a reasonable
14 # design at times when a version number was changed only once a month.
15 # Nowadays, people often assign a new version number once a week, or
16 # even change it each time a 'git' commit is made. Regenerating all
17 # the files that depend on configure.ac (aclocal.m4, configure,
18 # config.status, config.h, all Makefiles) may take 15 minutes. These
19 # delays can severely hamper development.
20 #
21 # An alternative is to store the version number in a file in $(srcdir)
22 # that is separate from configure.ac. It can be a data file, a shell
23 # script, a .m4 file, or other. The essential point is that the maintainer
24 # is responsible for creating Makefile dependencies to this version file
25 # for every file that needs to be rebuilt when the version changes. This
26 # typically includes
27 #   - distributable documentation files that carry the version number,
28 # but does not include
29 #   - aclocal.m4, configure, config.status, config.h, all Makefiles,
30 #   - executables.
31 #
32 # autoconf and automake make it hard to follow this approach:
33 #
34 # - If AC_INIT is used with arguments, there is a chicken-and-egg problem:
35 #   The arguments need to be read from a file in $(srcdir). The location
36 #   of $(srcdir) is only determined by AC_CONFIG_SRCDIR. AC_CONFIG_SRCDIR
37 #   can only appear after AC_INIT (otherwise aclocal gives an error:
38 #   "error: m4_defn: undefined macro: _m4_divert_diversion").
39 #   Furthermore, the arguments passed to AC_INIT must be literals; for
40 #   example, the assignment to PACKAGE_VERSION looks like this:
41 #     [PACKAGE_VERSION=']AC_PACKAGE_VERSION[']
42 #
43 # - If AC_INIT is used without arguments:
44 #   Automake provides its own variables, PACKAGE and VERSION, and uses them
45 #   instead of PACKAGE_NAME and PACKAGE_VERSION that come from Autoconf.
46 #   - If AM_INIT_AUTOMAKE is used with two arguments, automake options
47 #     like 'silent-rules' cannot be specified.
48 #   - If AM_INIT_AUTOMAKE is used in its one-argument form or without
49 #     arguments at all, it triggers an error
50 #     "error: AC_INIT should be called with package and version arguments".
51 #   - If AM_INIT_AUTOMAKE is used in its one-argument form or without
52 #     arguments at all, and _AC_INIT_PACKAGE is used before it, with
53 #     the package and version number from the file as arguments, we get
54 #     a warning: "warning: AC_INIT: not a literal: $VERSION_NUMBER".
55 #     The arguments passed to _AC_INIT_PACKAGE must be literals.
56 #
57 # With the macro defined in this file, the approach can be coded like this:
58 #
59 #   AC_INIT
60 #   AC_CONFIG_SRCDIR(WITNESS)
61 #   . $srcdir/../version.sh
62 #   gl_INIT_PACKAGE(PACKAGE, $VERSION_NUMBER)
63 #   AM_INIT_AUTOMAKE([OPTIONS])
64
65 # gl_INIT_PACKAGE(PACKAGE-NAME, VERSION)
66 # --------------------------------------
67 # followed by an AM_INIT_AUTOMAKE invocation,
68 # is like calling AM_INIT_AUTOMAKE(PACKAGE-NAME, VERSION)
69 # except that it can use computed non-literal arguments.
70 AC_DEFUN([gl_INIT_PACKAGE],
71 [
72   AC_BEFORE([$0], [AM_INIT_AUTOMAKE])
73   dnl Define AC_PACKAGE_NAME, because macros such as gnulib/m4/acl.m4 need it.
74   m4_ifndef([AC_PACKAGE_NAME], [m4_define([AC_PACKAGE_NAME], [$1])])
75   dnl Redefine AM_INIT_AUTOMAKE.
76   m4_define([gl_AM_INIT_AUTOMAKE],
77     m4_bpatsubst(m4_dquote(
78         m4_bpatsubst(m4_dquote(
79             m4_bpatsubst(m4_dquote(
80                 m4_defn([AM_INIT_AUTOMAKE])),
81               [AC_PACKAGE_NAME], [gl_INIT_DUMMY])),
82           [AC_PACKAGE_TARNAME], [gl_INIT_DUMMY])),
83       [AC_PACKAGE_VERSION], [gl_INIT_DUMMY])
84     [AC_SUBST([PACKAGE], [$1])
85      AC_SUBST([VERSION], [$2])
86     ])
87   m4_define([AM_INIT_AUTOMAKE],
88     m4_defn([gl_RPL_INIT_AUTOMAKE]))
89 ])
90 m4_define([gl_INIT_DUMMY], [])
91 AC_DEFUN([gl_RPL_INIT_AUTOMAKE], [
92   m4_ifval([$2],
93     [m4_fatal([After gl_INIT_PACKAGE, the two-argument form of AM_INIT_AUTOMAKE cannot be used.])])
94   gl_AM_INIT_AUTOMAKE([$1 no-define])
95   m4_if(m4_index([ $1 ], [ no-define ]), [-1],
96     [AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
97      AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])
98     ])
99 ])