bootstrap 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. #! /bin/sh
  2. # Print a version string.
  3. scriptversion=2022-01-26.05; # UTC
  4. # Bootstrap this package from checked-out sources.
  5. # Copyright (C) 2003-2022 Free Software Foundation, Inc.
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. # Originally written by Paul Eggert. The canonical version of this
  17. # script is maintained as build-aux/bootstrap in gnulib, however, to
  18. # be useful to your project, you should place a copy of it under
  19. # version control in the top-level directory of your project. The
  20. # intent is that all customization can be done with a bootstrap.conf
  21. # file also maintained in your version control; gnulib comes with a
  22. # template build-aux/bootstrap.conf to get you started.
  23. # Please report bugs or propose patches to bug-gnulib@gnu.org.
  24. nl='
  25. '
  26. # Ensure file names are sorted consistently across platforms.
  27. LC_ALL=C
  28. export LC_ALL
  29. # Ensure that CDPATH is not set. Otherwise, the output from cd
  30. # would cause trouble in at least one use below.
  31. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  32. local_gl_dir=gl
  33. # Honor $PERL, but work even if there is none.
  34. PERL="${PERL-perl}"
  35. me=$0
  36. default_gnulib_url=https://git.savannah.gnu.org/git/gnulib.git
  37. usage() {
  38. cat <<EOF
  39. Usage: $me [OPTION]...
  40. Bootstrap this package from the checked-out sources.
  41. Options:
  42. --gnulib-srcdir=DIRNAME specify the local directory where gnulib
  43. sources reside. Use this if you already
  44. have gnulib sources on your machine, and
  45. do not want to waste your bandwidth downloading
  46. them again. Defaults to \$GNULIB_SRCDIR
  47. --bootstrap-sync if this bootstrap script is not identical to
  48. the version in the local gnulib sources,
  49. update this script, and then restart it with
  50. /bin/sh or the shell \$CONFIG_SHELL
  51. --no-bootstrap-sync do not check whether bootstrap is out of sync
  52. --copy copy files instead of creating symbolic links
  53. --force attempt to bootstrap even if the sources seem
  54. not to have been checked out
  55. --no-git do not use git to update gnulib. Requires that
  56. --gnulib-srcdir point to a correct gnulib snapshot
  57. --skip-po do not download po files
  58. EOF
  59. bootstrap_print_option_usage_hook
  60. cat <<EOF
  61. If the file $me.conf exists in the same directory as this script, its
  62. contents are read as shell variables to configure the bootstrap.
  63. For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
  64. are honored.
  65. Gnulib sources can be fetched in various ways:
  66. * If this package is in a git repository with a 'gnulib' submodule
  67. configured, then that submodule is initialized and updated and sources
  68. are fetched from there. If \$GNULIB_SRCDIR is set (directly or via
  69. --gnulib-srcdir) and is a git repository, then it is used as a reference.
  70. * Otherwise, if \$GNULIB_SRCDIR is set (directly or via --gnulib-srcdir),
  71. then sources are fetched from that local directory. If it is a git
  72. repository and \$GNULIB_REVISION is set, then that revision is checked
  73. out.
  74. * Otherwise, if this package is in a git repository with a 'gnulib'
  75. submodule configured, then that submodule is initialized and updated and
  76. sources are fetched from there.
  77. * Otherwise, if the 'gnulib' directory does not exist, Gnulib sources are
  78. cloned into that directory using git from \$GNULIB_URL, defaulting to
  79. $default_gnulib_url.
  80. If \$GNULIB_REVISION is set, then that revision is checked out.
  81. * Otherwise, the existing Gnulib sources in the 'gnulib' directory are
  82. used. If it is a git repository and \$GNULIB_REVISION is set, then that
  83. revision is checked out.
  84. If you maintain a package and want to pin a particular revision of the
  85. Gnulib sources that has been tested with your package, then there are two
  86. possible approaches: either configure a 'gnulib' submodule with the
  87. appropriate revision, or set \$GNULIB_REVISION (and if necessary
  88. \$GNULIB_URL) in $me.conf.
  89. Running without arguments will suffice in most cases.
  90. EOF
  91. }
  92. copyright_year=`echo "$scriptversion" | sed -e 's/[^0-9].*//'`
  93. copyright="Copyright (C) ${copyright_year} Free Software Foundation, Inc.
  94. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
  95. This is free software: you are free to change and redistribute it.
  96. There is NO WARRANTY, to the extent permitted by law."
  97. # warnf_ FORMAT-STRING ARG1...
  98. warnf_ ()
  99. {
  100. warnf_format_=$1
  101. shift
  102. nl='
  103. '
  104. case $* in
  105. *$nl*) me_=$(printf "$me"|tr "$nl|" '??')
  106. printf "$warnf_format_" "$@" | sed "s|^|$me_: |" ;;
  107. *) printf "$me: $warnf_format_" "$@" ;;
  108. esac >&2
  109. }
  110. # warn_ WORD1...
  111. warn_ ()
  112. {
  113. # If IFS does not start with ' ', set it and emit the warning in a subshell.
  114. case $IFS in
  115. ' '*) warnf_ '%s\n' "$*";;
  116. *) (IFS=' '; warn_ "$@");;
  117. esac
  118. }
  119. # die WORD1...
  120. die() { warn_ "$@"; exit 1; }
  121. # Configuration.
  122. # Name of the Makefile.am
  123. gnulib_mk=gnulib.mk
  124. # List of gnulib modules needed.
  125. gnulib_modules=
  126. # Any gnulib files needed that are not in modules.
  127. gnulib_files=
  128. : ${AUTOPOINT=autopoint}
  129. : ${AUTORECONF=autoreconf}
  130. # A function to be called for each unrecognized option. Returns 0 if
  131. # the option in $1 has been processed by the function. Returns 1 if
  132. # the option has not been processed by the function. Override it via
  133. # your own definition in bootstrap.conf
  134. bootstrap_option_hook() { return 1; }
  135. # A function to be called in order to print the --help information
  136. # corresponding to user-defined command-line options.
  137. bootstrap_print_option_usage_hook() { :; }
  138. # A function to be called right after gnulib-tool is run.
  139. # Override it via your own definition in bootstrap.conf.
  140. bootstrap_post_import_hook() { :; }
  141. # A function to be called after everything else in this script.
  142. # Override it via your own definition in bootstrap.conf.
  143. bootstrap_epilogue() { :; }
  144. # The command to download all .po files for a specified domain into a
  145. # specified directory. Fill in the first %s with the destination
  146. # directory and the second with the domain name.
  147. po_download_command_format=\
  148. "wget --mirror --level=1 -nd -nv -A.po -P '%s' \
  149. https://translationproject.org/latest/%s/"
  150. # Prefer a non-empty tarname (4th argument of AC_INIT if given), else
  151. # fall back to the package name (1st argument with munging).
  152. extract_package_name='
  153. /^AC_INIT(\[*/{
  154. s///
  155. /^[^,]*,[^,]*,[^,]*,[ []*\([^][ ,)]\)/{
  156. s//\1/
  157. s/[],)].*//
  158. p
  159. q
  160. }
  161. s/[],)].*//
  162. s/^GNU //
  163. y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
  164. s/[^abcdefghijklmnopqrstuvwxyz0123456789_]/-/g
  165. p
  166. }
  167. '
  168. package=$(${AUTOCONF:-autoconf} --trace AC_INIT:\$4 configure.ac 2>/dev/null)
  169. if test -z "$package"; then
  170. package=$(sed -n "$extract_package_name" configure.ac) \
  171. || die 'cannot find package name in configure.ac'
  172. fi
  173. gnulib_name=lib$package
  174. build_aux=build-aux
  175. source_base=lib
  176. m4_base=m4
  177. doc_base=doc
  178. tests_base=tests
  179. gnulib_extra_files="
  180. build-aux/install-sh
  181. build-aux/mdate-sh
  182. build-aux/texinfo.tex
  183. build-aux/depcomp
  184. build-aux/config.guess
  185. build-aux/config.sub
  186. doc/INSTALL
  187. "
  188. # Additional gnulib-tool options to use. Use "\newline" to break lines.
  189. gnulib_tool_option_extras=
  190. # Other locale categories that need message catalogs.
  191. EXTRA_LOCALE_CATEGORIES=
  192. # Additional xgettext options to use. Use "\\\newline" to break lines.
  193. XGETTEXT_OPTIONS='\\\
  194. --flag=_:1:pass-c-format\\\
  195. --flag=N_:1:pass-c-format\\\
  196. --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
  197. '
  198. # Package bug report address and copyright holder for gettext files
  199. COPYRIGHT_HOLDER='Free Software Foundation, Inc.'
  200. MSGID_BUGS_ADDRESS=bug-$package@gnu.org
  201. # Files we don't want to import.
  202. excluded_files=
  203. # File that should exist in the top directory of a checked out hierarchy,
  204. # but not in a distribution tarball.
  205. checkout_only_file=README-hacking
  206. # Whether to use copies instead of symlinks.
  207. copy=false
  208. # Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
  209. # those files to be generated in directories like lib/, m4/, and po/.
  210. # Or set it to 'auto' to make this script select which to use based
  211. # on which version control system (if any) is used in the source directory.
  212. vc_ignore=auto
  213. # Set this to true in bootstrap.conf to enable --bootstrap-sync by
  214. # default.
  215. bootstrap_sync=false
  216. # Use git to update gnulib sources
  217. use_git=true
  218. check_exists() {
  219. if test "$1" = "--verbose"; then
  220. ($2 --version </dev/null) >/dev/null 2>&1
  221. if test $? -ge 126; then
  222. # If not found, run with diagnostics as one may be
  223. # presented with env variables to set to find the right version
  224. ($2 --version </dev/null)
  225. fi
  226. else
  227. ($1 --version </dev/null) >/dev/null 2>&1
  228. fi
  229. test $? -lt 126
  230. }
  231. # find_tool ENVVAR NAMES...
  232. # -------------------------
  233. # Search for a required program. Use the value of ENVVAR, if set,
  234. # otherwise find the first of the NAMES that can be run.
  235. # If found, set ENVVAR to the program name, die otherwise.
  236. #
  237. # FIXME: code duplication, see also gnu-web-doc-update.
  238. find_tool ()
  239. {
  240. find_tool_envvar=$1
  241. shift
  242. find_tool_names=$@
  243. eval "find_tool_res=\$$find_tool_envvar"
  244. if test x"$find_tool_res" = x; then
  245. for i; do
  246. if check_exists $i; then
  247. find_tool_res=$i
  248. break
  249. fi
  250. done
  251. fi
  252. if test x"$find_tool_res" = x; then
  253. warn_ "one of these is required: $find_tool_names;"
  254. die "alternatively set $find_tool_envvar to a compatible tool"
  255. fi
  256. eval "$find_tool_envvar=\$find_tool_res"
  257. eval "export $find_tool_envvar"
  258. }
  259. # Strip blank and comment lines to leave significant entries.
  260. gitignore_entries() {
  261. sed '/^#/d; /^$/d' "$@"
  262. }
  263. # If $STR is not already on a line by itself in $FILE, insert it at the start.
  264. # Entries are inserted at the start of the ignore list to ensure existing
  265. # entries starting with ! are not overridden. Such entries support
  266. # whitelisting exceptions after a more generic blacklist pattern.
  267. insert_if_absent() {
  268. file=$1
  269. str=$2
  270. test -f $file || touch $file
  271. test -r $file || die "Error: failed to read ignore file: $file"
  272. duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
  273. if [ "$duplicate_entries" ] ; then
  274. die "Error: Duplicate entries in $file: " $duplicate_entries
  275. fi
  276. linesold=$(gitignore_entries $file | wc -l)
  277. linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
  278. if [ $linesold != $linesnew ] ; then
  279. { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
  280. || die "insert_if_absent $file $str: failed"
  281. fi
  282. }
  283. # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
  284. # insert_if_absent.
  285. insert_vc_ignore() {
  286. vc_ignore_file="$1"
  287. pattern="$2"
  288. case $vc_ignore_file in
  289. *.gitignore)
  290. # A .gitignore entry that does not start with '/' applies
  291. # recursively to subdirectories, so prepend '/' to every
  292. # .gitignore entry.
  293. pattern=$(echo "$pattern" | sed s,^,/,);;
  294. esac
  295. insert_if_absent "$vc_ignore_file" "$pattern"
  296. }
  297. symlink_to_dir()
  298. {
  299. src=$1/$2
  300. dst=${3-$2}
  301. test -f "$src" && {
  302. # If the destination directory doesn't exist, create it.
  303. # This is required at least for "lib/uniwidth/cjk.h".
  304. dst_dir=$(dirname "$dst")
  305. if ! test -d "$dst_dir"; then
  306. mkdir -p "$dst_dir"
  307. # If we've just created a directory like lib/uniwidth,
  308. # tell version control system(s) it's ignorable.
  309. # FIXME: for now, this does only one level
  310. parent=$(dirname "$dst_dir")
  311. for dot_ig in x $vc_ignore; do
  312. test $dot_ig = x && continue
  313. ig=$parent/$dot_ig
  314. insert_vc_ignore $ig "${dst_dir##*/}"
  315. done
  316. fi
  317. if $copy; then
  318. {
  319. test ! -h "$dst" || {
  320. echo "$me: rm -f $dst" &&
  321. rm -f "$dst"
  322. }
  323. } &&
  324. test -f "$dst" &&
  325. cmp -s "$src" "$dst" || {
  326. echo "$me: cp -fp $src $dst" &&
  327. cp -fp "$src" "$dst"
  328. }
  329. else
  330. # Leave any existing symlink alone, if it already points to the source,
  331. # so that broken build tools that care about symlink times
  332. # aren't confused into doing unnecessary builds. Conversely, if the
  333. # existing symlink's timestamp is older than the source, make it afresh,
  334. # so that broken tools aren't confused into skipping needed builds. See
  335. # <https://lists.gnu.org/r/bug-gnulib/2011-05/msg00326.html>.
  336. test -h "$dst" &&
  337. src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
  338. dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
  339. test "$src_i" = "$dst_i" &&
  340. both_ls=$(ls -dt "$src" "$dst") &&
  341. test "X$both_ls" = "X$dst$nl$src" || {
  342. dot_dots=
  343. case $src in
  344. /*) ;;
  345. *)
  346. case /$dst/ in
  347. *//* | */../* | */./* | /*/*/*/*/*/)
  348. die "invalid symlink calculation: $src -> $dst";;
  349. /*/*/*/*/) dot_dots=../../../;;
  350. /*/*/*/) dot_dots=../../;;
  351. /*/*/) dot_dots=../;;
  352. esac;;
  353. esac
  354. echo "$me: ln -fs $dot_dots$src $dst" &&
  355. ln -fs "$dot_dots$src" "$dst"
  356. }
  357. fi
  358. }
  359. }
  360. # Override the default configuration, if necessary.
  361. # Make sure that bootstrap.conf is sourced from the current directory
  362. # if we were invoked as "sh bootstrap".
  363. case "$0" in
  364. */*) test -r "$0.conf" && . "$0.conf" ;;
  365. *) test -r "$0.conf" && . ./"$0.conf" ;;
  366. esac
  367. if test "$vc_ignore" = auto; then
  368. vc_ignore=
  369. test -d .git && vc_ignore=.gitignore
  370. test -d CVS && vc_ignore="$vc_ignore .cvsignore"
  371. fi
  372. if test x"$gnulib_modules$gnulib_files$gnulib_extra_files" = x; then
  373. use_gnulib=false
  374. else
  375. use_gnulib=true
  376. fi
  377. # Translate configuration into internal form.
  378. # Parse options.
  379. for option
  380. do
  381. case $option in
  382. --help)
  383. usage
  384. exit;;
  385. --version)
  386. set -e
  387. echo "bootstrap $scriptversion"
  388. echo "$copyright"
  389. exit 0
  390. ;;
  391. --gnulib-srcdir=*)
  392. GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
  393. --skip-po)
  394. SKIP_PO=t;;
  395. --force)
  396. checkout_only_file=;;
  397. --copy)
  398. copy=true;;
  399. --bootstrap-sync)
  400. bootstrap_sync=true;;
  401. --no-bootstrap-sync)
  402. bootstrap_sync=false;;
  403. --no-git)
  404. use_git=false;;
  405. *)
  406. bootstrap_option_hook $option || die "$option: unknown option";;
  407. esac
  408. done
  409. $use_git || test -d "$GNULIB_SRCDIR" \
  410. || die "Error: --no-git requires --gnulib-srcdir"
  411. if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
  412. die "Bootstrapping from a non-checked-out distribution is risky."
  413. fi
  414. # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
  415. found_aux_dir=no
  416. grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
  417. >/dev/null && found_aux_dir=yes
  418. grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
  419. >/dev/null && found_aux_dir=yes
  420. test $found_aux_dir = yes \
  421. || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
  422. # If $build_aux doesn't exist, create it now, otherwise some bits
  423. # below will malfunction. If creating it, also mark it as ignored.
  424. if test ! -d $build_aux; then
  425. mkdir $build_aux
  426. for dot_ig in x $vc_ignore; do
  427. test $dot_ig = x && continue
  428. insert_vc_ignore $dot_ig $build_aux
  429. done
  430. fi
  431. # Note this deviates from the version comparison in automake
  432. # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
  433. # but this should suffice as we won't be specifying old
  434. # version formats or redundant trailing .0 in bootstrap.conf.
  435. # If we did want full compatibility then we should probably
  436. # use m4_version_compare from autoconf.
  437. sort_ver() { # sort -V is not generally available
  438. ver1="$1"
  439. ver2="$2"
  440. # split on '.' and compare each component
  441. i=1
  442. while : ; do
  443. p1=$(echo "$ver1" | cut -d. -f$i)
  444. p2=$(echo "$ver2" | cut -d. -f$i)
  445. if [ ! "$p1" ]; then
  446. echo "$1 $2"
  447. break
  448. elif [ ! "$p2" ]; then
  449. echo "$2 $1"
  450. break
  451. elif [ ! "$p1" = "$p2" ]; then
  452. if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
  453. echo "$2 $1"
  454. elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
  455. echo "$1 $2"
  456. else # numeric, then lexicographic comparison
  457. lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
  458. if [ "$lp" = "$p2" ]; then
  459. echo "$1 $2"
  460. else
  461. echo "$2 $1"
  462. fi
  463. fi
  464. break
  465. fi
  466. i=$(($i+1))
  467. done
  468. }
  469. get_version_sed='
  470. # Move version to start of line.
  471. s/.*[v ]\([0-9]\)/\1/
  472. # Skip lines that do not start with version.
  473. /^[0-9]/!d
  474. # Remove characters after the version.
  475. s/[^.a-z0-9-].*//
  476. # The first component must be digits only.
  477. s/^\([0-9]*\)[a-z-].*/\1/
  478. #the following essentially does s/5.005/5.5/
  479. s/\.0*\([1-9]\)/.\1/g
  480. p
  481. q'
  482. get_version() {
  483. app=$1
  484. $app --version >/dev/null 2>&1 || { $app --version; return 1; }
  485. $app --version 2>&1 | sed -n "$get_version_sed"
  486. }
  487. check_versions() {
  488. ret=0
  489. while read app req_ver; do
  490. # We only need libtoolize from the libtool package.
  491. if test "$app" = libtool; then
  492. app=libtoolize
  493. fi
  494. # Exempt git if --no-git is in effect.
  495. if test "$app" = git; then
  496. $use_git || continue
  497. fi
  498. # Honor $APP variables ($TAR, $AUTOCONF, etc.)
  499. appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
  500. test "$appvar" = TAR && appvar=AMTAR
  501. case $appvar in
  502. GZIP) ;; # Do not use $GZIP: it contains gzip options.
  503. PERL::*) ;; # Keep perl modules as-is
  504. *) eval "app=\${$appvar-$app}" ;;
  505. esac
  506. # Handle the still-experimental Automake-NG programs specially.
  507. # They remain named as the mainstream Automake programs ("automake",
  508. # and "aclocal") to avoid gratuitous incompatibilities with
  509. # pre-existing usages (by, say, autoreconf, or custom autogen.sh
  510. # scripts), but correctly identify themselves (as being part of
  511. # "GNU automake-ng") when asked their version.
  512. case $app in
  513. automake-ng|aclocal-ng)
  514. app=${app%-ng}
  515. ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
  516. warn_ "Error: '$app' not found or not from Automake-NG"
  517. ret=1
  518. continue
  519. } ;;
  520. # Another check is for perl modules. These can be written as
  521. # e.g. perl::XML::XPath in case of XML::XPath module, etc.
  522. perl::*)
  523. # Extract module name
  524. app="${app#perl::}"
  525. if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
  526. warn_ "Error: perl module '$app' not found"
  527. ret=1
  528. fi
  529. continue
  530. ;;
  531. esac
  532. if [ "$req_ver" = "-" ]; then
  533. # Merely require app to exist; not all prereq apps are well-behaved
  534. # so we have to rely on $? rather than get_version.
  535. if ! check_exists --verbose $app; then
  536. warn_ "Error: '$app' not found"
  537. ret=1
  538. fi
  539. else
  540. # Require app to produce a new enough version string.
  541. inst_ver=$(get_version $app)
  542. if [ ! "$inst_ver" ]; then
  543. warn_ "Error: '$app' not found"
  544. ret=1
  545. else
  546. latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
  547. if [ ! "$latest_ver" = "$inst_ver" ]; then
  548. warnf_ '%s\n' \
  549. "Error: '$app' version == $inst_ver is too old" \
  550. " '$app' version >= $req_ver is required"
  551. ret=1
  552. fi
  553. fi
  554. fi
  555. done
  556. return $ret
  557. }
  558. print_versions() {
  559. echo "Program Min_version"
  560. echo "----------------------"
  561. printf %s "$buildreq"
  562. echo "----------------------"
  563. # can't depend on column -t
  564. }
  565. # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
  566. # Also find the compatible sha1 utility on the BSDs
  567. if test x"$SKIP_PO" = x; then
  568. find_tool SHA1SUM sha1sum gsha1sum shasum sha1
  569. fi
  570. use_libtool=0
  571. # We'd like to use grep -E, to see if any of LT_INIT,
  572. # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
  573. # but that's not portable enough (e.g., for Solaris).
  574. grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
  575. && use_libtool=1
  576. grep '^[ ]*LT_INIT' configure.ac >/dev/null \
  577. && use_libtool=1
  578. if test $use_libtool = 1; then
  579. find_tool LIBTOOLIZE glibtoolize libtoolize
  580. fi
  581. # gnulib-tool requires at least automake and autoconf.
  582. # If either is not listed, add it (with minimum version) as a prerequisite.
  583. case $buildreq in
  584. *automake*) ;;
  585. *) buildreq="automake 1.9
  586. $buildreq" ;;
  587. esac
  588. case $buildreq in
  589. *autoconf*) ;;
  590. *) buildreq="autoconf 2.59
  591. $buildreq" ;;
  592. esac
  593. # When we can deduce that gnulib-tool will require patch,
  594. # and when patch is not already listed as a prerequisite, add it, too.
  595. if test -d "$local_gl_dir" \
  596. && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
  597. case $buildreq in
  598. *patch*) ;;
  599. *) buildreq="patch -
  600. $buildreq" ;;
  601. esac
  602. fi
  603. if ! printf "$buildreq" | check_versions; then
  604. echo >&2
  605. if test -f README-prereq; then
  606. die "See README-prereq for how to get the prerequisite programs"
  607. else
  608. die "Please install the prerequisite programs"
  609. fi
  610. fi
  611. # Warn the user if autom4te appears to be broken; this causes known
  612. # issues with at least gettext 0.18.3.
  613. probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
  614. if test "x$probe" != xhi; then
  615. warn_ "WARNING: your autom4te wrapper eats stdin;"
  616. warn_ "if bootstrap fails, consider upgrading your autotools"
  617. fi
  618. echo "$0: Bootstrapping from checked-out $package sources..."
  619. # See if we can use gnulib's git-merge-changelog merge driver.
  620. if $use_git && test -d .git && check_exists git; then
  621. if git config merge.merge-changelog.driver >/dev/null ; then
  622. :
  623. elif check_exists git-merge-changelog; then
  624. echo "$0: initializing git-merge-changelog driver"
  625. git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
  626. git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
  627. else
  628. echo "$0: consider installing git-merge-changelog from gnulib"
  629. fi
  630. fi
  631. cleanup_gnulib() {
  632. status=$?
  633. rm -fr "$gnulib_path"
  634. exit $status
  635. }
  636. git_modules_config () {
  637. test -f .gitmodules && git config --file .gitmodules "$@"
  638. }
  639. if $use_gnulib; then
  640. if $use_git; then
  641. gnulib_path=$(git_modules_config submodule.gnulib.path)
  642. test -z "$gnulib_path" && gnulib_path=gnulib
  643. fi
  644. # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a
  645. # submodule, for use in the rest of the script.
  646. case ${GNULIB_SRCDIR--} in
  647. -)
  648. # Note that $use_git is necessarily true in this case.
  649. if git_modules_config submodule.gnulib.url >/dev/null; then
  650. echo "$0: getting gnulib files..."
  651. git submodule init -- "$gnulib_path" || exit $?
  652. git submodule update -- "$gnulib_path" || exit $?
  653. elif [ ! -d "$gnulib_path" ]; then
  654. echo "$0: getting gnulib files..."
  655. trap cleanup_gnulib 1 2 13 15
  656. shallow=
  657. if test -z "$GNULIB_REVISION"; then
  658. git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
  659. git clone $shallow ${GNULIB_URL:-$default_gnulib_url} "$gnulib_path" \
  660. || cleanup_gnulib
  661. else
  662. git fetch -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
  663. mkdir -p "$gnulib_path"
  664. # Only want a shallow checkout of $GNULIB_REVISION, but git does not
  665. # support cloning by commit hash. So attempt a shallow fetch by commit
  666. # hash to minimize the amount of data downloaded and changes needed to
  667. # be processed, which can drastically reduce download and processing
  668. # time for checkout. If the fetch by commit fails, a shallow fetch can
  669. # not be performed because we do not know what the depth of the commit
  670. # is without fetching all commits. So fallback to fetching all commits.
  671. git -C "$gnulib_path" init
  672. git -C "$gnulib_path" remote add origin ${GNULIB_URL:-$default_gnulib_url}
  673. git -C "$gnulib_path" fetch $shallow origin "$GNULIB_REVISION" \
  674. || git -C "$gnulib_path" fetch origin \
  675. || cleanup_gnulib
  676. git -C "$gnulib_path" reset --hard FETCH_HEAD
  677. fi
  678. trap - 1 2 13 15
  679. fi
  680. GNULIB_SRCDIR=$gnulib_path
  681. ;;
  682. *)
  683. # Use GNULIB_SRCDIR directly or as a reference.
  684. if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
  685. git_modules_config submodule.gnulib.url >/dev/null; then
  686. echo "$0: getting gnulib files..."
  687. if git submodule -h|grep -- --reference > /dev/null; then
  688. # Prefer the one-liner available in git 1.6.4 or newer.
  689. git submodule update --init --reference "$GNULIB_SRCDIR" \
  690. "$gnulib_path" || exit $?
  691. else
  692. # This fallback allows at least git 1.5.5.
  693. if test -f "$gnulib_path"/gnulib-tool; then
  694. # Since file already exists, assume submodule init already complete.
  695. git submodule update -- "$gnulib_path" || exit $?
  696. else
  697. # Older git can't clone into an empty directory.
  698. rmdir "$gnulib_path" 2>/dev/null
  699. git clone --reference "$GNULIB_SRCDIR" \
  700. "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
  701. && git submodule init -- "$gnulib_path" \
  702. && git submodule update -- "$gnulib_path" \
  703. || exit $?
  704. fi
  705. fi
  706. GNULIB_SRCDIR=$gnulib_path
  707. fi
  708. ;;
  709. esac
  710. if test -d "$GNULIB_SRCDIR"/.git && test -n "$GNULIB_REVISION" \
  711. && ! git_modules_config submodule.gnulib.url >/dev/null; then
  712. (cd "$GNULIB_SRCDIR" && git checkout "$GNULIB_REVISION") || cleanup_gnulib
  713. fi
  714. # $GNULIB_SRCDIR now points to the version of gnulib to use, and
  715. # we no longer need to use git or $gnulib_path below here.
  716. if $bootstrap_sync; then
  717. cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
  718. echo "$0: updating bootstrap and restarting..."
  719. case $(sh -c 'echo "$1"' -- a) in
  720. a) ignored=--;;
  721. *) ignored=ignored;;
  722. esac
  723. exec sh -c \
  724. 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
  725. $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
  726. "$0" "$@" --no-bootstrap-sync
  727. }
  728. fi
  729. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  730. <$gnulib_tool || exit $?
  731. fi
  732. # Get translations.
  733. download_po_files() {
  734. subdir=$1
  735. domain=$2
  736. echo "$me: getting translations into $subdir for $domain..."
  737. cmd=$(printf "$po_download_command_format" "$subdir" "$domain")
  738. eval "$cmd"
  739. }
  740. # Mirror .po files to $po_dir/.reference and copy only the new
  741. # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
  742. # Note po files that exist locally only are left in $po_dir but will
  743. # not be included in LINGUAS and hence will not be distributed.
  744. update_po_files() {
  745. # Directory containing primary .po files.
  746. # Overwrite them only when we're sure a .po file is new.
  747. po_dir=$1
  748. domain=$2
  749. # Mirror *.po files into this dir.
  750. # Usually contains *.s1 checksum files.
  751. ref_po_dir="$po_dir/.reference"
  752. test -d $ref_po_dir || mkdir $ref_po_dir || return
  753. download_po_files $ref_po_dir $domain \
  754. && ls "$ref_po_dir"/*.po 2>/dev/null |
  755. sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
  756. langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
  757. test "$langs" = '*' && langs=x
  758. for po in $langs; do
  759. case $po in x) continue;; esac
  760. new_po="$ref_po_dir/$po.po"
  761. cksum_file="$ref_po_dir/$po.s1"
  762. if ! test -f "$cksum_file" ||
  763. ! test -f "$po_dir/$po.po" ||
  764. ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
  765. echo "$me: updated $po_dir/$po.po..."
  766. cp "$new_po" "$po_dir/$po.po" \
  767. && $SHA1SUM < "$new_po" > "$cksum_file" || return
  768. fi
  769. done
  770. }
  771. case $SKIP_PO in
  772. '')
  773. if test -d po; then
  774. update_po_files po $package || exit
  775. fi
  776. if test -d runtime-po; then
  777. update_po_files runtime-po $package-runtime || exit
  778. fi;;
  779. esac
  780. version_controlled_file() {
  781. parent=$1
  782. file=$2
  783. if test -d .git; then
  784. git rm -n "$file" > /dev/null 2>&1
  785. elif test -d .svn; then
  786. svn log -r HEAD "$file" > /dev/null 2>&1
  787. elif test -d CVS; then
  788. grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
  789. grep '^/[^/]*/[0-9]' > /dev/null
  790. else
  791. warn_ "no version control for $file?"
  792. false
  793. fi
  794. }
  795. # NOTE: we have to be careful to run both autopoint and libtoolize
  796. # before gnulib-tool, since gnulib-tool is likely to provide newer
  797. # versions of files "installed" by these two programs.
  798. # Then, *after* gnulib-tool (see below), we have to be careful to
  799. # run autoreconf in such a way that it does not run either of these
  800. # two just-pre-run programs.
  801. # Import from gettext.
  802. with_gettext=yes
  803. grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
  804. with_gettext=no
  805. if test $with_gettext = yes || test $use_libtool = 1; then
  806. tempbase=.bootstrap$$
  807. trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
  808. > $tempbase.0 > $tempbase.1 &&
  809. find . ! -type d -print | sort > $tempbase.0 || exit
  810. if test $with_gettext = yes; then
  811. # Released autopoint has the tendency to install macros that have been
  812. # obsoleted in current gnulib, so run this before gnulib-tool.
  813. echo "$0: $AUTOPOINT --force"
  814. $AUTOPOINT --force || exit
  815. fi
  816. # Autoreconf runs aclocal before libtoolize, which causes spurious
  817. # warnings if the initial aclocal is confused by the libtoolized
  818. # (or worse out-of-date) macro directory.
  819. # libtoolize 1.9b added the --install option; but we support back
  820. # to libtoolize 1.5.22, where the install action was default.
  821. if test $use_libtool = 1; then
  822. install=
  823. case $($LIBTOOLIZE --help) in
  824. *--install*) install=--install ;;
  825. esac
  826. echo "running: $LIBTOOLIZE $install --copy"
  827. $LIBTOOLIZE $install --copy
  828. fi
  829. find . ! -type d -print | sort >$tempbase.1
  830. old_IFS=$IFS
  831. IFS=$nl
  832. for file in $(comm -13 $tempbase.0 $tempbase.1); do
  833. IFS=$old_IFS
  834. parent=${file%/*}
  835. version_controlled_file "$parent" "$file" || {
  836. for dot_ig in x $vc_ignore; do
  837. test $dot_ig = x && continue
  838. ig=$parent/$dot_ig
  839. insert_vc_ignore "$ig" "${file##*/}"
  840. done
  841. }
  842. done
  843. IFS=$old_IFS
  844. rm -f $tempbase.0 $tempbase.1
  845. trap - 1 2 13 15
  846. fi
  847. # Import from gnulib.
  848. if $use_gnulib; then
  849. gnulib_tool_options="\
  850. --no-changelog\
  851. --aux-dir=$build_aux\
  852. --doc-base=$doc_base\
  853. --lib=$gnulib_name\
  854. --m4-base=$m4_base/\
  855. --source-base=$source_base/\
  856. --tests-base=$tests_base\
  857. --local-dir=$local_gl_dir\
  858. $gnulib_tool_option_extras\
  859. "
  860. if test $use_libtool = 1; then
  861. case "$gnulib_tool_options " in
  862. *' --libtool '*) ;;
  863. *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
  864. esac
  865. fi
  866. echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
  867. $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
  868. || die "gnulib-tool failed"
  869. for file in $gnulib_files; do
  870. symlink_to_dir "$GNULIB_SRCDIR" $file \
  871. || die "failed to symlink $file"
  872. done
  873. fi
  874. bootstrap_post_import_hook \
  875. || die "bootstrap_post_import_hook failed"
  876. # Don't proceed if there are uninitialized submodules. In particular,
  877. # the next step will remove dangling links, which might be links into
  878. # uninitialized submodules.
  879. #
  880. # Uninitialized submodules are listed with an initial dash.
  881. if $use_git && git submodule | grep '^-' >/dev/null; then
  882. die "some git submodules are not initialized. " \
  883. "Run 'git submodule update --init' and bootstrap again."
  884. fi
  885. # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
  886. # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
  887. # The following requires GNU find 4.2.3 or newer. Considering the usual
  888. # portability constraints of this script, that may seem a very demanding
  889. # requirement, but it should be ok. Ignore any failure, which is fine,
  890. # since this is only a convenience to help developers avoid the relatively
  891. # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
  892. # between successive runs of this script.
  893. find "$m4_base" "$source_base" \
  894. -depth \( -name '*.m4' -o -name '*.[ch]' \) \
  895. -type l -xtype l -delete > /dev/null 2>&1
  896. # Invoke autoreconf with --force --install to ensure upgrades of tools
  897. # such as ylwrap.
  898. AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
  899. # Some systems (RHEL 5) are using ancient autotools, for which the
  900. # --no-recursive option had not been invented. Detect that lack and
  901. # omit the option when it's not supported. FIXME in 2017: remove this
  902. # hack when RHEL 5 autotools are updated, or when they become irrelevant.
  903. case $($AUTORECONF --help) in
  904. *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
  905. esac
  906. # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
  907. echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
  908. AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
  909. || die "autoreconf failed"
  910. # Get some extra files from gnulib, overriding existing files.
  911. for file in $gnulib_extra_files; do
  912. case $file in
  913. */INSTALL) dst=INSTALL;;
  914. build-aux/*) dst=$build_aux/${file#build-aux/};;
  915. *) dst=$file;;
  916. esac
  917. symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
  918. || die "failed to symlink $file"
  919. done
  920. if test $with_gettext = yes; then
  921. # Create gettext configuration.
  922. echo "$0: Creating po/Makevars from po/Makevars.template ..."
  923. rm -f po/Makevars
  924. sed '
  925. /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  926. /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
  927. /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
  928. /^XGETTEXT_OPTIONS *=/{
  929. s/$/ \\/
  930. a\
  931. '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  932. }
  933. ' po/Makevars.template >po/Makevars \
  934. || die 'cannot generate po/Makevars'
  935. # If the 'gettext' module is in use, grab the latest Makefile.in.in.
  936. # If only the 'gettext-h' module is in use, assume autopoint already
  937. # put the correct version of this file into place.
  938. case $gnulib_modules in
  939. *gettext-h*) ;;
  940. *gettext*)
  941. cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
  942. || die "cannot create po/Makefile.in.in"
  943. ;;
  944. esac
  945. if test -d runtime-po; then
  946. # Similarly for runtime-po/Makevars, but not quite the same.
  947. rm -f runtime-po/Makevars
  948. sed '
  949. /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
  950. /^subdir *=.*/s/=.*/= runtime-po/
  951. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  952. /^XGETTEXT_OPTIONS *=/{
  953. s/$/ \\/
  954. a\
  955. '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
  956. }
  957. ' po/Makevars.template >runtime-po/Makevars \
  958. || die 'cannot generate runtime-po/Makevars'
  959. # Copy identical files from po to runtime-po.
  960. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
  961. fi
  962. fi
  963. bootstrap_epilogue
  964. echo "$0: done. Now you can run './configure'."
  965. # Local Variables:
  966. # eval: (add-hook 'before-save-hook 'time-stamp)
  967. # time-stamp-start: "scriptversion="
  968. # time-stamp-format: "%:y-%02m-%02d.%02H"
  969. # time-stamp-time-zone: "UTC0"
  970. # time-stamp-end: "; # UTC"
  971. # End: