4c7d9e637c57913216ddc24ab15aed972d338695
[debian/tar] / bootstrap
1 #! /bin/sh
2
3 # Bootstrap this package from CVS.
4
5 # Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
6
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.
11
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.
16
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.
21
22 # Written by Paul Eggert and Sergey Poznyakoff.
23
24 nl='
25 '
26
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
31
32 usage() {
33   echo >&2 "\
34 Usage: $0 [OPTION]...
35 Bootstrap this package from the checked-out sources.
36
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[=LANG]       Update po file(s) and exit.
53  --cvs-user=USERNAME      Set the CVS username to be used when accessing
54                           the gnulib repository.
55
56 If the file bootstrap.conf exists in the current working directory, its
57 contents are read as shell variables to configure the bootstrap.
58
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. 
63
64 Running without arguments will suffice in most cases.
65 "
66 }
67
68 checkout() {
69   if [ ! -d $1 ]; then
70     echo "$0: getting $1 files..."
71
72     case ${CVS_AUTH-pserver} in
73     pserver)
74       CVS_PREFIX=':pserver:anonymous@';;
75     ssh)
76       CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
77     *)
78       echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
79       exit 1;;
80     esac
81
82     case $CVS_RSH in
83     '') CVS_RSH=ssh; export CVS_RSH;;
84     esac
85
86     trap "cleanup $1" 1 2 13 15
87
88     cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/"$1" co $1 ||
89       cleanup $1
90
91     trap - 1 2 13 15
92   fi
93 }
94
95 cleanup() {
96   status=$?
97   rm -fr $1
98   exit $status
99 }
100
101 # Configuration.
102
103 # List of gnulib modules needed.
104 gnulib_modules=
105
106 # Any gnulib files needed that are not in modules.
107 gnulib_files=
108
109 # Translation Project URL, for the registry of all projects
110 # and for the translation-team master directory.
111 tp_url() {
112         echo "http://translationproject.org/domain/$1.html"
113 }
114
115 extract_package_name='
116   /^AC_INIT(/{
117      /.*,.*,.*,/{
118        s///
119        s/[][]//g
120        p
121        q
122      }
123      s/AC_INIT(\[*//
124      s/]*,.*//
125      s/^GNU //
126      y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
127      s/[^A-Za-z0-9_]/-/g
128      p
129   }
130 '
131 package=`sed -n "$extract_package_name" configure.ac` || exit
132
133 # Extra files from gnulib, which override files from other sources.
134 gnulib_extra_files='
135         build-aux/announce-gen
136         build-aux/install-sh
137         build-aux/missing
138         build-aux/mdate-sh
139         build-aux/texinfo.tex
140         build-aux/depcomp
141         build-aux/config.guess
142         build-aux/config.sub
143         doc/INSTALL
144 '
145
146 # Other locale categories that need message catalogs.
147 EXTRA_LOCALE_CATEGORIES=
148
149 # Additional xgettext options to use.  Use "\\\newline" to break lines.
150 XGETTEXT_OPTIONS='\\\
151  --flag=_:1:pass-c-format\\\
152  --flag=N_:1:pass-c-format\\\
153  --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
154 '
155
156 # Files we don't want to import.
157 excluded_files=
158
159 # File that should exist in the top directory of a checked out hierarchy,
160 # but not in a distribution tarball.
161 CVS_only_file=README-cvs
162
163 # Whether to use copies instead of symlinks.
164 copy=false
165
166 # Override the default configuration, if necessary.
167 test -r bootstrap.conf && . ./bootstrap.conf
168
169 # Read local configuration file
170 if [ -r .bootstrap ]; then
171   echo "$0: Reading configuration file .bootstrap"
172   eval set -- "`sed 's/#.*$//;/^$/d' .bootstrap | tr '\n' ' '` $*"
173 fi
174
175 # Translate configuration into internal form.
176
177 # Parse options.
178
179 for option
180 do
181   case $option in
182   --help)
183     usage
184     exit;;
185   --paxutils-srcdir=*)
186     PAXUTILS_SRCDIR=`expr "$option" : '--paxutils-srcdir=\(.*\)'`;;
187   --gnulib-srcdir=*)
188     GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
189   --cvs-user=*)
190     CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
191   --skip-po | --no-po) # --no-po is for compatibility with 'tar' tradition.
192     DOWNLOAD_PO=skip;;
193   --update-po=*)
194     DOWNLOAD_PO=`expr "$option" : '--update-po=\(.*\)'`;;
195   --update-po)
196     DOWNLOAD_PO=only;;
197   --force)
198     CVS_only_file=;;
199   --copy)
200     copy=true;;
201   *)
202     echo >&2 "$0: $option: unknown option"
203     exit 1;;
204   esac
205 done
206
207 if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
208   echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
209   exit 1
210 fi
211
212 echo "$0: Bootstrapping CVS $package..."
213
214 # Get translations.
215
216 get_translations() {
217   subdir=$1
218   domain=$2
219   po_file=$3
220
221   case $WGET_COMMAND in
222   '')
223     echo "$0: wget not available; skipping translations";;
224   ?*)
225     url=`tp_url $domain`
226     baseurl=`expr "$url" : '\(.*\)/.*'`
227     echo "$0: getting translations into $subdir for $domain..." &&
228     case $po_file in
229     '') (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`);;
230     esac &&
231
232     $WGET_COMMAND -O "$subdir/$domain.html" "$url" &&
233
234     sed -n 's|.*href="\(.*\)/\([^/][^/]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\2:\3:\1|p' <"$subdir/$domain.html" |
235     sort -t: -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
236     awk -F: '
237       { if (lang && $1 != lang) print lang, ver, $3 }
238       { lang = $1; ver = $2 }
239       END { if (lang) print lang, ver, $3 }
240     ' | awk -v domain="$domain" -v baseurl="$baseurl" -v subdir="$subdir" \
241             -v po_file="$po_file" '
242       {
243         lang = $1
244         if (po_file && po_file != (lang ".po")) next
245         ver = $2
246         printf "{ $WGET_COMMAND -O %s/%s.po %s/%s/%s/%s-%s.%s.po &&\n", subdir, lang, baseurl, $3, lang, domain, ver, lang
247         printf "  msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
248         printf "    echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
249         printf "    rm -f %s/%s.po; }; } &&\n", subdir, lang
250       }
251       END { print ":" }
252     ' | WGET_COMMAND="$WGET_COMMAND" sh 
253     ;;
254   esac &&
255   ls "$subdir"/*.po 2>/dev/null |
256     sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
257   rm -f "$subdir/$domain.html"
258 }
259
260 case `wget --help` in
261 *'--no-cache'*)
262     WGET_COMMAND='wget -nv --no-cache';;
263 *'--cache=on/off'*)
264     WGET_COMMAND='wget -nv --cache=off';;
265 *'--non-verbose'*)
266     WGET_COMMAND='wget -nv';;
267 *)
268     WGET_COMMAND='';;
269 esac
270
271 case $DOWNLOAD_PO in
272 'skip')
273   ;;
274 '')
275   get_translations po $package || exit
276   ;;
277 'only')
278   get_translations po $package
279   exit
280   ;;
281 *.po)
282   get_translations po $package "$DOWNLOAD_PO"
283   exit
284   ;;
285 *)
286   get_translations po $package "${DOWNLOAD_PO}.po"
287   exit
288 esac
289
290 # Get paxutils files.
291
292 case ${PAXUTILS_SRCDIR--} in
293 -) checkout paxutils
294    PAXUTILS_SRCDIR=paxutils
295 esac
296
297 if [ -r $PAXUTILS_SRCDIR/gnulib.modules ]; then
298   gnulib_modules=`
299     (echo "$gnulib_modules"; grep '^[^#]' $PAXUTILS_SRCDIR/gnulib.modules) |
300     sort -u
301   `
302 fi
303
304 ignore_file_list=
305 cleanup_ifl() {
306         test -n "$ignore_file_list" && rm -f $ignore_file_list
307 }
308
309 trap 'cleanup_ifl' 1 2 3 15
310
311 # ignorefile DIR FILE 
312 #  add FILE to the temporary ignorelist in the directory DIR
313 ignorefile() {
314   file=$1/.ignore.$$ 
315   echo "$2" >> $file
316   if `echo $ignore_list | grep -qv $file`; then
317     ignore_file_list="$ignore_file_list
318 $file"
319   fi
320 }  
321
322 # copy_files srcdir dstdir
323 copy_files() {
324   for file in `cat $1/DISTFILES`
325   do
326     case $file in
327     "#*")  continue;;
328     esac
329     dst=`echo $file | sed 's^.*/^^'`
330     if [ $# -eq 3 ]; then
331       case $dst in
332       ${3}*) ;;
333       *) dst=${3}$dst;;
334       esac
335     fi
336     echo "$0: Copying file $1/$file to $2/$dst"
337     cp -p $1/$file $2/$dst
338     ignorefile $2 $dst
339   done
340 }
341
342 copy_files ${PAXUTILS_SRCDIR}/m4 m4
343 echo "$0: Creating m4/paxutils.m4"
344 (echo "# This file is generated automatically. Please, do not edit."
345  echo "#"
346  echo "AC_DEFUN([${package}_PAXUTILS],["
347  cat ${PAXUTILS_SRCDIR}/m4/DISTFILES | sed '/^#/d;s/\(.*\)\.m4/pu_\1/' | tr a-z A-Z
348  echo "])") > ./m4/paxutils.m4
349 ignorefile m4 paxutils.m4
350
351 if [ -d rmt ]; then
352    :
353 else
354    mkdir rmt
355 fi
356
357 for dir in doc rmt lib tests
358 do
359         copy_files ${PAXUTILS_SRCDIR}/$dir $dir
360 done
361
362 copy_files ${PAXUTILS_SRCDIR}/paxlib lib pax
363
364 # Get gnulib files.
365
366 case ${GNULIB_SRCDIR--} in
367 -)
368   checkout gnulib
369   GNULIB_SRCDIR=gnulib
370 esac
371
372 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
373 <$gnulib_tool || exit
374
375 ensure_dir_exists()
376 {
377   d=`dirname $dst`
378   test -d "$d" || mkdir -p -- "$d"
379 }
380
381 symlink_to_gnulib()
382 {
383   src=$GNULIB_SRCDIR/$1
384   dst=${2-$1}
385
386   test -f "$src" && {
387     if $copy; then
388       {
389         test ! -h "$dst" || {
390           echo "$0: rm -f $dst" &&
391           rm -f "$dst"
392         }
393       } &&
394       test -f "$dst" &&
395       cmp -s "$src" "$dst" || {
396         echo "$0: cp -fp $src $dst" &&
397         ensure_dir_exists $dst &&
398         cp -fp "$src" "$dst"
399       }
400     else
401       test -h "$dst" &&
402       src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
403       dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
404       test "$src_i" = "$dst_i" || {
405         dot_dots=
406         case $src in
407         /*) ;;
408         *)
409           case /$dst/ in
410           *//* | */../* | */./* | /*/*/*/*/*/)
411              echo >&2 "$0: invalid symlink calculation: $src -> $dst"
412              exit 1;;
413           /*/*/*/*/)    dot_dots=../../../;;
414           /*/*/*/)      dot_dots=../../;;
415           /*/*/)        dot_dots=../;;
416           esac;;
417         esac
418
419         echo "$0: ln -fs $dot_dots$src $dst" &&
420         ensure_dir_exists $dst &&
421         ln -fs "$dot_dots$src" "$dst"
422       }
423     fi
424   }
425 }
426
427 cp_mark_as_generated()
428 {
429   cp_src=$1
430   cp_dst=$2
431
432   if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
433     symlink_to_gnulib "$cp_dst"
434   else
435     case $cp_dst in
436       *.[ch])             c1='/* '; c2=' */';;
437       *.texi)             c1='@c '; c2=     ;;
438       *.m4|*/Make*|Make*) c1='# ' ; c2=     ;;
439       *)                  c1=     ; c2=     ;;
440     esac
441
442     if test -z "$c1"; then
443       cmp -s "$cp_src" "$cp_dst" || {
444         echo "$0: cp -f $cp_src $cp_dst" &&
445         cp -f "$cp_src" "$cp_dst"
446       }
447     else
448       # Copy the file first to get proper permissions if it
449       # doesn't already exist.  Then overwrite the copy.
450       cp "$cp_src" "$cp_dst-t" &&
451       (
452         echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
453         echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
454         cat "$cp_src"
455       ) > $cp_dst-t &&
456       if cmp -s "$cp_dst-t" "$cp_dst"; then
457         rm -f "$cp_dst-t"
458       else
459         echo "$0: cp $cp_src $cp_dst # with edits" &&
460         mv -f "$cp_dst-t" "$cp_dst"
461       fi
462     fi
463   fi
464 }
465
466 version_controlled_file() {
467   dir=$1
468   file=$2
469   found=no
470   if test -d CVS; then
471     grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
472              grep '^/[^/]*/[0-9]' > /dev/null && found=yes
473   elif test -d .git; then
474     git-rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
475   else
476     echo "$0: no version control for $dir/$file?" >&2
477   fi
478   test $found = yes
479 }
480
481 slurp() {
482   for dir in . `(cd $1 && find * -type d -print)`; do
483     copied=
484     sep=
485     for file in `ls $1/$dir`; do
486       test -d $1/$dir/$file && continue
487       for excluded_file in $excluded_files; do
488         test "$dir/$file" = "$excluded_file" && continue 2
489       done
490       if test $file = Makefile.am; then
491         copied=$copied${sep}gnulib.mk; sep=$nl
492         remove_intl='/^[^#].*\/intl/s/^/#/;'"s,/$bt,,g"
493         sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/gnulib.mk || {
494           echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
495           rm -f $dir/gnulib.mk &&
496           sed "$remove_intl" $1/$dir/$file >$dir/gnulib.mk
497         }
498       elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
499            version_controlled_file $dir $file; then
500         echo "$0: $dir/$file overrides $1/$dir/$file"
501       else
502         copied=$copied$sep$file; sep=$nl
503         if test $file = gettext.m4; then
504           echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
505           rm -f $dir/$file
506           sed '
507             /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
508               AC_DEFUN([AM_INTL_SUBDIR], [
509             /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
510               AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
511             $a\
512               AC_DEFUN([gl_LOCK_EARLY], [])
513           ' $1/$dir/$file >$dir/$file
514         else
515           cp_mark_as_generated $1/$dir/$file $dir/$file
516         fi
517       fi || exit
518     done
519
520     if test -n "$copied"; then
521       copied="Makefile
522 Makefile.in
523 $copied"
524       if test -d CVS; then
525         dot_ig=.cvsignore
526       else
527         dor_ig=.gitignore
528       fi
529
530       ig=$dir/$dot_ig
531       if [ -f $dir/.ignore.$$ ]; then
532          tfile=$dir/.ignore.$$
533       else
534          tfile=
535       fi
536       if test -f $ig; then
537           echo "$copied" | sort -u - $ig | cmp -s - $ig ||
538           echo "$copied" | sort -u - $ig $tfile -o $ig
539       else
540           copied="$dot_ig
541 $copied"          
542           if [ "$dir" = "po" ]; then
543             copied="LINGUAS
544 Makevars
545 POTFILES
546 *.mo
547 *.gmo
548 *.po
549 remove-potcdate.sed
550 stamp-po
551 $package.pot
552 $copied"
553           fi  
554           echo "$copied" | sort -u - $tfile -o $ig
555       fi || exit
556     fi
557   done
558 }
559
560
561 # Create boot temporary directories to import from gnulib and gettext.
562
563 bt='.#bootmp'
564 bt2=${bt}2
565 rm -fr $bt $bt2 &&
566 mkdir $bt $bt2 || exit
567
568 # Import from gnulib.
569
570 test -d build-aux || {
571   echo "$0: mkdir build-aux ..." &&
572   mkdir build-aux
573 } || exit
574 gnulib_tool_options="\
575  --import\
576  --no-changelog\
577  --aux-dir $bt/build-aux\
578  --doc-base $bt/doc\
579  --lib lib$package\
580  --m4-base $bt/m4/\
581  --source-base $bt/lib/\
582  --tests-base $bt/tests\
583  --local-dir gl\
584 "
585 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
586 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
587 slurp $bt || exit
588
589 for file in $gnulib_files; do
590   symlink_to_gnulib $file || exit
591 done
592
593
594 # Import from gettext.
595
596 echo "$0: (cd $bt2; autopoint) ..."
597 cp configure.ac $bt2 &&
598 (cd $bt2 && autopoint && rm configure.ac) &&
599 slurp $bt2 $bt || exit
600
601 rm -fr $bt $bt2 || exit
602
603
604 # Reconfigure, getting other files.
605
606 for command in \
607   'aclocal --force -I m4' \
608   'autoconf --force' \
609   'autoheader --force' \
610   'automake --add-missing --copy --force-missing';
611 do
612   echo "$0: $command ..."
613   $command || exit
614 done
615
616
617 # Get some extra files from gnulib, overriding existing files.
618
619 for file in $gnulib_extra_files; do
620   case $file in
621   */INSTALL) dst=INSTALL;;
622   *) dst=$file;;
623   esac
624   symlink_to_gnulib $file $dst || exit
625 done
626
627
628 # Create gettext configuration.
629 echo "$0: Creating po/Makevars from po/Makevars.template ..."
630 rm -f po/Makevars
631 sed '
632   /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
633   /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
634   /^XGETTEXT_OPTIONS *=/{
635     s/$/ \\/
636     a\
637         '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
638   }
639 ' po/Makevars.template >po/Makevars
640
641 if test -d runtime-po; then
642   # Similarly for runtime-po/Makevars, but not quite the same.
643   rm -f runtime-po/Makevars
644   sed '
645     /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
646     /^subdir *=.*/s/=.*/= runtime-po/
647     /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
648     /^XGETTEXT_OPTIONS *=/{
649       s/$/ \\/
650       a\
651           '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
652     }
653   ' <po/Makevars.template >runtime-po/Makevars
654
655   # Copy identical files from po to runtime-po.
656   (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
657 fi
658 cleanup_ifl
659 echo "$0: done.  Now you can run './configure'."