declare smobs in alloc.c
[bpt/emacs.git] / admin / update_autogen
index 316c933..90431fa 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 ### update_autogen - update some auto-generated files in the Emacs tree
 
-## Copyright (C) 2011-2013 Free Software Foundation, Inc.
+## Copyright (C) 2011-2014 Free Software Foundation, Inc.
 
 ## Author: Glenn Morris <rgm@gnu.org>
 
@@ -47,11 +47,19 @@ cd $PD
 cd ../
 [ -d admin ] || die "Could not locate admin directory"
 
+if [ -d .bzr ]; then
+    vcs=bzr
+elif [ -d .git ]; then
+    vcs=git
+else
+    die "Cannot determine vcs"
+fi
+
 
 usage ()
 {
     cat 1>&2 <<EOF
-Usage: ${PN} [-f] [-c] [-q] [-A dir] [-L] [-C] [-- make-flags]
+Usage: ${PN} [-f] [-c] [-q] [-A dir] [-I] [-L] [-C] [-- make-flags]
 Update some auto-generated files in the Emacs tree.
 By default, only does the versioned loaddefs-like files in lisp/.
 This requires a build.  Passes any non-option args to make (eg -- -j2).
@@ -61,6 +69,7 @@ Options:
     commit them (caution).
 -q: be quiet; only give error messages, not status messages.
 -A: only update autotools files, copying into specified dir.
+-I: also update info/dir.
 -L: also update ldefs-boot.el.
 -C: start from a clean state.  Slower, but more correct.
 EOF
@@ -77,6 +86,7 @@ clean=
 autogendir=                     # was "autogen"
 ldefs_flag=1
 lboot_flag=
+info_flag=
 
 ## Parameters.
 ldefs_in=lisp/loaddefs.el
@@ -103,7 +113,7 @@ tempfile=/tmp/$PN.$$
 trap "rm -f $tempfile 2> /dev/null" EXIT
 
 
-while getopts ":hcfqA:CL" option ; do
+while getopts ":hcfqA:CIL" option ; do
     case $option in
         (h) usage ;;
 
@@ -119,6 +129,8 @@ while getopts ":hcfqA:CL" option ; do
 
         (C) clean=1 ;;
 
+        (I) info_flag=1 ;;
+
         (L) lboot_flag=1 ;;
 
         (\?) die "Bad option -$OPTARG" ;;
@@ -136,23 +148,39 @@ OPTIND=1
 [ "$quiet" ] && exec 1> /dev/null
 
 
-echo "Running bzr status..."
+## Run status on inputs, list modified files on stdout.
+status ()
+{
+    local statflag="-S"
+    [ "$vcs" = "git" ] && statflag="-s"
 
-bzr status -S ${autogendir:+$sources} ${ldefs_flag:+lisp} >| $tempfile || \
-    die "bzr status error for input files"
+    $vcs status $statflag "$@" >| $tempfile || die "$vcs status error for $@"
 
-## The lisp portion could be more permissive, eg only care about .el files.
-while read stat file; do
+    local stat file modified
 
-    case $stat in
-        M)
-            echo "Locally modified: $file"
-            [ "$force" ] || die "There are local modifications"
-            ;;
+    while read stat file; do
 
-        *) die "Unexpected status ($stat) for $file" ;;
-    esac
-done < $tempfile
+        [ "$stat" != "M" ] && \
+            die "Unexpected status ($stat) for generated $file"
+        modified="$modified $file"
+
+    done < $tempfile
+
+    echo "$modified"
+
+    return 0
+}                               # function status
+
+
+echo "Checking input file status..."
+
+## The lisp portion could be more permissive, eg only care about .el files.
+modified=$(status ${autogendir:+$sources} ${ldefs_flag:+lisp} ${info_flag:+doc}) || die
+
+[ "$modified" ] && {
+    echo "Locally modified: $modified"
+    [ "$force" ] || die "There are local modifications"
+}
 
 
 ## Probably this is overkill, and there's no need to "bootstrap" just
@@ -200,58 +228,110 @@ commit ()
 
     echo "Committing..."
 
-    ## bzr status output is always relative to top-level, not PWD.
-    bzr commit -m "Auto-commit of $type files." "$@" || return $?
+    $vcs commit -m "Auto-commit of $type files." "$@" || return $?
+
+    [ "$vcs" = "git" ] && {
+        $vcs push || return $?
+    }
 
     echo "Committed files: $@"
 }                               # function commit
 
 
-[ "$autogendir" ] && {
+## No longer used since info/dir is now generated at install time if needed,
+## and is not in the repository any more.
+info_dir ()
+{
+    local basefile=build-aux/dir_top outfile=info/dir
 
-    oldpwd=$PWD
+    echo "Regenerating info/dir..."
 
-    cp $genfiles $autogendir/
+    ## Header contains non-printing characters, so this is more
+    ## reliable than using echo.
+    rm -f $outfile
+    cp $basefile $outfile
 
-    cd $autogendir || die "cd error for $autogendir"
+    local topic file dircat dirent
 
-    echo "Checking status of generated files..."
+    ## FIXME inefficient looping.
+    for topic in "Texinfo documentation system" "Emacs" "GNU Emacs Lisp" \
+        "Emacs editing modes" "Emacs network features" "Emacs misc features" \
+        "Emacs lisp libraries"; do
 
-    bzr status -S $basegen >| $tempfile || \
-        die "bzr status error for generated files"
+        cat - <<EOF >> $outfile
 
-    modified=
+$topic
+EOF
+        ## Bit faster than doc/*/*.texi.
+        for file in doc/emacs/emacs.texi doc/lispintro/*.texi \
+            doc/lispref/elisp.texi doc/misc/*.texi; do
 
-    while read stat file; do
+            ## FIXME do not ignore w32 if OS is w32.
+            case $file in
+                *-xtra.texi|*efaq-w32.texi) continue ;;
+            esac
 
-        [ "$stat" != "M" ] && \
-            die "Unexpected status ($stat) for generated $file"
+            dircat=$(sed -n -e 's/@value{emacsname}/Emacs/' -e 's/^@dircategory //p' $file)
 
-        modified="$modified $file"
+            ## TODO warn about unknown topics (check-info in top-level
+            ## Makefile does this).
+            [ "$dircat" = "$topic" ] || continue
 
-    done < $tempfile
+            sed -n -e 's/@value{emacsname}/Emacs/' \
+                -e 's/@acronym{\([A-Z]*\)}/\1/' \
+                -e '/^@direntry/,/^@end direntry/ s/^\([^@]\)/\1/p' \
+                $file >> $outfile
+
+        done
+    done
 
-    cd $oldpwd
+    local modified
 
-    commit "generated" $modified || die "bzr commit error"
+    modified=$(status $outfile) || die
+
+    commit "info/dir" $modified || die "commit error"
+}                               # function info_dir
+
+
+[ "$autogendir" ] && {
+
+    oldpwd=$PWD
+
+    cp $genfiles $autogendir/
+
+    cd $autogendir || die "cd error for $autogendir"
+
+    echo "Checking status of generated files..."
+
+    modified=$(status $basegen) || die
+
+    ## bzr status output is always relative to top-level, not PWD.
+    [ "$vcs" = "bzr" ] && cd $oldpwd
+
+    commit "generated" $modified || die "commit error"
 
     exit 0
 }                               # $autogendir
 
 
+[ "$info_flag" ] && info_dir
+
+
 [ "$ldefs_flag" ] || exit 0
 
 
 echo "Finding loaddef targets..."
 
-sed -n -e '/^AUTOGEN_VCS/,/^$/ s/\\//p' lisp/Makefile.in | \
-    sed '/AUTOGEN_VCS/d' >| $tempfile || die "sed error"
+sed -n -e '/^AUTOGEN_VCS/,/^$/p' lisp/Makefile.in | \
+    sed -e '/AUTOGEN_VCS/d' -e '/^$/d' -e 's/\\//' \
+    >| $tempfile || die "sed error"
 
 genfiles=
 
 while read genfile; do
 
-    [ -r lisp/$genfile ] || die "Unable to read $genfile"
+    genfile=lisp/$genfile
+    [ -r $genfile ] || die "Unable to read $genfile"
 
     genfiles="$genfiles $genfile"
 done < $tempfile
@@ -290,31 +370,15 @@ make -C lisp "$@" autoloads EMACS=../src/bootstrap-emacs || die "make src error"
     cp $ldefs_in $ldefs_out || die "cp ldefs_boot error"
 
 
-cd lisp
-
 echo "Checking status of loaddef files..."
 
 ## It probably would be fine to just check+commit lisp/, since
 ## making autoloads should not effect any other files.  But better
 ## safe than sorry.
-bzr status -S $genfiles ${ldefs_out#lisp/} >| $tempfile || \
-    die "bzr status error for generated files"
-
-
-modified=
-
-while read stat file; do
-
-    [ "$stat" != "M" ] && die "Unexpected status ($stat) for generated $file"
-    modified="$modified $file"
-
-done < $tempfile
-
-
-cd ../
+modified=$(status $genfiles $ldefs_out) || die
 
 
-commit "loaddefs" $modified || die "bzr commit error"
+commit "loaddefs" $modified || die "commit error"
 
 
 exit 0