bootstrap 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. #! /bin/sh
  2. # Bootstrap this package from CVS.
  3. # Copyright (C) 2003, 2004, 2005, 2006 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 2, 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[=LANG] Update po file(s) and exit.
  43. --cvs-user=USERNAME Set the CVS username to be used when accessing
  44. the gnulib 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 ${CVS_AUTH-pserver} in
  58. pserver)
  59. CVS_PREFIX=':pserver:anonymous@';;
  60. ssh)
  61. CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
  62. *)
  63. echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
  64. exit 1;;
  65. esac
  66. case $CVS_RSH in
  67. '') CVS_RSH=ssh; export CVS_RSH;;
  68. esac
  69. trap "cleanup $1" 1 2 13 15
  70. cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/"$1" co $1 ||
  71. cleanup $1
  72. trap - 1 2 13 15
  73. fi
  74. }
  75. cleanup() {
  76. status=$?
  77. rm -fr $1
  78. exit $status
  79. }
  80. # Configuration.
  81. # List of gnulib modules needed.
  82. gnulib_modules=
  83. # Any gnulib files needed that are not in modules.
  84. gnulib_files=
  85. # Translation Project URL, for the registry of all projects
  86. # and for the translation-team master directory.
  87. TP_URL='http://www.iro.umontreal.ca/translation/registry.cgi?domain='
  88. TP_PO_URL='http://www.iro.umontreal.ca/translation/teams/PO/'
  89. extract_package_name='
  90. /^AC_INIT(/{
  91. /.*,.*,.*,/{
  92. s///
  93. s/[][]//g
  94. p
  95. q
  96. }
  97. s/AC_INIT(\[*//
  98. s/]*,.*//
  99. s/^GNU //
  100. y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
  101. s/[^A-Za-z0-9_]/-/g
  102. p
  103. }
  104. '
  105. package=`sed -n "$extract_package_name" configure.ac` || exit
  106. # Extra files from gnulib, which override files from other sources.
  107. gnulib_extra_files='
  108. build-aux/announce-gen
  109. build-aux/install-sh
  110. build-aux/missing
  111. build-aux/mdate-sh
  112. build-aux/texinfo.tex
  113. build-aux/depcomp
  114. build-aux/config.guess
  115. build-aux/config.sub
  116. doc/INSTALL
  117. '
  118. # Other locale categories that need message catalogs.
  119. EXTRA_LOCALE_CATEGORIES=
  120. # Additional xgettext options to use. Use "\\\newline" to break lines.
  121. XGETTEXT_OPTIONS='\\\
  122. --flag=_:1:pass-c-format\\\
  123. --flag=N_:1:pass-c-format\\\
  124. --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
  125. '
  126. # Files we don't want to import.
  127. excluded_files=
  128. # File that should exist in the top directory of a checked out hierarchy,
  129. # but not in a distribution tarball.
  130. CVS_only_file=README-cvs
  131. # Whether to use copies instead of symlinks.
  132. copy=false
  133. # Override the default configuration, if necessary.
  134. test -r bootstrap.conf && . ./bootstrap.conf
  135. # Read local configuration file
  136. if [ -r .bootstrap ]; then
  137. echo "$0: Reading configuration file .bootstrap"
  138. eval set -- "`sed 's/#.*$//;/^$/d' .bootstrap | tr '\n' ' '` $*"
  139. fi
  140. # Translate configuration into internal form.
  141. # Parse options.
  142. for option
  143. do
  144. case $option in
  145. --help)
  146. usage
  147. exit;;
  148. --paxutils-srcdir=*)
  149. PAXUTILS_SRCDIR=`expr "$option" : '--paxutils-srcdir=\(.*\)'`;;
  150. --gnulib-srcdir=*)
  151. GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
  152. --cvs-user=*)
  153. CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
  154. --skip-po | --no-po) # --no-po is for compatibility with 'tar' tradition.
  155. DOWNLOAD_PO=skip;;
  156. --update-po=*)
  157. DOWNLOAD_PO=`expr "$option" : '--update-po=\(.*\)'`;;
  158. --update-po)
  159. DOWNLOAD_PO=only;;
  160. --force)
  161. CVS_only_file=;;
  162. --copy)
  163. copy=true;;
  164. *)
  165. echo >&2 "$0: $option: unknown option"
  166. exit 1;;
  167. esac
  168. done
  169. if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
  170. echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
  171. exit 1
  172. fi
  173. echo "$0: Bootstrapping CVS $package..."
  174. # Get translations.
  175. get_translations() {
  176. subdir=$1
  177. domain=$2
  178. po_file=$3
  179. case $WGET_COMMAND in
  180. '')
  181. echo "$0: wget not available; skipping translations";;
  182. ?*)
  183. echo "$0: getting ${po_file:-translations} into $subdir for $domain..." &&
  184. case $po_file in
  185. '') (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`);;
  186. esac &&
  187. $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
  188. sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
  189. sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
  190. awk -F. '
  191. { if (lang && $1 != lang) print lang, ver }
  192. { lang = $1; ver = substr($0, index($0, ".") + 1) }
  193. END { if (lang) print lang, ver }
  194. ' | awk -v domain="$domain" -v po_file="$po_file" -v subdir="$subdir" '
  195. {
  196. lang = $1
  197. if (po_file && po_file != (lang ".po")) next
  198. ver = $2
  199. urlfmt = ""
  200. printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
  201. printf " msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
  202. printf " echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
  203. printf " rm -f %s/%s.po; }; } &&\n", subdir, lang
  204. }
  205. END { print ":" }
  206. ' | WGET_COMMAND="$WGET_COMMAND" sh;;
  207. esac &&
  208. ls "$subdir"/*.po 2>/dev/null |
  209. sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
  210. rm -f "$subdir/$domain.html"
  211. }
  212. case `wget --help` in
  213. *'--no-cache'*)
  214. WGET_COMMAND='wget -nv --no-cache';;
  215. *'--cache=on/off'*)
  216. WGET_COMMAND='wget -nv --cache=off';;
  217. *'--non-verbose'*)
  218. WGET_COMMAND='wget -nv';;
  219. *)
  220. WGET_COMMAND='';;
  221. esac
  222. case $DOWNLOAD_PO in
  223. 'skip')
  224. ;;
  225. '')
  226. get_translations po $package || exit
  227. ;;
  228. 'only')
  229. get_translations po $package
  230. exit
  231. ;;
  232. *.po)
  233. get_translations po $package "$DOWNLOAD_PO"
  234. exit
  235. ;;
  236. *)
  237. get_translations po $package "${DOWNLOAD_PO}.po"
  238. exit
  239. esac
  240. # Get paxutils files.
  241. case ${PAXUTILS_SRCDIR--} in
  242. -) checkout paxutils
  243. PAXUTILS_SRCDIR=paxutils
  244. esac
  245. if [ -r $PAXUTILS_SRCDIR/gnulib.modules ]; then
  246. gnulib_modules=`
  247. (echo "$gnulib_modules"; grep '^[^#]' $PAXUTILS_SRCDIR/gnulib.modules) |
  248. sort -u
  249. `
  250. fi
  251. # copy_files srcdir dstdir
  252. copy_files() {
  253. for file in `cat $1/DISTFILES`
  254. do
  255. case $file in
  256. "#*") continue;;
  257. esac
  258. dst=`echo $file | sed 's^.*/^^'`
  259. if [ $# -eq 3 ]; then
  260. case $dst in
  261. ${3}*) ;;
  262. *) dst=${3}$dst;;
  263. esac
  264. fi
  265. echo "$0: Copying file $1/$file to $2/$dst"
  266. cp -p $1/$file $2/$dst
  267. done
  268. }
  269. copy_files ${PAXUTILS_SRCDIR}/m4 m4
  270. echo "$0: Creating m4/paxutils.m4"
  271. (echo "# This file is generated automatically. Please, do not edit."
  272. echo "#"
  273. echo "AC_DEFUN([${package}_PAXUTILS],["
  274. cat ${PAXUTILS_SRCDIR}/m4/DISTFILES | sed '/^#/d;s/\(.*\)\.m4/pu_\1/' | tr a-z A-Z
  275. echo "])") > ./m4/paxutils.m4
  276. if [ -d rmt ]; then
  277. :
  278. else
  279. mkdir rmt
  280. fi
  281. for dir in doc rmt lib tests
  282. do
  283. copy_files ${PAXUTILS_SRCDIR}/$dir $dir
  284. done
  285. copy_files ${PAXUTILS_SRCDIR}/paxlib lib pax
  286. # Get gnulib files.
  287. case ${GNULIB_SRCDIR--} in
  288. -)
  289. checkout gnulib
  290. GNULIB_SRCDIR=gnulib
  291. esac
  292. gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
  293. <$gnulib_tool || exit
  294. symlink_to_gnulib()
  295. {
  296. src=$GNULIB_SRCDIR/$1
  297. dst=${2-$1}
  298. test -f "$src" && {
  299. if $copy; then
  300. {
  301. test ! -h "$dst" || {
  302. echo "$0: rm -f $dst" &&
  303. rm -f "$dst"
  304. }
  305. } &&
  306. test -f "$dst" &&
  307. cmp -s "$src" "$dst" || {
  308. echo "$0: cp -fp $src $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. ln -fs "$dot_dots$src" "$dst"
  331. }
  332. fi
  333. }
  334. }
  335. cp_mark_as_generated()
  336. {
  337. cp_src=$1
  338. cp_dst=$2
  339. if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
  340. symlink_to_gnulib "$cp_dst"
  341. else
  342. case $cp_dst in
  343. *.[ch]) c1='/* '; c2=' */';;
  344. *.texi) c1='@c '; c2= ;;
  345. *.m4|*/Make*|Make*) c1='# ' ; c2= ;;
  346. *) c1= ; c2= ;;
  347. esac
  348. if test -z "$c1"; then
  349. cmp -s "$cp_src" "$cp_dst" || {
  350. echo "$0: cp -f $cp_src $cp_dst" &&
  351. cp -f "$cp_src" "$cp_dst"
  352. }
  353. else
  354. # Copy the file first to get proper permissions if it
  355. # doesn't already exist. Then overwrite the copy.
  356. cp "$cp_src" "$cp_dst-t" &&
  357. (
  358. echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
  359. echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
  360. cat "$cp_src"
  361. ) > $cp_dst-t &&
  362. if cmp -s "$cp_dst-t" "$cp_dst"; then
  363. rm -f "$cp_dst-t"
  364. else
  365. echo "$0: cp $cp_src $cp_dst # with edits" &&
  366. mv -f "$cp_dst-t" "$cp_dst"
  367. fi
  368. fi
  369. fi
  370. }
  371. version_controlled_file() {
  372. dir=$1
  373. file=$2
  374. found=no
  375. if test -d CVS; then
  376. grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
  377. grep '^/[^/]*/[0-9]' > /dev/null && found=yes
  378. elif test -d .git; then
  379. git-rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
  380. else
  381. echo "$0: no version control for $dir/$file?" >&2
  382. fi
  383. test $found = yes
  384. }
  385. slurp() {
  386. for dir in . `(cd $1 && find * -type d -print)`; do
  387. copied=
  388. sep=
  389. for file in `ls $1/$dir`; do
  390. test -d $1/$dir/$file && continue
  391. for excluded_file in $excluded_files; do
  392. test "$dir/$file" = "$excluded_file" && continue 2
  393. done
  394. if test $file = Makefile.am; then
  395. copied=$copied${sep}gnulib.mk; sep=$nl
  396. remove_intl='/^[^#].*\/intl/s/^/#/'
  397. sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/gnulib.mk || {
  398. echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
  399. rm -f $dir/gnulib.mk &&
  400. sed "$remove_intl" $1/$dir/$file >$dir/gnulib.mk
  401. }
  402. elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
  403. version_controlled_file $dir $file; then
  404. echo "$0: $dir/$file overrides $1/$dir/$file"
  405. else
  406. copied=$copied$sep$file; sep=$nl
  407. if test $file = gettext.m4; then
  408. echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
  409. rm -f $dir/$file
  410. sed '
  411. /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
  412. AC_DEFUN([AM_INTL_SUBDIR], [
  413. /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
  414. AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
  415. $a\
  416. AC_DEFUN([gl_LOCK_EARLY], [])
  417. ' $1/$dir/$file >$dir/$file
  418. else
  419. cp_mark_as_generated $1/$dir/$file $dir/$file
  420. fi
  421. fi || exit
  422. done
  423. for dot_ig in .cvsignore .gitignore; do
  424. ig=$dir/$dot_ig
  425. if test -n "$copied" && test -f $ig; then
  426. echo "$copied" | sort -u - $ig | cmp -s - $ig ||
  427. echo "$copied" | sort -u - $ig -o $ig || exit
  428. fi
  429. done
  430. done
  431. }
  432. # Create boot temporary directories to import from gnulib and gettext.
  433. bt='.#bootmp'
  434. bt2=${bt}2
  435. rm -fr $bt $bt2 &&
  436. mkdir $bt $bt2 || exit
  437. # Import from gnulib.
  438. test -d build-aux || {
  439. echo "$0: mkdir build-aux ..." &&
  440. mkdir build-aux
  441. } || exit
  442. gnulib_tool_options="\
  443. --import\
  444. --no-changelog\
  445. --aux-dir $bt/build-aux\
  446. --doc-base $bt/doc\
  447. --lib lib$package\
  448. --m4-base $bt/m4/\
  449. --source-base $bt/lib/\
  450. --tests-base $bt/tests\
  451. --local-dir gl\
  452. "
  453. echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
  454. $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
  455. slurp $bt || exit
  456. for file in $gnulib_files; do
  457. symlink_to_gnulib $file || exit
  458. done
  459. # Import from gettext.
  460. echo "$0: (cd $bt2; autopoint) ..."
  461. cp configure.ac $bt2 &&
  462. (cd $bt2 && autopoint && rm configure.ac) &&
  463. slurp $bt2 $bt || exit
  464. rm -fr $bt $bt2 || exit
  465. # Reconfigure, getting other files.
  466. for command in \
  467. 'aclocal --force -I m4' \
  468. 'autoconf --force' \
  469. 'autoheader --force' \
  470. 'automake --add-missing --copy --force-missing';
  471. do
  472. echo "$0: $command ..."
  473. $command || exit
  474. done
  475. # Get some extra files from gnulib, overriding existing files.
  476. for file in $gnulib_extra_files; do
  477. case $file in
  478. */INSTALL) dst=INSTALL;;
  479. *) dst=$file;;
  480. esac
  481. symlink_to_gnulib $file $dst || exit
  482. done
  483. # Create gettext configuration.
  484. echo "$0: Creating po/Makevars from po/Makevars.template ..."
  485. rm -f po/Makevars
  486. sed '
  487. /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
  488. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  489. /^XGETTEXT_OPTIONS *=/{
  490. s/$/ \\/
  491. a\
  492. '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
  493. }
  494. ' po/Makevars.template >po/Makevars
  495. if test -d runtime-po; then
  496. # Similarly for runtime-po/Makevars, but not quite the same.
  497. rm -f runtime-po/Makevars
  498. sed '
  499. /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
  500. /^subdir *=.*/s/=.*/= runtime-po/
  501. /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
  502. /^XGETTEXT_OPTIONS *=/{
  503. s/$/ \\/
  504. a\
  505. '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
  506. }
  507. ' <po/Makevars.template >runtime-po/Makevars
  508. # Copy identical files from po to runtime-po.
  509. (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
  510. fi
  511. echo "$0: done. Now you can run './configure'."