650-package-version.patch 6.4 KB

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