* 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 # Other locale categories that need message catalogs.
101 EXTRA_LOCALE_CATEGORIES=
102
103 # Whether to use gettext by default.
104 IMPORT_FROM_GETTEXT=yes
105
106 # Additional xgettext options to use.  Use "\\\newline" to break lines.
107 XGETTEXT_OPTIONS='\\\
108  --flag=_:1:pass-c-format\\\
109  --flag=N_:1:pass-c-format\\\
110  --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
111 '
112
113 # Files we don't want to import.
114 excluded_files=
115
116 # File that should exist in the top directory of a checked out hierarchy,
117 # but not in a distribution tarball.
118 CVS_only_file=README-cvs
119
120 # Whether to use copies instead of symlinks.
121 copy=false
122
123 # Override the default configuration, if necessary.
124 test -r bootstrap.conf && . ./bootstrap.conf
125
126 # Translate configuration into internal form.
127
128 # Parse options.
129
130 for option
131 do
132   case $option in
133   --help)
134     usage
135     exit;;
136   --gnulib-srcdir=*)
137     GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
138   --cvs-user=*)
139     CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
140   --skip-po)
141     SKIP_PO=t;;
142   --force)
143     CVS_only_file=;;
144   --copy)
145     copy=true;;
146   *)
147     echo >&2 "$0: $option: unknown option"
148     exit 1;;
149   esac
150 done
151
152 if test -n "$CVS_only_file" && test ! -r "$CVS_only_file"; then
153   echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
154   exit 1
155 fi
156
157 echo "$0: Bootstrapping CVS $package..."
158
159 cleanup_gnulib() {
160   status=$?
161   rm -fr gnulib
162   exit $status
163 }
164
165 # Get gnulib files.
166
167 case ${GNULIB_SRCDIR--} in
168 -)
169   if [ ! -d gnulib ]; then
170     echo "$0: getting gnulib files..."
171
172     case ${CVS_AUTH-pserver} in
173     pserver)
174       CVS_PREFIX=':pserver:anonymous@';;
175     ssh)
176       CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
177     *)
178       echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
179       exit 1;;
180     esac
181
182     case $CVS_RSH in
183     '') CVS_RSH=ssh; export CVS_RSH;;
184     esac
185
186     trap cleanup_gnulib 1 2 13 15
187
188     cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/gnulib co gnulib ||
189       cleanup_gnulib
190
191     trap - 1 2 13 15
192   fi
193   GNULIB_SRCDIR=gnulib
194 esac
195
196 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
197 <$gnulib_tool || exit
198
199 # Get translations.
200
201 get_translations() {
202   subdir=$1
203   domain=$2
204
205   case $WGET_COMMAND in
206   '')
207     echo "$0: wget not available; skipping translations";;
208   ?*)
209     echo "$0: getting translations into $subdir for $domain..." &&
210
211     (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`) &&
212     $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
213
214     sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
215     sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
216     awk -F. '
217       { if (lang && $1 != lang) print lang, ver }
218       { lang = $1; ver = substr($0, index($0, ".") + 1) }
219       END { if (lang) print lang, ver }
220     ' | awk -v domain="$domain" -v subdir="$subdir" '
221       {
222         lang = $1
223         ver = $2
224         urlfmt = ""
225         printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
226         printf "  msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
227         printf "    echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
228         printf "    rm -f %s/%s.po; }; } &&\n", subdir, lang
229       }
230       END { print ":" }
231     ' | WGET_COMMAND="$WGET_COMMAND" sh;;
232   esac &&
233   ls "$subdir"/*.po 2>/dev/null |
234     sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
235   rm -f "$subdir/$domain.html"
236 }
237
238 case $SKIP_PO in
239 '')
240   case `wget --help` in
241   *'--no-cache'*)
242     WGET_COMMAND='wget -nv --no-cache';;
243   *'--cache=on/off'*)
244     WGET_COMMAND='wget -nv --cache=off';;
245   *'--non-verbose'*)
246     WGET_COMMAND='wget -nv';;
247   *)
248     WGET_COMMAND='';;
249   esac
250
251   if test -d po; then
252     get_translations po $package || exit
253   fi
254
255   if test -d runtime-po; then
256     get_translations runtime-po $package-runtime || exit
257   fi;;
258 esac
259
260 symlink_to_gnulib()
261 {
262   src=$GNULIB_SRCDIR/$1
263   dst=${2-$1}
264
265   test -f "$src" && {
266     if $copy; then
267       {
268         test ! -h "$dst" || {
269           echo "$0: rm -f $dst" &&
270           rm -f "$dst"
271         }
272       } &&
273       test -f "$dst" &&
274       cmp -s "$src" "$dst" || {
275         echo "$0: cp -fp $src $dst" &&
276         cp -fp "$src" "$dst"
277       }
278     else
279       test -h "$dst" &&
280       src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
281       dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
282       test "$src_i" = "$dst_i" || {
283         dot_dots=
284         case $src in
285         /*) ;;
286         *)
287           case /$dst/ in
288           *//* | */../* | */./* | /*/*/*/*/*/)
289              echo >&2 "$0: invalid symlink calculation: $src -> $dst"
290              exit 1;;
291           /*/*/*/*/)    dot_dots=../../../;;
292           /*/*/*/)      dot_dots=../../;;
293           /*/*/)        dot_dots=../;;
294           esac;;
295         esac
296
297         echo "$0: ln -fs $dot_dots$src $dst" &&
298         ln -fs "$dot_dots$src" "$dst"
299       }
300     fi
301   }
302 }
303
304 cp_mark_as_generated()
305 {
306   cp_src=$1
307   cp_dst=$2
308
309   if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
310     symlink_to_gnulib "$cp_dst"
311   else
312     case $cp_dst in
313       *.[ch])             c1='/* '; c2=' */';;
314       *.texi)             c1='@c '; c2=     ;;
315       *.m4|*/Make*|Make*) c1='# ' ; c2=     ;;
316       *)                  c1=     ; c2=     ;;
317     esac
318
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
343 version_controlled_file() {
344   dir=$1
345   file=$2
346   found=no
347   if test -d CVS; then
348     grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
349              grep '^/[^/]*/[0-9]' > /dev/null && found=yes
350   elif test -d .git; then
351     git-rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
352   else
353     echo "$0: no version control for $dir/$file?" >&2
354   fi
355   test $found = yes
356 }
357
358 slurp() {
359   for dir in . `(cd $1 && find * -type d -print)`; do
360     copied=
361     sep=
362     for file in `ls $1/$dir`; do
363       test -d $1/$dir/$file && continue
364       for excluded_file in $excluded_files; do
365         test "$dir/$file" = "$excluded_file" && continue 2
366       done
367       if test $file = Makefile.am; then
368         copied=$copied${sep}gnulib.mk; sep=$nl
369         remove_intl='/^[^#].*\/intl/s/^/#/'
370         sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/gnulib.mk || {
371           echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
372           rm -f $dir/gnulib.mk &&
373           sed "$remove_intl" $1/$dir/$file >$dir/gnulib.mk
374         }
375       elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
376            version_controlled_file $dir $file; then
377         echo "$0: $dir/$file overrides $1/$dir/$file"
378       else
379         copied=$copied$sep$file; sep=$nl
380         if test $file = gettext.m4; then
381           echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
382           rm -f $dir/$file
383           sed '
384             /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
385               AC_DEFUN([AM_INTL_SUBDIR], [
386             /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
387               AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
388             $a\
389               AC_DEFUN([gl_LOCK_EARLY], [])
390           ' $1/$dir/$file >$dir/$file
391         else
392           cp_mark_as_generated $1/$dir/$file $dir/$file
393         fi
394       fi || exit
395     done
396
397     for dot_ig in .cvsignore .gitignore; do
398       ig=$dir/$dot_ig
399       if test -n "$copied" && test -f $ig; then
400         echo "$copied" | sort -u - $ig | cmp -s - $ig ||
401         echo "$copied" | sort -u - $ig -o $ig || exit
402       fi
403     done
404   done
405 }
406
407
408 # Create boot temporary directories to import from gnulib and gettext.
409
410 bt='.#bootmp'
411 bt2=${bt}2
412 rm -fr $bt $bt2 &&
413 mkdir $bt $bt2 || exit
414
415
416 # Import from gnulib.
417
418 gnulib_tool_options="\
419  --import\
420  --no-changelog\
421  --aux-dir $bt/build-aux\
422  --doc-base $bt/doc\
423  --lib lib$package\
424  --m4-base $bt/m4/\
425  --source-base $bt/lib/\
426  --tests-base $bt/tests\
427  --local-dir gl\
428 "
429 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
430 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
431 slurp $bt || exit
432
433 for file in $gnulib_files; do
434   symlink_to_gnulib $file || exit
435 done
436
437
438 # Import from gettext.
439
440 case $IMPORT_FROM_GETTEXT in
441 yes)
442   echo "$0: (cd $bt2; autopoint) ..."
443   cp configure.ac $bt2 &&
444   (cd $bt2 && autopoint && rm configure.ac) &&
445   slurp $bt2 $bt || exit
446
447   rm -fr $bt $bt2 || exit;;
448 esac
449
450
451 # Reconfigure, getting other files.
452
453 for command in \
454   'aclocal --force -I m4' \
455   'autoconf --force' \
456   'autoheader --force' \
457   'automake --add-missing --copy --force-missing';
458 do
459   echo "$0: $command ..."
460   $command || exit
461 done
462
463
464 # Get some extra files from gnulib, overriding existing files.
465
466 for file in $gnulib_extra_files; do
467   case $file in
468   */INSTALL) dst=INSTALL;;
469   *) dst=$file;;
470   esac
471   dstdir=`dirname $dst` || exit
472   test -d $dstdir || mkdir -p $dstdir || exit
473   symlink_to_gnulib $file $dst || exit
474 done
475
476
477 # Create gettext configuration.
478 if test -d po; then
479   echo "$0: Creating po/Makevars from po/Makevars.template ..."
480   rm -f po/Makevars
481   sed '
482     /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
483     /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
484     /^XGETTEXT_OPTIONS *=/{
485       s/$/ \\/
486       a\
487           '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
488     }
489   ' po/Makevars.template >po/Makevars
490 fi
491
492 if test -d runtime-po; then
493   # Likewise for runtime-po/Makevars, except also change a few other parameters.
494   rm -f runtime-po/Makevars
495   sed '
496     s/^\(DOMAIN\) *=.*/\1 = '"$package"'-runtime/
497     s/^\(subdir\) *=.*/\1 = runtime-po/
498     s/^\(XGETTEXT_OPTIONS\) *=.*/\1 = '"$XGETTEXT_OPTIONS_RUNTIME"'/
499   ' <po/Makevars >runtime-po/Makevars
500
501   # Copy identical files from po to runtime-po.
502   (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
503 fi
504
505 echo "$0: done.  Now you can run './configure'."