updates.
[autodist.git] / apps / autodist / autodist.in
index d969cd856d085f891cf1b6ba4aae80e35e680855..b16f696bf61307b3fd041dc9744bbbdd2a6ebeea 100755 (executable)
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
+###############################################################################
+# Shell compatibility
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  # Despite of this, we have managed to segfault some zsh's.
+  emulate sh
+  NULLCMD=:
+  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+  LC_TELEPHONE LC_TIME
+do
+  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+    eval $as_var=C; export $as_var
+  else
+    $as_unset $as_var
+  fi
+done
+
+
 ###############################################################################
 # Global variables
 
@@ -60,7 +101,7 @@ distdefs=
 undistdefs=
 
 # All distribution options
-options=
+doptions=
 opt_template=false
 opt_no_dist=false
 opt_no_inherit=false
@@ -214,14 +255,19 @@ ad_create_distdefs_h()
 #
 ad_make_configure()
 {
-  ad_debug ">ad_make_configure"
   local run_autoconf=false
 
+  ad_debug ">ad_make_configure"
+
   rm -f configure
 
   if test "$ACLOCAL"; then
     ad_debug "Running aclocal"
-    $ACLOCAL 1>/dev/null 2>/dev/null
+    if test x$debug = xtrue; then
+      $ACLOCAL
+    else
+      $ACLOCAL 1>/dev/null 2>/dev/null
+    fi
     if test $? != 0; then
       ad_fatal "aclocal failed"
     fi
@@ -270,13 +316,15 @@ ad_make_configure()
 #
 ad_make_configure_ac()
 {
+  local check
+
   ad_debug ">ad_make_configure_ac: $1"
 
   if test '!' -f $1; then
     ad_fatal "The configure file '$1' does not exist"
   fi
 
-  local check="`cat $1 | sed 's/^[     ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
+  check="`cat $1 | sed 's/^[   ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
   if test -z $check; then
     rm -f configure.ad.cfs
     rm -f $fname $fname.tmp
@@ -296,7 +344,7 @@ ad_make_configure_ac()
   done
 
   if test -f configure.ad.cfs; then
-    local check="`cat $1 | sed 's/^[   ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
+    check="`cat $1 | sed 's/^[         ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
     if test -z $check; then
       rm -f configure.ad.cfs
       ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
@@ -332,7 +380,7 @@ ad_make_configure_ac()
 
   # Remove any trailing backslashes
   if test -f "$fname"; then
-    cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
+    cat $fname | sed -e :a -e '/\\$/N; s/[     ]*\\\n//; ta' > configure.ac
   else
     cp -p $fname.tmp configure.ac
   fi
@@ -393,7 +441,7 @@ ad_make_makefile_ams()
 
     # Remove any trailing backslashes
     if test -f "$fname.tmp"; then
-      cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
+      cat $fname.tmp | sed -e :a -e '/\\$/N; s/[       ]*\\\n//; ta' >> $fname.am
     else
       cat $ff >> $fname.am
     fi
@@ -455,13 +503,15 @@ ad_process_ads()
 #
 ad_dist_includes()
 {
+  local incs
+
   ad_debug ">ad_dist_includes: $1 $2"
 
   # By default do not expand pathnames
   set -f
 
   # Add : separator at the end
-  local incs="`echo "$1" | sed 's/$/ : /'`"
+  incs="`echo "$1" | sed 's/$/ : /'`"
 
   src=
   dst=
@@ -732,7 +782,7 @@ ad_makedist_makesane()
     ad_fatal "Makefile: No such file or directory"
   fi
 
-  configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
+  configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[    ]*//'`
   touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
 
   files=`find $am_distdir -name Makefile\.in`
@@ -776,11 +826,11 @@ ad_makedist()
   fi
 
   # Parse the requested distribution
-  distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
-  dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
+  distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2` || exit 1
+  dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2` || exit 1
+  am_distdir=`cat autodist.dist | grep "distdir:" | cut -d: -f2` || exit 1
   ad_parse_distribution $distribution false
   ad_process_distdefs
-  am_distdir="$package-$dist_version"
 
   if test x$opt_no_dist = xtrue; then
     ad_fatal "The '$distribution' distribution cannot be packaged"
@@ -920,6 +970,23 @@ ad_clear_options()
 #
 ad_parse_distribution()
 {
+  local inhs
+  local defs
+  local undefs
+  local incs
+  local excs
+  local nops
+  local opts
+  local dname
+  local dpname
+  local bugr
+  local prh
+  local poh
+  local prdh
+  local podh
+  local prpdh
+  local popdh
+
   ad_debug ">ad_parse_distribution: $1 $2"
 
   if test '!' -f $distdir/$1; then
@@ -927,11 +994,11 @@ ad_parse_distribution()
   fi
 
   # Get inherited
-  local inhs=`cat $distdir/$1 | sed 's/^[      ]*//' | grep -v "^#" \
+  inhs=`cat $distdir/$1 | sed 's/^[    ]*//' | grep -v "^#" \
     | grep "inherit " | cut -d' ' -f2 | sort | uniq`
 
   # Get distdefs
-  local defs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  defs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
    | grep "define " | cut -d' ' -f2 | sort | uniq`
 
   if test "$inhs" = "" && test "$defs" = ""; then
@@ -939,23 +1006,23 @@ ad_parse_distribution()
   fi
 
   # Get undefined distdefs
-  local undefs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  undefs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
    | grep "undef " | cut -d' ' -f2 | sort | uniq`
 
   # Get includes
-  local incs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  incs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
     | grep "include " | sed 's/include / : /'`
 
   # Get excludes
-  local excs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  excs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
     | grep "exclude " | cut -d' ' -f2- | sort | uniq`
 
   # Get noprocesses
-  local nops=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  nops=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
     | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
 
   # Get options
-  local opts=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+  opts=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
     | grep "option " | cut -d' ' -f2- | sort | uniq`
 
   # Check options
@@ -967,13 +1034,13 @@ ad_parse_distribution()
     ad_fatal "Template distribution '$1' cannot be prepared or packaged"
   fi
 
-  ad_debug "inherits=$inhs"
-  ad_debug "distdefs=$defs"
-  ad_debug "includes=$incs"
-  ad_debug "excludes=$excs"
-  ad_debug "noprocess=$nops"
-  ad_debug "undistdefs=$undefs"
-  ad_debug "options=$opts"
+  ad_debug "inherits$inhs"
+  ad_debug "distdefs$defs"
+  ad_debug "includes$incs"
+  ad_debug "excludes$excs"
+  ad_debug "noprocess$nops"
+  ad_debug "undistdefs$undefs"
+  ad_debug "options$opts"
 
   # Expand distdefs from inherited distributions
   for i in $inhs
@@ -997,12 +1064,12 @@ ad_parse_distribution()
   licenseh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
     | grep "license-header " | sed 's/license-header / : /'`
 
-  ad_debug "license=$license"
-  ad_debug "licenseh=$licenseh"
+  ad_debug "license$license"
+  ad_debug "licenseh$licenseh"
 
   if test x$2 = xfalse; then
     # Get distribution name
-    local dname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    dname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
       | grep "name " | cut -d' ' -f2-`
 
     if test "$dname"; then
@@ -1010,7 +1077,7 @@ ad_parse_distribution()
     fi
 
     # Get distribution package name (optional)
-    local dpname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    dpname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "package " | cut -d' ' -f2`
 
     if test "$dpname"; then
@@ -1020,29 +1087,29 @@ ad_parse_distribution()
     fi
 
     # Get Bug-report email address (optional)
-    local bugr=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    bugr=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "bug-report " | cut -d' ' -f2-`
 
     if test "$bugr"; then
       bug_report=$bugr
     fi
 
-    ad_debug "distribution=$distribution"
-    ad_debug "package=$package"
-    ad_debug "bug-report=$bug_report"
+    ad_debug "distribution$distribution"
+    ad_debug "package$package"
+    ad_debug "bug-report$bug_report"
 
     # Get hooks (optional)
-    local prh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    prh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "pre-hook " | cut -d' ' -f2-`
-    local poh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    poh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "post-hook " | cut -d' ' -f2-`
-    local prdh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    prdh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "pre-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
-    local podh=`cat $distdir/$1 | grep -v "^#" \
+    podh=`cat $distdir/$1 | grep -v "^#" \
      | grep "post-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
-    local prpdh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
+    prpdh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
      | grep "pre-process-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
-    local popdh=`cat $distdir/$1 | grep -v "^#" \
+    popdh=`cat $distdir/$1 | grep -v "^#" \
      | grep "post-process-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
 
     pre_hooks="$pre_hooks $prh"
@@ -1051,10 +1118,10 @@ ad_parse_distribution()
     post_dist_hooks="$post_dist_hooks $podh"
     pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
     post_p_dist_hooks="$post_p_dist_hooks $popdh"
-    options="$options $opts"
+    doptions="$doptions $opts"
 
-    ad_handle_options "$options"
-    ad_debug "options=$options"
+    ad_handle_options "$doptions"
+    ad_debug "options: $doptions"
   fi
 
   # Return to caller
@@ -1085,8 +1152,7 @@ ad_process_distdefs()
     distdefs=`echo $distdefs | sed s/$i//`
   done
 
-  rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
-  rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
+  rm -f autodist.tmp.defs
 
   # Remove duplicate distdefs
   for i in $distdefs
@@ -1161,11 +1227,11 @@ ad_process_license_header()
 #
 ad_process_noprocess()
 {
-  ad_debug ">ad_process_noprocess"
   local np=false
-
   local n="sed "
 
+  ad_debug ">ad_process_noprocess"
+
   for i in $noprocess
   do
     # Escape
@@ -1191,6 +1257,9 @@ ad_process_noprocess()
 ad_process_file()
 {
   local found=false
+  local f
+  local defs
+  local ndefs
 
   # Process only regular files
   if test '!' -f $1; then
@@ -1199,7 +1268,7 @@ ad_process_file()
 
   ad_debug ">ad_process_file: $1 $2"
 
-  local f="autodist.tmp.script"
+  f="autodist.tmp.script"
   rm -f $f
 
   # If license header is provided, replace the license header in the file.
@@ -1208,15 +1277,15 @@ ad_process_file()
   ad_debug "Getting #ifdef's and #ifndef's"
 
   # Get defined distribution defines
-  local defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
+  defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
     $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
 
   # Get explicitly not-defined distribution defines
-  local ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
+  ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
     $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
 
-  ad_debug "defs=$defs"
-  ad_debug "ndefs=$ndefs"
+  ad_debug "defs in $1: $defs"
+  ad_debug "ndefs in $1: $ndefs"
 
   # Create the script to include and exclude stuff in the file according
   # to the distribution defines
@@ -1293,6 +1362,9 @@ ad_process_file()
 ad_process_source_file()
 {
   local found=false
+  local f
+  local defs
+  local ndefs
 
   # Process only regular files
   if test '!' -f $1; then
@@ -1301,7 +1373,7 @@ ad_process_source_file()
 
   ad_debug ">ad_process_source_file: $1 $2"
 
-  local f="autodist.tmp.script"
+  f="autodist.tmp.script"
   rm -f $f
 
   # If license header is provided, replace the license header in the file.
@@ -1310,14 +1382,15 @@ ad_process_source_file()
   ad_debug "Getting #ifdef's and #ifndef's"
 
   # Get defined distribution defines
-  local defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
+  defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
     $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
 
   # Get explicitly not-defined distribution defines
-  local ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
+  ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
     $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
 
-  ad_debug "defs=$defs ndefs=$ndefs"
+  ad_debug "defs in $1: $defs"
+  ad_debug "ndefs in $1: $ndefs"
 
   # Create the script to include and exclude stuff in the file according
   # to the distribution defines
@@ -1400,7 +1473,7 @@ ad_run_hooks()
     if test '!' -f $i; then
       ad_fatal "Hook script $i does not exist"
     fi
-    sh $i $distribution $dist_version $package || exit 1
+    sh $i "$distribution" "$dist_version" "$package" || exit 1
   done
 
   ad_debug "<ad_run_hooks: $1"
@@ -1420,7 +1493,7 @@ ad_run_dist_hooks()
     if test '!' -f $i; then
       ad_fatal "Dist hook script $i does not exist"
     fi
-    sh $i $distribution $dist_version $package $am_distdir || exit 1
+    sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1
   done
 
   ad_debug "<ad_run_dist_hooks: $1"
@@ -1582,6 +1655,11 @@ ad_make_makefile_ams
 #
 ad_make_configure_ac ./configure.ad
 
+#
+# Process all files with .ad suffix for distribution processing
+#
+ad_process_ads
+
 #
 # Generate configure script
 #
@@ -1592,18 +1670,13 @@ ad_make_configure
 #
 ad_make_makefile_ins
 
-#
-# Process all files with .ad suffix for distribution processing
-#
-ad_process_ads
-
 #
 # Create autodist.dist
 #
 ad_debug "Creating autodist.dist"
 echo "dist:$distfile" > autodist.dist
 echo "ver:$dist_version" >> autodist.dist
-echo "$package-$dist_version" >> autodist.dist
+echo "distdir:$package-$dist_version" >> autodist.dist
 
 #
 # Run post-hooks