autogen.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. #!/bin/sh
  2. # Convenience script for regenerating all autogeneratable files that are
  3. # omitted from the version control repository. In particular, this script
  4. # also regenerates all aclocal.m4, config.h.in, Makefile.in, configure files
  5. # with new versions of autoconf or automake.
  6. # Copyright (C) 2003-2022 Free Software Foundation, Inc.
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. # Originally written by Paul Eggert. The canonical version of this
  21. # script is maintained as build-aux/autogen.sh in gnulib. However,
  22. # to be useful to your package, you should place a copy of it under
  23. # version control in the top-level directory of your package. The
  24. # intent is that all customization can be done with a bootstrap.conf
  25. # file also maintained in your version control; gnulib comes with a
  26. # template build-aux/bootstrap.conf to get you started.
  27. #
  28. # Alternatively, you can use an autogen.sh script that is specific
  29. # to your package.
  30. scriptversion=2022-07-24.15; # UTC
  31. me="$0"
  32. medir=`dirname "$me"`
  33. # Read the function library and the configuration.
  34. . "$medir"/bootstrap-funclib.sh
  35. # Ensure that CDPATH is not set. Otherwise, the output from cd
  36. # would cause trouble in at least one use below.
  37. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  38. # Environment variables that may be set by the user.
  39. : "${AUTOPOINT=autopoint}"
  40. : "${AUTORECONF=autoreconf}"
  41. if test "$vc_ignore" = auto; then
  42. vc_ignore=
  43. test -d .git && vc_ignore=.gitignore
  44. test -d CVS && vc_ignore="$vc_ignore .cvsignore"
  45. fi
  46. usage() {
  47. cat <<EOF
  48. Usage: $me [OPTION]...
  49. Bootstrap this package from the checked-out sources.
  50. Optional environment variables:
  51. GNULIB_SRCDIR Specifies the local directory where gnulib
  52. sources reside. Use this if you already
  53. have gnulib sources on your machine, and
  54. you want to use these sources.
  55. Options:
  56. --copy copy files instead of creating symbolic links
  57. --force attempt to bootstrap even if the sources seem
  58. not to have been checked out
  59. EOF
  60. bootstrap_print_option_usage_hook
  61. cat <<EOF
  62. If the file bootstrap.conf exists in the same directory as this script, its
  63. contents are read as shell variables to configure the bootstrap.
  64. For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
  65. are honored.
  66. Gnulib sources are assumed to be present:
  67. * in \$GNULIB_SRCDIR, if that environment variable is set,
  68. * otherwise, in the 'gnulib' submodule, if such a submodule is configured,
  69. * otherwise, in the 'gnulib' subdirectory.
  70. Running without arguments will suffice in most cases.
  71. EOF
  72. }
  73. # Parse options.
  74. # Whether to use copies instead of symlinks.
  75. copy=false
  76. for option
  77. do
  78. case $option in
  79. --help)
  80. usage
  81. exit;;
  82. --version)
  83. set -e
  84. echo "autogen.sh $scriptversion"
  85. echo "$copyright"
  86. exit 0
  87. ;;
  88. --force)
  89. checkout_only_file=;;
  90. --copy)
  91. copy=true;;
  92. *)
  93. bootstrap_option_hook $option || die "$option: unknown option";;
  94. esac
  95. done
  96. test -z "$GNULIB_SRCDIR" || test -d "$GNULIB_SRCDIR" \
  97. || die "Error: \$GNULIB_SRCDIR environment variable or --gnulib-srcdir option is specified, but does not denote a directory"
  98. if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
  99. die "Running this script from a non-checked-out distribution is risky."
  100. fi
  101. if $use_gnulib; then
  102. if test -z "$GNULIB_SRCDIR"; then
  103. gnulib_path=$(test -f .gitmodules && git config --file .gitmodules submodule.gnulib.path)
  104. test -z "$gnulib_path" && gnulib_path=gnulib
  105. GNULIB_SRCDIR=$gnulib_path
  106. fi
  107. fi
  108. version_controlled_file() {
  109. parent=$1
  110. file=$2
  111. if test -d .git; then
  112. git rm -n "$file" > /dev/null 2>&1
  113. elif test -d .svn; then
  114. svn log -r HEAD "$file" > /dev/null 2>&1
  115. elif test -d CVS; then
  116. grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
  117. grep '^/[^/]*/[0-9]' > /dev/null
  118. else
  119. warn_ "no version control for $file?"
  120. false
  121. fi
  122. }
  123. # Strip blank and comment lines to leave significant entries.
  124. gitignore_entries() {
  125. sed '/^#/d; /^$/d' "$@"
  126. }
  127. # If $STR is not already on a line by itself in $FILE, insert it at the start.
  128. # Entries are inserted at the start of the ignore list to ensure existing
  129. # entries starting with ! are not overridden. Such entries support
  130. # whitelisting exceptions after a more generic blacklist pattern.
  131. insert_if_absent() {
  132. file=$1
  133. str=$2
  134. test -f $file || touch $file
  135. test -r $file || die "Error: failed to read ignore file: $file"
  136. duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
  137. if [ "$duplicate_entries" ] ; then
  138. die "Error: Duplicate entries in $file: " $duplicate_entries
  139. fi
  140. linesold=$(gitignore_entries $file | wc -l)
  141. linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
  142. if [ $linesold != $linesnew ] ; then
  143. { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
  144. || die "insert_if_absent $file $str: failed"
  145. fi
  146. }
  147. # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
  148. # insert_if_absent.
  149. insert_vc_ignore() {
  150. vc_ignore_file="$1"
  151. pattern="$2"
  152. case $vc_ignore_file in
  153. *.gitignore)
  154. # A .gitignore entry that does not start with '/' applies
  155. # recursively to subdirectories, so prepend '/' to every
  156. # .gitignore entry.
  157. pattern=$(echo "$pattern" | sed s,^,/,);;
  158. esac
  159. insert_if_absent "$vc_ignore_file" "$pattern"
  160. }
  161. symlink_to_dir()
  162. {
  163. src=$1/$2
  164. dst=${3-$2}
  165. test -f "$src" && {
  166. # If the destination directory doesn't exist, create it.
  167. # This is required at least for "lib/uniwidth/cjk.h".
  168. dst_dir=$(dirname "$dst")
  169. if ! test -d "$dst_dir"; then
  170. mkdir -p "$dst_dir"
  171. # If we've just created a directory like lib/uniwidth,
  172. # tell version control system(s) it's ignorable.
  173. # FIXME: for now, this does only one level
  174. parent=$(dirname "$dst_dir")
  175. for dot_ig in x $vc_ignore; do
  176. test $dot_ig = x && continue
  177. ig=$parent/$dot_ig
  178. insert_vc_ignore $ig "${dst_dir##*/}"
  179. done
  180. fi
  181. if $copy; then
  182. {
  183. test ! -h "$dst" || {
  184. echo "$me: rm -f $dst" &&
  185. rm -f "$dst"
  186. }
  187. } &&
  188. test -f "$dst" &&
  189. cmp -s "$src" "$dst" || {
  190. echo "$me: cp -fp $src $dst" &&
  191. cp -fp "$src" "$dst"
  192. }
  193. else
  194. # Leave any existing symlink alone, if it already points to the source,
  195. # so that broken build tools that care about symlink times
  196. # aren't confused into doing unnecessary builds. Conversely, if the
  197. # existing symlink's timestamp is older than the source, make it afresh,
  198. # so that broken tools aren't confused into skipping needed builds. See
  199. # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
  200. test -h "$dst" &&
  201. src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
  202. dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
  203. test "$src_i" = "$dst_i" &&
  204. both_ls=$(ls -dt "$src" "$dst") &&
  205. test "X$both_ls" = "X$dst$nl$src" || {
  206. dot_dots=
  207. case $src in
  208. /*) ;;
  209. *)
  210. case /$dst/ in
  211. *//* | */../* | */./* | /*/*/*/*/*/)
  212. die "invalid symlink calculation: $src -> $dst";;
  213. /*/*/*/*/) dot_dots=../../../;;
  214. /*/*/*/) dot_dots=../../;;
  215. /*/*/) dot_dots=../;;
  216. esac;;
  217. esac
  218. echo "$me: ln -fs $dot_dots$src $dst" &&
  219. ln -fs "$dot_dots$src" "$dst"
  220. }
  221. fi
  222. }
  223. }
  224. # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
  225. found_aux_dir=no
  226. grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'])' configure.ac \
  227. >/dev/null && found_aux_dir=yes
  228. grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
  229. >/dev/null && found_aux_dir=yes
  230. test $found_aux_dir = yes \
  231. || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
  232. # If $build_aux doesn't exist, create it now, otherwise some bits
  233. # below will malfunction. If creating it, also mark it as ignored.
  234. if test ! -d $build_aux; then
  235. mkdir $build_aux
  236. for dot_ig in x $vc_ignore; do
  237. test $dot_ig = x && continue
  238. insert_vc_ignore $dot_ig $build_aux
  239. done
  240. fi
  241. check_build_prerequisites false
  242. use_libtool=0
  243. # We'd like to use grep -E, to see if any of LT_INIT,
  244. # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
  245. # but that's not portable enough (e.g., for Solaris).
  246. grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
  247. && use_libtool=1
  248. grep '^[ ]*LT_INIT' configure.ac >/dev/null \
  249. && use_libtool=1
  250. if test $use_libtool = 1; then
  251. find_tool LIBTOOLIZE glibtoolize libtoolize
  252. fi
  253. if $use_gnulib; then
  254. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  255. <$gnulib_tool || exit $?
  256. fi
  257. # NOTE: we have to be careful to run both autopoint and libtoolize
  258. # before gnulib-tool, since gnulib-tool is likely to provide newer
  259. # versions of files "installed" by these two programs.
  260. # Then, *after* gnulib-tool (see below), we have to be careful to
  261. # run autoreconf in such a way that it does not run either of these
  262. # two just-pre-run programs.
  263. # Import from gettext.
  264. with_gettext=yes
  265. grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
  266. with_gettext=no
  267. if test $with_gettext = yes || test $use_libtool = 1; then
  268. tempbase=.bootstrap$$
  269. trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
  270. > $tempbase.0 > $tempbase.1 &&
  271. find . ! -type d -print | sort > $tempbase.0 || exit
  272. if test $with_gettext = yes; then
  273. # Released autopoint has the tendency to install macros that have been
  274. # obsoleted in current gnulib, so run this before gnulib-tool.
  275. echo "$0: $AUTOPOINT --force"
  276. $AUTOPOINT --force || exit
  277. fi
  278. # Autoreconf runs aclocal before libtoolize, which causes spurious
  279. # warnings if the initial aclocal is confused by the libtoolized
  280. # (or worse out-of-date) macro directory.
  281. # libtoolize 1.9b added the --install option; but we support back
  282. # to libtoolize 1.5.22, where the install action was default.
  283. if test $use_libtool = 1; then
  284. install=
  285. case $($LIBTOOLIZE --help) in
  286. *--install*) install=--install ;;
  287. esac
  288. echo "running: $LIBTOOLIZE $install --copy"
  289. $LIBTOOLIZE $install --copy
  290. fi
  291. find . ! -type d -print | sort >$tempbase.1
  292. old_IFS=$IFS
  293. IFS=$nl
  294. for file in $(comm -13 $tempbase.0 $tempbase.1); do
  295. IFS=$old_IFS
  296. parent=${file%/*}
  297. version_controlled_file "$parent" "$file" || {
  298. for dot_ig in x $vc_ignore; do
  299. test $dot_ig = x && continue
  300. ig=$parent/$dot_ig
  301. insert_vc_ignore "$ig" "${file##*/}"
  302. done
  303. }
  304. done
  305. IFS=$old_IFS
  306. rm -f $tempbase.0 $tempbase.1
  307. trap - 1 2 13 15
  308. fi
  309. # Import from gnulib.
  310. if $use_gnulib; then
  311. gnulib_tool_options="\
  312. --no-changelog\
  313. --aux-dir=$build_aux\
  314. --doc-base=$doc_base\
  315. --lib=$gnulib_name\
  316. --m4-base=$m4_base/\
  317. --source-base=$source_base/\
  318. --tests-base=$tests_base\
  319. --local-dir=$local_gl_dir\
  320. $gnulib_tool_option_extras\
  321. "
  322. if test $use_libtool = 1; then
  323. case "$gnulib_tool_options " in
  324. *' --libtool '*) ;;
  325. *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
  326. esac
  327. fi
  328. echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
  329. $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
  330. || die "gnulib-tool failed"
  331. for file in $gnulib_files; do
  332. symlink_to_dir "$GNULIB_SRCDIR" $file \
  333. || die "failed to symlink $file"
  334. done
  335. fi
  336. bootstrap_post_import_hook \
  337. || die "bootstrap_post_import_hook failed"
  338. # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
  339. # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
  340. # The following requires GNU find 4.2.3 or newer. Considering the usual
  341. # portability constraints of this script, that may seem a very demanding
  342. # requirement, but it should be ok. Ignore any failure, which is fine,
  343. # since this is only a convenience to help developers avoid the relatively
  344. # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
  345. # between successive runs of this script.
  346. find "$m4_base" "$source_base" \
  347. -depth \( -name '*.m4' -o -name '*.[ch]' \) \
  348. -type l -xtype l -delete > /dev/null 2>&1
  349. # Invoke autoreconf with --force --install to ensure upgrades of tools
  350. # such as ylwrap.
  351. AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
  352. # Some systems (RHEL 5) are using ancient autotools, for which the
  353. # --no-recursive option had not been invented. Detect that lack and
  354. # omit the option when it's not supported. FIXME in 2017: remove this
  355. # hack when RHEL 5 autotools are updated, or when they become irrelevant.
  356. case $($AUTORECONF --help) in
  357. *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
  358. esac
  359. # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
  360. echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
  361. AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
  362. || die "autoreconf failed"
  363. # Get some extra files from gnulib, overriding existing files.
  364. for file in $gnulib_extra_files; do
  365. case $file in
  366. */INSTALL) dst=INSTALL;;
  367. build-aux/*) dst=$build_aux/${file#build-aux/};;
  368. *) dst=$file;;
  369. esac
  370. symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
  371. || die "failed to symlink $file"
  372. done
  373. if test $with_gettext = yes; then
  374. # Create gettext configuration.
  375. echo "$0: Creating po/Makevars from po/Makevars.template ..."
  376. rm -f po/Makevars
  377. sed '
  378. /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  379. /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
  380. /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
  381. /^XGETTEXT_OPTIONS *=/{
  382. s/$/ \\/
  383. a\
  384. '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  385. }
  386. ' po/Makevars.template >po/Makevars \
  387. || die 'cannot generate po/Makevars'
  388. # If the 'gettext' module is in use, grab the latest Makefile.in.in.
  389. # If only the 'gettext-h' module is in use, assume autopoint already
  390. # put the correct version of this file into place.
  391. case $gnulib_modules in
  392. *gettext-h*) ;;
  393. *gettext*)
  394. cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
  395. || die "cannot create po/Makefile.in.in"
  396. ;;
  397. esac
  398. if test -d runtime-po; then
  399. # Similarly for runtime-po/Makevars, but not quite the same.
  400. rm -f runtime-po/Makevars
  401. sed '
  402. /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
  403. /^subdir *=.*/s/=.*/= runtime-po/
  404. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  405. /^XGETTEXT_OPTIONS *=/{
  406. s/$/ \\/
  407. a\
  408. '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
  409. }
  410. ' po/Makevars.template >runtime-po/Makevars \
  411. || die 'cannot generate runtime-po/Makevars'
  412. # Copy identical files from po to runtime-po.
  413. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
  414. fi
  415. fi
  416. bootstrap_epilogue
  417. echo "$0: done. Now you can run './configure'."
  418. # ----------------------------------------------------------------------------
  419. # Local Variables:
  420. # eval: (add-hook 'before-save-hook 'time-stamp)
  421. # time-stamp-start: "scriptversion="
  422. # time-stamp-format: "%:y-%02m-%02d.%02H"
  423. # time-stamp-time-zone: "UTC0"
  424. # time-stamp-end: "; # UTC"
  425. # End: