Debian Codegraph @

lib/gnulib-m4/init-package-version.m4

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