X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fautodist%2Fautodist.in;h=b4c1d864296bf6c3e564fb5df326995783ff2cb4;hb=HEAD;hp=6da94f7f38418977136b0d726428d0ad0c05b025;hpb=12e583d56eed7a65a777e117cbac94a38051421d;p=autodist.git diff --git a/apps/autodist/autodist.in b/apps/autodist/autodist.in index 6da94f7..b4c1d86 100755 --- a/apps/autodist/autodist.in +++ b/apps/autodist/autodist.in @@ -2,7 +2,7 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2005 Pekka Riikonen +# Copyright (C) 2005 - 2007 Pekka Riikonen # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -129,6 +129,7 @@ licenseh= # Whether to output ad_debug information debug=false +nolog=false # Autodist version ver=@VERSION@ @@ -210,7 +211,9 @@ EOF # ad_log() { - echo "$1" >&5 + if test x$nolog = xfalse; then + echo "$1" >&5 + fi } # @@ -225,7 +228,7 @@ ad_initialize() # Create default distdir if test '!' -f $distdir; then - mkdir -p $distdir + mkdir -p -- $distdir fi # Create Autodist configuration file @@ -405,8 +408,8 @@ EOF 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 + sed '/^AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp + sed -e "/^AD_INCLUDE_CONFIGURE/d" $fname.tmp >> $fname rm -f configure.ad.cfs $fname.tmp else cat $1 >> $fname @@ -415,15 +418,18 @@ EOF # Process AD_INIT sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp + # Remove AD_DISABLE_DEPENDENCIES + sed -e "/^AD_DISABLE_DEPENDENCIES/d" $fname.tmp > $fname + # Process for distribution - rm -f $fname - ad_process_file $fname.tmp $fname false + rm -f $fname.tmp + ad_process_file $fname $fname.tmp false # Remove any trailing backslashes - if test -f "$fname"; then - sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname > configure.ac + if test -f "$fname.tmp"; then + sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp > configure.ac else - cp -p $fname.tmp configure.ac + cp -p $fname configure.ac fi rm -f $fname $fname.tmp @@ -473,35 +479,72 @@ ad_make_makefile_ams() do ad_log " $ff" fname=`echo $ff | sed s/\.ad//` + ad_make_makefile_am $ff $fname.am + done + ad_log "" + + ad_debug "Ending creating Makefile.am files" +} - # Header for the Makefile.am - cat > $fname.am < +# +ad_make_makefile_am() +{ + local am_deps=true + local f=$1 + local fname=$2 + + # Disable dependencies if requested + dc=`sed 's/^[ ]*//' < configure.ad | grep -v "^#" \ + | grep "AD_DISABLE_DEPENDENCIES"` + if test "$dc" = "AD_DISABLE_DEPENDENCIES"; then + am_deps=false + fi + + # Header for the Makefile.am + cat > $fname <> $fname.am - else - cat $ff >> $fname.am - fi + # Remove any trailing backslashes + if test -f "$fname.tmp"; then + sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp >> $fname + else + cat $f >> $fname + fi - rm -f $fname.tmp - done - ad_log "" + # Enable dependencies if requested + if test x$am_deps = xtrue; then + # Get list of configure.ad's to get them into deps also + cfs=`find . -type f -name configure\*\.ad` + cfs=`echo $cfs | sed 's/\.\///g'` - ad_debug "Ending creating Makefile.am files" + cat >> $fname < +# +ad_remove_dependencies() +{ + ad_debug "Removing dependencies" + + ams=`find $1 -type f -name Makefile\.\*` + for i in $ams + do + sed -e "/^# S_AD_ENABLE_DEPENDENCIES/,/^# E_AD_ENABLE_DEPENDENCIES/d" $i > $i.tmp + mv $i.tmp $i + done +} + # # Makes distribution sane, ala modtimes. Since we modify the distribution # we need to make it sane after that. @@ -936,6 +1006,7 @@ ad_makedist() 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 + params=`grep "params:" < autodist.dist | cut -d: -f2` || exit 1 ad_parse_distribution $distribution false ad_log " Distribution: $distribution $dist_version" ad_log " Destination directory: $am_distdir" @@ -947,7 +1018,7 @@ ad_makedist() fi # Run pre-dist-hooks - ad_run_dist_hooks "$pre_dist_hooks" + ad_run_dist_hooks "$pre_dist_hooks" "$params" # Create distribution directory ad_debug "Creating distribution directory $am_distdir" @@ -959,7 +1030,7 @@ ad_makedist() fi # Run pre-process-dist-hooks - ad_run_dist_hooks "$pre_p_dist_hooks" + ad_run_dist_hooks "$pre_p_dist_hooks" "$params" # Run excludes ad_dist_excludes "$excludes" true @@ -977,6 +1048,9 @@ ad_makedist() cp -p $license $am_distdir/COPYING || exit 1 fi + # Remove dependencies + ad_remove_dependencies $am_distdir + # Process noprocesses, first pass ad_process_noprocess true @@ -998,7 +1072,7 @@ ad_makedist() ad_process_noprocess false # Run post-process_dist-hooks - ad_run_dist_hooks "$post_p_dist_hooks" + ad_run_dist_hooks "$post_p_dist_hooks" "$params" # Make distribution sane ad_makedist_makesane @@ -1029,7 +1103,7 @@ ad_makedist() rm -f $am_distdir.tar # Run post-dist-hooks - ad_run_dist_hooks "$post_dist_hooks" + ad_run_dist_hooks "$post_dist_hooks" "$params" # Cleanup rm -rf $am_distdir @@ -1118,6 +1192,15 @@ ad_parse_distribution() ad_fatal "Distribution '$1' is not declared" fi + # Get and enforce prereq version + prereq=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ + | grep "prereq " | cut -d' ' -f2- | sort | uniq` + if test '!' -z $prereq; then + if test "$ver" \< "$prereq"; then + ad_fatal "Autodist $prereq or newer is required for distribution $1" + fi + fi + # Get inherited inhs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \ | grep "inherit " | cut -d' ' -f2 | sort | uniq` @@ -1127,7 +1210,9 @@ ad_parse_distribution() | grep "define " | cut -d' ' -f2 | sort | uniq` if test "$inhs" = "" && test "$defs" = ""; then - ad_fatal "Distribution '$1' does not define anything" + if test "$1" != "default"; then + ad_fatal "Distribution '$1' does not define anything" + fi fi # Get undefined distdefs @@ -1298,7 +1383,9 @@ ad_process_distdefs() do echo $i >>autodist.tmp.defs done - distdefs=`sort < autodist.tmp.defs | uniq` + if test -f autodist.tmp.defs; then + distdefs=`sort < autodist.tmp.defs | uniq` + fi distdefs=`echo $distdefs` rm -f autodist.tmp.defs @@ -1393,7 +1480,7 @@ ad_process_noprocess() f="$cur/autodist__noprocess" rm -rf $f - mkdir -p $f || exit 1 + mkdir -p -- $f || exit 1 # First, include them to new location with correct directory structure. old_am_distdir="$am_distdir" @@ -1460,14 +1547,12 @@ ad_process_file() ad_process_license_header $f $1 fi - ad_debug "Getting #ifdef's and #ifndef's" - # Get defined distribution defines - 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 - 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 in $1: $defs" @@ -1493,9 +1578,9 @@ ad_process_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 + echo "/^#ifdef $d$/,/^#else !$d$|^#endif $d$/ { next; }" >> $f else - echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f + echo "/^#else !$d$/,/^#endif $d$/ { next; }" >> $f fi done @@ -1516,9 +1601,9 @@ ad_process_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 + echo "/^#ifndef $d$/,/^#else $d$|^#endif $d$/ { next; }" >> $f else - echo "/^#else $d/,/^#endif $d/ { next; }" >> $f + echo "/^#else $d$/,/^#endif $d$/ { next; }" >> $f fi done @@ -1573,14 +1658,12 @@ ad_process_source_file() ad_process_license_header $f $1 fi - ad_debug "Getting #ifdef's and #ifndef's" - # Get defined distribution defines - defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_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 - ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_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 in $1: $defs" @@ -1606,9 +1689,9 @@ ad_process_source_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 + echo "/^#ifdef $d$/,/^#else \/\* \!$d |^#endif \/\* $d / { next; }" >> $f else - echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f + echo "/^#else \/\* \!$d /,/^#endif \/\* $d / { next; }" >> $f fi done @@ -1629,9 +1712,9 @@ ad_process_source_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 + echo "/^#ifndef $d$/,/^#else \/\* $d |^#endif \/\* $d / { next; }" >> $f else - echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f + echo "/^#else \/\* $d /,/^#endif \/\* $d / { next; }" >> $f fi done @@ -1640,7 +1723,7 @@ ad_process_source_file() # 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 "/^#ifdef "$DP"_DIST_|^#endif \/\* "$DP"_DIST_|^#else \/\* "$DP"_DIST_|^#else \/\* \!"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f echo "{ print; }" >> $f # Execute the script @@ -1659,10 +1742,64 @@ ad_process_source_file() ad_debug "Ending processing source file: $1 $2" } +# +# Processes a file. This is the -p, --process option. +# +# Arguments: ad_process +# +ad_process() +{ + ad_debug "Starting process: $1 $2 $3" + + nolog=true + + if test '!' -f autodist.dist; then + ad_fatal "Autodist has not been run yet to prepare source tree" + fi + + # Parse distribution + distribution=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1 + dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1 + ad_parse_distribution $distribution false + ad_process_distdefs + + # Process file + case "$1" in + makefile) + if test -z $3; then + ad_fatal "File type $1 requires argument" + fi + ad_make_makefile_am $2 $3 + exit 0;; + + configure) + ad_make_configure_ac $2 + exit 0;; + + non-source) + if test -z $3; then + ad_fatal "File type $1 requires argument" + fi + ad_process_file $2 $3 false + exit 0;; + + source) + if test -z $3; then + ad_fatal "File type $1 requires argument" + fi + ad_process_source_file $2 $3 false + exit 0;; + + *) + ad_fatal "Unknown file type: $1"; + ;; + esac +} + # # Run hooks # -# Arguments: ad_run_hooks +# Arguments: ad_run_hooks # ad_run_hooks() { @@ -1677,8 +1814,8 @@ ad_run_hooks() if test '!' -f $i; then ad_fatal "Hook script $i does not exist" fi - ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\"" - sh $i "$distribution" "$dist_version" "$package" || exit 1 + ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\" \"$2\"" + sh $i "$distribution" "$dist_version" "$package" "$2" || exit 1 done ad_log "" @@ -1688,7 +1825,7 @@ ad_run_hooks() # # Run dist hooks # -# Arguments: ad_run_dist_hooks +# Arguments: ad_run_dist_hooks # ad_run_dist_hooks() { @@ -1704,8 +1841,8 @@ ad_run_dist_hooks() ad_fatal "Dist hook script $i does not exist" fi - ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\" \"$am_distdir\"" - sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1 + ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\" \"$am_distdir\" \"$2\"" + sh $i "$distribution" "$dist_version" "$package" "$am_distdir" "$2" || exit 1 done ad_log "" @@ -1715,14 +1852,13 @@ ad_run_dist_hooks() ############################################################################### # Autodist code -usage="Usage: autodist [options] [distribution] [version]" +usage="Usage: autodist [OPTIONS] [DISTRIBUTION] [VERSION] [PARAMS]" help="\ Autodist prepares source tree for configuration, compilation and -distribution. Prepares the source tree from the \`autodist.ad' -configuration file. Generates Automake.am files from Automake.ad -files, configure.ac file from configure.ad file(s), generates the -configure script by running Autoconf tool, and generates Makefile.in -files by running Automake tool. +distribution. Generates Automake.am files from Automake.ad files, +configure.ac file from configure.ad file(s), generates the configure +script by running Autoconf tool, and generates Makefile.in files by +running Automake tool. Operation modes: -h, --help print this help, then exit @@ -1732,6 +1868,10 @@ Operation modes: -s, --distdefs [] print distribution defines of , then exit -i, --init initialize Autodist environment, create default distribution directory and distribution, then exit + -p, --process [] + process file into for distribution, + is 'makefile', 'configure', 'non-source' + or 'source' and defines the type of -m, --makedist create and package distribution --gzip create package compressed with gzip (default) --bzip2 create also package compressed with bzip2 @@ -1774,6 +1914,15 @@ while test $# -gt 0; do ad_initialize; exit 0;; + -p | --process) + shift; + if test $# -ge 2; then + ad_process $1 $2 $3 + else + echo "${usage}" 1>&2; + fi + exit 0;; + -m | --makedist) ad_makedist exit 0;; @@ -1809,7 +1958,7 @@ while test $# -gt 0; do 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 "Copyright (C) 2004 - 2007 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; @@ -1844,15 +1993,18 @@ if test $# != 0; then distfile=$distribution shift fi + ad_parse_distribution $distribution false -ad_log " Distribution: $distribution $dist_version" -ad_log "" -ad_process_distdefs if test $# != 0; then dist_version="${1}"; fi +ad_log " Distribution: $distribution $dist_version" +ad_log "" + +ad_process_distdefs + ad_debug "Preparing source tree for configuration and compilation..." ad_debug "Preparing $distribution distribution version $dist_version" @@ -1861,14 +2013,17 @@ ad_debug "Preparing $distribution distribution version $dist_version" # if test "$DISTDEFS"; then ad_create_distdefs_h -else - ad_fatal "DISTDEFS not defined in $distdir/autodist.conf" +fi + +# Get extra parameters from command line +if test $# != 0; then + shift fi # # Run pre-hooks # -ad_run_hooks "$pre_hooks" +ad_run_hooks "$pre_hooks" "$@" # # Generate the Makefile.am files from Makefile.ad files @@ -1902,11 +2057,12 @@ ad_debug "Creating autodist.dist" echo "dist:$distfile" > autodist.dist echo "ver:$dist_version" >> autodist.dist echo "distdir:$package-$dist_version" >> autodist.dist +echo "params:$@" >> autodist.dist # # Run post-hooks # -ad_run_hooks "$post_hooks" +ad_run_hooks "$post_hooks" "$@" ad_log "Source tree processed successfully." ad_debug "Done, now run ./configure and make."