have bootstrap initialize git-merge-changelog if found
[gnulib.git] / build-aux / bootstrap
index 1a24e82..93fe859 100755 (executable)
@@ -165,7 +165,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,17 +218,40 @@ 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
@@ -239,6 +262,20 @@ case ${GNULIB_SRCDIR--} in
     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 +310,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 +420,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
@@ -416,7 +457,7 @@ version_controlled_file() {
   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  
+    svn log -r HEAD "$dir/$file" > /dev/null 2>&1 && found=yes
   else
     echo "$0: no version control for $dir/$file?" >&2
   fi
@@ -525,38 +566,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.