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