4
0

bootstrap 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. #! /bin/sh
  2. # Bootstrap this package from CVS.
  3. # Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3, or (at your option)
  7. # any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. # 02110-1301, USA.
  16. # Written by Paul Eggert and Sergey Poznyakoff.
  17. nl='
  18. '
  19. # Ensure file names are sorted consistently across platforms.
  20. # Also, ensure diagnostics are in English, e.g., "wget --help" below.
  21. LC_ALL=C
  22. export LC_ALL
  23. usage() {
  24. echo >&2 "\
  25. Usage: $0 [OPTION]...
  26. Bootstrap this package from the checked-out sources.
  27. Options:
  28. --paxutils-srcdir=DIRNAME Specify the local directory where paxutils
  29. sources reside. Use this if you already
  30. have paxutils sources on your machine, and
  31. do not want to waste your bandwidth dowloading
  32. them again.
  33. --gnulib-srcdir=DIRNAME Specify the local directory where gnulib
  34. sources reside. Use this if you already
  35. have gnulib sources on your machine, and
  36. do not want to waste your bandwidth dowloading
  37. them again.
  38. --copy Copy files instead of creating symbolic links.
  39. --force Attempt to bootstrap even if the sources seem
  40. not to have been checked out.
  41. --skip-po Do not download po files.
  42. --update-po Update po files and exit.
  43. --cvs-user=USERNAME Set the CVS username to be used when accessing
  44. the paxutils repository.
  45. If the file bootstrap.conf exists in the current working directory, its
  46. contents are read as shell variables to configure the bootstrap.
  47. Local defaults can be provided by placing the file \`.bootstrap' in the
  48. current working directory. The file is read after bootstrap.conf, comments
  49. and empty lines are removed, shell variables expanded and the result is
  50. prepended to the command line options.
  51. Running without arguments will suffice in most cases.
  52. "
  53. }
  54. checkout() {
  55. if [ ! -d $1 ]; then
  56. echo "$0: getting $1 files..."
  57. case $1 in
  58. paxutils)
  59. case ${CVS_AUTH-pserver} in
  60. pserver)
  61. CVS_PREFIX=':pserver:anonymous@';;
  62. ssh)
  63. CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
  64. *)
  65. echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
  66. exit 1;;
  67. esac
  68. case $CVS_RSH in
  69. '') CVS_RSH=ssh; export CVS_RSH;;
  70. esac
  71. CVSURL=${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/"$1"
  72. ;;
  73. gnulib)
  74. CVSURL=:pserver:[email protected]:/gnulib.git
  75. ;;
  76. esac
  77. trap "cleanup $1" 1 2 13 15
  78. cvs -z3 -q -d $CVSURL co $1 || cleanup $1
  79. trap - 1 2 13 15
  80. fi
  81. }
  82. cleanup() {
  83. status=$?
  84. rm -fr $1
  85. exit $status
  86. }
  87. # Configuration.
  88. # List of gnulib modules needed.
  89. gnulib_modules=
  90. # Any gnulib files needed that are not in modules.
  91. gnulib_files=
  92. # The command to download all .po files for a specified domain into
  93. # a specified directory. Fill in the first %s is the domain name, and
  94. # the second with the destination directory. Use rsync's -L and -r
  95. # options because the latest/%s directory and the .po files within are
  96. # all symlinks.
  97. po_download_command_format=\
  98. "rsync -Lrtvz 'translationproject.org::tp/latest/%s/' '%s'"
  99. extract_package_name='
  100. /^AC_INIT(/{
  101. /.*,.*,.*,/{
  102. s///
  103. s/[][]//g
  104. p
  105. q
  106. }
  107. s/AC_INIT(\[*//
  108. s/]*,.*//
  109. s/^GNU //
  110. y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
  111. s/[^A-Za-z0-9_]/-/g
  112. p
  113. }
  114. '
  115. package=`sed -n "$extract_package_name" configure.ac` || exit
  116. # Extra files from gnulib, which override files from other sources.
  117. gnulib_extra_files='
  118. build-aux/announce-gen
  119. build-aux/install-sh
  120. build-aux/missing
  121. build-aux/mdate-sh
  122. build-aux/texinfo.tex
  123. build-aux/depcomp
  124. build-aux/config.guess
  125. build-aux/config.sub
  126. doc/INSTALL
  127. '
  128. # Other locale categories that need message catalogs.
  129. EXTRA_LOCALE_CATEGORIES=
  130. # Additional xgettext options to use. Use "\\\newline" to break lines.
  131. XGETTEXT_OPTIONS='\\\
  132. --flag=_:1:pass-c-format\\\
  133. --flag=N_:1:pass-c-format\\\
  134. --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
  135. '
  136. # Files we don't want to import.
  137. excluded_files=
  138. # File that should exist in the top directory of a checked out hierarchy,
  139. # but not in a distribution tarball.
  140. CVS_only_file=README-cvs
  141. # Whether to use copies instead of symlinks.
  142. copy=false
  143. # Override the default configuration, if necessary.
  144. test -r bootstrap.conf && . ./bootstrap.conf
  145. # Read local configuration file
  146. if [ -r .bootstrap ]; then
  147. echo "$0: Reading configuration file .bootstrap"
  148. eval set -- "`sed 's/#.*$//;/^$/d' .bootstrap | tr '\n' ' '` $*"
  149. fi
  150. # Translate configuration into internal form.
  151. # Parse options.
  152. for option
  153. do
  154. case $option in
  155. --help)
  156. usage
  157. exit;;
  158. --paxutils-srcdir=*)
  159. PAXUTILS_SRCDIR=`expr "$option" : '--paxutils-srcdir=\(.*\)'`;;
  160. --gnulib-srcdir=*)
  161. GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
  162. --cvs-user=*)
  163. CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
  164. --skip-po | --no-po) # --no-po is for compatibility with 'tar' tradition.
  165. DOWNLOAD_PO=skip;;
  166. --update-po=*)
  167. DOWNLOAD_PO=`expr "$option" : '--update-po=\(.*\)'`;;
  168. --update-po)
  169. DOWNLOAD_PO=only;;
  170. --force)
  171. CVS_only_file=;;
  172. --copy)
  173. copy=true;;
  174. *)
  175. echo >&2 "$0: $option: unknown option"
  176. exit 1;;
  177. esac
  178. done
  179. if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
  180. echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
  181. exit 1
  182. fi
  183. echo "$0: Bootstrapping CVS $package..."
  184. # Get translations.
  185. download_po_files() {
  186. subdir=$1
  187. domain=$2
  188. echo "$0: getting translations into $subdir for $domain..."
  189. cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
  190. eval "$cmd"
  191. }
  192. # Download .po files to $po_dir/.reference and copy only the new
  193. # or modified ones into $po_dir. Also update $po_dir/LINGUAS.
  194. update_po_files() {
  195. # Directory containing primary .po files.
  196. # Overwrite them only when we're sure a .po file is new.
  197. po_dir=$1
  198. domain=$2
  199. # Download *.po files into this dir.
  200. # Usually contains *.s1 checksum files.
  201. ref_po_dir="$po_dir/.reference"
  202. test -d $ref_po_dir || mkdir $ref_po_dir || return
  203. download_po_files $ref_po_dir $domain \
  204. && ls "$ref_po_dir"/*.po 2>/dev/null |
  205. sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
  206. langs=`cd $ref_po_dir && echo *.po|sed 's/\.po//g'`
  207. test "$langs" = '*' && langs=x
  208. for po in `cd $ref_po_dir && echo *.po|sed 's/\.po//g'`; do
  209. case $po in x) continue;; esac
  210. new_po="$ref_po_dir/$po.po"
  211. cksum_file="$ref_po_dir/$po.s1"
  212. if ! test -f "$cksum_file" ||
  213. ! test -f "$po_dir/$po.po" ||
  214. ! sha1sum -c --status "$cksum_file" < "$new_po" > /dev/null; then
  215. echo "updated $po_dir/$po.po..."
  216. cp "$new_po" "$po_dir/$po.po" && sha1sum < "$new_po" > "$cksum_file"
  217. fi
  218. done
  219. }
  220. case $DOWNLOAD_PO in
  221. 'skip')
  222. ;;
  223. '')
  224. if test -d po; then
  225. update_po_files po $package || exit
  226. fi
  227. ;;
  228. 'only')
  229. if test -d po; then
  230. update_po_files po $package || exit
  231. fi
  232. exit
  233. ;;
  234. esac
  235. # Get paxutils files.
  236. case ${PAXUTILS_SRCDIR--} in
  237. -) checkout paxutils
  238. PAXUTILS_SRCDIR=paxutils
  239. esac
  240. if [ -r $PAXUTILS_SRCDIR/gnulib.modules ]; then
  241. gnulib_modules=`
  242. (echo "$gnulib_modules"; grep '^[^#]' $PAXUTILS_SRCDIR/gnulib.modules) |
  243. sort -u
  244. `
  245. fi
  246. ignore_file_list=
  247. cleanup_ifl() {
  248. test -n "$ignore_file_list" && rm -f $ignore_file_list
  249. }
  250. trap 'cleanup_ifl' 1 2 3 15
  251. # ignorefile DIR FILE
  252. # add FILE to the temporary ignorelist in the directory DIR
  253. ignorefile() {
  254. file=$1/.ignore.$$
  255. echo "$2" >> $file
  256. if `echo $ignore_list | grep -qv $file`; then
  257. ignore_file_list="$ignore_file_list
  258. $file"
  259. fi
  260. }
  261. # copy_files srcdir dstdir
  262. copy_files() {
  263. for file in `cat $1/DISTFILES`
  264. do
  265. case $file in
  266. "#*") continue;;
  267. esac
  268. dst=`echo $file | sed 's^.*/^^'`
  269. if [ $# -eq 3 ]; then
  270. case $dst in
  271. ${3}*) ;;
  272. *) dst=${3}$dst;;
  273. esac
  274. fi
  275. echo "$0: Copying file $1/$file to $2/$dst"
  276. cp -p $1/$file $2/$dst
  277. ignorefile $2 $dst
  278. done
  279. }
  280. # Get gnulib files.
  281. case ${GNULIB_SRCDIR--} in
  282. -)
  283. checkout gnulib
  284. GNULIB_SRCDIR=gnulib
  285. esac
  286. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  287. <$gnulib_tool || exit
  288. ensure_dir_exists()
  289. {
  290. d=`dirname $dst`
  291. test -d "$d" || mkdir -p -- "$d"
  292. }
  293. symlink_to_gnulib()
  294. {
  295. src=$GNULIB_SRCDIR/$1
  296. dst=${2-$1}
  297. test -f "$src" && {
  298. if $copy; then
  299. {
  300. test ! -h "$dst" || {
  301. echo "$0: rm -f $dst" &&
  302. rm -f "$dst"
  303. }
  304. } &&
  305. test -f "$dst" &&
  306. cmp -s "$src" "$dst" || {
  307. echo "$0: cp -fp $src $dst" &&
  308. ensure_dir_exists $dst &&
  309. cp -fp "$src" "$dst"
  310. }
  311. else
  312. test -h "$dst" &&
  313. src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
  314. dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
  315. test "$src_i" = "$dst_i" || {
  316. dot_dots=
  317. case $src in
  318. /*) ;;
  319. *)
  320. case /$dst/ in
  321. *//* | */../* | */./* | /*/*/*/*/*/)
  322. echo >&2 "$0: invalid symlink calculation: $src -> $dst"
  323. exit 1;;
  324. /*/*/*/*/) dot_dots=../../../;;
  325. /*/*/*/) dot_dots=../../;;
  326. /*/*/) dot_dots=../;;
  327. esac;;
  328. esac
  329. echo "$0: ln -fs $dot_dots$src $dst" &&
  330. ensure_dir_exists $dst &&
  331. ln -fs "$dot_dots$src" "$dst"
  332. }
  333. fi
  334. }
  335. }
  336. cp_mark_as_generated()
  337. {
  338. cp_src=$1
  339. cp_dst=$2
  340. if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
  341. symlink_to_gnulib "$cp_dst"
  342. else
  343. case $cp_dst in
  344. *.[ch]) c1='/* '; c2=' */';;
  345. *.texi) c1='@c '; c2= ;;
  346. *.m4|*/Make*|Make*) c1='# ' ; c2= ;;
  347. *) c1= ; c2= ;;
  348. esac
  349. if test -z "$c1"; then
  350. cmp -s "$cp_src" "$cp_dst" || {
  351. echo "$0: cp -f $cp_src $cp_dst" &&
  352. cp -f "$cp_src" "$cp_dst"
  353. }
  354. else
  355. # Copy the file first to get proper permissions if it
  356. # doesn't already exist. Then overwrite the copy.
  357. cp "$cp_src" "$cp_dst-t" &&
  358. (
  359. echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
  360. echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
  361. cat "$cp_src"
  362. ) > $cp_dst-t &&
  363. if cmp -s "$cp_dst-t" "$cp_dst"; then
  364. rm -f "$cp_dst-t"
  365. else
  366. echo "$0: cp $cp_src $cp_dst # with edits" &&
  367. mv -f "$cp_dst-t" "$cp_dst"
  368. fi
  369. fi
  370. fi
  371. }
  372. version_controlled_file() {
  373. dir=$1
  374. file=$2
  375. found=no
  376. if test -d CVS; then
  377. grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
  378. grep '^/[^/]*/[0-9]' > /dev/null && found=yes
  379. elif test -d .git; then
  380. git-rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
  381. else
  382. echo "$0: no version control for $dir/$file?" >&2
  383. fi
  384. test $found = yes
  385. }
  386. slurp() {
  387. for dir in . `(cd $1 && find * -type d -print)`; do
  388. copied=
  389. sep=
  390. for file in `ls $1/$dir`; do
  391. test -d $1/$dir/$file && continue
  392. for excluded_file in $excluded_files; do
  393. test "$dir/$file" = "$excluded_file" && continue 2
  394. done
  395. if test $file = Makefile.am; then
  396. copied=$copied${sep}gnulib.mk; sep=$nl
  397. remove_intl='/^[^#].*\/intl/s/^/#/;'"s,/$bt,,g"
  398. sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/gnulib.mk || {
  399. echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
  400. rm -f $dir/gnulib.mk &&
  401. sed "$remove_intl" $1/$dir/$file >$dir/gnulib.mk
  402. }
  403. elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
  404. version_controlled_file $dir $file; then
  405. echo "$0: $dir/$file overrides $1/$dir/$file"
  406. else
  407. copied=$copied$sep$file; sep=$nl
  408. if test $file = gettext.m4; then
  409. echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
  410. rm -f $dir/$file
  411. sed '
  412. /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
  413. AC_DEFUN([AM_INTL_SUBDIR], [
  414. /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
  415. AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
  416. $a\
  417. AC_DEFUN([gl_LOCK_EARLY], [])
  418. ' $1/$dir/$file >$dir/$file
  419. else
  420. cp_mark_as_generated $1/$dir/$file $dir/$file
  421. fi
  422. fi || exit
  423. done
  424. if test -n "$copied"; then
  425. copied="Makefile
  426. Makefile.in
  427. $copied"
  428. if test -d CVS; then
  429. dot_ig=.cvsignore
  430. else
  431. dor_ig=.gitignore
  432. fi
  433. ig=$dir/$dot_ig
  434. if [ -f $dir/.ignore.$$ ]; then
  435. tfile=$dir/.ignore.$$
  436. else
  437. tfile=
  438. fi
  439. if test -f $ig; then
  440. echo "$copied" | sort -u - $ig | cmp -s - $ig ||
  441. echo "$copied" | sort -u - $ig $tfile -o $ig
  442. else
  443. copied="$dot_ig
  444. $copied"
  445. if [ "$dir" = "po" ]; then
  446. copied="LINGUAS
  447. Makevars
  448. POTFILES
  449. *.mo
  450. *.gmo
  451. *.po
  452. remove-potcdate.sed
  453. stamp-po
  454. $package.pot
  455. $copied"
  456. fi
  457. echo "$copied" | sort -u - $tfile -o $ig
  458. fi || exit
  459. fi
  460. done
  461. }
  462. # Create boot temporary directories to import from gnulib and gettext.
  463. bt='.#bootmp'
  464. bt2=${bt}2
  465. rm -fr $bt $bt2 &&
  466. mkdir $bt $bt2 || exit
  467. # Import from gnulib.
  468. test -d build-aux || {
  469. echo "$0: mkdir build-aux ..." &&
  470. mkdir build-aux
  471. } || exit
  472. gnulib_tool_options="\
  473. --import\
  474. --no-changelog\
  475. --aux-dir $bt/build-aux\
  476. --doc-base $bt/doc\
  477. --lib lib$package\
  478. --m4-base $bt/m4/\
  479. --source-base $bt/lib/\
  480. --tests-base $bt/tests\
  481. --local-dir gl\
  482. "
  483. echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
  484. $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
  485. slurp $bt || exit
  486. for file in $gnulib_files; do
  487. symlink_to_gnulib $file || exit
  488. done
  489. # Import from gettext.
  490. echo "$0: (cd $bt2; autopoint) ..."
  491. cp configure.ac $bt2 &&
  492. (cd $bt2 && autopoint && rm configure.ac) &&
  493. slurp $bt2 $bt || exit
  494. rm -fr $bt $bt2 || exit
  495. # Import from paxutils
  496. copy_files ${PAXUTILS_SRCDIR}/m4 m4
  497. echo "$0: Creating m4/paxutils.m4"
  498. (echo "# This file is generated automatically. Please, do not edit."
  499. echo "#"
  500. echo "AC_DEFUN([${package}_PAXUTILS],["
  501. cat ${PAXUTILS_SRCDIR}/m4/DISTFILES | sed '/^#/d;s/\(.*\)\.m4/pu_\1/' | tr a-z A-Z
  502. echo "])") > ./m4/paxutils.m4
  503. ignorefile m4 paxutils.m4
  504. if [ -d rmt ]; then
  505. :
  506. else
  507. mkdir rmt
  508. fi
  509. for dir in doc rmt lib tests
  510. do
  511. copy_files ${PAXUTILS_SRCDIR}/$dir $dir
  512. done
  513. copy_files ${PAXUTILS_SRCDIR}/paxlib lib pax
  514. # Reconfigure, getting other files.
  515. for command in \
  516. 'aclocal --force -I m4' \
  517. 'autoconf --force' \
  518. 'autoheader --force' \
  519. 'automake --add-missing --copy --force-missing';
  520. do
  521. echo "$0: $command ..."
  522. $command || exit
  523. done
  524. # Get some extra files from gnulib, overriding existing files.
  525. for file in $gnulib_extra_files; do
  526. case $file in
  527. */INSTALL) dst=INSTALL;;
  528. *) dst=$file;;
  529. esac
  530. symlink_to_gnulib $file $dst || exit
  531. done
  532. # Create gettext configuration.
  533. echo "$0: Creating po/Makevars from po/Makevars.template ..."
  534. rm -f po/Makevars
  535. sed '
  536. /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  537. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  538. /^XGETTEXT_OPTIONS *=/{
  539. s/$/ \\/
  540. a\
  541. '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  542. }
  543. ' po/Makevars.template >po/Makevars
  544. if test -d runtime-po; then
  545. # Similarly for runtime-po/Makevars, but not quite the same.
  546. rm -f runtime-po/Makevars
  547. sed '
  548. /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
  549. /^subdir *=.*/s/=.*/= runtime-po/
  550. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  551. /^XGETTEXT_OPTIONS *=/{
  552. s/$/ \\/
  553. a\
  554. '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
  555. }
  556. ' <po/Makevars.template >runtime-po/Makevars
  557. # Copy identical files from po to runtime-po.
  558. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
  559. fi
  560. cleanup_ifl
  561. echo "$0: done. Now you can run './configure'."