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