bootstrap 33 KB

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