autogen.sh 0.4.0:
authorHans Ulrich Niedermann <hun@n-dimensional.de>
Sat, 16 Apr 2005 01:48:18 +0000 (03:48 +0200)
committerHans Ulrich Niedermann <hun@n-dimensional.de>
Sat, 16 Apr 2005 01:48:18 +0000 (03:48 +0200)
  - properly handle recursion
  - add --dry-run mode

autogen.sh

index 1f7547abc5cc22078a2519b28990c3876a9954cb..d31421878975b1c2cd75b31edc8cb8be8f6ac93e 100755 (executable)
@@ -15,32 +15,32 @@ fi
 ########################################################################
 # Constant and initial values
 
-debug=false
+debug="false"
+recursive="false"
+dryrun="false"
 self="$(basename "$0")"
-autogen_version="0.3.2"
+autogen_version="0.4.0"
 
 
 ########################################################################
 # Print help message
 
 print_help() {
-    cat<<EOF
-$self - initialize automake/autoconf/gettext/libtool based build system
+    cat<<__HELP_EOF__
+${self} - initialize automake/autoconf/gettext/libtool based build system
 
 Usage:
-    $self [<command>...] [<directory>...]
+    ${self} [<command>|<flag>|...] [<directory>...]
 
 Runs given command sequence on all given directories, in sequence.
 If there is no command given, --init is assumed.
-If there is no directory given, the location of $self is assumed.
+If there is no directory given, the location of ${self} is assumed.
 
 Commands:
     --help
         Print this help text
     --version
         Print the tool versions
-    --verbose
-        Verbose output
 
     --clean
         Clean all files and directories generated by "$self --init"
@@ -49,12 +49,22 @@ Commands:
         can be processed further by running the classic
           ./configure && make && make install
 
-$self depends on automake, autoconf, libtool and gettext.
+Flags:
+    --verbose
+        Verbose output
+    --dry-run
+        Only print the commands to be run, not actually execute
+        them.
+    --recursive
+        Used internally. Do everything which doesn't recurse on
+        its own.
+
+${self} depends on automake, autoconf, libtool and gettext.
 
 You may want to set AUTOCONF, AUTOHEADER, AUTOMAKE, ACLOCAL,
 AUTOPOINT, LIBTOOLIZE to use specific version of these tools, and
 AUTORECONF_OPTS to add options to the call to autoreconf.
-EOF
+__HELP_EOF__
 }
 
 
@@ -103,7 +113,7 @@ init_vars() {
        fi
     fi
 
-    echo -n "Initializing variables for \`${dir}'..."
+    "$debug" && echo -n "Initializing variables for \`${dir}'..."
     # FIXME: Just getting those directories and cleaning them isn't enough.
     #        OK, the "init" part is done recursively by autopoint, so that is easy.
     #        But the cleaning should also work recursively, but that is difficult
@@ -164,100 +174,91 @@ README
 EOF
     AG_GEN_GETTEXT="$AG_AUX/mkinstalldirs $AG_AUX/config.rpath ABOUT-NLS"
     while read file; do
-       AG_GEN_GETTEXT="${AG_GEN_GETTEXT} ${file}"
+       AG_GEN_GETTEXT="${AG_GEN_GETTEXT} m4/${file} m4m/${file}"
     done <<EOF
-m4/codeset.m4
-m4/gettext.m4
-m4/glibc21.m4
-m4/iconv.m4
-m4/intdiv0.m4
-m4/intmax.m4
-m4/inttypes-pri.m4
-m4/inttypes.m4
-m4/inttypes_h.m4
-m4/isc-posix.m4
-m4/lcmessage.m4
-m4/lib-ld.m4
-m4/lib-link.m4
-m4/lib-prefix.m4
-m4/longdouble.m4
-m4/longlong.m4
-m4/nls.m4
-m4/po.m4
-m4/printf-posix.m4
-m4/progtest.m4
-m4/signed.m4
-m4/size_max.m4
-m4/stdint_h.m4
-m4/uintmax_t.m4
-m4/ulonglong.m4
-m4/wchar_t.m4
-m4/wint_t.m4
-m4/xsize.m4
-m4m/codeset.m4
-m4m/gettext.m4
-m4m/glibc21.m4
-m4m/iconv.m4
-m4m/intdiv0.m4
-m4m/intmax.m4
-m4m/inttypes-pri.m4
-m4m/inttypes.m4
-m4m/inttypes_h.m4
-m4m/isc-posix.m4
-m4m/lcmessage.m4
-m4m/lib-ld.m4
-m4m/lib-link.m4
-m4m/lib-prefix.m4
-m4m/longdouble.m4
-m4m/longlong.m4
-m4m/nls.m4
-m4m/po.m4
-m4m/printf-posix.m4
-m4m/progtest.m4
-m4m/signed.m4
-m4m/size_max.m4
-m4m/stdint_h.m4
-m4m/uintmax_t.m4
-m4m/ulonglong.m4
-m4m/wchar_t.m4
-m4m/wint_t.m4
-m4m/xsize.m4
-po/Makefile.in.in
-po/Makevars.template
-po/Rules-quot
-po/boldquot.sed
-po/en@boldquot.header
-po/en@quot.header
-po/insert-header.sin
-po/quot.sed
-po/remove-potcdate.sin
-po/stamp-po
+codeset.m4
+gettext.m4
+glibc21.m4
+iconv.m4
+intdiv0.m4
+intmax.m4
+inttypes-pri.m4
+inttypes.m4
+inttypes_h.m4
+isc-posix.m4
+lcmessage.m4
+lib-ld.m4
+lib-link.m4
+lib-prefix.m4
+longdouble.m4
+longlong.m4
+nls.m4
+po.m4
+printf-posix.m4
+progtest.m4
+signed.m4
+size_max.m4
+stdint_h.m4
+uintmax_t.m4
+ulonglong.m4
+wchar_t.m4
+wint_t.m4
+xsize.m4
+EOF
+    while read file; do
+       AG_GEN_GETTEXT="${AG_GEN_GETTEXT} po/${file}"
+    done <<EOF
+Makefile.in.in
+Makevars.template
+Rules-quot
+boldquot.sed
+en@boldquot.header
+en@quot.header
+insert-header.sin
+quot.sed
+remove-potcdate.sin
+stamp-po
 EOF
     AG_GEN_CONF="config.status config.log"
     AG_GEN_FILES="$AG_GEN_ACAM $AG_GEN_RECONF $AG_GEN_GETTEXT"
     AG_GEN_FILES="$AG_GEN_FILES $AG_GEN_CONFIG_H $AG_GEN_CONF $AG_GEN_LIBTOOL"
     AG_GEN_DIRS="autom4te.cache ${AG_LIBLTDL_DIR}/autom4te.cache ${AG_LIBLTDL_DIR}"
-    echo " done."
+    "$debug" && echo " done."
 
     if "$debug"; then set | grep '^AG_'; fi
+    dryrun_param=""
+    if "$dryrun"; then dryrun_param="--dry-run"; fi
+}
+
+
+########################################################################
+# Print command to be executed and, if not dryrun, actually execute it.
+
+execute_command() {
+    if "$dryrun" || "$debug"; then
+       echo "Running <<" "$@" ">>"
+    fi
+    if "$dryrun"; then :; else
+       "$@"
+    fi
 }
 
 
 ########################################################################
 # Clean generated files from $* directories
 
-clean() {
+command_clean() {
     if test "x$AG_GEN_FILES" = "x"; then echo "Internal error"; exit 2; fi
     dir="$1"
-    while test "$dir"; do
+    #while test "$dir"; do
        echo "$self:clean: Entering directory \`${dir}'"
        (
            if cd "$dir"; then
                echo -n "Cleaning autogen generated files..."
-               rm -rf ${AG_GEN_DIRS}
-               rm -f ${AG_GEN_FILES}
+               execute_command rm -rf ${AG_GEN_DIRS}
+               execute_command rm -f ${AG_GEN_FILES}
                echo " done."
-               if test -h INSTALL; then rm -f INSTALL; fi
+               if test -h INSTALL; then execute_command rm -f INSTALL; fi
                echo -n "Cleaning generated Makefile, Makefile.in files..."
                if "$debug"; then echo; fi
                find . -type f -name 'Makefile.am' -print | \
@@ -269,25 +270,30 @@ clean() {
                    if "$debug"; then
                        echo -e "  Removing files created from ${file}"
                    fi
-                   rm -f "${base}" "${base}.in"
+                   execute_command rm -f "${base}" "${base}.in"
                done
                if "$debug"; then :; else echo " done."; fi
                echo -n "Removing *~ backup files..."
-               find . -type f -name '*~' -exec rm -f {} \;
+               find . -type f -name '*~' -print | while read fname; do
+                   execute_command rm -f "$fname"
+               done
                echo " done."
+               if test -n "${AG_SUBDIRS}"; then
+                   "$0" --clean ${dryrun_param} --recursive ${AG_SUBDIRS}
+               fi
            fi
        )
        echo "$self:clean: Left directory \`${dir}'"
-       shift
-       dir="$1"
-    done
+       #shift
+       #dir="$1"
+    #done
 }
 
 
 ########################################################################
 # Initialize build system in $1 directory
 
-init() {
+command_init() {
     dir="$1"
     if test "x$AG_GEN_FILES" = "x"; then echo "Internal error"; exit 2; fi
     echo "$self:init: Entering directory \`${dir}'"
@@ -296,23 +302,26 @@ if cd "${dir}"; then
     if test "x$AG_LIBLTDL_DIR" != "x"; then
        # We have to run libtoolize --ltdl ourselves because
        #   - autoreconf doesn't run it at all
-       echo "Running <<" ${LIBTOOLIZE-"libtoolize"} --ltdl ">>"
-       ${LIBTOOLIZE-"libtoolize"} --ltdl
+       execute_command "${LIBTOOLIZE-"libtoolize"}" --ltdl
        # And we have to clean up the generated files after libtoolize because
        #   - we still want symlinks for the files
        #   - but we want to (implicitly) AC_CONFIG_SUBDIR and that writes to
        #     these files.
-       (cd "${AG_LIBLTDL_DIR}" && rm -f aclocal.m4 config.guess config.sub configure install-sh ltmain.sh Makefile.in missing)
+       (cd "${AG_LIBLTDL_DIR}" && execute_command rm -f aclocal.m4 config.guess config.sub configure install-sh ltmain.sh Makefile.in missing)
+    fi
+    if test -n "${AG_SUBDIRS}"; then
+       "$0" --init ${dryrun_param} --recursive ${AG_SUBDIRS}
+    fi
+    if "$recursive"; then :; else
+       if execute_command autoreconf --install --symlink ${AUTORECONF_OPTS}; then
+           :; else
+           status="$?"
+           echo "autoreconf quit with exit code $status, aborting."
+           exit "$status"
+       fi    
+       echo "You may run ./configure now in \`${dir}'."
+       echo "Run as \"./configure --help\" to find out about config options."
     fi
-    echo "Running <<" autoreconf --install --symlink ${AUTORECONF_OPTS} ">>"
-    if autoreconf --install --symlink ${AUTORECONF_OPTS}; then
-       :; else
-       status="$?"
-       echo "autoreconf quit with exit code $status, aborting."
-       exit "$status"
-    fi    
-    echo "You may run ./configure now in \`${dir}'."
-    echo "Run as \"./configure --help\" to find out about config options."
 else
     exit "$?"
 fi
@@ -348,7 +357,13 @@ for param in $@; do
            check_versions=:
            ;;
        --verbose)
-           debug="true"
+           debug=:
+           ;;
+       --dry-run)
+           dryrun=:
+           ;;
+       --recursive)
+           recursive=:
            ;;
        --version)
            print_versions
@@ -385,6 +400,7 @@ if "$check_versions"; then
 "
        while read tool minversion; do
                version="$("$tool" --version | sed 's/^.*(.*) *\(.*\)$/\1/g;1q')"
+               # compare version and minversion
                first="$(echo "$version$lf$minversion" | sort -n | sed '1q')"
                if test "x$minversion" != "x$first" && test "x$version" = "x$first"; then
                        echo "Version \`$version' of \`$tool' not sufficient. At least \`$minversion' required."
@@ -410,13 +426,13 @@ fi
 # Actually run the commands
 
 for dir in ${dirs}; do
-    echo "Running commands on directory \`${dir}'"
+    "$debug" && echo "Running commands on directory \`${dir}'"
     if test ! -d "$dir"; then
        echo "Could not find directory \`${dir}'"       
     fi
     init_vars "$dir"
     for command in ${commands}; do
-       "$command" "$dir" ${AG_SUBDIRS}
+       "command_$command" "$dir"
     done
 done