]> code.delx.au - gnu-emacs/blobdiff - autogen.sh
Do not require that .git be a directory
[gnu-emacs] / autogen.sh
index bc9c5a008e034479aa1c146332de6f0b318399c4..2e10a77cb3731e5b072e8eebc5ff577edee3c4a9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 ### autogen.sh - tool to help build Emacs from a repository checkout
 
-## Copyright (C) 2011-2015 Free Software Foundation, Inc.
+## Copyright (C) 2011-2016 Free Software Foundation, Inc.
 
 ## Author: Glenn Morris <rgm@gnu.org>
 ## Maintainer: emacs-devel@gnu.org
@@ -103,16 +103,36 @@ check_version ()
     return 2
 }
 
+do_autoconf=false
+test $# -eq 0 && do_autoconf=true
+do_git=false
+
+for arg; do
+    case $arg in
+      --help)
+       exec echo "$0: usage: $0 [all|autoconf|git]";;
+      all)
+       do_autoconf=true do_git=true;;
+      autoconf)
+       do_autoconf=true;;
+      git)
+       do_git=true;;
+      *)
+       echo >&2 "$0: $arg: unknown argument"; exit 1;;
+    esac
+done
+
 
-cat <<EOF
-Checking whether you have the necessary tools...
-(Read INSTALL.REPO for more details on building Emacs)
+# Generate Autoconf and Automake related files, if requested.
 
-EOF
+if $do_autoconf; then
 
-missing=
+  echo 'Checking whether you have the necessary tools...
+(Read INSTALL.REPO for more details on building Emacs)'
 
-for prog in $progs; do
+  missing=
+
+  for prog in $progs; do
 
     sprog=`echo "$prog" | sed 's/-/_/g'`
 
@@ -138,15 +158,13 @@ for prog in $progs; do
         eval ${sprog}_why=\""$stat"\"
     fi
 
-done
+  done
 
 
-if [ x"$missing" != x ]; then
+  if [ x"$missing" != x ]; then
 
-    cat <<EOF
-
-Building Emacs from the repository requires the following specialized programs:
-EOF
+    echo '
+Building Emacs from the repository requires the following specialized programs:'
 
     for prog in $progs; do
         sprog=`echo "$prog" | sed 's/-/_/g'`
@@ -157,10 +175,8 @@ EOF
     done
 
 
-    cat <<EOF
-
-Your system seems to be missing the following tool(s):
-EOF
+    echo '
+Your system seems to be missing the following tool(s):'
 
     for prog in $missing; do
         sprog=`echo "$prog" | sed 's/-/_/g'`
@@ -170,8 +186,7 @@ EOF
         echo "$prog ($why)"
     done
 
-    cat <<EOF
-
+    echo '
 If you think you have the required tools, please add them to your PATH
 and re-run this script.
 
@@ -198,53 +213,107 @@ autoreconf -fi -I m4
 
 instead of this script.
 
-Please report any problems with this script to bug-gnu-emacs@gnu.org .
-EOF
+Please report any problems with this script to bug-gnu-emacs@gnu.org .'
 
     exit 1
+  fi
+
+  echo 'Your system has the required tools.'
+  echo "Running 'autoreconf -fi -I m4' ..."
+
+
+  ## Let autoreconf figure out what, if anything, needs doing.
+  ## Use autoreconf's -f option in case autoreconf itself has changed.
+  autoreconf -fi -I m4 || exit $?
+
+  ## Create a timestamp, so that './autogen.sh; make' doesn't
+  ## cause 'make' to needlessly run 'autoheader'.
+  echo timestamp > src/stamp-h.in || exit
 fi
 
-echo 'Your system has the required tools.'
-echo "Running 'autoreconf -fi -I m4' ..."
 
+# True if the Git setup was OK before autogen.sh was run.
 
-## Let autoreconf figure out what, if anything, needs doing.
-## Use autoreconf's -f option in case autoreconf itself has changed.
-autoreconf -fi -I m4 || exit $?
+git_was_ok=true
 
-## Create a timestamp, so that './autogen.sh; make' doesn't
-## cause 'make' to needlessly run 'autoheader'.
-echo timestamp > src/stamp-h.in || exit
+if $do_git; then
+    case `cp --help 2>/dev/null` in
+      *--backup*--verbose*)
+       cp_options='--backup=numbered --verbose';;
+      *)
+       cp_options='-f';;
+    esac
+fi
 
-## Install Git hooks, if using Git.
-if test -d .git/hooks; then
-    tailored_hooks=
-    sample_hooks=
 
-    for hook in commit-msg pre-commit; do
-       cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
+# Like 'git config NAME VALUE' but verbose on change and exiting on failure.
+# Also, do not configure unless requested.
+
+git_config ()
+{
+    name=$1
+    value=$2
+
+    ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
+       if $do_git; then
+           if $git_was_ok; then
+               echo 'Configuring local git repository...'
+               case $cp_options in
+                 --backup=*)
+                   cp $cp_options --force .git/config .git/config || exit;;
+               esac
+           fi
+           echo "git config $name '$value'"
+           git config "$name" "$value" || exit
+       fi
+       git_was_ok=false
+    }
+}
+
+## Configure Git, if requested.
+
+# Check hashes when transferring objects among repositories.
+
+git_config transfer.fsckObjects true
+
+
+# Configure 'git diff' hunk header format.
+
+git_config diff.elisp.xfuncname \
+          '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
+git_config 'diff.m4.xfuncname' '^((m4_)?define|A._DEFUN(_ONCE)?)\([^),]*'
+git_config 'diff.make.xfuncname' \
+          '^([$.[:alnum:]_].*:|[[:alnum:]_]+[[:space:]]*([*:+]?[:?]?|!?)=|define .*)'
+git_config 'diff.shell.xfuncname' \
+          '^([[:space:]]*[[:alpha:]_][[:alnum:]_]*[[:space:]]*\(\)|[[:alpha:]_][[:alnum:]_]*=)'
+git_config diff.texinfo.xfuncname \
+          '^@node[[:space:]]+([^,[:space:]][^,]+)'
+
+
+# Install Git hooks.
+
+tailored_hooks=
+sample_hooks=
+
+for hook in commit-msg pre-commit; do
+    cmp build-aux/git-hooks/$hook .git/hooks/$hook >/dev/null 2>&1 ||
        tailored_hooks="$tailored_hooks $hook"
-    done
-    for hook in applypatch-msg pre-applypatch; do
-       test ! -r .git/hooks/$hook.sample ||
-       cmp .git/hooks/$hook.sample .git/hooks/$hook >/dev/null 2>&1 ||
+done
+for hook in applypatch-msg pre-applypatch; do
+    src=.git/hooks/$hook.sample
+    cmp "$src" .git/hooks/$hook >/dev/null 2>&1 ||
        sample_hooks="$sample_hooks $hook"
-    done
+done
 
-    if test -n "$tailored_hooks$sample_hooks"; then
+if test -n "$tailored_hooks$sample_hooks"; then
+    if $do_git; then
        echo "Installing git hooks..."
 
-       case `cp --help 2>/dev/null` in
-         *--backup*--verbose*)
-           cp_options='--backup=numbered --verbose';;
-         *)
-           cp_options='-f';;
-       esac
-
        if test -n "$tailored_hooks"; then
            for hook in $tailored_hooks; do
-               cp $cp_options build-aux/git-hooks/$hook .git/hooks || exit
-               chmod a-w .git/hooks/$hook || exit
+               dst=.git/hooks/$hook
+               cp $cp_options build-aux/git-hooks/$hook "$dst" || exit
+               chmod a-w "$dst" || exit
            done
        fi
 
@@ -254,10 +323,19 @@ if test -d .git/hooks; then
                chmod a-w .git/hooks/$hook || exit
            done
        fi
+    else
+       git_was_ok=false
     fi
 fi
 
-echo "You can now run './configure'."
+if test ! -f configure; then
+    echo "You can now run '$0 autoconf'."
+elif test -e .git && test $git_was_ok = false && test $do_git = false; then
+    echo "You can now run '$0 git'."
+elif test ! -f config.status ||
+       test -n "`find src/stamp-h.in -newer config.status`"; then
+    echo "You can now run './configure'."
+fi
 
 exit 0