bootstrap 14 KB

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