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