Accept Bison's NEWS format.
[gnulib.git] / build-aux / bootstrap
index cf6b73b..2087bab 100755 (executable)
@@ -49,7 +49,7 @@ Options:
                           not to have been checked out.
  --skip-po                Do not download po files.
 
-If the file bootstrap.conf exists in the current working directory, its
+If the file $0.conf exists in the same directory as this script, its
 contents are read as shell variables to configure the bootstrap.
 
 Running without arguments will suffice in most cases.
@@ -146,7 +146,13 @@ copy=false
 vc_ignore=auto
 
 # Override the default configuration, if necessary.
-test -r bootstrap.conf && . ./bootstrap.conf
+# Make sure that bootstrap.conf is sourced from the current directory
+# if we were invoked as "sh bootstrap".
+case "$0" in
+  */*) test -r "$0.conf" && . "$0.conf" ;;
+  *) test -r "$0.conf" && . ./"$0.conf" ;;
+esac
+
 
 if test "$vc_ignore" = auto; then
   vc_ignore=
@@ -165,7 +171,7 @@ do
     usage
     exit;;
   --gnulib-srcdir=*)
-    GNULIB_SRCDIR=`expr "$option" : '--gnulib-srcdir=\(.*\)'`;;
+    GNULIB_SRCDIR=`expr "X$option" : 'X--gnulib-srcdir=\(.*\)'`;;
   --skip-po)
     SKIP_PO=t;;
   --force)
@@ -218,27 +224,65 @@ fi
 
 echo "$0: Bootstrapping from checked-out $package sources..."
 
+# See if we can use gnulib's git-merge-changelog merge driver.
+if test -d .git && (git --version) >/dev/null 2>/dev/null ; then
+  if git config merge.merge-changelog.driver >/dev/null ; then
+    :
+  elif (git-merge-changelog --version) >/dev/null 2>/dev/null ; then
+    echo "initializing git-merge-changelog driver"
+    git config merge.merge-changelog.name 'GNU-style ChangeLog merge driver'
+    git config merge.merge-changelog.driver 'git-merge-changelog %O %A %B'
+  else
+    echo "consider installing git-merge-changelog from gnulib"
+  fi
+fi
+
+
 cleanup_gnulib() {
   status=$?
   rm -fr gnulib
   exit $status
 }
 
+git_modules_config () {
+  GIT_CONFIG_LOCAL=.gitmodules git config "$@"
+}
+
 # Get gnulib files.
 
 case ${GNULIB_SRCDIR--} in
 -)
-  if [ ! -d gnulib ]; then
+  if git_modules_config submodule.gnulib.url >/dev/null; then
+    echo "$0: getting gnulib files..."
+    git submodule init || exit $?
+    git submodule update || exit $?
+
+  elif [ ! -d gnulib ]; then
     echo "$0: getting gnulib files..."
 
     trap cleanup_gnulib 1 2 13 15
 
-    git clone --depth 2 git://git.sv.gnu.org/gnulib ||
+    git clone --help|grep depth > /dev/null && shallow='--depth 2' || shallow=
+    git clone $shallow git://git.sv.gnu.org/gnulib ||
       cleanup_gnulib
 
     trap - 1 2 13 15
   fi
   GNULIB_SRCDIR=gnulib
+  ;;
+*)
+  # Redirect the gnulib submodule to the directory on the command line
+  # if possible.
+  if test -d "$GNULIB_SRCDIR"/.git && \
+       git_modules_config submodule.gnulib.url >/dev/null; then
+    git submodule init
+    GNULIB_SRCDIR=`cd $GNULIB_SRCDIR && pwd`
+    git config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
+    echo "$0: getting gnulib files..."
+    git submodule update || exit $?
+    GNULIB_SRCDIR=gnulib
+  fi
+  ;;
 esac
 
 gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
@@ -273,7 +317,7 @@ update_po_files() {
 
   langs=`cd $ref_po_dir && echo *.po|sed 's/\.po//g'`
   test "$langs" = '*' && langs=x
-  for po in `cd $ref_po_dir && echo *.po|sed 's/\.po//g'`; do
+  for po in $langs; do
     case $po in x) continue;; esac
     new_po="$ref_po_dir/$po.po"
     cksum_file="$ref_po_dir/$po.s1"
@@ -383,9 +427,13 @@ cp_mark_as_generated()
 
     if test -z "$c1"; then
       cmp -s "$cp_src" "$cp_dst" || {
+       # Copy the file first to get proper permissions if it
+       # doesn't already exist.  Then overwrite the copy.
        echo "$0: cp -f $cp_src $cp_dst" &&
        rm -f "$cp_dst" &&
-       sed "s!$bt_regex/!!g" "$cp_src" > "$cp_dst"
+       cp "$cp_src" "$cp_dst-t" &&
+       sed "s!$bt_regex/!!g" "$cp_src" > "$cp_dst-t" &&
+       mv -f "$cp_dst-t" "$cp_dst"
       }
     else
       # Copy the file first to get proper permissions if it
@@ -415,6 +463,8 @@ version_controlled_file() {
             grep '^/[^/]*/[0-9]' > /dev/null && found=yes
   elif test -d .git; then
     git rm -n "$dir/$file" > /dev/null 2>&1 && found=yes
+  elif test -d .svn; then
+    svn log -r HEAD "$dir/$file" > /dev/null 2>&1 && found=yes
   else
     echo "$0: no version control for $dir/$file?" >&2
   fi
@@ -523,38 +573,20 @@ if test $with_gettext = yes; then
   cp configure.ac $bt2 &&
   (cd $bt2 && autopoint && rm configure.ac) &&
   slurp $bt2 $bt || exit
-
-  rm -fr $bt $bt2 || exit
-fi
-
-# Coreutils is unusual in that it generates some of its test-related
-# Makefile.am files.  That must be done before invoking automake.
-mam_template=tests/Makefile.am.in
-if test -f $mam_template; then
-  PERL=perl
-  for tool in cut head join pr sort tac tail test tr uniq wc; do
-    m=tests/$tool/Makefile.am
-    t=${m}t
-    rm -f $m $t
-    sed -n '1,/^##test-files-begin/p' $mam_template > $t
-    echo "x = $tool" >> $t
-    srcdir=tests/$tool
-    $PERL -I$srcdir -w -- tests/mk-script $srcdir --list >> $t
-    sed -n '/^##test-files-end/,$p' $mam_template >> $t
-    chmod -w $t
-    mv $t $m
-  done
 fi
+rm -fr $bt $bt2 || exit
 
-# Remove any dangling symlink matching "*.m4" in the gnulib-populated
-# $m4_base directory, since such a file would cause aclocal to fail.
+# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
+# gnulib-populated directories.  Such .m4 files would cause aclocal to fail.
 # The following requires GNU find 4.2.3 or newer.  Considering the usual
 # portability constraints of this script, that may seem a very demanding
 # requirement, but it should be ok.  Ignore any failure, which is fine,
 # since this is only a convenience to help developers avoid the relatively
 # unusual case in which a symlinked-to .m4 file is git-removed from gnulib
 # between successive runs of this script.
-find "$m4_base" -name '*.m4' -depth -type l -xtype l -delete > /dev/null 2>&1
+find "$m4_base" "$source_base" \
+  -depth \( -name '*.m4' -o -name '*.[ch]' \) \
+  -type l -xtype l -delete > /dev/null 2>&1
 
 # Reconfigure, getting other files.
 
@@ -566,8 +598,16 @@ for command in \
   'automake --add-missing --copy --force-missing';
 do
   if test "$command" = libtool; then
-    grep '^[    ]*AM_PROG_LIBTOOL\>' configure.ac >/dev/null ||
-      continue
+    use_libtool=0
+    # We'd like to use grep -E, to see if any of LT_INIT,
+    # AC_PROG_LIBTOOL, AM_PROG_LIBTOOL is used in configure.ac,
+    # but that's not portable enough (e.g., for Solaris).
+    grep '^[    ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
+      && use_libtool=1
+    grep '^[    ]*LT_INIT' configure.ac >/dev/null \
+      && use_libtool=1
+    test $use_libtool = 0 \
+      && continue
     command='libtoolize -c -f'
   fi
   echo "$0: $command ..."