bootstrap 31 KB

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