* NEWS: Document that mkdir -p and install -d now fork on occasion.
[coreutils.git] / bootstrap
blobb4eec8985706d13481ce72088171bc1a35bf51a8
1 #! /bin/sh
3 # Bootstrap this package from CVS.
5 # Copyright (C) 2003, 2004, 2005, 2006 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 2, 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.
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
33 # Configuration.
35 # List of gnulib modules needed.
36 gnulib_modules=
38 # Any extra gnulib files needed.
39 gnulib_files=
41 # Translation Project URL, for the registry of all projects
42 # and for the translation-team master directory.
43 TP_URL='http://www.iro.umontreal.ca/translation/registry.cgi?domain='
44 TP_PO_URL='http://www.iro.umontreal.ca/translation/teams/PO/'
46 extract_package_name='
47 /^AC_INIT(/{
48 /.*,.*,.*,/{
49 s///
50 s/[][]//g
54 s/AC_INIT(\[*//
55 s/]*,.*//
56 s/^GNU //
57 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
58 s/[^A-Za-z0-9_]/-/g
62 package=`sed -n "$extract_package_name" configure.ac` || exit
64 # Extra files from gnulib, which are not part of any module yet.
65 gnulib_extra_files='
66 build-aux/install-sh
67 build-aux/missing
68 build-aux/mdate-sh
69 build-aux/texinfo.tex
70 build-aux/depcomp
71 build-aux/config.guess
72 build-aux/config.sub
73 doc/INSTALL
76 # Other locale categories that need message catalogs.
77 EXTRA_LOCALE_CATEGORIES=
79 # Additional xgettext options to use. Use "\\\newline" to break lines.
80 XGETTEXT_OPTIONS='\\\
81 --flag=_:1:pass-c-format\\\
82 --flag=N_:1:pass-c-format\\\
83 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
86 # Files we don't want to import.
87 excluded_files=
89 # Override the default configuration, if necessary.
90 test -r bootstrap.conf && . ./bootstrap.conf
92 # Translate configuration into internal form.
94 # Parse options.
96 for option
98 case $option in
99 --help)
100 echo "$0: usage: $0 [--gnulib-srcdir=DIR] [--cvs-user=USERNAME] [--skip-po]"
101 exit;;
102 --gnulib-srcdir=*)
103 GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
104 --cvs-user=*)
105 CVS_USER=`expr "$option" : '--cvs-user=\(.*\)'`;;
106 --skip-po)
107 SKIP_PO=t;;
109 echo >&2 "$0: $option: unknown option"
110 exit 1;;
111 esac
112 done
114 echo "$0: Bootstrapping CVS $package..."
116 cleanup_gnulib() {
117 status=$?
118 rm -fr gnulib
119 exit $status
122 # Get gnulib files.
124 case ${GNULIB_SRCDIR--} in
126 if [ ! -d gnulib ]; then
127 echo "$0: getting gnulib files..."
129 case ${CVS_AUTH-pserver} in
130 pserver)
131 CVS_PREFIX=':pserver:anonymous@';;
132 ssh)
133 CVS_PREFIX="$CVS_USER${CVS_USER+@}";;
135 echo "$0: $CVS_AUTH: Unknown CVS access method" >&2
136 exit 1;;
137 esac
139 case $CVS_RSH in
140 '') CVS_RSH=ssh; export CVS_RSH;;
141 esac
143 trap cleanup_gnulib 1 2 13 15
145 cvs -z3 -q -d ${CVS_PREFIX}cvs.savannah.gnu.org:/cvsroot/gnulib co gnulib ||
146 cleanup_gnulib
148 trap - 1 2 13 15
150 GNULIB_SRCDIR=gnulib
151 esac
153 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
154 <$gnulib_tool || exit
156 # Get translations.
158 get_translations() {
159 subdir=$1
160 domain=$2
162 case $WGET_COMMAND in
164 echo "$0: wget not available; skipping translations";;
166 echo "$0: getting translations into $subdir for $domain..." &&
168 (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`) &&
169 $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
171 sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
172 sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
173 awk -F. '
174 { if (lang && $1 != lang) print lang, ver }
175 { lang = $1; ver = substr($0, index($0, ".") + 1) }
176 END { if (lang) print lang, ver }
177 ' | awk -v domain="$domain" -v subdir="$subdir" '
179 lang = $1
180 ver = $2
181 urlfmt = ""
182 printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
183 printf " msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
184 printf " echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
185 printf " rm -f %s/%s.po; }; } &&\n", subdir, lang
187 END { print ":" }
188 ' | WGET_COMMAND="$WGET_COMMAND" sh;;
189 esac &&
190 ls "$subdir"/*.po 2>/dev/null |
191 sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
192 rm -f "$subdir/$domain.html"
195 case $SKIP_PO in
197 case `wget --help` in
198 *'--no-cache'*)
199 WGET_COMMAND='wget -nv --no-cache';;
200 *'--cache=on/off'*)
201 WGET_COMMAND='wget -nv --cache=off';;
202 *'--non-verbose'*)
203 WGET_COMMAND='wget -nv';;
205 WGET_COMMAND='';;
206 esac
208 get_translations po $package || exit
210 if test -d runtime-po; then
211 get_translations runtime-po $package-runtime || exit
212 fi;;
213 esac
215 cp_mark_as_generated()
217 cp_src=$1
218 cp_dst=$2
219 case $cp_dst in
220 *.[ch]) c1='/* '; c2=' */';;
221 *.texi) c1='@c '; c2= ;;
222 *.m4|*/Make*|Make*) c1='# ' ; c2= ;;
223 *) c1= ; c2= ;;
224 esac
226 if test -z "$c1"; then
227 cp "$cp_src" "$cp_dst"
228 return
232 echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2"
233 echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2"
234 cat "$cp_src"
235 ) >> "$cp_dst"
238 slurp() {
239 for dir in . `(cd $1 && find * -type d -print)`; do
240 copied=
241 sep=
242 for file in `ls $1/$dir`; do
243 test -d $1/$dir/$file && continue
244 for excluded_file in $excluded_files; do
245 test "$dir/$file" = "$excluded_file" && continue 2
246 done
247 if test $file = Makefile.am; then
248 copied=$copied${sep}gnulib.mk; sep=$nl
249 echo "$0: Copying $1/$dir/$file to $dir/gnulib.mk ..." &&
250 rm -f $dir/gnulib.mk
251 sed '/^[^#].*\/intl/s/^/#/' $1/$dir/$file >$dir/gnulib.mk
252 elif test -r ${2-no/such/dir}/$dir/$file ||
253 grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
254 grep -q '^/[^/]*/[0-9]'; then
255 echo "$0: $dir/$file overrides $1/$dir/$file"
256 else
257 copied=$copied$sep$file; sep=$nl
258 if test $file = gettext.m4; then
259 echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
260 rm -f $dir/$file
261 sed '
262 /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
263 AC_DEFUN([AM_INTL_SUBDIR], [
264 /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
265 AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
267 AC_DEFUN([gl_LOCK_EARLY], [])
268 ' $1/$dir/$file >$dir/$file
269 else
270 rm -f $dir/$file
271 cp_mark_as_generated $1/$dir/$file $dir/$file
273 fi || exit
274 done
276 ig=$dir/.cvsignore
277 if test -n "$copied" && test -f $ig; then
278 echo "$copied" | sort -u - $ig | cmp -s - $ig ||
279 echo "$copied" | sort -u - $ig -o $ig || exit
281 done
285 # Create boot temporary directories to import from gnulib and gettext.
287 bt='.#bootmp'
288 bt2=${bt}2
289 rm -fr $bt $bt2 &&
290 mkdir $bt $bt2 || exit
292 # Import from gnulib.
294 gnulib_tool_options="\
295 --import\
296 --no-changelog\
297 --aux-dir $bt/build-aux\
298 --doc-base $bt/doc\
299 --lib lib$package\
300 --m4-base $bt/m4/\
301 --source-base $bt/lib/\
302 --tests-base $bt/tests\
304 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
305 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
306 slurp $bt || exit
309 # Import from gettext.
311 echo "$0: (cd $bt2; autopoint) ..."
312 cp configure.ac $bt2 &&
313 (cd $bt2 && autopoint && rm configure.ac) &&
314 slurp $bt2 $bt || exit
316 rm -fr $bt $bt2 || exit
319 # Reconfigure, getting other files.
321 for command in \
322 'aclocal --force -I m4' \
323 'autoconf --force' \
324 'autoheader --force' \
325 'automake --add-missing --copy --force-missing';
327 echo "$0: $command ..."
328 $command || exit
329 done
332 # Get some extra files from gnulib, overriding existing files.
334 for file in $gnulib_extra_files; do
335 src=$GNULIB_SRCDIR/$file
336 case $file in
337 */INSTALL) dest=.;;
338 *) dest=$file;;
339 esac
340 echo "$0: cp -fp $src $dest" &&
341 cp -fp $src $dest || exit
342 done
345 # Create gettext configuration.
346 echo "$0: Creating po/Makevars from po/Makevars.template ..."
347 rm -f po/Makevars
348 sed '
349 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
350 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
351 /^XGETTEXT_OPTIONS *=/{
352 s/$/ \\/
354 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
356 ' po/Makevars.template >po/Makevars
358 if test -d runtime-po; then
359 # Likewise for runtime-po/Makevars, except also change a few other parameters.
360 rm -f runtime-po/Makevars
361 sed '
362 s/^\(DOMAIN\) *=.*/\1 = '"$package"'-runtime/
363 s/^\(subdir\) *=.*/\1 = runtime-po/
364 s/^\(XGETTEXT_OPTIONS\) *=.*/\1 = '"$XGETTEXT_OPTIONS_RUNTIME"'/
365 ' <po/Makevars >runtime-po/Makevars
367 # Copy identical files from po to runtime-po.
368 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
371 echo "$0: done. Now you can run './configure'."