]> git.saurik.com Git - bison.git/blame - bootstrap
lalr1.cc: don't generate location.hh when location_type is defined
[bison.git] / bootstrap
CommitLineData
01c56de4
AD
1#! /bin/sh
2
bbb44d83 3# Bootstrap this package from checked-out sources.
01c56de4 4
e141f4d4 5# Copyright (C) 2003-2010 Free Software Foundation, Inc.
1f65350a 6
f16b0819 7# This program is free software: you can redistribute it and/or modify
1f65350a 8# it under the terms of the GNU General Public License as published by
f16b0819
PE
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
6d8e724d 11
1f65350a
PE
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.
6d8e724d 16
1f65350a 17# You should have received a copy of the GNU General Public License
f16b0819 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
1f65350a
PE
19
20# Written by Paul Eggert.
21
3b2942e6
PE
22nl='
23'
5a2baae7 24
62a9592d 25# Ensure file names are sorted consistently across platforms.
b5240ba5 26# Also, ensure diagnostics are in English, e.g., "wget --help" below.
a9f027b9
PE
27LC_ALL=C
28export LC_ALL
29
6d8e724d
PE
30local_gl_dir=gl
31
bbb44d83
PE
32# Temporary directory names.
33bt='._bootmp'
34bt_regex=`echo "$bt"| sed 's/\./[.]/g'`
35bt2=${bt}2
36
e3ddc1e3 37usage() {
78f65418 38 cat <<EOF
e3ddc1e3 39Usage: $0 [OPTION]...
10f429ef 40Bootstrap this package from the checked-out sources.
e3ddc1e3
PE
41
42Options:
43 --gnulib-srcdir=DIRNAME Specify the local directory where gnulib
3320a276
JD
44 sources reside. Use this if you already
45 have gnulib sources on your machine, and
46 do not want to waste your bandwidth downloading
47 them again.
46356ea4 48 --copy Copy files instead of creating symbolic links.
10f429ef 49 --force Attempt to bootstrap even if the sources seem
3320a276 50 not to have been checked out.
e3ddc1e3 51 --skip-po Do not download po files.
e3ddc1e3 52
3320a276 53If the file $0.conf exists in the same directory as this script, its
e3ddc1e3
PE
54contents are read as shell variables to configure the bootstrap.
55
3320a276
JD
56For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
57are honored.
58
e3ddc1e3 59Running without arguments will suffice in most cases.
78f65418 60EOF
e3ddc1e3 61}
3b2942e6
PE
62
63# Configuration.
64
6d8e724d
PE
65# Name of the Makefile.am
66gnulib_mk=gnulib.mk
67
3b2942e6
PE
68# List of gnulib modules needed.
69gnulib_modules=
70
71# Any gnulib files needed that are not in modules.
72gnulib_files=
73
3320a276
JD
74# A function to be called after everything else in this script.
75# Override it via your own definition in bootstrap.conf.
76bootstrap_epilogue() { :; }
77
6d8e724d
PE
78# The command to download all .po files for a specified domain into
79# a specified directory. Fill in the first %s is the domain name, and
80# the second with the destination directory. Use rsync's -L and -r
81# options because the latest/%s directory and the .po files within are
82# all symlinks.
83po_download_command_format=\
84"rsync -Lrtvz 'translationproject.org::tp/latest/%s/' '%s'"
3b2942e6
PE
85
86extract_package_name='
87 /^AC_INIT(/{
3320a276 88 /.*,.*,.*, */{
3b2942e6
PE
89 s///
90 s/[][]//g
3320a276 91 s/)$//
3b2942e6
PE
92 p
93 q
94 }
95 s/AC_INIT(\[*//
96 s/]*,.*//
97 s/^GNU //
98 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
99 s/[^A-Za-z0-9_]/-/g
100 p
101 }
102'
103package=`sed -n "$extract_package_name" configure.ac` || exit
bbb44d83 104gnulib_name=lib$package
3b2942e6 105
bbb44d83 106build_aux=build-aux
3320a276
JD
107source_base=lib
108m4_base=m4
109doc_base=doc
110tests_base=tests
111
3b2942e6 112# Extra files from gnulib, which override files from other sources.
bbb44d83 113gnulib_extra_files="
3320a276
JD
114 $build_aux/install-sh
115 $build_aux/missing
116 $build_aux/mdate-sh
117 $build_aux/texinfo.tex
118 $build_aux/depcomp
119 $build_aux/config.guess
120 $build_aux/config.sub
121 doc/INSTALL
bbb44d83 122"
3b2942e6 123
6d8e724d
PE
124# Additional gnulib-tool options to use. Use "\newline" to break lines.
125gnulib_tool_option_extras=
126
3b2942e6
PE
127# Other locale categories that need message catalogs.
128EXTRA_LOCALE_CATEGORIES=
129
130# Additional xgettext options to use. Use "\\\newline" to break lines.
131XGETTEXT_OPTIONS='\\\
132 --flag=_:1:pass-c-format\\\
133 --flag=N_:1:pass-c-format\\\
134 --flag=error:3:c-format --flag=error_at_line:5:c-format\\\
135'
136
3320a276
JD
137# Package bug report address for gettext files
138MSGID_BUGS_ADDRESS=bug-$package@gnu.org
139
3b2942e6
PE
140# Files we don't want to import.
141excluded_files=
142
10f429ef
PE
143# File that should exist in the top directory of a checked out hierarchy,
144# but not in a distribution tarball.
f7e241f4 145checkout_only_file=HACKING
e3ddc1e3 146
46356ea4
PE
147# Whether to use copies instead of symlinks.
148copy=false
149
6d8e724d
PE
150# Set this to '.cvsignore .gitignore' in bootstrap.conf if you want
151# those files to be generated in directories like lib/, m4/, and po/.
152# Or set it to 'auto' to make this script select which to use based
153# on which version control system (if any) is used in the source directory.
154vc_ignore=auto
155
d7be4085
AD
156# find_tool ENVVAR NAMES...
157# -------------------------
3320a276
JD
158# Search for a required program. Use the value of ENVVAR, if set,
159# otherwise find the first of the NAMES that can be run (i.e.,
1deef26d
AD
160# supports --version). If found, set ENVVAR to the program name,
161# die otherwise.
d7be4085
AD
162find_tool ()
163{
1deef26d 164 # Find sha1sum, named gsha1sum on MacPorts.
d7be4085
AD
165 find_tool_envvar=$1
166 shift
1deef26d
AD
167 find_tool_names=$@
168 eval "find_tool_res=\$$find_tool_envvar"
169 if test x"$find_tool_res" = x; then
d7be4085
AD
170 for i
171 do
172 if ($i --version </dev/null) >/dev/null 2>&1; then
1deef26d
AD
173 find_tool_res=$i
174 break
d7be4085
AD
175 fi
176 done
1deef26d
AD
177 else
178 find_tool_error_prefix="\$$find_tool_envvar: "
d7be4085
AD
179 fi
180 if test x"$find_tool_res" = x; then
070e6509 181 echo >&2 "$0: one of these is required: $find_tool_names"
d7be4085
AD
182 exit 1
183 fi
184 ($find_tool_res --version </dev/null) >/dev/null 2>&1 || {
1deef26d 185 echo >&2 "$0: ${find_tool_error_prefix}cannot run $find_tool_res --version"
d7be4085
AD
186 exit 1
187 }
1deef26d 188 eval "$find_tool_envvar=\$find_tool_res"
d7be4085
AD
189 eval "export $find_tool_envvar"
190}
191
192# Find sha1sum, named gsha1sum on MacPorts.
193find_tool SHA1SUM sha1sum gsha1sum
194
3b2942e6 195# Override the default configuration, if necessary.
3320a276
JD
196# Make sure that bootstrap.conf is sourced from the current directory
197# if we were invoked as "sh bootstrap".
198case "$0" in
199 */*) test -r "$0.conf" && . "$0.conf" ;;
200 *) test -r "$0.conf" && . ./"$0.conf" ;;
201esac
202
3b2942e6 203
6d8e724d
PE
204if test "$vc_ignore" = auto; then
205 vc_ignore=
206 test -d .git && vc_ignore=.gitignore
207 test -d CVS && vc_ignore="$vc_ignore .cvsignore"
208fi
209
3b2942e6
PE
210# Translate configuration into internal form.
211
1f65350a
PE
212# Parse options.
213
214for option
215do
216 case $option in
217 --help)
e3ddc1e3 218 usage
1f65350a
PE
219 exit;;
220 --gnulib-srcdir=*)
3320a276 221 GNULIB_SRCDIR=`expr "X$option" : 'X--gnulib-srcdir=\(.*\)'`;;
1f65350a
PE
222 --skip-po)
223 SKIP_PO=t;;
e3ddc1e3 224 --force)
bbb44d83 225 checkout_only_file=;;
46356ea4
PE
226 --copy)
227 copy=true;;
1f65350a
PE
228 *)
229 echo >&2 "$0: $option: unknown option"
230 exit 1;;
231 esac
232done
233
bbb44d83 234if test -n "$checkout_only_file" && test ! -r "$checkout_only_file"; then
10f429ef 235 echo "$0: Bootstrapping from a non-checked-out distribution is risky." >&2
e3ddc1e3
PE
236 exit 1
237fi
238
3320a276 239# If $STR is not already on a line by itself in $FILE, insert it,
bbb44d83
PE
240# sorting the new contents of the file and replacing $FILE with the result.
241insert_sorted_if_absent() {
242 file=$1
243 str=$2
6d8e724d 244 test -f $file || touch $file
3320a276 245 echo "$str" | sort -u - $file | cmp - $file > /dev/null \
bbb44d83
PE
246 || echo "$str" | sort -u - $file -o $file \
247 || exit 1
248}
249
9aacab9a
JD
250# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
251# insert_sorted_if_absent.
252insert_vc_ignore() {
253 vc_ignore_file="$1"
254 case $vc_ignore_file in
255 *.gitignore)
256 # A .gitignore entry that does not start with `/' applies recursively to
257 # subdirectories, so prepend `/' to every .gitignore entry.
258 pattern=`echo "$2" | sed s,^,/,`;;
259 *)
260 pattern="$2";;
261 esac
262 insert_sorted_if_absent "$vc_ignore_file" "$pattern"
263}
264
bbb44d83
PE
265# Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
266found_aux_dir=no
267grep '^[ ]*AC_CONFIG_AUX_DIR(\['"$build_aux"'\])' configure.ac \
268 >/dev/null && found_aux_dir=yes
269grep '^[ ]*AC_CONFIG_AUX_DIR('"$build_aux"')' configure.ac \
270 >/dev/null && found_aux_dir=yes
271if test $found_aux_dir = no; then
272 echo "$0: expected line not found in configure.ac. Add the following:" >&2
6d8e724d
PE
273 echo " AC_CONFIG_AUX_DIR([$build_aux])" >&2
274 exit 1
bbb44d83
PE
275fi
276
277# If $build_aux doesn't exist, create it now, otherwise some bits
278# below will malfunction. If creating it, also mark it as ignored.
279if test ! -d $build_aux; then
280 mkdir $build_aux
6d8e724d
PE
281 for dot_ig in x $vc_ignore; do
282 test $dot_ig = x && continue
9aacab9a 283 insert_vc_ignore $dot_ig $build_aux
bbb44d83
PE
284 done
285fi
286
3320a276
JD
287# Note this deviates from the version comparison in automake
288# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a
289# but this should suffice as we won't be specifying old
290# version formats or redundant trailing .0 in bootstrap.conf.
291# If we did want full compatibility then we should probably
292# use m4_version_compare from autoconf.
293sort_ver() { # sort -V is not generally available
294 ver1="$1"
295 ver2="$2"
296
297 # split on '.' and compare each component
298 i=1
299 while : ; do
300 p1=$(echo "$ver1" | cut -d. -f$i)
301 p2=$(echo "$ver2" | cut -d. -f$i)
302 if [ ! "$p1" ]; then
303 echo "$1 $2"
304 break
305 elif [ ! "$p2" ]; then
306 echo "$2 $1"
307 break
308 elif [ ! "$p1" = "$p2" ]; then
309 if [ "$p1" -gt "$p2" ] 2>/dev/null; then # numeric comparison
310 echo "$2 $1"
311 elif [ "$p2" -gt "$p1" ] 2>/dev/null; then # numeric comparison
312 echo "$1 $2"
313 else # numeric, then lexicographic comparison
314 lp=$(printf "$p1\n$p2\n" | LANG=C sort -n | tail -n1)
315 if [ "$lp" = "$p2" ]; then
316 echo "$1 $2"
317 else
318 echo "$2 $1"
319 fi
320 fi
321 break
322 fi
323 i=$(($i+1))
324 done
325}
1f65350a 326
3320a276
JD
327get_version() {
328 app=$1
329
330 $app --version >/dev/null 2>&1 || return 1
331
332 $app --version 2>&1 |
333 sed -n '# extract version within line
334 s/.*[v ]\{1,\}\([0-9]\{1,\}\.[.a-z0-9-]*\).*/\1/
335 t done
336
337 # extract version at start of line
338 s/^\([0-9]\{1,\}\.[.a-z0-9-]*\).*/\1/
339 t done
340
341 d
342
343 :done
344 #the following essentially does s/5.005/5.5/
345 s/\.0*\([1-9]\)/.\1/g
346 p
347 q'
e10a80ee
PE
348}
349
3320a276
JD
350check_versions() {
351 ret=0
352
353 while read app req_ver; do
354 # Honor $APP variables ($TAR, $AUTOCONF, etc.)
355 appvar=`echo $app | tr '[a-z]' '[A-Z]'`
356 test "$appvar" = TAR && appvar=AMTAR
357 eval "app=\${$appvar-$app}"
358 inst_ver=$(get_version $app)
359 if [ ! "$inst_ver" ]; then
360 echo "Error: '$app' not found" >&2
361 ret=1
362 elif [ ! "$req_ver" = "-" ]; then
363 latest_ver=$(sort_ver $req_ver $inst_ver | cut -d' ' -f2)
364 if [ ! "$latest_ver" = "$inst_ver" ]; then
365 echo "Error: '$app' version == $inst_ver is too old" >&2
366 echo " '$app' version >= $req_ver is required" >&2
367 ret=1
368 fi
369 fi
370 done
371
372 return $ret
373}
fee2ed87 374
3320a276
JD
375print_versions() {
376 echo "Program Min_version"
377 echo "----------------------"
378 printf "$buildreq"
379 echo "----------------------"
380 # can't depend on column -t
381}
382
383if ! printf "$buildreq" | check_versions; then
384 test -f README-prereq &&
385 echo "See README-prereq for notes on obtaining these prerequisite programs:" >&2
386 echo
387 print_versions
388 exit 1
389fi
390
391echo "$0: Bootstrapping from checked-out $package sources..."
392
393# See if we can use gnulib's git-merge-changelog merge driver.
fee2ed87
PB
394if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
395 if git config merge.merge-changelog.driver >/dev/null ; then
396 :
397 elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
398 echo "initializing git-merge-changelog driver"
399 git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
400 git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
401 else
402 echo "consider installing git-merge-changelog from gnulib"
403 fi
404fi
405
3320a276
JD
406
407cleanup_gnulib() {
408 status=$?
409 rm -fr gnulib
410 exit $status
411}
412
413git_modules_config () {
414 test -f .gitmodules && git config --file .gitmodules "$@"
415}
416
1f65350a
PE
417# Get gnulib files.
418
419case ${GNULIB_SRCDIR--} in
420-)
3320a276 421 if git_modules_config submodule.gnulib.url >/dev/null; then
1f65350a 422 echo "$0: getting gnulib files..."
3320a276
JD
423 git submodule init || exit $?
424 git submodule update || exit $?
1f65350a 425
3320a276
JD
426 elif [ ! -d gnulib ]; then
427 echo "$0: getting gnulib files..."
1f65350a 428
e10a80ee
PE
429 trap cleanup_gnulib 1 2 13 15
430
3320a276
JD
431 git clone --help|grep depth > /dev/null && shallow='--depth 2' || shallow=
432 git clone $shallow git://git.sv.gnu.org/gnulib ||
e10a80ee 433 cleanup_gnulib
1f65350a 434
e10a80ee 435 trap - 1 2 13 15
1f65350a
PE
436 fi
437 GNULIB_SRCDIR=gnulib
3320a276
JD
438 ;;
439*)
440 # Redirect the gnulib submodule to the directory on the command line
441 # if possible.
442 if test -d "$GNULIB_SRCDIR"/.git && \
443 git_modules_config submodule.gnulib.url >/dev/null; then
444 git submodule init
445 GNULIB_SRCDIR=`cd $GNULIB_SRCDIR && pwd`
446 git_modules_config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
447 echo "$0: getting gnulib files..."
448 git submodule update || exit $?
449 GNULIB_SRCDIR=gnulib
450 fi
451 ;;
1f65350a
PE
452esac
453
284d8a13
PE
454gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
455<$gnulib_tool || exit
1f65350a 456
1f65350a
PE
457# Get translations.
458
6d8e724d 459download_po_files() {
5a2baae7
PE
460 subdir=$1
461 domain=$2
6d8e724d
PE
462 echo "$0: getting translations into $subdir for $domain..."
463 cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
464 eval "$cmd"
465}
5a2baae7 466
6d8e724d
PE
467# Download .po files to $po_dir/.reference and copy only the new
468# or modified ones into $po_dir. Also update $po_dir/LINGUAS.
469update_po_files() {
470 # Directory containing primary .po files.
471 # Overwrite them only when we're sure a .po file is new.
472 po_dir=$1
473 domain=$2
474
475 # Download *.po files into this dir.
476 # Usually contains *.s1 checksum files.
477 ref_po_dir="$po_dir/.reference"
478
479 test -d $ref_po_dir || mkdir $ref_po_dir || return
480 download_po_files $ref_po_dir $domain \
481 && ls "$ref_po_dir"/*.po 2>/dev/null |
482 sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
483
3320a276
JD
484 langs=`cd $ref_po_dir && echo *.po|sed 's/\.po//g'`
485 test "$langs" = '*' && langs=x
486 for po in $langs; do
487 case $po in x) continue;; esac
488 new_po="$ref_po_dir/$po.po"
489 cksum_file="$ref_po_dir/$po.s1"
490 if ! test -f "$cksum_file" ||
491 ! test -f "$po_dir/$po.po" ||
492 ! $SHA1SUM -c --status "$cksum_file" \
493 < "$new_po" > /dev/null; then
494 echo "updated $po_dir/$po.po..."
495 cp "$new_po" "$po_dir/$po.po" \
496 && $SHA1SUM < "$new_po" > "$cksum_file"
497 fi
6d8e724d 498 done
5a2baae7
PE
499}
500
1f65350a
PE
501case $SKIP_PO in
502'')
bbb44d83 503 if test -d po; then
6d8e724d 504 update_po_files po $package || exit
bbb44d83 505 fi
f7ab6a50 506
3b2942e6 507 if test -d runtime-po; then
6d8e724d 508 update_po_files runtime-po $package-runtime || exit
3b2942e6 509 fi;;
1f65350a
PE
510esac
511
1cfe6375
JD
512check_dst_dir()
513{
514 dst=$1
515 # If the destination directory doesn't exist, create it.
516 # This is required at least for "lib/uniwidth/cjk.h".
517 dst_dir=`dirname "$dst"`
518 if ! test -d "$dst_dir"; then
519 mkdir -p "$dst_dir"
520
521 # If we've just created a directory like lib/uniwidth,
522 # tell version control system(s) it's ignorable.
523 # FIXME: for now, this does only one level
524 parent=`dirname "$dst_dir"`
525 for dot_ig in x $vc_ignore; do
526 test $dot_ig = x && continue
527 ig=$parent/$dot_ig
9aacab9a 528 insert_vc_ignore $ig `echo "$dst_dir"|sed 's,.*/,,'`
1cfe6375
JD
529 done
530 fi
531}
532
6d8e724d 533symlink_to_dir()
e70f46d1 534{
6d8e724d
PE
535 src=$1/$2
536 dst=${3-$2}
e70f46d1
PE
537
538 test -f "$src" && {
6d8e724d 539
1cfe6375 540 check_dst_dir "$dst"
6d8e724d 541
46356ea4
PE
542 if $copy; then
543 {
3320a276
JD
544 test ! -h "$dst" || {
545 echo "$0: rm -f $dst" &&
546 rm -f "$dst"
547 }
46356ea4
PE
548 } &&
549 test -f "$dst" &&
550 cmp -s "$src" "$dst" || {
3320a276
JD
551 echo "$0: cp -fp $src $dst" &&
552 cp -fp "$src" "$dst"
46356ea4
PE
553 }
554 else
555 test -h "$dst" &&
556 src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
557 dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
558 test "$src_i" = "$dst_i" || {
3320a276
JD
559 dot_dots=
560 case $src in
561 /*) ;;
562 *)
563 case /$dst/ in
564 *//* | */../* | */./* | /*/*/*/*/*/)
565 echo >&2 "$0: invalid symlink calculation: $src -> $dst"
566 exit 1;;
567 /*/*/*/*/) dot_dots=../../../;;
568 /*/*/*/) dot_dots=../../;;
569 /*/*/) dot_dots=../;;
570 esac;;
571 esac
572
573 echo "$0: ln -fs $dot_dots$src $dst" &&
574 ln -fs "$dot_dots$src" "$dst"
46356ea4
PE
575 }
576 fi
e70f46d1
PE
577 }
578}
579
3b2942e6
PE
580cp_mark_as_generated()
581{
582 cp_src=$1
583 cp_dst=$2
1f65350a 584
e70f46d1 585 if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
6d8e724d
PE
586 symlink_to_dir "$GNULIB_SRCDIR" "$cp_dst"
587 elif cmp -s "$cp_src" "$local_gl_dir/$cp_dst"; then
588 symlink_to_dir $local_gl_dir "$cp_dst"
e70f46d1
PE
589 else
590 case $cp_dst in
591 *.[ch]) c1='/* '; c2=' */';;
592 *.texi) c1='@c '; c2= ;;
593 *.m4|*/Make*|Make*) c1='# ' ; c2= ;;
594 *) c1= ; c2= ;;
595 esac
1f65350a 596
e70f46d1
PE
597 if test -z "$c1"; then
598 cmp -s "$cp_src" "$cp_dst" || {
3320a276
JD
599 # Copy the file first to get proper permissions if it
600 # doesn't already exist. Then overwrite the copy.
601 echo "$0: cp -f $cp_src $cp_dst" &&
602 rm -f "$cp_dst" &&
603 cp "$cp_src" "$cp_dst-t" &&
604 sed "s!$bt_regex/!!g" "$cp_src" > "$cp_dst-t" &&
605 mv -f "$cp_dst-t" "$cp_dst"
e70f46d1
PE
606 }
607 else
1cfe6375 608 check_dst_dir "$cp_dst"
e70f46d1
PE
609 # Copy the file first to get proper permissions if it
610 # doesn't already exist. Then overwrite the copy.
611 cp "$cp_src" "$cp_dst-t" &&
612 (
3320a276
JD
613 echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
614 echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
615 sed "s!$bt_regex/!!g" "$cp_src"
e70f46d1
PE
616 ) > $cp_dst-t &&
617 if cmp -s "$cp_dst-t" "$cp_dst"; then
3320a276 618 rm -f "$cp_dst-t"
e70f46d1 619 else
3320a276
JD
620 echo "$0: cp $cp_src $cp_dst # with edits" &&
621 mv -f "$cp_dst-t" "$cp_dst"
e70f46d1
PE
622 fi
623 fi
624 fi
3b2942e6 625}
1f65350a 626
10f429ef
PE
627version_controlled_file() {
628 dir=$1
629 file=$2
630 found=no
631 if test -d CVS; then
632 grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
3320a276 633 grep '^/[^/]*/[0-9]' > /dev/null && found=yes
10f429ef 634 elif test -d .git; then
3320a276
JD
635 git rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
636 elif test -d .svn; then
637 svn log -r HEAD "$dir/$file" > /dev/null 2>&1 && found=yes
10f429ef
PE
638 else
639 echo "$0: no version control for $dir/$file?" >&2
640 fi
641 test $found = yes
642}
643
3b2942e6
PE
644slurp() {
645 for dir in . `(cd $1 && find * -type d -print)`; do
646 copied=
647 sep=
6d8e724d
PE
648 for file in `ls -a $1/$dir`; do
649 case $file in
650 .|..) continue;;
651 .*) continue;; # FIXME: should all file names starting with "." be ignored?
652 esac
653 test -d $1/$dir/$file && continue
3b2942e6 654 for excluded_file in $excluded_files; do
3320a276 655 test "$dir/$file" = "$excluded_file" && continue 2
3b2942e6
PE
656 done
657 if test $file = Makefile.am; then
3320a276
JD
658 copied=$copied${sep}$gnulib_mk; sep=$nl
659 remove_intl='/^[^#].*\/intl/s/^/#/;'"s!$bt_regex/!!g"
660 echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..."
661 rm -f $dir/$gnulib_mk
662 sed "$remove_intl" $1/$dir/$file >$dir/$gnulib_mk
feda5527 663 etc/prefix-gnulib-mk $dir/$gnulib_mk
e70f46d1 664 elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
3320a276
JD
665 version_controlled_file $dir $file; then
666 echo "$0: $dir/$file overrides $1/$dir/$file"
3b2942e6 667 else
3320a276
JD
668 copied=$copied$sep$file; sep=$nl
669 if test $file = gettext.m4; then
670 echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
671 rm -f $dir/$file
672 sed '
673 /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
674 AC_DEFUN([AM_INTL_SUBDIR], [
675 /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
676 AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
677 $a\
678 AC_DEFUN([gl_LOCK_EARLY], [])
679 ' $1/$dir/$file >$dir/$file
680 else
681 cp_mark_as_generated $1/$dir/$file $dir/$file
682 fi
3b2942e6
PE
683 fi || exit
684 done
685
6d8e724d
PE
686 for dot_ig in x $vc_ignore; do
687 test $dot_ig = x && continue
5691bf57 688 ig=$dir/$dot_ig
6d8e724d 689 if test -n "$copied"; then
3320a276
JD
690 insert_vc_ignore $ig "$copied"
691 # If an ignored file name ends with .in.h, then also add
692 # the name with just ".h". Many gnulib headers are generated,
693 # e.g., stdint.in.h -> stdint.h, dirent.in.h ->..., etc.
694 # Likewise for .gperf -> .h, .y -> .c, and .sin -> .sed
695 f=`echo "$copied"|sed 's/\.in\.h$/.h/;s/\.sin$/.sed/;s/\.y$/.c/;s/\.gperf$/.h/'`
696 insert_vc_ignore $ig "$f"
697
698 # For files like sys_stat.in.h and sys_time.in.h, record as
699 # ignorable the directory we might eventually create: sys/.
700 f=`echo "$copied"|sed 's/sys_.*\.in\.h$/sys/'`
701 insert_vc_ignore $ig "$f"
5691bf57
PE
702 fi
703 done
3b2942e6
PE
704 done
705}
1f65350a
PE
706
707
3b2942e6 708# Create boot temporary directories to import from gnulib and gettext.
3b2942e6
PE
709rm -fr $bt $bt2 &&
710mkdir $bt $bt2 || exit
711
712# Import from gnulib.
713
714gnulib_tool_options="\
715 --import\
716 --no-changelog\
bbb44d83 717 --aux-dir $bt/$build_aux\
3320a276 718 --doc-base $bt/$doc_base\
bbb44d83 719 --lib $gnulib_name\
3320a276
JD
720 --m4-base $bt/$m4_base/\
721 --source-base $bt/$source_base/\
722 --tests-base $bt/$tests_base\
6d8e724d 723 --local-dir $local_gl_dir\
3320a276 724 $gnulib_tool_option_extras\
3b2942e6
PE
725"
726echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
727$gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
728slurp $bt || exit
729
730for file in $gnulib_files; do
6d8e724d 731 symlink_to_dir "$GNULIB_SRCDIR" $file || exit
3b2942e6 732done
1f65350a 733
e23d0dd7 734
3b2942e6 735# Import from gettext.
bbb44d83
PE
736with_gettext=yes
737grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
738 with_gettext=no
62a9592d 739
bbb44d83 740if test $with_gettext = yes; then
3320a276 741 echo "$0: (cd $bt2; ${AUTOPOINT-autopoint}) ..."
bbb44d83 742 cp configure.ac $bt2 &&
3320a276 743 (cd $bt2 && ${AUTOPOINT-autopoint} && rm configure.ac) &&
bbb44d83 744 slurp $bt2 $bt || exit
6d8e724d 745fi
3320a276
JD
746rm -fr $bt $bt2 || exit
747
748# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
749# gnulib-populated directories. Such .m4 files would cause aclocal to fail.
750# The following requires GNU find 4.2.3 or newer. Considering the usual
751# portability constraints of this script, that may seem a very demanding
752# requirement, but it should be ok. Ignore any failure, which is fine,
753# since this is only a convenience to help developers avoid the relatively
754# unusual case in which a symlinked-to .m4 file is git-removed from gnulib
755# between successive runs of this script.
756find "$m4_base" "$source_base" \
757 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
758 -type l -xtype l -delete > /dev/null 2>&1
3b2942e6
PE
759
760# Reconfigure, getting other files.
62a9592d 761
3320a276
JD
762# Skip autoheader if it's not needed.
763grep -E '^[ ]*AC_CONFIG_HEADERS?\>' configure.ac >/dev/null ||
764 AUTOHEADER=true
765
62a9592d 766for command in \
bbb44d83 767 libtool \
3320a276
JD
768 "${ACLOCAL-aclocal} --force -I m4" \
769 "${AUTOCONF-autoconf} --force" \
770 "${AUTOHEADER-autoheader} --force" \
771 "${AUTOMAKE-automake} --add-missing --copy --force-missing"
62a9592d 772do
bbb44d83 773 if test "$command" = libtool; then
3320a276
JD
774 use_libtool=0
775 # We'd like to use grep -E, to see if any of LT_INIT,
776 # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
777 # but that's not portable enough (e.g., for Solaris).
778 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
779 && use_libtool=1
780 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
781 && use_libtool=1
782 test $use_libtool = 0 \
783 && continue
784 command="${LIBTOOLIZE-libtoolize} -c -f"
bbb44d83 785 fi
62a9592d
PE
786 echo "$0: $command ..."
787 $command || exit
788done
789
790
3b2942e6 791# Get some extra files from gnulib, overriding existing files.
3b2942e6 792for file in $gnulib_extra_files; do
3b2942e6 793 case $file in
e70f46d1 794 */INSTALL) dst=INSTALL;;
6d8e724d 795 build-aux/*) dst=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
e70f46d1 796 *) dst=$file;;
3b2942e6 797 esac
6d8e724d 798 symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit
3b2942e6
PE
799done
800
bbb44d83
PE
801if test $with_gettext = yes; then
802 # Create gettext configuration.
803 echo "$0: Creating po/Makevars from po/Makevars.template ..."
804 rm -f po/Makevars
3b2942e6 805 sed '
bbb44d83 806 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
3320a276 807 /^MSGID_BUGS_ADDRESS *=/s/=.*/= '"$MSGID_BUGS_ADDRESS"'/
bbb44d83
PE
808 /^XGETTEXT_OPTIONS *=/{
809 s/$/ \\/
810 a\
3320a276 811 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
bbb44d83
PE
812 }
813 ' po/Makevars.template >po/Makevars
3b2942e6 814
bbb44d83
PE
815 if test -d runtime-po; then
816 # Similarly for runtime-po/Makevars, but not quite the same.
817 rm -f runtime-po/Makevars
818 sed '
819 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
820 /^subdir *=.*/s/=.*/= runtime-po/
821 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
822 /^XGETTEXT_OPTIONS *=/{
3320a276
JD
823 s/$/ \\/
824 a\
825 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
bbb44d83
PE
826 }
827 ' <po/Makevars.template >runtime-po/Makevars
828
829 # Copy identical files from po to runtime-po.
830 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
831 fi
3b2942e6 832fi
1f65350a 833
3320a276
JD
834bootstrap_epilogue
835
1f65350a 836echo "$0: done. Now you can run './configure'."
3320a276
JD
837
838# Local Variables:
839# indent-tabs-mode: nil
840# End: