]> code.delx.au - gnu-emacs/blobdiff - autogen.sh
* cl-generic.el (cl-defmethod): Make docstring dynamic
[gnu-emacs] / autogen.sh
index 4a0fbb791e965bf96e15a9f451be9b09bbc9458e..b1bd86b461483ead5ed3c2a24e18dbd318c17f59 100755 (executable)
@@ -103,31 +103,37 @@ check_version ()
     return 2
 }
 
+do_autoconf=false
+test $# -eq 0 && do_autoconf=true
+do_git=false
 
-git_config=true
-
-for arg
-do
+for arg; do
     case $arg in
-       --git-config=false) git_config=false;;
-       --git-config=true)  git_config=true ;;
-       --help)
-           exec echo "$0: usage: $0 [--help|--git-config=[false|true]]";;
-       *)
-           echo >&2 "$0: $arg: unknown option"; exit 1;;
+      --help)
+       exec echo "$0: usage: $0 [all|autoconf|git]";;
+      all)
+       do_autoconf=true
+       test -e .git && 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.
+
+if $do_autoconf; then
 
-EOF
+  echo 'Checking whether you have the necessary tools...
+(Read INSTALL.REPO for more details on building Emacs)'
 
-missing=
+  missing=
 
-for prog in $progs; do
+  for prog in $progs; do
 
     sprog=`echo "$prog" | sed 's/-/_/g'`
 
@@ -153,15 +159,13 @@ for prog in $progs; do
         eval ${sprog}_why=\""$stat"\"
     fi
 
-done
-
+  done
 
-if [ x"$missing" != x ]; then
 
-    cat <<EOF
+  if [ x"$missing" != x ]; then
 
-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'`
@@ -172,10 +176,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'`
@@ -185,8 +187,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.
 
@@ -213,102 +214,139 @@ 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
+  fi
+
+  echo 'Your system has the required tools.'
+  echo "Running 'autoreconf -fi -I m4' ..."
+
 
-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
 
-## 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
+# True if the Git setup was OK before autogen.sh was run.
 
+git_was_ok=true
 
-## Configure Git, if using Git.
-if test -d .git && (git status -s) >/dev/null 2>&1; then
+if $do_git; then
+    case `cp --help 2>/dev/null` in
+      *--backup*--verbose*)
+       cp_options='--backup=numbered --verbose';;
+      *)
+       cp_options='-f';;
+    esac
+fi
 
-    # Like 'git config NAME VALUE', but conditional on --git-config,
-    # verbose on change, and exiting on failure.
 
-    git_config ()
-    {
-       name=$1
-       value=$2
+# Like 'git config NAME VALUE' but verbose on change and exiting on failure.
+# Also, do not configure unless requested.
 
-       if $git_config; then
-         ovalue=`git config --get "$name"` && test "$ovalue" = "$value" || {
-           echo "${Configuring_git}git config $name '$value'"
-           Configuring_git=
+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=*)
+                   config=$git_common_dir/config
+                   cp $cp_options --force -- "$config" "$config" || exit;;
+               esac
+           fi
+           echo "git config $name '$value'"
            git config "$name" "$value" || exit
-         }
        fi
+       git_was_ok=false
     }
-    Configuring_git='Configuring git...
-'
+}
+
+## Configure Git, if requested.
 
-    # Check hashes when transferring objects among repositories.
+# Get location of Git's common configuration directory.  For older Git
+# versions this is just '.git'.  Newer Git versions support worktrees.
 
-    git_config transfer.fsckObjects true
+{ test -e .git &&
+  git_common_dir=`git rev-parse --no-flags --git-common-dir 2>/dev/null` &&
+  test -n "$git_common_dir"
+} || git_common_dir=.git
+hooks=$git_common_dir/hooks
 
+# Check hashes when transferring objects among repositories.
 
-    # Configure 'git diff' hunk header format.
+git_config transfer.fsckObjects true
 
-    git_config 'diff.elisp.xfuncname' \
-       '^\(def[^[:space:]]+[[:space:]]+([^()[:space:]]+)'
-    git_config 'diff.texinfo.xfuncname' \
-       '^@node[[:space:]]+([^,[:space:]][^,]+)'
 
+# Configure 'git diff' hunk header format.
 
-    # Install Git hooks.
+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:]][^,]+)'
 
-    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 ||
+# Install Git hooks.
+
+tailored_hooks=
+sample_hooks=
+
+for hook in commit-msg pre-commit; do
+    cmp -- build-aux/git-hooks/$hook "$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
+    cmp -- "$hooks/$hook.sample" "$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=$hooks/$hook
+               cp $cp_options -- build-aux/git-hooks/$hook "$dst" || exit
+               chmod -- a-w "$dst" || exit
            done
        fi
 
        if test -n "$sample_hooks"; then
            for hook in $sample_hooks; do
-               cp $cp_options .git/hooks/$hook.sample .git/hooks/$hook || exit
-               chmod a-w .git/hooks/$hook || exit
+               dst=$hooks/$hook
+               cp $cp_options -- "$dst.sample" "$dst" || exit
+               chmod -- a-w "$dst" || 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