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