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