]> git.saurik.com Git - bison.git/blame - bootstrap
* cfg.mk (gnulib_dir): Assume gnulib is a subdirectory.
[bison.git] / bootstrap
CommitLineData
01c56de4
AD
1#! /bin/sh
2
bbb44d83 3# Bootstrap this package from checked-out sources.
01c56de4 4
1462fcee 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() {
c1455bab 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
f0a43dd1
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
f0a43dd1 50 not to have been checked out.
e3ddc1e3 51 --skip-po Do not download po files.
e3ddc1e3 52
f0a43dd1 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
f0a43dd1
JD
56For build prerequisites, environment variables like \$AUTOCONF and \$AMTAR
57are honored.
58
e3ddc1e3 59Running without arguments will suffice in most cases.
c1455bab 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
f0a43dd1
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(/{
f0a43dd1 88 /.*,.*,.*, */{
3b2942e6
PE
89 s///
90 s/[][]//g
f0a43dd1 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
f0a43dd1
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="
f0a43dd1
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
f0a43dd1
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.
2075a82a 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# -------------------------
f0a43dd1
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.,
3710dd02
AD
160# supports --version). If found, set ENVVAR to the program name,
161# die otherwise.
d7be4085
AD
162find_tool ()
163{
164 # Find sha1sum, named gsha1sum on MacPorts.
165 find_tool_envvar=$1
166 shift
3710dd02
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
3710dd02
AD
173 find_tool_res=$i
174 break
d7be4085
AD
175 fi
176 done
3710dd02
AD
177 else
178 find_tool_error_prefix="\$$find_tool_envvar: "
d7be4085
AD
179 fi
180 if test x"$find_tool_res" = x; then
3710dd02 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 || {
3710dd02 185 echo >&2 "$0: ${find_tool_error_prefix}cannot run $find_tool_res --version"
d7be4085
AD
186 exit 1
187 }
3710dd02 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.
f0a43dd1
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=*)
f0a43dd1 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
f0a43dd1 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
f0a43dd1 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
f0a43dd1
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
f0a43dd1
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
f0a43dd1
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
f0a43dd1
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
f0a43dd1
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-)
f0a43dd1 421 if git_modules_config submodule.gnulib.url >/dev/null; then
1f65350a 422 echo "$0: getting gnulib files..."
f0a43dd1
JD
423 git submodule init || exit $?
424 git submodule update || exit $?
1f65350a 425
f0a43dd1
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
f0a43dd1
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
f0a43dd1
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
f0a43dd1
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 {
f0a43dd1
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" || {
f0a43dd1
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" || {
f0a43dd1
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" || {
f0a43dd1
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 (
f0a43dd1
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
f0a43dd1 618 rm -f "$cp_dst-t"
e70f46d1 619 else
f0a43dd1
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 |
f0a43dd1 633 grep '^/[^/]*/[0-9]' > /dev/null && found=yes
10f429ef 634 elif test -d .git; then
f0a43dd1
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
f0a43dd1 655 test "$dir/$file" = "$excluded_file" && continue 2
3b2942e6
PE
656 done
657 if test $file = Makefile.am; then
f0a43dd1
JD
658 copied=$copied${sep}$gnulib_mk; sep=$nl
659 remove_intl='/^[^#].*\/intl/s/^/#/;'"s!$bt_regex/!!g"
660 sed "$remove_intl" $1/$dir/$file | cmp - $dir/$gnulib_mk > /dev/null || {
661 echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..." &&
662 rm -f $dir/$gnulib_mk &&
663 sed "$remove_intl" $1/$dir/$file >$dir/$gnulib_mk
664 }
e70f46d1 665 elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
f0a43dd1
JD
666 version_controlled_file $dir $file; then
667 echo "$0: $dir/$file overrides $1/$dir/$file"
3b2942e6 668 else
f0a43dd1
JD
669 copied=$copied$sep$file; sep=$nl
670 if test $file = gettext.m4; then
671 echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
672 rm -f $dir/$file
673 sed '
674 /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
675 AC_DEFUN([AM_INTL_SUBDIR], [
676 /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
677 AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
678 $a\
679 AC_DEFUN([gl_LOCK_EARLY], [])
680 ' $1/$dir/$file >$dir/$file
681 else
682 cp_mark_as_generated $1/$dir/$file $dir/$file
683 fi
3b2942e6
PE
684 fi || exit
685 done
686
6d8e724d
PE
687 for dot_ig in x $vc_ignore; do
688 test $dot_ig = x && continue
5691bf57 689 ig=$dir/$dot_ig
6d8e724d 690 if test -n "$copied"; then
f0a43dd1
JD
691 insert_vc_ignore $ig "$copied"
692 # If an ignored file name ends with .in.h, then also add
693 # the name with just ".h". Many gnulib headers are generated,
694 # e.g., stdint.in.h -> stdint.h, dirent.in.h ->..., etc.
695 # Likewise for .gperf -> .h, .y -> .c, and .sin -> .sed
696 f=`echo "$copied"|sed 's/\.in\.h$/.h/;s/\.sin$/.sed/;s/\.y$/.c/;s/\.gperf$/.h/'`
697 insert_vc_ignore $ig "$f"
698
699 # For files like sys_stat.in.h and sys_time.in.h, record as
700 # ignorable the directory we might eventually create: sys/.
701 f=`echo "$copied"|sed 's/sys_.*\.in\.h$/sys/'`
702 insert_vc_ignore $ig "$f"
5691bf57
PE
703 fi
704 done
3b2942e6
PE
705 done
706}
1f65350a
PE
707
708
3b2942e6 709# Create boot temporary directories to import from gnulib and gettext.
3b2942e6
PE
710rm -fr $bt $bt2 &&
711mkdir $bt $bt2 || exit
712
713# Import from gnulib.
714
715gnulib_tool_options="\
716 --import\
717 --no-changelog\
bbb44d83 718 --aux-dir $bt/$build_aux\
f0a43dd1 719 --doc-base $bt/$doc_base\
bbb44d83 720 --lib $gnulib_name\
f0a43dd1
JD
721 --m4-base $bt/$m4_base/\
722 --source-base $bt/$source_base/\
723 --tests-base $bt/$tests_base\
6d8e724d 724 --local-dir $local_gl_dir\
f0a43dd1 725 $gnulib_tool_option_extras\
3b2942e6
PE
726"
727echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
728$gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
729slurp $bt || exit
730
731for file in $gnulib_files; do
6d8e724d 732 symlink_to_dir "$GNULIB_SRCDIR" $file || exit
3b2942e6 733done
1f65350a 734
e23d0dd7 735
3b2942e6 736# Import from gettext.
bbb44d83
PE
737with_gettext=yes
738grep '^[ ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
739 with_gettext=no
62a9592d 740
bbb44d83 741if test $with_gettext = yes; then
f0a43dd1 742 echo "$0: (cd $bt2; ${AUTOPOINT-autopoint}) ..."
bbb44d83 743 cp configure.ac $bt2 &&
f0a43dd1 744 (cd $bt2 && ${AUTOPOINT-autopoint} && rm configure.ac) &&
bbb44d83 745 slurp $bt2 $bt || exit
6d8e724d 746fi
f0a43dd1
JD
747rm -fr $bt $bt2 || exit
748
749# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
750# gnulib-populated directories. Such .m4 files would cause aclocal to fail.
751# The following requires GNU find 4.2.3 or newer. Considering the usual
752# portability constraints of this script, that may seem a very demanding
753# requirement, but it should be ok. Ignore any failure, which is fine,
754# since this is only a convenience to help developers avoid the relatively
755# unusual case in which a symlinked-to .m4 file is git-removed from gnulib
756# between successive runs of this script.
757find "$m4_base" "$source_base" \
758 -depth \( -name '*.m4' -o -name '*.[ch]' \) \
759 -type l -xtype l -delete > /dev/null 2>&1
3b2942e6
PE
760
761# Reconfigure, getting other files.
62a9592d 762
f0a43dd1
JD
763# Skip autoheader if it's not needed.
764grep -E '^[ ]*AC_CONFIG_HEADERS?\>' configure.ac >/dev/null ||
765 AUTOHEADER=true
766
62a9592d 767for command in \
bbb44d83 768 libtool \
f0a43dd1
JD
769 "${ACLOCAL-aclocal} --force -I m4" \
770 "${AUTOCONF-autoconf} --force" \
771 "${AUTOHEADER-autoheader} --force" \
772 "${AUTOMAKE-automake} --add-missing --copy --force-missing"
62a9592d 773do
bbb44d83 774 if test "$command" = libtool; then
f0a43dd1
JD
775 use_libtool=0
776 # We'd like to use grep -E, to see if any of LT_INIT,
777 # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
778 # but that's not portable enough (e.g., for Solaris).
779 grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
780 && use_libtool=1
781 grep '^[ ]*LT_INIT' configure.ac >/dev/null \
782 && use_libtool=1
783 test $use_libtool = 0 \
784 && continue
785 command="${LIBTOOLIZE-libtoolize} -c -f"
bbb44d83 786 fi
62a9592d
PE
787 echo "$0: $command ..."
788 $command || exit
789done
790
791
3b2942e6 792# Get some extra files from gnulib, overriding existing files.
3b2942e6 793for file in $gnulib_extra_files; do
3b2942e6 794 case $file in
e70f46d1 795 */INSTALL) dst=INSTALL;;
6d8e724d 796 build-aux/*) dst=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
e70f46d1 797 *) dst=$file;;
3b2942e6 798 esac
6d8e724d 799 symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit
3b2942e6
PE
800done
801
bbb44d83
PE
802if test $with_gettext = yes; then
803 # Create gettext configuration.
804 echo "$0: Creating po/Makevars from po/Makevars.template ..."
805 rm -f po/Makevars
3b2942e6 806 sed '
bbb44d83 807 /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
f0a43dd1 808 /^MSGID_BUGS_ADDRESS *=/s/=.*/= '"$MSGID_BUGS_ADDRESS"'/
bbb44d83
PE
809 /^XGETTEXT_OPTIONS *=/{
810 s/$/ \\/
811 a\
f0a43dd1 812 '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
bbb44d83
PE
813 }
814 ' po/Makevars.template >po/Makevars
3b2942e6 815
bbb44d83
PE
816 if test -d runtime-po; then
817 # Similarly for runtime-po/Makevars, but not quite the same.
818 rm -f runtime-po/Makevars
819 sed '
820 /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
821 /^subdir *=.*/s/=.*/= runtime-po/
822 /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
823 /^XGETTEXT_OPTIONS *=/{
f0a43dd1
JD
824 s/$/ \\/
825 a\
826 '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
bbb44d83
PE
827 }
828 ' <po/Makevars.template >runtime-po/Makevars
829
830 # Copy identical files from po to runtime-po.
831 (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
832 fi
3b2942e6 833fi
1f65350a 834
f0a43dd1
JD
835bootstrap_epilogue
836
1f65350a 837echo "$0: done. Now you can run './configure'."
f0a43dd1
JD
838
839# Local Variables:
840# indent-tabs-mode: nil
841# End: