X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=apps%2Fautodist%2Fautodist.in;h=2e8a361498693d01395340acc9abd003f645a958;hp=27e6c22247dc15ee1b04c3fd2a7ad71919c88bfa;hb=816a5b080c797c0db47b7b274a85646343c3466e;hpb=c257b555225193e54d85daf541d29578b3c93882 diff --git a/apps/autodist/autodist.in b/apps/autodist/autodist.in index 27e6c222..2e8a3614 100755 --- a/apps/autodist/autodist.in +++ b/apps/autodist/autodist.in @@ -30,6 +30,47 @@ # 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 @@ -74,11 +115,13 @@ excludes= # All noprocesses noprocess= -# All pre, post pre-dist and post-dist hooks +# All hooks pre_hooks= post_hooks= pre_dist_hooks= post_dist_hooks= +pre_p_dist_hooks= +post_p_dist_hooks= # Distribution license and license header license= @@ -181,26 +224,29 @@ ad_create_distdefs_h() fname=$DISTDEFS rm -f $fname - echo "/*" > $fname - echo " Automatically generated by Autodist $ver. Do not edit." >> $fname - echo >> $fname - echo " Generated: `date` by `whoami`" >> $fname - echo " Distribution: $distribution" >> $fname - echo " License: $license" >> $fname - echo "*/" >> $fname - echo >> $fname - echo "#ifndef _"$DP"_DISTDEFS_H" >> $fname - echo "#define _"$DP"_DISTDEFS_H" >> $fname - echo >> $fname + cat > $fname <>$fname done - echo >> $fname - echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname + cat >> $fname <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 @@ -268,13 +319,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="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INIT"`" if test -z $check; then rm -f configure.ad.cfs rm -f $fname $fname.tmp @@ -294,7 +347,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="`sed 's/^[ ]*//' < $1 | 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" @@ -303,14 +356,16 @@ ad_make_configure_ac() # Header for configure.ac fname="configure.tmp.ac" - echo "# Automatically generated by Autodist $ver. Do not edit." > $fname - echo "# To make changes edit the $i file in the source tree." >> $fname - echo >> $fname - echo "# Source: $i" >> $fname - echo "# Generated: `date` by `whoami`" >> $fname - echo "# Distribution: $distribution" >> $fname - echo "# License: $license" >> $fname - echo >> $fname + cat > $fname < configure.ac + sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname > configure.ac else cp -p $fname.tmp configure.ac fi @@ -376,14 +431,16 @@ ad_make_makefile_ams() fname=`echo $ff | sed s/\.ad//` # Header for the Makefile.am - echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am - echo "# To make changes edit the $ff file in the source tree." >> $fname.am - echo >> $fname.am - echo "# Source: $ff" >> $fname.am - echo "# Generated: `date` by `whoami`" >> $fname.am - echo "# Distribution: $distribution" >> $fname.am - echo "# License: $license" >> $fname.am - echo >> $fname.am + cat > $fname.am <> $fname.am + sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp >> $fname.am else cat $ff >> $fname.am fi @@ -417,16 +474,6 @@ ad_process_ads() do fname=`echo $i | sed s/\.ad//` - # Header - echo "# Automatically generated by Autodist $ver. Do not edit." > $fname - echo "# To make changes edit the $i file in the source tree." >> $fname - echo >> $fname - echo "# Source: $i" >> $fname - echo "# Generated: `date` by `whoami`" >> $fname - echo "# Distribution: $distribution" >> $fname - echo "# License: $license" >> $fname - echo >> $fname - # Run the distribution processing for this file ad_debug "Processing $i to be $fname" ad_process_file $i $fname @@ -453,13 +500,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= @@ -553,7 +602,7 @@ ad_dist_includes() fi # Recursively call this function with expanded pathnames. The - # reason why we don't let sh by default expand patnames is that + # reason why we don't let sh by default expand pathnames is that # the include's destination is optional. If sh expands by default # we don't know the destination. For this reason, we handle the # expansion here ourselves. @@ -639,16 +688,21 @@ ad_process_tree() { ad_debug ">ad_process_tree: $1" - # We take all files, other than *.ad, including source files, in case - # they use the non-C-compiler-friendly format of distdefs, which is - # possible. - - files=`find $am_distdir \! -name \*\.ad` + # Take files, except source and .ad files. + files=`find $am_distdir \! -name \*\.ad \( \ + \! -name \*\.[cC] -a \ + \! -name \*\.[cC][cCpP] -a \ + \! -name \*\.[cC][xX][xX] -a \ + \! -name \*\.[cC][pP][pP] -a \ + \! -name \*\.[cC]++ -a \ + \! -name \*\.m -a \ + \! -name \*\.[hH] -a \ + \! -name \*\.hh \)` files=`echo $files | sed 's/$am_distdir//'` # Take away noprocess list if test -f autodist.noprocess; then - files=`echo $files | sh autodist.noprocess` || exit 1 + files=`echo $files" " | sh autodist.noprocess` || exit 1 fi for ff in $files @@ -692,7 +746,7 @@ ad_process_source_tree() # Take away noprocess list if test -f autodist.noprocess; then - files=`echo $files | sh autodist.noprocess` || exit 1 + files=`echo $files" " | sh autodist.noprocess` || exit 1 fi for ff in $files @@ -730,7 +784,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` @@ -774,16 +828,19 @@ 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=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1 + dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1 + am_distdir=`grep "distdir:" < autodist.dist | 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" fi + # Run pre-dist-hooks + ad_run_dist_hooks "$pre_dist_hooks" + # Create distribution directory ad_debug "Creating distribution directory $am_distdir" $MAKE distdir || exit 1 @@ -793,8 +850,8 @@ ad_makedist() ad_fatal "Distribution directory $am_distdir not created" fi - # Run pre-dist-hooks - ad_run_dist_hooks "$pre_dist_hooks" + # Run pre-process-dist-hooks + ad_run_dist_hooks "$pre_p_dist_hooks" # Run excludes ad_dist_excludes "$excludes" @@ -818,8 +875,8 @@ ad_makedist() ad_debug "Process distribution tree" ad_process_tree $am_distdir - # Run post-dist-hooks - ad_run_dist_hooks "$post_dist_hooks" + # Run post-process_dist-hooks + ad_run_dist_hooks "$post_p_dist_hooks" # Make distribution sane ad_makedist_makesane @@ -845,6 +902,9 @@ ad_makedist() fi rm -f $am_distdir.tar + # Run post-dist-hooks + ad_run_dist_hooks "$post_dist_hooks" + # Cleanup rm -rf $am_distdir rm -f autodist.noprocess @@ -912,6 +972,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 @@ -919,11 +996,11 @@ ad_parse_distribution() fi # Get inherited - local inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + inhs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "inherit " | cut -d' ' -f2 | sort | uniq` # Get distdefs - local defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + defs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "define " | cut -d' ' -f2 | sort | uniq` if test "$inhs" = "" && test "$defs" = ""; then @@ -931,23 +1008,23 @@ ad_parse_distribution() fi # Get undefined distdefs - local undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + undefs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "undef " | cut -d' ' -f2 | sort | uniq` # Get includes - local incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + incs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "include " | sed 's/include / : /'` # Get excludes - local excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + excs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "exclude " | cut -d' ' -f2- | sort | uniq` # Get noprocesses - local nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + nops=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "noprocess " | cut -d' ' -f2- | sort | uniq` # Get options - local opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + opts=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "option " | cut -d' ' -f2- | sort | uniq` # Check options @@ -959,13 +1036,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 @@ -984,17 +1061,17 @@ ad_parse_distribution() done # Get license - license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + license=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "license " | cut -d' ' -f2` - licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + licenseh=`sed 's/^[ ]*//' < $distdir/$1 | 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=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "name " | cut -d' ' -f2-` if test "$dname"; then @@ -1002,7 +1079,7 @@ ad_parse_distribution() fi # Get distribution package name (optional) - local dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + dpname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "package " | cut -d' ' -f2` if test "$dpname"; then @@ -1012,35 +1089,41 @@ ad_parse_distribution() fi # Get Bug-report email address (optional) - local bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + bugr=`sed 's/^[ ]*//' < $distdir/$1 | 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=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "pre-hook " | cut -d' ' -f2-` - local poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ + poh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "post-hook " | cut -d' ' -f2-` - local prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ - | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-` - local podh=`cat $distdir/$1 | grep -v "^#" \ - | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-` + prdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ + | grep "pre-dist-hook " | cut -d' ' -f2-` + podh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ + | grep "post-dist-hook " | cut -d' ' -f2-` + prpdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ + | grep "pre-process-dist-hook " | cut -d' ' -f2-` + popdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ + | grep "post-process-dist-hook " | cut -d' ' -f2-` pre_hooks="$pre_hooks $prh" post_hooks="$post_hooks $poh" pre_dist_hooks="$pre_dist_hooks $prdh" post_dist_hooks="$post_dist_hooks $podh" - options="$options $opts" + pre_p_dist_hooks="$pre_p_dist_hooks $prpdh" + post_p_dist_hooks="$post_p_dist_hooks $popdh" + doptions="$doptions $opts" - ad_handle_options "$options" - ad_debug "options=$options" + ad_handle_options "$doptions" + ad_debug "options: $doptions" fi # Return to caller @@ -1071,15 +1154,14 @@ 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 do echo $i >>autodist.tmp.defs done - distdefs=`cat autodist.tmp.defs | sort | uniq` + distdefs=`sort < autodist.tmp.defs | uniq` distdefs=`echo $distdefs` rm -f autodist.tmp.defs @@ -1147,19 +1229,22 @@ ad_process_license_header() # ad_process_noprocess() { - ad_debug ">ad_process_noprocess" local np=false - local n="sed " + ad_debug ">ad_process_noprocess" + + cur=`pwd` + cd $am_distdir || exit 1 for i in $noprocess do # Escape ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1 - n="$n -e 's/$am_distdir\\/$ie//'" + n="$n -e 's/$am_distdir\\/$ie //'" np=true done + cd $cur || exit 1 rm -f autodist.noprocess if test x$np = xtrue; then @@ -1177,6 +1262,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 @@ -1185,7 +1273,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. @@ -1194,15 +1282,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 @@ -1279,6 +1367,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 @@ -1287,7 +1378,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. @@ -1296,14 +1387,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 @@ -1386,7 +1478,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 " autodist.dist echo "ver:$dist_version" >> autodist.dist -echo "$package-$dist_version" >> autodist.dist +echo "distdir:$package-$dist_version" >> autodist.dist # # Run post-hooks