bootstrap: improve some comments
[gnulib.git] / 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.  Assumes git 1.6.4 or newer.
435   if test -d "$GNULIB_SRCDIR"/.git && \
436         git_modules_config submodule.gnulib.url >/dev/null; then
437     echo "$0: getting gnulib files..."
438     git submodule update --init --reference "$GNULIB_SRCDIR" \
439         "$gnulib_path" || exit $?
440     GNULIB_SRCDIR=$gnulib_path
441   fi
442   ;;
443 esac
444
445 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
446 <$gnulib_tool || exit
447
448 # Get translations.
449
450 download_po_files() {
451   subdir=$1
452   domain=$2
453   echo "$0: getting translations into $subdir for $domain..."
454   cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
455   eval "$cmd"
456 }
457
458 # Download .po files to $po_dir/.reference and copy only the new
459 # or modified ones into $po_dir.  Also update $po_dir/LINGUAS.
460 update_po_files() {
461   # Directory containing primary .po files.
462   # Overwrite them only when we're sure a .po file is new.
463   po_dir=$1
464   domain=$2
465
466   # Download *.po files into this dir.
467   # Usually contains *.s1 checksum files.
468   ref_po_dir="$po_dir/.reference"
469
470   test -d $ref_po_dir || mkdir $ref_po_dir || return
471   download_po_files $ref_po_dir $domain \
472     && ls "$ref_po_dir"/*.po 2>/dev/null |
473       sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
474
475   langs=`cd $ref_po_dir && echo *.po|sed 's/\.po//g'`
476   test "$langs" = '*' && langs=x
477   for po in $langs; do
478     case $po in x) continue;; esac
479     new_po="$ref_po_dir/$po.po"
480     cksum_file="$ref_po_dir/$po.s1"
481     if ! test -f "$cksum_file" ||
482         ! test -f "$po_dir/$po.po" ||
483         ! $SHA1SUM -c --status "$cksum_file" \
484             < "$new_po" > /dev/null; then
485       echo "updated $po_dir/$po.po..."
486       cp "$new_po" "$po_dir/$po.po" \
487           && $SHA1SUM < "$new_po" > "$cksum_file"
488     fi
489   done
490 }
491
492 case $SKIP_PO in
493 '')
494   if test -d po; then
495     update_po_files po $package || exit
496   fi
497
498   if test -d runtime-po; then
499     update_po_files runtime-po $package-runtime || exit
500   fi;;
501 esac
502
503 symlink_to_dir()
504 {
505   src=$1/$2
506   dst=${3-$2}
507
508   test -f "$src" && {
509
510     # If the destination directory doesn't exist, create it.
511     # This is required at least for "lib/uniwidth/cjk.h".
512     dst_dir=`dirname "$dst"`
513     if ! test -d "$dst_dir"; then
514       mkdir -p "$dst_dir"
515
516       # If we've just created a directory like lib/uniwidth,
517       # tell version control system(s) it's ignorable.
518       # FIXME: for now, this does only one level
519       parent=`dirname "$dst_dir"`
520       for dot_ig in x $vc_ignore; do
521         test $dot_ig = x && continue
522         ig=$parent/$dot_ig
523         insert_sorted_if_absent $ig `echo "$dst_dir"|sed 's,.*/,,'`
524       done
525     fi
526
527     if $copy; then
528       {
529         test ! -h "$dst" || {
530           echo "$0: rm -f $dst" &&
531           rm -f "$dst"
532         }
533       } &&
534       test -f "$dst" &&
535       cmp -s "$src" "$dst" || {
536         echo "$0: cp -fp $src $dst" &&
537         cp -fp "$src" "$dst"
538       }
539     else
540       test -h "$dst" &&
541       src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
542       dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
543       test "$src_i" = "$dst_i" || {
544         dot_dots=
545         case $src in
546         /*) ;;
547         *)
548           case /$dst/ in
549           *//* | */../* | */./* | /*/*/*/*/*/)
550              echo >&2 "$0: invalid symlink calculation: $src -> $dst"
551              exit 1;;
552           /*/*/*/*/)    dot_dots=../../../;;
553           /*/*/*/)      dot_dots=../../;;
554           /*/*/)        dot_dots=../;;
555           esac;;
556         esac
557
558         echo "$0: ln -fs $dot_dots$src $dst" &&
559         ln -fs "$dot_dots$src" "$dst"
560       }
561     fi
562   }
563 }
564
565 cp_mark_as_generated()
566 {
567   cp_src=$1
568   cp_dst=$2
569
570   if cmp -s "$cp_src" "$GNULIB_SRCDIR/$cp_dst"; then
571     symlink_to_dir "$GNULIB_SRCDIR" "$cp_dst"
572   elif cmp -s "$cp_src" "$local_gl_dir/$cp_dst"; then
573     symlink_to_dir $local_gl_dir "$cp_dst"
574   else
575     case $cp_dst in
576       *.[ch])             c1='/* '; c2=' */';;
577       *.texi)             c1='@c '; c2=     ;;
578       *.m4|*/Make*|Make*) c1='# ' ; c2=     ;;
579       *)                  c1=     ; c2=     ;;
580     esac
581
582     # If the destination directory doesn't exist, create it.
583     # This is required at least for "lib/uniwidth/cjk.h".
584     dst_dir=`dirname "$cp_dst"`
585     test -d "$dst_dir" || mkdir -p "$dst_dir"
586
587     if test -z "$c1"; then
588       cmp -s "$cp_src" "$cp_dst" || {
589         # Copy the file first to get proper permissions if it
590         # doesn't already exist.  Then overwrite the copy.
591         echo "$0: cp -f $cp_src $cp_dst" &&
592         rm -f "$cp_dst" &&
593         cp "$cp_src" "$cp_dst-t" &&
594         sed "s!$bt_regex/!!g" "$cp_src" > "$cp_dst-t" &&
595         mv -f "$cp_dst-t" "$cp_dst"
596       }
597     else
598       # Copy the file first to get proper permissions if it
599       # doesn't already exist.  Then overwrite the copy.
600       cp "$cp_src" "$cp_dst-t" &&
601       (
602         echo "$c1-*- buffer-read-only: t -*- vi: set ro:$c2" &&
603         echo "${c1}DO NOT EDIT! GENERATED AUTOMATICALLY!$c2" &&
604         sed "s!$bt_regex/!!g" "$cp_src"
605       ) > $cp_dst-t &&
606       if cmp -s "$cp_dst-t" "$cp_dst"; then
607         rm -f "$cp_dst-t"
608       else
609         echo "$0: cp $cp_src $cp_dst # with edits" &&
610         mv -f "$cp_dst-t" "$cp_dst"
611       fi
612     fi
613   fi
614 }
615
616 version_controlled_file() {
617   dir=$1
618   file=$2
619   found=no
620   if test -d CVS; then
621     grep -F "/$file/" $dir/CVS/Entries 2>/dev/null |
622              grep '^/[^/]*/[0-9]' > /dev/null && found=yes
623   elif test -d .git; then
624     git rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
625   elif test -d .svn; then
626     svn log -r HEAD "$dir/$file" > /dev/null 2>&1 && found=yes
627   else
628     echo "$0: no version control for $dir/$file?" >&2
629   fi
630   test $found = yes
631 }
632
633 slurp() {
634   for dir in . `(cd $1 && find * -type d -print)`; do
635     copied=
636     sep=
637     for file in `ls -a $1/$dir`; do
638       case $file in
639       .|..) continue;;
640       .*) continue;; # FIXME: should all file names starting with "." be ignored?
641       esac
642       test -d $1/$dir/$file && continue
643       for excluded_file in $excluded_files; do
644         test "$dir/$file" = "$excluded_file" && continue 2
645       done
646       if test $file = Makefile.am && test "X$gnulib_mk" != XMakefile.am; then
647         copied=$copied${sep}$gnulib_mk; sep=$nl
648         remove_intl='/^[^#].*\/intl/s/^/#/;'"s!$bt_regex/!!g"
649         sed "$remove_intl" $1/$dir/$file | cmp - $dir/$gnulib_mk > /dev/null || {
650           echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..." &&
651           rm -f $dir/$gnulib_mk &&
652           sed "$remove_intl" $1/$dir/$file >$dir/$gnulib_mk
653         }
654       elif { test "${2+set}" = set && test -r $2/$dir/$file; } ||
655            version_controlled_file $dir $file; then
656         echo "$0: $dir/$file overrides $1/$dir/$file"
657       else
658         copied=$copied$sep$file; sep=$nl
659         if test $file = gettext.m4; then
660           echo "$0: patching m4/gettext.m4 to remove need for intl/* ..."
661           rm -f $dir/$file
662           sed '
663             /^AC_DEFUN(\[AM_INTL_SUBDIR],/,/^]/c\
664               AC_DEFUN([AM_INTL_SUBDIR], [])
665             /^AC_DEFUN(\[gt_INTL_SUBDIR_CORE],/,/^]/c\
666               AC_DEFUN([gt_INTL_SUBDIR_CORE], [])
667             $a\
668               AC_DEFUN([gl_LOCK_EARLY], [])
669           ' $1/$dir/$file >$dir/$file
670         else
671           cp_mark_as_generated $1/$dir/$file $dir/$file
672         fi
673       fi || exit
674     done
675
676     for dot_ig in x $vc_ignore; do
677       test $dot_ig = x && continue
678       ig=$dir/$dot_ig
679       if test -n "$copied"; then
680         insert_sorted_if_absent $ig "$copied"
681         # If an ignored file name ends with .in.h, then also add
682         # the name with just ".h".  Many gnulib headers are generated,
683         # e.g., stdint.in.h -> stdint.h, dirent.in.h ->..., etc.
684         # Likewise for .gperf -> .h, .y -> .c, and .sin -> .sed
685         f=`echo "$copied"|sed 's/\.in\.h$/.h/;s/\.sin$/.sed/;s/\.y$/.c/;s/\.gperf$/.h/'`
686         insert_sorted_if_absent $ig "$f"
687
688         # For files like sys_stat.in.h and sys_time.in.h, record as
689         # ignorable the directory we might eventually create: sys/.
690         f=`echo "$copied"|sed 's/sys_.*\.in\.h$/sys/'`
691         insert_sorted_if_absent $ig "$f"
692       fi
693     done
694   done
695 }
696
697
698 # Create boot temporary directories to import from gnulib and gettext.
699 rm -fr $bt $bt2 &&
700 mkdir $bt $bt2 || exit
701
702 # Import from gnulib.
703
704 gnulib_tool_options="\
705  --import\
706  --no-changelog\
707  --aux-dir $bt/$build_aux\
708  --doc-base $bt/$doc_base\
709  --lib $gnulib_name\
710  --m4-base $bt/$m4_base/\
711  --source-base $bt/$source_base/\
712  --tests-base $bt/$tests_base\
713  --local-dir $local_gl_dir\
714  $gnulib_tool_option_extras\
715 "
716 echo "$0: $gnulib_tool $gnulib_tool_options --import ..."
717 $gnulib_tool $gnulib_tool_options --import $gnulib_modules &&
718 slurp $bt || exit
719
720 for file in $gnulib_files; do
721   symlink_to_dir "$GNULIB_SRCDIR" $file || exit
722 done
723
724
725 # Import from gettext.
726 with_gettext=yes
727 grep '^[         ]*AM_GNU_GETTEXT_VERSION(' configure.ac >/dev/null || \
728     with_gettext=no
729
730 if test $with_gettext = yes; then
731   echo "$0: (cd $bt2; ${AUTOPOINT-autopoint}) ..."
732   cp configure.ac $bt2 &&
733   (cd $bt2 && ${AUTOPOINT-autopoint} && rm configure.ac) &&
734   slurp $bt2 $bt || exit
735 fi
736 rm -fr $bt $bt2 || exit
737
738 # Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
739 # gnulib-populated directories.  Such .m4 files would cause aclocal to fail.
740 # The following requires GNU find 4.2.3 or newer.  Considering the usual
741 # portability constraints of this script, that may seem a very demanding
742 # requirement, but it should be ok.  Ignore any failure, which is fine,
743 # since this is only a convenience to help developers avoid the relatively
744 # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
745 # between successive runs of this script.
746 find "$m4_base" "$source_base" \
747   -depth \( -name '*.m4' -o -name '*.[ch]' \) \
748   -type l -xtype l -delete > /dev/null 2>&1
749
750 # Reconfigure, getting other files.
751
752 # Skip autoheader if it's not needed.
753 grep -E '^[      ]*AC_CONFIG_HEADERS?\>' configure.ac >/dev/null ||
754   AUTOHEADER=true
755
756 for command in \
757   libtool \
758   "${ACLOCAL-aclocal} --force -I m4" \
759   "${AUTOCONF-autoconf} --force" \
760   "${AUTOHEADER-autoheader} --force" \
761   "${AUTOMAKE-automake} --add-missing --copy --force-missing"
762 do
763   if test "$command" = libtool; then
764     use_libtool=0
765     # We'd like to use grep -E, to see if any of LT_INIT,
766     # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
767     # but that's not portable enough (e.g., for Solaris).
768     grep '^[     ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
769       && use_libtool=1
770     grep '^[     ]*LT_INIT' configure.ac >/dev/null \
771       && use_libtool=1
772     test $use_libtool = 0 \
773       && continue
774     command="${LIBTOOLIZE-libtoolize} -c -f"
775   fi
776   echo "$0: $command ..."
777   $command || exit
778 done
779
780
781 # Get some extra files from gnulib, overriding existing files.
782 for file in $gnulib_extra_files; do
783   case $file in
784   */INSTALL) dst=INSTALL;;
785   build-aux/*) dst=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
786   *) dst=$file;;
787   esac
788   symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit
789 done
790
791 if test $with_gettext = yes; then
792   # Create gettext configuration.
793   echo "$0: Creating po/Makevars from po/Makevars.template ..."
794   rm -f po/Makevars
795   sed '
796     /^EXTRA_LOCALE_CATEGORIES *=/s/=.*/= '"$EXTRA_LOCALE_CATEGORIES"'/
797     /^COPYRIGHT_HOLDER *=/s/=.*/= '"$COPYRIGHT_HOLDER"'/
798     /^MSGID_BUGS_ADDRESS *=/s|=.*|= '"$MSGID_BUGS_ADDRESS"'|
799     /^XGETTEXT_OPTIONS *=/{
800       s/$/ \\/
801       a\
802           '"$XGETTEXT_OPTIONS"' $${end_of_xgettext_options+}
803     }
804   ' po/Makevars.template >po/Makevars
805
806   if test -d runtime-po; then
807     # Similarly for runtime-po/Makevars, but not quite the same.
808     rm -f runtime-po/Makevars
809     sed '
810       /^DOMAIN *=.*/s/=.*/= '"$package"'-runtime/
811       /^subdir *=.*/s/=.*/= runtime-po/
812       /^MSGID_BUGS_ADDRESS *=/s/=.*/= bug-'"$package"'@gnu.org/
813       /^XGETTEXT_OPTIONS *=/{
814         s/$/ \\/
815         a\
816             '"$XGETTEXT_OPTIONS_RUNTIME"' $${end_of_xgettext_options+}
817       }
818     ' <po/Makevars.template >runtime-po/Makevars
819
820     # Copy identical files from po to runtime-po.
821     (cd po && cp -p Makefile.in.in *-quot *.header *.sed *.sin ../runtime-po)
822   fi
823 fi
824
825 bootstrap_epilogue
826
827 echo "$0: done.  Now you can run './configure'."