#!/bin/sh # # Author: Pekka Riikonen # # Copyright (C) 2005 Pekka Riikonen # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ############################################################################### # Global variables # Packaging and compressing ad_gzip=true ad_bzip2=false ad_compress=false ad_zip=false # Distribution subdirectory distdir="distdir" am_distdir= # This current distribution distribution=default distfile=$distribution dist_version=0.0 package= bug_report= # All inherited distributions in this distribution inherits= # All distribution defines for this distribution distdefs= # All distribution undefines for this distribution undistdefs= # All distribution options options= opt_template=false opt_no_dist=false opt_no_inherit=false # All includes includes= # All excludes excludes= # All noprocesses noprocess= # 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= licenseh= # Whether to output ad_debug information debug=false # Autodist version ver=@VERSION@ ############################################################################### # Configuration file if test -f "$distdir/autodist.conf"; then . $distdir/autodist.conf fi DP=$DISTPREFIX ############################################################################### # Functions # # Print out debug information if debugging is enabled. To enable debugging # set the global variable "debug" to true value. # # Arguments: ad_debug # ad_debug() { if test x$debug = xtrue; then set -f echo autodist: $1 set +f fi } # # Prints out error message and exits the script. # # Arguments: ad_fatal # ad_fatal() { set -f echo autodist: error: $1 set +f exit 1 } # # Prints out warning message # # Arguments: ad_warning # ad_warning() { set -f echo autodist: warning: $1 set +f } # # Initializes the Autodist environment, creates default distribution # directory, and default distribution. # # Arguments: ad_initialize # ad_initialize() { ad_debug ">ad_initialize" # Create default distdir if test '!' -f $distdir; then mkdir -p $distdir fi # Create Autodist configuration file if test -f @AUTODISTDIR@/autodist.conf; then cp -p @AUTODISTDIR@/autodist.conf $distdir fi # Create default distribution if test -f @AUTODISTDIR@/default; then cp -p @AUTODISTDIR@/default $distdir fi ad_debug "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 for i in $distdefs do echo "#define $i 1" >>$fname done echo >> $fname echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname 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 $? != 0; then ad_fatal "aclocal failed" fi fi if test "$AUTOCONF"; then ad_debug "Running autoconf" $AUTOCONF if test $? != 0; then ad_fatal "autoconf failed" fi run_autoconf=true fi if test "$AUTOHEADER"; then ad_debug "Running autoheader" $AUTOHEADER if test $? != 0; then ad_fatal "autoheader failed" fi fi if test "$LIBTOOLIZE"; then ad_debug "Running libtoolize" $LIBTOOLIZE if test $? != 0; then ad_fatal "libtoolize failed" fi fi if test x$run_autoconf = xtrue; then if test '!' -f configure; then ad_fatal "creating configure script failed" fi fi ad_debug " # 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 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 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac" fi rm -f configure.ac configure.ad.cfs cfs=`find . -name configure\*\.ad` for i in $cfs do if test "x$i" = "x$1"; then continue fi ad_debug "including $i" cat $i >> configure.ad.cfs done if test -f configure.ad.cfs; then 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" fi fi # Header for configure.ac fname="configure.tmp.ac" echo "# Automatically generated by Autodist $ver. Do not edit." > $fname echo "# To make changes edit the configure.ad file in the source tree." >> $fname echo >> $fname echo "# Source: configure.ad" >> $fname echo "# Generated: `date` by `whoami`" >> $fname echo "# Distribution: $distribution" >> $fname echo "# License: $license" >> $fname echo >> $fname ad_debug "creating configure.ac" if test -f configure.ad.cfs; then sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname rm -f configure.ad.cfs $fname.tmp else cat $1 >> $fname.tmp fi # Process AD_INIT sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp # Process for distribution rm -f $fname ad_process_file $fname.tmp $fname # Remove any trailing backslashes if test -f "$fname"; then cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac else cp -p $fname.tmp configure.ac fi rm -f $fname $fname.tmp ad_debug "ad_make_makefile_ins" if test "$AUTOMAKE"; then ad_debug "Running automake" $AUTOMAKE if test $? != 0; then ad_fatal "automake failed" fi fi ad_debug "ad_make_makefile_ams" files=`find . -name Makefile\.ad` for ff in $files do 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 # Run the distribution processing for this Makefile.ad ad_debug "Processing $ff to be $fname.am" ad_process_file $ff $fname.tmp # Remove any trailing backslashes if test -f "$fname.tmp"; then cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am else cat $ff >> $fname.am fi rm -f $fname.tmp done ad_debug "ad_process_ads" files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad` for i in $files 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 done ad_debug " [] # # If only source path, which may be file, directory or regular expression, # is specified the path will be same in distribution. If the destination # path is specified that will be the new name and/or new location of the # source path. This, in effect, is a cp utility with ability to create # directories if they do not exist. # # Arguments: ad_dist_includes # 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 incs="`echo "$1" | sed 's/$/ : /'`" src= dst= for i in $incs do if test "$i" = ":" && test -z "$src"; then continue fi if test -z "$src"; then src=$i continue fi if test -z "$dst" && test "$i" != ":"; then dst=$i else dst=$src fi ad_debug "Including $src into $dst" if test -f "$src"; then # Add file if test "$src" = "$dst"; then # Add to same location d=`echo $src | sed 's,/[^/]*$,,'` if test "$d" != "$src" && test "$d" != "." && \ test '!' -d $am_distdir/$d; then mkdir -p $am_distdir/$d || exit 1 fi else # Add to different location check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'` if test "$check" != "$dst"; then ad_fatal "Invalid destination in 'include $src $dst'" fi d=`echo $dst | sed 's,/[^/]*$,,'` if test "$d" != "$dst" && test "$d" != "." && \ test '!' -d $am_distdir/$d; then mkdir -p $am_distdir/$d || exit 1 fi fi cp -p $src $am_distdir/$d || exit 1 elif test -d "$src"; then # Add directory if test "$src" = "$dst"; then # Add to same location d=`echo $src | sed 's,/[^/]*$,,'` ds=`echo $src | sed 's/\/$//'` if test "$ds" = "$d"; then d=`echo $d | sed 's,/[^/]*$,,'` fi if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then mkdir -p $am_distdir/$d || exit 1 fi cp -pR $src $am_distdir/$d || exit 1 else # Add to different location check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'` if test "$check" != "$dst"; then ad_fatal "Invalid destination in 'include $src $dst'" fi d=`echo $dst | sed 's,/[^/]*$,,'` ds=`echo $dst | sed 's/\/$//'` if test "$ds" = "$d"; then d=`echo $d | sed 's,/[^/]*$,,'` fi if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then mkdir -p $am_distdir/$d || exit 1 fi cp -pR $src $am_distdir/$dst || exit 1 fi elif test x$2 != xtrue; then # We assume regular expression in filename check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'` if test "$check" == "$src"; then if test '!' -a $src; then ad_fatal "Including $src: No such file or directory" fi src= dst= continue fi # Recursively call this function with expanded pathnames. The # reason why we don't let sh by default expand patnames 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. # If src and dst are same, then expand the pathname as we'll copy # matches to their own locations. if test "$src" = "$dst"; then # Expand pathnames, and format to our include format set +f srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1 set -f else # Destination is new, and it has to be a directory. check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'` if test "$check" != "$dst"; then ad_fatal "Invalid destination in 'include $src $dst'" fi # Make sure dst has / at the end, as this must be a directory dst=`echo $dst | sed 's/\/$//; s/$/\//'` # Escape dst for sed dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1 # Expand pathnames, and format to our include format set +f srcs=`echo $src | sed -e "s/ / $dste : /g" \ -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1 set -f fi # Include recursively ad_dist_includes "$srcs" true elif test '!' -a $src; then ad_fatal "Including $src: No such file or directory" fi src= dst= done set +f ad_debug " # # The path may be file, directory or regular expression. # # Arguments: ad_dist_includes # ad_dist_excludes() { ad_debug ">ad_dist_excludes: $1" for i in $1 do ad_debug "Excluding $i" rm -rf $am_distdir/$i done ad_debug " # 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` 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 fi for ff in $files do ad_process_file $ff $ff.tmp if test -f $ff.tmp; then rm -f $ff || exit 1 mv -f $ff.tmp $ff || exit 1 fi done ad_debug " # ad_process_source_tree() { ad_debug ">ad_process_source_tree: $1" # We take only C/C++ files since they use the C compiler friendly # version of distdefs. Other files are not assumed to use them. files=`find $am_distdir \! -name \*\.ad \( \ -name \*\.[cC] -o \ -name \*\.[cC][cCpP] -o \ -name \*\.[cC][xX][xX] -o \ -name \*\.[cC][pP][pP] -o \ -name \*\.[cC]++ -o \ -name \*\.m -o \ -name \*\.[hH] -o \ -name \*\.hh \)` # Take away noprocess list if test -f autodist.noprocess; then files=`echo $files | sh autodist.noprocess` || exit 1 fi for ff in $files do ad_process_source_file $ff $ff.tmp if test -f $ff.tmp; then rm -f $ff || exit 1 mv -f $ff.tmp $ff || exit 1 fi done ad_debug "ad_makedist_makesane:" # DO NOT change these order unless you know what you are doing. if test -f $am_distdir/configure.ac; then touch $am_distdir/configure.ac fi if test -f $am_distdir/aclocal.m4; then touch $am_distdir/aclocal.m4 fi if test '!' -f Makefile; then ad_fatal "Makefile: No such file or directory" fi configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'` touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null files=`find $am_distdir -name Makefile\.in` for i in $files do touch $i done if test -f $am_distdir/configure; then touch $am_distdir/configure fi if test -f $am_distdir/config.status; then touch $am_distdir/config.status fi ad_debug "ad_makedist" if test '!' -f autodist.dist; then ad_fatal "Autodist has not been run yet to prepare source tree" fi if test -z $MAKE; then ad_fatal "The MAKE variable is not set in autodist.conf" fi # Get distdir from Makefile if test '!' -f Makefile; then ad_fatal "The source tree is not configured, run ./configure first" fi # Parse the requested distribution distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2` dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2` 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 chmod -R a+r $am_distdir if test '!' -d $am_distdir; then ad_fatal "Distribution directory $am_distdir not created" fi # Run pre-process-dist-hooks ad_run_dist_hooks "$pre_p_dist_hooks" # Run excludes ad_dist_excludes "$excludes" # Run includes ad_dist_includes "$includes" # Include specific license file if specified if test "$license" != ""; then cp -p $license $am_distdir/COPYING || exit 1 fi # Process noprocesses ad_process_noprocess # Process source files ad_debug "Process distribution source tree" ad_process_source_tree $am_distdir # Process non-source files ad_debug "Process distribution tree" ad_process_tree $am_distdir # Run post-process_dist-hooks ad_run_dist_hooks "$post_p_dist_hooks" # Make distribution sane ad_makedist_makesane # Package ad_debug "Packaging distribution" tar chof $am_distdir.tar $am_distdir || exit 1 # Compress ad_debug "Compressing distribution package" if test x$ad_gzip = xtrue; then gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1 fi if test x$ad_bzip2 = xtrue; then bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1 fi if test x$ad_compress = xtrue; then compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1 fi if test x$ad_zip = xtrue; then rm -f $am_distdir.zip zip -rq $am_distdir.zip $am_distdir || exit 1 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 ad_debug " # # Following options are supported: # # template # no-dist # no-inherit # # Arguments: ad_handle_options # ad_handle_options() { ad_debug ">ad_handle_options: $1" for i in $1 do if test "$i" = "template"; then opt_template=true continue elif test "$i" = "no-dist"; then opt_no_dist=true continue elif test "$i" = "no-inherit"; then opt_no_inherit=true continue fi done ad_debug "ad_clear_options" opt_template=false opt_no_dist=false opt_no_inherit=false ad_debug " # 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 ad_fatal "Distribution '$1' is not declared" fi # Get inherited inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "inherit " | cut -d' ' -f2 | sort | uniq` # Get distdefs defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "define " | cut -d' ' -f2 | sort | uniq` if test "$inhs" = "" && test "$defs" = ""; then ad_fatal "Distribution '$1' does not define anything" fi # Get undefined distdefs undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "undef " | cut -d' ' -f2 | sort | uniq` # Get includes incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "include " | sed 's/include / : /'` # Get excludes excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "exclude " | cut -d' ' -f2- | sort | uniq` # Get noprocesses nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "noprocess " | cut -d' ' -f2- | sort | uniq` # Get options opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "option " | cut -d' ' -f2- | sort | uniq` # Check options ad_handle_options "$opts" if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then ad_fatal "Distribution '$1' cannot be inherited" fi if test x$2 = xfalse && test x$opt_template = xtrue; then 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" # Expand distdefs from inherited distributions for i in $inhs do if test x$1 = x$i; then ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \ distribution to not have 'inherit $i' declared." fi if test '!' -f $distdir/$i; then ad_fatal "Distribution '$i' is not declared (inherited from '$1')" fi ad_parse_distribution $i true ad_clear_options done # Get license license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "license " | cut -d' ' -f2` licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "license-header " | sed 's/license-header / : /'` ad_debug "license=$license" ad_debug "licenseh=$licenseh" if test x$2 = xfalse; then # Get distribution name dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "name " | cut -d' ' -f2-` if test "$dname"; then distribution=$dname fi # Get distribution package name (optional) dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "package " | cut -d' ' -f2` if test "$dpname"; then package=$dpname else package=$distribution fi # Get Bug-report email address (optional) 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" # Get hooks (optional) prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "pre-hook " | cut -d' ' -f2-` poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "post-hook " | cut -d' ' -f2-` prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-` podh=`cat $distdir/$1 | grep -v "^#" \ | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-` prpdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \ | grep "pre-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-` popdh=`cat $distdir/$1 | grep -v "^#" \ | grep "post-process-dist-hook " | sed 's/^[ ]*//' | 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" pre_p_dist_hooks="$pre_p_dist_hooks $prpdh" post_p_dist_hooks="$post_p_dist_hooks $popdh" options="$options $opts" ad_handle_options "$options" ad_debug "options=$options" fi # Return to caller inherits="$inherits $inhs" distdefs="$distdefs $defs" includes="$includes $incs" excludes="$excludes $excs" noprocess="$noprocess $nops" undistdefs="$undistdefs $undefs" ad_debug "ad_process_distdefs" # Remove all undefined distribution defines for i in $undistdefs do ad_debug "undefining $i distdef" 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 # Remove duplicate distdefs for i in $distdefs do echo $i >>autodist.tmp.defs done distdefs=`cat autodist.tmp.defs | sort | uniq` distdefs=`echo $distdefs` rm -f autodist.tmp.defs ad_debug "distdefs=$distdefs" ad_debug " # ad_process_license_header() { ad_debug ">ad_process_license_header" # Add : separator at the end lics=`echo "$licenseh" | sed 's/$/ : /'` src= dst= for i in $lics do if test "$i" = ":" && test -z "$src"; then continue fi if test -z "$src"; then src=$i continue fi if test -z "$dst" && test "$i" != ":"; then dst=$i else ad_fatal "Missing argument in 'license-header $src'" fi ad_debug "Replacing $src license with $dst license" if test '!' -f $src; then ad_fatal "License header $src: No such file or directory" fi if test '!' -f $dst; then ad_fatal "License header $dst: No such file or directory" fi # Awk script to replace the license header fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1 echo "/`cat autodist.lsrc`/,/`cat autodist.ldst`/ { FILE1=\"$src\"; FILE2=\"$dst\"; getline F1 < FILE1; getline F2 < FILE2; if (F1) sub(F1, F2); else { F1=\"\$\"; sub(F1, F2); } }" >> $1 rm -f autodist.lsrc autodist.ldst src= dst= done ad_debug "ad_process_noprocess" for i in $noprocess do # Escape ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1 n="$n -e 's/$am_distdir\\/$ie//'" np=true done rm -f autodist.noprocess if test x$np = xtrue; then echo $n > autodist.noprocess || exit 1 fi ad_debug " # ad_process_file() { local found=false local f local defs local ndefs # Process only regular files if test '!' -f $1; then return fi ad_debug ">ad_process_file: $1 $2" f="autodist.tmp.script" rm -f $f # If license header is provided, replace the license header in the file. ad_process_license_header $f ad_debug "Getting #ifdef's and #ifndef's" # Get defined distribution defines defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \ $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq` # Get explicitly not-defined distribution defines 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" # Create the script to include and exclude stuff in the file according # to the distribution defines # ifdefs ad_debug "processing ifdefs" for d in $defs do found=false for i in $distdefs do if test x$d = x$i; then found=true break fi done # If distribution define was not found exclude those lines from the file. # This also handles the #ifdef's #else (ie. #ifndef) branch. if test x$found = xfalse; then ad_debug "ifdef $d will be excluded (it is NOT defined)" echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f else echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f fi done # ifndefs ad_debug "processing ifndefs" for d in $ndefs do found=false for i in $distdefs do if test x$d = x$i; then found=true break fi done # If distribution define was found exclude those lines from the file. # This also handles the #ifndef's #else (ie. #ifdef) branch. if test x$found = xtrue; then ad_debug "ifndef $d will be excluded (it IS defined)" echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f else echo "/^#else $d/,/^#endif $d/ { next; }" >> $f fi done # Now process the file with the script if test -f $f; then # Those distdef lines that remain in the file are removed to make # the appearance prettier echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f echo "{ print; }" >> $f # Execute the script cp -p $1 $2 || exit 1 awk -f $f $1 > $2 || exit 1 fi rm -f $f ad_debug " # ad_process_source_file() { local found=false local f local defs local ndefs # Process only regular files if test '!' -f $1; then return fi ad_debug ">ad_process_source_file: $1 $2" f="autodist.tmp.script" rm -f $f # If license header is provided, replace the license header in the file. ad_process_license_header $f ad_debug "Getting #ifdef's and #ifndef's" # Get defined distribution defines defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \ $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq` # Get explicitly not-defined distribution defines 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" # Create the script to include and exclude stuff in the file according # to the distribution defines # ifdefs ad_debug "processing ifdefs" for d in $defs do found=false for i in $distdefs do if test x$d = x$i; then found=true break fi done # If distribution define was not found exclude those lines from the file. # This also handles the #ifdef's #else (ie. #ifndef) branch. if test x$found = xfalse; then ad_debug "ifdef $d will be excluded (it is NOT defined)" echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f else echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f fi done # ifndefs ad_debug "processing ifndefs" for d in $ndefs do found=false for i in $distdefs do if test x$d = x$i; then found=true break fi done # If distribution define was found exclude those lines from the file. # This also handles the #ifndef's #else (ie. #ifdef) branch. if test x$found = xtrue; then ad_debug "ifndef $d will be excluded (it IS defined)" echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f else echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f fi done # Now process the file with the script if test -f $f; then # Those distdef lines that remain in the file are removed to make # the appearance prettier echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f echo "{ print; }" >> $f # Execute the script cp -p $1 $2 || exit 1 awk -f $f $1 > $2 || exit 1 fi rm -f $f ad_debug " # ad_run_hooks() { ad_debug ">ad_run_hooks: $1" for i in $1 do if test '!' -f $i; then ad_fatal "Hook script $i does not exist" fi sh $i $distribution $dist_version $package || exit 1 done ad_debug " # ad_run_dist_hooks() { ad_debug ">ad_run_dist_hooks: $1" for i in $1 do 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 done ad_debug "&2; exit 1; } distdir="${1}"; shift;; --list) exit 0;; -s | --distdefs) shift; if test $# -eq 0; then ad_parse_distribution $distribution false echo "Distribution: ${distribution}" 1>&2; else ad_parse_distribution $1 false echo "Distribution: ${1}" 1>&2; fi ad_process_distdefs echo "Distdefs:" 1>&2; echo "${distdefs}"; exit 0;; -i | --init) ad_initialize; exit 0;; -m | --makedist) ad_makedist exit 0;; --gzip) ad_gzip=true shift;; --bzip2) ad_bzip2=true shift;; --compress) ad_compress=true shift;; --zip) ad_zip=true shift;; -v | --verbose) debug=true shift;; -h | --help | --h*) echo "${usage}" 1>&2; echo 1>&2; echo "${help}" 1>&2; echo 1>&2; exit 0;; -V | --version) echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2; echo "Written by Pekka Riikonen" 1>&2; echo 1>&2; echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2; echo "\ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2; exit 0;; --) shift; break;; -*) echo "${usage}" 1>&2; exit 1;; *) break;; esac done # # Parse the requested distribution # if test $# != 0; then distribution="${1}"; distfile=$distribution shift fi ad_parse_distribution $distribution false ad_process_distdefs if test $# != 0; then dist_version="${1}"; fi ad_debug "Preparing source tree for configuration and compilation..." ad_debug "Preparing $distribution distribution version $dist_version" # # Create the distribution defines header file # if test "$DISTDEFS"; then ad_create_distdefs_h else ad_fatal "DISTDEFS not defined in $distdir/autodist.conf" fi # # Run pre-hooks # ad_run_hooks "$pre_hooks" # # Generate the Makefile.am files from Makefile.ad files # ad_make_makefile_ams # # Generate the configure.ac from configure.ad file(s) # ad_make_configure_ac ./configure.ad # # Process all files with .ad suffix for distribution processing # ad_process_ads # # Generate configure script # ad_make_configure # # Generate Makefile.in files # ad_make_makefile_ins # # 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 # # Run post-hooks # ad_run_hooks "$post_hooks" ad_debug "Done, now run ./configure and make." exit 0