bootstrap 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. #! /bin/sh
  2. # Print a version string.
  3. scriptversion=2015-08-24.08; # 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 [email protected].
  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. # Honour $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. [email protected]
  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. symlink_to_dir()
  214. {
  215. src=$1/$2
  216. dst=${3-$2}
  217. test -f "$src" && {
  218. # If the destination directory doesn't exist, create it.
  219. # This is required at least for "lib/uniwidth/cjk.h".
  220. dst_dir=$(dirname "$dst")
  221. if ! test -d "$dst_dir"; then
  222. mkdir -p "$dst_dir"
  223. # If we've just created a directory like lib/uniwidth,
  224. # tell version control system(s) it's ignorable.
  225. # FIXME: for now, this does only one level
  226. parent=$(dirname "$dst_dir")
  227. for dot_ig in x $vc_ignore; do
  228. test $dot_ig = x && continue
  229. ig=$parent/$dot_ig
  230. insert_vc_ignore $ig "${dst_dir##*/}"
  231. done
  232. fi
  233. if $copy; then
  234. {
  235. test ! -h "$dst" || {
  236. echo "$me: rm -f $dst" &&
  237. rm -f "$dst"
  238. }
  239. } &&
  240. test -f "$dst" &&
  241. cmp -s "$src" "$dst" || {
  242. echo "$me: cp -fp $src $dst" &&
  243. cp -fp "$src" "$dst"
  244. }
  245. else
  246. # Leave any existing symlink alone, if it already points to the source,
  247. # so that broken build tools that care about symlink times
  248. # aren't confused into doing unnecessary builds. Conversely, if the
  249. # existing symlink's time stamp is older than the source, make it afresh,
  250. # so that broken tools aren't confused into skipping needed builds. See
  251. # <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00326.html>.
  252. test -h "$dst" &&
  253. src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
  254. dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
  255. test "$src_i" = "$dst_i" &&
  256. both_ls=$(ls -dt "$src" "$dst") &&
  257. test "X$both_ls" = "X$dst$nl$src" || {
  258. dot_dots=
  259. case $src in
  260. /*) ;;
  261. *)
  262. case /$dst/ in
  263. *//* | */../* | */./* | /*/*/*/*/*/)
  264. die "invalid symlink calculation: $src -> $dst";;
  265. /*/*/*/*/) dot_dots=../../../;;
  266. /*/*/*/) dot_dots=../../;;
  267. /*/*/) dot_dots=../;;
  268. esac;;
  269. esac
  270. echo "$me: ln -fs $dot_dots$src $dst" &&
  271. ln -fs "$dot_dots$src" "$dst"
  272. }
  273. fi
  274. }
  275. }
  276. # Override the default configuration, if necessary.
  277. # Make sure that bootstrap.conf is sourced from the current directory
  278. # if we were invoked as "sh bootstrap".
  279. case "$0" in
  280. */*) test -r "$0.conf" && . "$0.conf" ;;
  281. *) test -r "$0.conf" && . ./"$0.conf" ;;
  282. esac
  283. # Extra files from gnulib, which override files from other sources.
  284. test -z "${gnulib_extra_files}" && \
  285. gnulib_extra_files="
  286. build-aux/install-sh
  287. build-aux/mdate-sh
  288. build-aux/texinfo.tex
  289. build-aux/depcomp
  290. build-aux/config.guess
  291. build-aux/config.sub
  292. doc/INSTALL
  293. "
  294. if test "$vc_ignore" = auto; then
  295. vc_ignore=
  296. test -d .git && vc_ignore=.gitignore
  297. test -d CVS && vc_ignore="$vc_ignore .cvsignore"
  298. fi
  299. # Translate configuration into internal form.
  300. # Parse options.
  301. for option
  302. do
  303. case $option in
  304. --help)
  305. usage
  306. exit;;
  307. --gnulib-srcdir=*)
  308. GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
  309. --skip-po)
  310. SKIP_PO=t;;
  311. --force)
  312. checkout_only_file=;;
  313. --copy)
  314. copy=true;;
  315. --bootstrap-sync)
  316. bootstrap_sync=true;;
  317. --no-bootstrap-sync)
  318. bootstrap_sync=false;;
  319. --no-git)
  320. use_git=false;;
  321. *)
  322. die "$option: unknown option";;
  323. esac
  324. done
  325. $use_git || test -d "$GNULIB_SRCDIR" \
  326. || die "Error: --no-git requires --gnulib-srcdir"
  327. if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
  328. die "Bootstrapping from a non-checked-out distribution is risky."
  329. fi
  330. # Strip blank and comment lines to leave significant entries.
  331. gitignore_entries() {
  332. sed '/^#/d; /^$/d' "$@"
  333. }
  334. # If $STR is not already on a line by itself in $FILE, insert it at the start.
  335. # Entries are inserted at the start of the ignore list to ensure existing
  336. # entries starting with ! are not overridden. Such entries support
  337. # whitelisting exceptions after a more generic blacklist pattern.
  338. insert_if_absent() {
  339. file=$1
  340. str=$2
  341. test -f $file || touch $file
  342. test -r $file || die "Error: failed to read ignore file: $file"
  343. duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
  344. if [ "$duplicate_entries" ] ; then
  345. die "Error: Duplicate entries in $file: " $duplicate_entries
  346. fi
  347. linesold=$(gitignore_entries $file | wc -l)
  348. linesnew=$( { echo "$str"; cat $file; } | gitignore_entries | sort -u | wc -l)
  349. if [ $linesold != $linesnew ] ; then
  350. { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
  351. || die "insert_if_absent $file $str: failed"
  352. fi
  353. }
  354. # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
  355. # insert_if_absent.
  356. insert_vc_ignore() {
  357. vc_ignore_file="$1"
  358. pattern="$2"
  359. case $vc_ignore_file in
  360. *.gitignore)
  361. # A .gitignore entry that does not start with '/' applies
  362. # recursively to subdirectories, so prepend '/' to every
  363. # .gitignore entry.
  364. pattern=$(echo "$pattern" | sed s,^,/,);;
  365. esac
  366. insert_if_absent "$vc_ignore_file" "$pattern"
  367. }
  368. # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
  369. found_aux_dir=no
  370. grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
  371. >/dev/null && found_aux_dir=yes
  372. grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
  373. >/dev/null && found_aux_dir=yes
  374. test $found_aux_dir = yes \
  375. || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
  376. # If $build_aux doesn't exist, create it now, otherwise some bits
  377. # below will malfunction. If creating it, also mark it as ignored.
  378. if test ! -d $build_aux; then
  379. mkdir $build_aux
  380. for dot_ig in x $vc_ignore; do
  381. test $dot_ig = x && continue
  382. insert_vc_ignore $dot_ig $build_aux
  383. done
  384. fi
  385. # Note this deviates from the version comparison in automake
  386. # in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
  387. # but this should suffice as we won't be specifying old
  388. # version formats or redundant trailing .0 in bootstrap.conf.
  389. # If we did want full compatibility then we should probably
  390. # use m4_version_compare from autoconf.
  391. sort_ver() { # sort -V is not generally available
  392. ver1="$1"
  393. ver2="$2"
  394. # split on '.' and compare each component
  395. i=1
  396. while : ; do
  397. p1=$(echo "$ver1" | cut -d. -f$i)
  398. p2=$(echo "$ver2" | cut -d. -f$i)
  399. if [ ! "$p1" ]; then
  400. echo "$1 $2"
  401. break
  402. elif [ ! "$p2" ]; then
  403. echo "$2 $1"
  404. break
  405. elif [ ! "$p1" = "$p2" ]; then
  406. if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
  407. echo "$2 $1"
  408. elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
  409. echo "$1 $2"
  410. else # numeric, then lexicographic comparison
  411. lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
  412. if [ "$lp" = "$p2" ]; then
  413. echo "$1 $2"
  414. else
  415. echo "$2 $1"
  416. fi
  417. fi
  418. break
  419. fi
  420. i=$(($i+1))
  421. done
  422. }
  423. get_version() {
  424. app=$1
  425. $app --version >/dev/null 2>&1 || { $app --version; return 1; }
  426. $app --version 2>&1 |
  427. sed -n '# Move version to start of line.
  428. s/.*[v ]\([0-9]\)/\1/
  429. # Skip lines that do not start with version.
  430. /^[0-9]/!d
  431. # Remove characters after the version.
  432. s/[^.a-z0-9-].*//
  433. # The first component must be digits only.
  434. s/^\([0-9]*\)[a-z-].*/\1/
  435. #the following essentially does s/5.005/5.5/
  436. s/\.0*\([1-9]\)/.\1/g
  437. p
  438. q'
  439. }
  440. check_versions() {
  441. ret=0
  442. while read app req_ver; do
  443. # We only need libtoolize from the libtool package.
  444. if test "$app" = libtool; then
  445. app=libtoolize
  446. fi
  447. # Exempt git if --no-git is in effect.
  448. if test "$app" = git; then
  449. $use_git || continue
  450. fi
  451. # Honor $APP variables ($TAR, $AUTOCONF, etc.)
  452. appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
  453. test "$appvar" = TAR && appvar=AMTAR
  454. case $appvar in
  455. GZIP) ;; # Do not use $GZIP: it contains gzip options.
  456. PERL::*) ;; # Keep perl modules as-is
  457. *) eval "app=\${$appvar-$app}" ;;
  458. esac
  459. # Handle the still-experimental Automake-NG programs specially.
  460. # They remain named as the mainstream Automake programs ("automake",
  461. # and "aclocal") to avoid gratuitous incompatibilities with
  462. # pre-existing usages (by, say, autoreconf, or custom autogen.sh
  463. # scripts), but correctly identify themselves (as being part of
  464. # "GNU automake-ng") when asked their version.
  465. case $app in
  466. automake-ng|aclocal-ng)
  467. app=${app%-ng}
  468. ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
  469. warn_ "Error: '$app' not found or not from Automake-NG"
  470. ret=1
  471. continue
  472. } ;;
  473. # Another check is for perl modules. These can be written as
  474. # e.g. perl::XML::XPath in case of XML::XPath module, etc.
  475. perl::*)
  476. # Extract module name
  477. app="${app#perl::}"
  478. if ! $PERL -m"$app" -e 'exit 0' >/dev/null 2>&1; then
  479. warn_ "Error: perl module '$app' not found"
  480. ret=1
  481. fi
  482. continue
  483. ;;
  484. esac
  485. if [ "$req_ver" = "-" ]; then
  486. # Merely require app to exist; not all prereq apps are well-behaved
  487. # so we have to rely on $? rather than get_version.
  488. if ! check_exists --verbose $app; then
  489. warn_ "Error: '$app' not found"
  490. ret=1
  491. fi
  492. else
  493. # Require app to produce a new enough version string.
  494. inst_ver=$(get_version $app)
  495. if [ ! "$inst_ver" ]; then
  496. warn_ "Error: '$app' not found"
  497. ret=1
  498. else
  499. latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
  500. if [ ! "$latest_ver" = "$inst_ver" ]; then
  501. warnf_ '%s\n' \
  502. "Error: '$app' version == $inst_ver is too old" \
  503. " '$app' version >= $req_ver is required"
  504. ret=1
  505. fi
  506. fi
  507. fi
  508. done
  509. return $ret
  510. }
  511. print_versions() {
  512. echo "Program Min_version"
  513. echo "----------------------"
  514. printf %s "$buildreq"
  515. echo "----------------------"
  516. # can't depend on column -t
  517. }
  518. # Find sha1sum, named gsha1sum on MacPorts, shasum on Mac OS X 10.6.
  519. # Also find the compatible sha1 utility on the BSDs
  520. if test x"$SKIP_PO" = x; then
  521. find_tool SHA1SUM sha1sum gsha1sum shasum sha1
  522. fi
  523. use_libtool=0
  524. # We'd like to use grep -E, to see if any of LT_INIT,
  525. # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
  526. # but that's not portable enough (e.g., for Solaris).
  527. grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
  528. && use_libtool=1
  529. grep '^[ ]*LT_INIT' configure.ac >/dev/null \
  530. && use_libtool=1
  531. if test $use_libtool = 1; then
  532. find_tool LIBTOOLIZE glibtoolize libtoolize
  533. fi
  534. # gnulib-tool requires at least automake and autoconf.
  535. # If either is not listed, add it (with minimum version) as a prerequisite.
  536. case $buildreq in
  537. *automake*) ;;
  538. *) buildreq="automake 1.9
  539. $buildreq" ;;
  540. esac
  541. case $buildreq in
  542. *autoconf*) ;;
  543. *) buildreq="autoconf 2.59
  544. $buildreq" ;;
  545. esac
  546. # When we can deduce that gnulib-tool will require patch,
  547. # and when patch is not already listed as a prerequisite, add it, too.
  548. if test -d "$local_gl_dir" \
  549. && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
  550. case $buildreq in
  551. *patch*) ;;
  552. *) buildreq="patch -
  553. $buildreq" ;;
  554. esac
  555. fi
  556. if ! printf "$buildreq" | check_versions; then
  557. echo >&2
  558. if test -f README-prereq; then
  559. die "See README-prereq for how to get the prerequisite programs"
  560. else
  561. die "Please install the prerequisite programs"
  562. fi
  563. fi
  564. # Warn the user if autom4te appears to be broken; this causes known
  565. # issues with at least gettext 0.18.3.
  566. probe=$(echo 'm4_quote([hi])' | autom4te -l M4sugar -t 'm4_quote:$%' -)
  567. if test "x$probe" != xhi; then
  568. warn_ "WARNING: your autom4te wrapper eats stdin;"
  569. warn_ "if bootstrap fails, consider upgrading your autotools"
  570. fi
  571. echo "$0: Bootstrapping from checked-out $package sources..."
  572. # See if we can use gnulib's git-merge-changelog merge driver.
  573. if $use_git && test -d .git && check_exists git; then
  574. if git config merge.merge-changelog.driver >/dev/null ; then
  575. :
  576. elif check_exists git-merge-changelog; then
  577. echo "$0: initializing git-merge-changelog driver"
  578. git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
  579. git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
  580. else
  581. echo "$0: consider installing git-merge-changelog from gnulib"
  582. fi
  583. fi
  584. cleanup_gnulib() {
  585. status=$?
  586. rm -fr "$gnulib_path"
  587. exit $status
  588. }
  589. git_modules_config () {
  590. test -f .gitmodules && git config --file .gitmodules "$@"
  591. }
  592. if $use_git; then
  593. gnulib_path=$(git_modules_config submodule.gnulib.path)
  594. test -z "$gnulib_path" && gnulib_path=gnulib
  595. fi
  596. # Get gnulib files. Populate $GNULIB_SRCDIR, possibly updating a
  597. # submodule, for use in the rest of the script.
  598. case ${GNULIB_SRCDIR--} in
  599. -)
  600. # Note that $use_git is necessarily true in this case.
  601. if git_modules_config submodule.gnulib.url >/dev/null; then
  602. echo "$0: getting gnulib files..."
  603. git submodule init -- "$gnulib_path" || exit $?
  604. git submodule update -- "$gnulib_path" || exit $?
  605. elif [ ! -d "$gnulib_path" ]; then
  606. echo "$0: getting gnulib files..."
  607. trap cleanup_gnulib 1 2 13 15
  608. shallow=
  609. git clone -h 2>&1 | grep -- --depth > /dev/null && shallow='--depth 2'
  610. git clone $shallow git://git.sv.gnu.org/gnulib "$gnulib_path" ||
  611. cleanup_gnulib
  612. trap - 1 2 13 15
  613. fi
  614. GNULIB_SRCDIR=$gnulib_path
  615. ;;
  616. *)
  617. # Use GNULIB_SRCDIR directly or as a reference.
  618. if $use_git && test -d "$GNULIB_SRCDIR"/.git && \
  619. git_modules_config submodule.gnulib.url >/dev/null; then
  620. echo "$0: getting gnulib files..."
  621. if git submodule -h|grep -- --reference > /dev/null; then
  622. # Prefer the one-liner available in git 1.6.4 or newer.
  623. git submodule update --init --reference "$GNULIB_SRCDIR" \
  624. "$gnulib_path" || exit $?
  625. else
  626. # This fallback allows at least git 1.5.5.
  627. if test -f "$gnulib_path"/gnulib-tool; then
  628. # Since file already exists, assume submodule init already complete.
  629. git submodule update -- "$gnulib_path" || exit $?
  630. else
  631. # Older git can't clone into an empty directory.
  632. rmdir "$gnulib_path" 2>/dev/null
  633. git clone --reference "$GNULIB_SRCDIR" \
  634. "$(git_modules_config submodule.gnulib.url)" "$gnulib_path" \
  635. && git submodule init -- "$gnulib_path" \
  636. && git submodule update -- "$gnulib_path" \
  637. || exit $?
  638. fi
  639. fi
  640. GNULIB_SRCDIR=$gnulib_path
  641. fi
  642. ;;
  643. esac
  644. # $GNULIB_SRCDIR now points to the version of gnulib to use, and
  645. # we no longer need to use git or $gnulib_path below here.
  646. if $bootstrap_sync; then
  647. cmp -s "$0" "$GNULIB_SRCDIR/build-aux/bootstrap" || {
  648. echo "$0: updating bootstrap and restarting..."
  649. case $(sh -c 'echo "$1"' -- a) in
  650. a) ignored=--;;
  651. *) ignored=ignored;;
  652. esac
  653. exec sh -c \
  654. 'cp "$1" "$2" && shift && exec "${CONFIG_SHELL-/bin/sh}" "$@"' \
  655. $ignored "$GNULIB_SRCDIR/build-aux/bootstrap" \
  656. "$0" "$@" --no-bootstrap-sync
  657. }
  658. fi
  659. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  660. <$gnulib_tool || exit $?
  661. # Get translations.
  662. download_po_files() {
  663. subdir=$1
  664. domain=$2
  665. echo "$me: getting translations into $subdir for $domain..."
  666. cmd=$(printf "$po_download_command_format" "$domain" "$subdir")
  667. eval "$cmd" && return
  668. # Fallback to HTTP.
  669. cmd=$(printf "$po_download_command_format2" "$subdir" "$domain")
  670. eval "$cmd"
  671. }
  672. # Mirror .po files to $po_dir/.reference and copy only the new
  673. # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
  674. # Note po files that exist locally only are left in $po_dir but will
  675. # not be included in LINGUAS and hence will not be distributed.
  676. update_po_files() {
  677. # Directory containing primary .po files.
  678. # Overwrite them only when we're sure a .po file is new.
  679. po_dir=$1
  680. domain=$2
  681. # Mirror *.po files into this dir.
  682. # Usually contains *.s1 checksum files.
  683. ref_po_dir="$po_dir/.reference"
  684. test -d $ref_po_dir || mkdir $ref_po_dir || return
  685. download_po_files $ref_po_dir $domain \
  686. && ls "$ref_po_dir"/*.po 2>/dev/null |
  687. sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
  688. langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
  689. test "$langs" = '*' && langs=x
  690. for po in $langs; do
  691. case $po in x) continue;; esac
  692. new_po="$ref_po_dir/$po.po"
  693. cksum_file="$ref_po_dir/$po.s1"
  694. if ! test -f "$cksum_file" ||
  695. ! test -f "$po_dir/$po.po" ||
  696. ! $SHA1SUM -c "$cksum_file" < "$new_po" > /dev/null 2>&1; then
  697. echo "$me: updated $po_dir/$po.po..."
  698. cp "$new_po" "$po_dir/$po.po" \
  699. && $SHA1SUM < "$new_po" > "$cksum_file" || return
  700. fi
  701. done
  702. }
  703. case $SKIP_PO in
  704. '')
  705. if test -d po; then
  706. update_po_files po $package || exit
  707. fi
  708. if test -d runtime-po; then
  709. update_po_files runtime-po $package-runtime || exit
  710. fi;;
  711. esac
  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: "UTC"
  892. # time-stamp-end: "; # UTC"
  893. # End: