bootstrap 33 KB

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