bootstrap 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. #! /bin/sh
  2. # Print a version string.
  3. scriptversion=2016-01-24.06; # UTC
  4. # Bootstrap this package from checked-out sources.
  5. # Copyright (C) 2003-2016 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 <http://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. http://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() {
  361. app=$1
  362. $app --version >/dev/null 2>&1 || { $app --version; return 1; }
  363. $app --version 2>&1 |
  364. sed -n '# Move version to start of line.
  365. s/.*[v ]\([0-9]\)/\1/
  366. # Skip lines that do not start with version.
  367. /^[0-9]/!d
  368. # Remove characters after the version.
  369. s/[^.a-z0-9-].*//
  370. # The first component must be digits only.
  371. s/^\([0-9]*\)[a-z-].*/\1/
  372. #the following essentially does s/5.005/5.5/
  373. s/\.0*\([1-9]\)/.\1/g
  374. p
  375. q'
  376. }
  377. check_versions() {
  378. ret=0
  379. while read app req_ver; do
  380. # We only need libtoolize from the libtool package.
  381. if test "$app" = libtool; then
  382. app=libtoolize
  383. fi
  384. # Exempt git if --no-git is in effect.
  385. if test "$app" = git; then
  386. $use_git || continue
  387. fi
  388. # Honor $APP variables ($TAR, $AUTOCONF, etc.)
  389. appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
  390. test "$appvar" = TAR && appvar=AMTAR
  391. case $appvar in
  392. GZIP) ;; # Do not use $GZIP: it contains gzip options.
  393. PERL::*) ;; # Keep perl modules as-is
  394. *) eval "app=\${$appvar-$app}" ;;
  395. esac
  396. # Handle the still-experimental Automake-NG programs specially.
  397. # They remain named as the mainstream Automake programs ("automake",
  398. # and "aclocal") to avoid gratuitous incompatibilities with
  399. # pre-existing usages (by, say, autoreconf, or custom autogen.sh
  400. # scripts), but correctly identify themselves (as being part of
  401. # "GNU automake-ng") when asked their version.
  402. case $app in
  403. automake-ng|aclocal-ng)
  404. app=${app%-ng}
  405. ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
  406. warn_ "Error: '$app' not found or not from Automake-NG"
  407. ret=1
  408. continue
  409. } ;;
  410. # Another check is for perl modules. These can be written as
  411. # e.g. perl::XML::XPath in case of XML::XPath module, etc.
  412. perl::*)
  413. # Extract module name
  414. app="${app#perl::}"
  415. if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
  416. warn_ "Error: perl module '$app' not found"
  417. ret=1
  418. fi
  419. continue
  420. ;;
  421. esac
  422. if [ "$req_ver" = "-" ]; then
  423. # Merely require app to exist; not all prereq apps are well-behaved
  424. # so we have to rely on $? rather than get_version.
  425. if ! check_exists --verbose $app; then
  426. warn_ "Error: '$app' not found"
  427. ret=1
  428. fi
  429. else
  430. # Require app to produce a new enough version string.
  431. inst_ver=$(get_version $app)
  432. if [ ! "$inst_ver" ]; then
  433. warn_ "Error: '$app' not found"
  434. ret=1
  435. else
  436. latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
  437. if [ ! "$latest_ver" = "$inst_ver" ]; then
  438. warnf_ '%s\n' \
  439. "Error: '$app' version == $inst_ver is too old" \
  440. " '$app' version >= $req_ver is required"
  441. ret=1
  442. fi
  443. fi
  444. fi
  445. done
  446. return $ret
  447. }
  448. print_versions() {
  449. echo "Program Min_version"
  450. echo "----------------------"
  451. printf %s "$buildreq"
  452. echo "----------------------"
  453. # can't depend on column -t
  454. }
  455. # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
  456. # Also find the compatible sha1 utility on the BSDs
  457. if test x"$SKIP_PO" = x; then
  458. find_tool SHA1SUM sha1sum gsha1sum shasum sha1
  459. fi
  460. use_libtool=0
  461. # We'd like to use grep -E, to see if any of LT_INIT,
  462. # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
  463. # but that's not portable enough (e.g., for Solaris).
  464. grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
  465. && use_libtool=1
  466. grep '^[ ]*LT_INIT' configure.ac >/dev/null \
  467. && use_libtool=1
  468. if test $use_libtool = 1; then
  469. find_tool LIBTOOLIZE glibtoolize libtoolize
  470. fi
  471. # gnulib-tool requires at least automake and autoconf.
  472. # If either is not listed, add it (with minimum version) as a prerequisite.
  473. case $buildreq in
  474. *automake*) ;;
  475. *) buildreq="automake 1.9
  476. $buildreq" ;;
  477. esac
  478. case $buildreq in
  479. *autoconf*) ;;
  480. *) buildreq="autoconf 2.59
  481. $buildreq" ;;
  482. esac
  483. # When we can deduce that gnulib-tool will require patch,
  484. # and when patch is not already listed as a prerequisite, add it, too.
  485. if test -d "$local_gl_dir" \
  486. && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
  487. case $buildreq in
  488. *patch*) ;;
  489. *) buildreq="patch -
  490. $buildreq" ;;
  491. esac
  492. fi
  493. if ! printf "$buildreq" | check_versions; then
  494. echo >&2
  495. if test -f README-prereq; then
  496. die "See README-prereq for how to get the prerequisite programs"
  497. else
  498. die "Please install the prerequisite programs"
  499. fi
  500. fi
  501. # Warn the user if autom4te appears to be broken; this causes known
  502. # issues with at least gettext 0.18.3.
  503. probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
  504. if test "x$probe" != xhi; then
  505. warn_ "WARNING: your autom4te wrapper eats stdin;"
  506. warn_ "if bootstrap fails, consider upgrading your autotools"
  507. fi
  508. echo "$0: Bootstrapping from checked-out $package sources..."
  509. # See if we can use gnulib's git-merge-changelog merge driver.
  510. if $use_git && test -d .git && check_exists git; then
  511. if git config merge.merge-changelog.driver >/dev/null ; then
  512. :
  513. elif check_exists git-merge-changelog; then
  514. echo "$0: initializing git-merge-changelog driver"
  515. git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
  516. git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
  517. else
  518. echo "$0: consider installing git-merge-changelog from gnulib"
  519. fi
  520. fi
  521. cleanup_gnulib() {
  522. status=$?
  523. rm -fr "$gnulib_path"
  524. exit $status
  525. }
  526. git_modules_config () {
  527. test -f .gitmodules && git config --file .gitmodules "$@"
  528. }
  529. if $use_git; then
  530. gnulib_path=$(git_modules_config submodule.gnulib.path)
  531. test -z "$gnulib_path" && gnulib_path=gnulib
  532. fi
  533. # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a
  534. # submodule, for use in the rest of the script.
  535. case ${GNULIB_SRCDIR--} in
  536. -)
  537. # Note that $use_git is necessarily true in this case.
  538. if git_modules_config submodule.gnulib.url >/dev/null; then
  539. echo "$0: getting gnulib files..."
  540. git submodule init -- "$gnulib_path" || exit $?
  541. git submodule update -- "$gnulib_path" || exit $?
  542. elif [ ! -d "$gnulib_path" ]; then
  543. echo "$0: getting gnulib files..."
  544. trap cleanup_gnulib 1 2 13 15
  545. shallow=
  546. git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
  547. git clone $shallow git://git.sv.gnu.org/gnulib "$gnulib_path" ||
  548. cleanup_gnulib
  549. trap - 1 2 13 15
  550. fi
  551. GNULIB_SRCDIR=$gnulib_path
  552. ;;
  553. *)
  554. # Use GNULIB_SRCDIR directly or as a reference.
  555. if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
  556. git_modules_config submodule.gnulib.url >/dev/null; then
  557. echo "$0: getting gnulib files..."
  558. if git submodule -h|grep -- --reference > /dev/null; then
  559. # Prefer the one-liner available in git 1.6.4 or newer.
  560. git submodule update --init --reference "$GNULIB_SRCDIR" \
  561. "$gnulib_path" || exit $?
  562. else
  563. # This fallback allows at least git 1.5.5.
  564. if test -f "$gnulib_path"/gnulib-tool; then
  565. # Since file already exists, assume submodule init already complete.
  566. git submodule update -- "$gnulib_path" || exit $?
  567. else
  568. # Older git can't clone into an empty directory.
  569. rmdir "$gnulib_path" 2>/dev/null
  570. git clone --reference "$GNULIB_SRCDIR" \
  571. "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
  572. && git submodule init -- "$gnulib_path" \
  573. && git submodule update -- "$gnulib_path" \
  574. || exit $?
  575. fi
  576. fi
  577. GNULIB_SRCDIR=$gnulib_path
  578. fi
  579. ;;
  580. esac
  581. # $GNULIB_SRCDIR now points to the version of gnulib to use, and
  582. # we no longer need to use git or $gnulib_path below here.
  583. if $bootstrap_sync; then
  584. cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
  585. echo "$0: updating bootstrap and restarting..."
  586. case $(sh -c 'echo "$1"' -- a) in
  587. a) ignored=--;;
  588. *) ignored=ignored;;
  589. esac
  590. exec sh -c \
  591. 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
  592. $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
  593. "$0" "$@" --no-bootstrap-sync
  594. }
  595. fi
  596. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  597. <$gnulib_tool || exit $?
  598. # Get translations.
  599. download_po_files() {
  600. subdir=$1
  601. domain=$2
  602. echo "$me: getting translations into $subdir for $domain..."
  603. cmd=$(printf "$po_download_command_format" "$domain" "$subdir")
  604. eval "$cmd" && return
  605. # Fallback to HTTP.
  606. cmd=$(printf "$po_download_command_format2" "$subdir" "$domain")
  607. eval "$cmd"
  608. }
  609. # Mirror .po files to $po_dir/.reference and copy only the new
  610. # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
  611. # Note po files that exist locally only are left in $po_dir but will
  612. # not be included in LINGUAS and hence will not be distributed.
  613. update_po_files() {
  614. # Directory containing primary .po files.
  615. # Overwrite them only when we're sure a .po file is new.
  616. po_dir=$1
  617. domain=$2
  618. # Mirror *.po files into this dir.
  619. # Usually contains *.s1 checksum files.
  620. ref_po_dir="$po_dir/.reference"
  621. test -d $ref_po_dir || mkdir $ref_po_dir || return
  622. download_po_files $ref_po_dir $domain \
  623. && ls "$ref_po_dir"/*.po 2>/dev/null |
  624. sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
  625. langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
  626. test "$langs" = '*' && langs=x
  627. for po in $langs; do
  628. case $po in x) continue;; esac
  629. new_po="$ref_po_dir/$po.po"
  630. cksum_file="$ref_po_dir/$po.s1"
  631. if ! test -f "$cksum_file" ||
  632. ! test -f "$po_dir/$po.po" ||
  633. ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
  634. echo "$me: updated $po_dir/$po.po..."
  635. cp "$new_po" "$po_dir/$po.po" \
  636. && $SHA1SUM < "$new_po" > "$cksum_file" || return
  637. fi
  638. done
  639. }
  640. case $SKIP_PO in
  641. '')
  642. if test -d po; then
  643. update_po_files po $package || exit
  644. fi
  645. if test -d runtime-po; then
  646. update_po_files runtime-po $package-runtime || exit
  647. fi;;
  648. esac
  649. symlink_to_dir()
  650. {
  651. src=$1/$2
  652. dst=${3-$2}
  653. test -f "$src" && {
  654. # If the destination directory doesn't exist, create it.
  655. # This is required at least for "lib/uniwidth/cjk.h".
  656. dst_dir=$(dirname "$dst")
  657. if ! test -d "$dst_dir"; then
  658. mkdir -p "$dst_dir"
  659. # If we've just created a directory like lib/uniwidth,
  660. # tell version control system(s) it's ignorable.
  661. # FIXME: for now, this does only one level
  662. parent=$(dirname "$dst_dir")
  663. for dot_ig in x $vc_ignore; do
  664. test $dot_ig = x && continue
  665. ig=$parent/$dot_ig
  666. insert_vc_ignore $ig "${dst_dir##*/}"
  667. done
  668. fi
  669. if $copy; then
  670. {
  671. test ! -h "$dst" || {
  672. echo "$me: rm -f $dst" &&
  673. rm -f "$dst"
  674. }
  675. } &&
  676. test -f "$dst" &&
  677. cmp -s "$src" "$dst" || {
  678. echo "$me: cp -fp $src $dst" &&
  679. cp -fp "$src" "$dst"
  680. }
  681. else
  682. # Leave any existing symlink alone, if it already points to the source,
  683. # so that broken build tools that care about symlink times
  684. # aren't confused into doing unnecessary builds. Conversely, if the
  685. # existing symlink's time stamp is older than the source, make it afresh,
  686. # so that broken tools aren't confused into skipping needed builds. See
  687. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00326.html>.
  688. test -h "$dst" &&
  689. src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
  690. dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
  691. test "$src_i" = "$dst_i" &&
  692. both_ls=$(ls -dt "$src" "$dst") &&
  693. test "X$both_ls" = "X$dst$nl$src" || {
  694. dot_dots=
  695. case $src in
  696. /*) ;;
  697. *)
  698. case /$dst/ in
  699. *//* | */../* | */./* | /*/*/*/*/*/)
  700. die "invalid symlink calculation: $src -> $dst";;
  701. /*/*/*/*/) dot_dots=../../../;;
  702. /*/*/*/) dot_dots=../../;;
  703. /*/*/) dot_dots=../;;
  704. esac;;
  705. esac
  706. echo "$me: ln -fs $dot_dots$src $dst" &&
  707. ln -fs "$dot_dots$src" "$dst"
  708. }
  709. fi
  710. }
  711. }
  712. version_controlled_file() {
  713. parent=$1
  714. file=$2
  715. if test -d .git; then
  716. git rm -n "$file" > /dev/null 2>&1
  717. elif test -d .svn; then
  718. svn log -r HEAD "$file" > /dev/null 2>&1
  719. elif test -d CVS; then
  720. grep -F "/${file##*/}/" "$parent/CVS/Entries" 2>/dev/null |
  721. grep '^/[^/]*/[0-9]' > /dev/null
  722. else
  723. warn_ "no version control for $file?"
  724. false
  725. fi
  726. }
  727. # NOTE: we have to be careful to run both autopoint and libtoolize
  728. # before gnulib-tool, since gnulib-tool is likely to provide newer
  729. # versions of files "installed" by these two programs.
  730. # Then, *after* gnulib-tool (see below), we have to be careful to
  731. # run autoreconf in such a way that it does not run either of these
  732. # two just-pre-run programs.
  733. # Import from gettext.
  734. with_gettext=yes
  735. grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
  736. with_gettext=no
  737. if test $with_gettext = yes || test $use_libtool = 1; then
  738. tempbase=.bootstrap$$
  739. trap "rm -f $tempbase.0 $tempbase.1" 1 2 13 15
  740. > $tempbase.0 > $tempbase.1 &&
  741. find . ! -type d -print | sort > $tempbase.0 || exit
  742. if test $with_gettext = yes; then
  743. # Released autopoint has the tendency to install macros that have been
  744. # obsoleted in current gnulib, so run this before gnulib-tool.
  745. echo "$0: $AUTOPOINT --force"
  746. $AUTOPOINT --force || exit
  747. fi
  748. # Autoreconf runs aclocal before libtoolize, which causes spurious
  749. # warnings if the initial aclocal is confused by the libtoolized
  750. # (or worse out-of-date) macro directory.
  751. # libtoolize 1.9b added the --install option; but we support back
  752. # to libtoolize 1.5.22, where the install action was default.
  753. if test $use_libtool = 1; then
  754. install=
  755. case $($LIBTOOLIZE --help) in
  756. *--install*) install=--install ;;
  757. esac
  758. echo "running: $LIBTOOLIZE $install --copy"
  759. $LIBTOOLIZE $install --copy
  760. fi
  761. find . ! -type d -print | sort >$tempbase.1
  762. old_IFS=$IFS
  763. IFS=$nl
  764. for file in $(comm -13 $tempbase.0 $tempbase.1); do
  765. IFS=$old_IFS
  766. parent=${file%/*}
  767. version_controlled_file "$parent" "$file" || {
  768. for dot_ig in x $vc_ignore; do
  769. test $dot_ig = x && continue
  770. ig=$parent/$dot_ig
  771. insert_vc_ignore "$ig" "${file##*/}"
  772. done
  773. }
  774. done
  775. IFS=$old_IFS
  776. rm -f $tempbase.0 $tempbase.1
  777. trap - 1 2 13 15
  778. fi
  779. # Import from gnulib.
  780. gnulib_tool_options="\
  781. --import\
  782. --no-changelog\
  783. --aux-dir $build_aux\
  784. --doc-base $doc_base\
  785. --lib $gnulib_name\
  786. --m4-base $m4_base/\
  787. --source-base $source_base/\
  788. --tests-base $tests_base\
  789. --local-dir $local_gl_dir\
  790. $gnulib_tool_option_extras\
  791. "
  792. if test $use_libtool = 1; then
  793. case "$gnulib_tool_options " in
  794. *' --libtool '*) ;;
  795. *) gnulib_tool_options="$gnulib_tool_options --libtool" ;;
  796. esac
  797. fi
  798. echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
  799. $gnulib_tool $gnulib_tool_options --import $gnulib_modules \
  800. || die "gnulib-tool failed"
  801. for file in $gnulib_files; do
  802. symlink_to_dir "$GNULIB_SRCDIR" $file \
  803. || die "failed to symlink $file"
  804. done
  805. bootstrap_post_import_hook \
  806. || die "bootstrap_post_import_hook failed"
  807. # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
  808. # gnulib-populated directories. Such .m4 files would cause aclocal to fail.
  809. # The following requires GNU find 4.2.3 or newer. Considering the usual
  810. # portability constraints of this script, that may seem a very demanding
  811. # requirement, but it should be ok. Ignore any failure, which is fine,
  812. # since this is only a convenience to help developers avoid the relatively
  813. # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
  814. # between successive runs of this script.
  815. find "$m4_base" "$source_base" \
  816. -depth \( -name '*.m4' -o -name '*.[ch]' \) \
  817. -type l -xtype l -delete > /dev/null 2>&1
  818. # Invoke autoreconf with --force --install to ensure upgrades of tools
  819. # such as ylwrap.
  820. AUTORECONFFLAGS="--verbose --install --force -I $m4_base $ACLOCAL_FLAGS"
  821. # Some systems (RHEL 5) are using ancient autotools, for which the
  822. # --no-recursive option had not been invented. Detect that lack and
  823. # omit the option when it's not supported. FIXME in 2017: remove this
  824. # hack when RHEL 5 autotools are updated, or when they become irrelevant.
  825. case $($AUTORECONF --help) in
  826. *--no-recursive*) AUTORECONFFLAGS="$AUTORECONFFLAGS --no-recursive";;
  827. esac
  828. # Tell autoreconf not to invoke autopoint or libtoolize; they were run above.
  829. echo "running: AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS"
  830. AUTOPOINT=true LIBTOOLIZE=true $AUTORECONF $AUTORECONFFLAGS \
  831. || die "autoreconf failed"
  832. # Get some extra files from gnulib, overriding existing files.
  833. for file in $gnulib_extra_files; do
  834. case $file in
  835. */INSTALL) dst=INSTALL;;
  836. build-aux/*) dst=$build_aux/${file#build-aux/};;
  837. *) dst=$file;;
  838. esac
  839. symlink_to_dir "$GNULIB_SRCDIR" $file $dst \
  840. || die "failed to symlink $file"
  841. done
  842. if test $with_gettext = yes; then
  843. # Create gettext configuration.
  844. echo "$0: Creating po/Makevars from po/Makevars.template ..."
  845. rm -f po/Makevars
  846. sed '
  847. /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  848. /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
  849. /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
  850. /^XGETTEXT_OPTIONS *=/{
  851. s/$/ \\/
  852. a\
  853. '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  854. }
  855. ' po/Makevars.template >po/Makevars \
  856. || die 'cannot generate po/Makevars'
  857. # If the 'gettext' module is in use, grab the latest Makefile.in.in.
  858. # If only the 'gettext-h' module is in use, assume autopoint already
  859. # put the correct version of this file into place.
  860. case $gnulib_modules in
  861. *gettext-h*) ;;
  862. *gettext*)
  863. cp $GNULIB_SRCDIR/build-aux/po/Makefile.in.in po/Makefile.in.in \
  864. || die "cannot create po/Makefile.in.in"
  865. ;;
  866. esac
  867. if test -d runtime-po; then
  868. # Similarly for runtime-po/Makevars, but not quite the same.
  869. rm -f runtime-po/Makevars
  870. sed '
  871. /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
  872. /^subdir *=.*/s/=.*/= runtime-po/
  873. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  874. /^XGETTEXT_OPTIONS *=/{
  875. s/$/ \\/
  876. a\
  877. '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
  878. }
  879. ' po/Makevars.template >runtime-po/Makevars \
  880. || die 'cannot generate runtime-po/Makevars'
  881. # Copy identical files from po to runtime-po.
  882. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
  883. fi
  884. fi
  885. bootstrap_epilogue
  886. echo "$0: done. Now you can run './configure'."
  887. # Local variables:
  888. # eval: (add-hook 'write-file-hooks 'time-stamp)
  889. # time-stamp-start: "scriptversion="
  890. # time-stamp-format: "%:y-%02m-%02d.%02H"
  891. # time-stamp-time-zone: "UTC0"
  892. # time-stamp-end: "; # UTC"
  893. # End: