3 # Author: Pekka Riikonen <priikone@silcnet.org>
5 # Copyright (C) 2005 Pekka Riikonen
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. The name of the author may not be used to endorse or promote
18 # products derived from this software without specific prior written
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 # NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26 # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ###############################################################################
36 # Packaging and compressing
42 # Distribution subdirectory
46 # This current distribution
48 distfile=$distribution
53 # All inherited distributions in this distribution
56 # All distribution defines for this distribution
59 # All distribution undefines for this distribution
62 # All distribution options
77 # All pre, post pre-dist and post-dist hooks
83 # Distribution license and license header
87 # Whether to output ad_debug information
93 ###############################################################################
95 if test -f "$distdir/autodist.conf"; then
96 . $distdir/autodist.conf
102 ###############################################################################
106 # Print out debug information if debugging is enabled. To enable debugging
107 # set the global variable "debug" to true value.
109 # Arguments: ad_debug <ad_debug string>
113 if test x$debug = xtrue; then
121 # Prints out error message and exits the script.
123 # Arguments: ad_fatal <error message>
128 echo autodist: error: $1
134 # Prints out warning message
136 # Arguments: ad_warning <warning message>
141 echo autodist: warning: $1
146 # Initializes the Autodist environment, creates default distribution
147 # directory, and default distribution.
149 # Arguments: ad_initialize
153 ad_debug ">ad_initialize"
155 # Create default distdir
156 if test '!' -f $distdir; then
160 # Create Autodist configuration file
161 if test -f @AUTODISTDIR@/autodist.conf; then
162 cp -p @AUTODISTDIR@/autodist.conf $distdir
165 # Create default distribution
166 if test -f @AUTODISTDIR@/default; then
167 cp -p @AUTODISTDIR@/default $distdir
170 ad_debug "<ad_initialize"
174 # Creates the distdefs header file including defined distdefs
176 # Arguments: ad_create_distdefs_h
178 ad_create_distdefs_h()
180 ad_debug ">ad_create_distdefs_h"
185 echo " Automatically generated by Autodist $ver. Do not edit." >> $fname
187 echo " Generated: `date` by `whoami`" >> $fname
188 echo " Distribution: $distribution" >> $fname
189 echo " License: $license" >> $fname
192 echo "#ifndef _"$DP"_DISTDEFS_H" >> $fname
193 echo "#define _"$DP"_DISTDEFS_H" >> $fname
198 echo "#define $i 1" >>$fname
202 echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname
204 ad_debug "<ad_create_distdefs_h"
208 # Creates the main configure script for the distribution. This runs
209 # the aclocal, autoheader and autoconf tools.
211 # Arguments: ad_make_configure
215 ad_debug ">ad_make_configure"
216 local run_autoconf=false
220 if test "$ACLOCAL"; then
221 ad_debug "Running aclocal"
222 $ACLOCAL 1>/dev/null 2>/dev/null
223 if test $? != 0; then
224 ad_fatal "aclocal failed"
228 if test "$AUTOCONF"; then
229 ad_debug "Running autoconf"
231 if test $? != 0; then
232 ad_fatal "autoconf failed"
237 if test "$AUTOHEADER"; then
238 ad_debug "Running autoheader"
240 if test $? != 0; then
241 ad_fatal "autoheader failed"
245 if test "$LIBTOOLIZE"; then
246 ad_debug "Running libtoolize"
248 if test $? != 0; then
249 ad_fatal "libtoolize failed"
253 if test x$run_autoconf = xtrue; then
254 if test '!' -f configure; then
255 ad_fatal "creating configure script failed"
259 ad_debug "<ad_make_configure"
263 # Creates the configure.ac script from the configure.ad fragments in
264 # the source tree. Takes the source configure file as argument which
265 # is used to create the actual configure.ac.
267 # Arguments: ad_make_configure_ac <configure_ac_source>
269 ad_make_configure_ac()
271 ad_debug ">ad_make_configure_ac: $1"
273 if test '!' -f $1; then
274 ad_fatal "The configure file '$1' does not exist"
277 local check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
278 if test -z $check; then
279 rm -f configure.ad.cfs
280 rm -f $fname $fname.tmp
281 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
284 rm -f configure.ac configure.ad.cfs
286 cfs=`find . -name configure\*\.ad`
289 if test "x$i" = "x$1"; then
292 ad_debug "including $i"
293 cat $i >> configure.ad.cfs
296 if test -f configure.ad.cfs; then
297 local check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
298 if test -z $check; then
299 rm -f configure.ad.cfs
300 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
304 # Header for configure.ac
305 fname="configure.tmp.ac"
306 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
307 echo "# To make changes edit the $i file in the source tree." >> $fname
309 echo "# Source: $i" >> $fname
310 echo "# Generated: `date` by `whoami`" >> $fname
311 echo "# Distribution: $distribution" >> $fname
312 echo "# License: $license" >> $fname
315 ad_debug "creating configure.ac"
316 if test -f configure.ad.cfs; then
317 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
318 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
319 rm -f configure.ad.cfs $fname.tmp
325 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
327 # Process for distribution
329 ad_process_file $fname.tmp $fname
331 # Remove any trailing backslashes
332 if test -f "$fname"; then
333 cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
335 cp -p $fname.tmp configure.ac
337 rm -f $fname $fname.tmp
339 ad_debug "<ad_make_configure_ac: $1"
343 # Creates the Makefile.in files by running the automake tool.
345 # Arguments: ad_make_makefile_ins
347 ad_make_makefile_ins()
349 ad_debug ">ad_make_makefile_ins"
351 if test "$AUTOMAKE"; then
352 ad_debug "Running automake"
354 if test $? != 0; then
355 ad_fatal "automake failed"
359 ad_debug "<ad_make_makefile_ins"
363 # Creates the Makefile.am files from the Makefile.ad files in the
364 # source tree. This runs the distribution specific processing for the
367 # Arguments: ad_make_makefile_ams
369 ad_make_makefile_ams()
371 ad_debug ">ad_make_makefile_ams"
373 files=`find . -name Makefile\.ad`
376 fname=`echo $ff | sed s/\.ad//`
378 # Header for the Makefile.am
379 echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am
380 echo "# To make changes edit the $ff file in the source tree." >> $fname.am
382 echo "# Source: $ff" >> $fname.am
383 echo "# Generated: `date` by `whoami`" >> $fname.am
384 echo "# Distribution: $distribution" >> $fname.am
385 echo "# License: $license" >> $fname.am
388 # Run the distribution processing for this Makefile.ad
389 ad_debug "Processing $ff to be $fname.am"
390 ad_process_file $ff $fname.tmp
392 # Remove any trailing backslashes
393 if test -f "$fname.tmp"; then
394 cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
402 ad_debug "<ad_make_makefile_ams"
406 # Processes all files with .ad suffix, with exception of configure*.ad
407 # and Makefile.ad files, for distribution from the source tree.
409 # Arguments: ad_process_ads
413 ad_debug ">ad_process_ads"
415 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
418 fname=`echo $i | sed s/\.ad//`
421 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
422 echo "# To make changes edit the $i file in the source tree." >> $fname
424 echo "# Source: $i" >> $fname
425 echo "# Generated: `date` by `whoami`" >> $fname
426 echo "# Distribution: $distribution" >> $fname
427 echo "# License: $license" >> $fname
430 # Run the distribution processing for this file
431 ad_debug "Processing $i to be $fname"
432 ad_process_file $i $fname
435 ad_debug "<ad_process_ads"
439 # Includes files specified in the distribution for inclusion. Used when
440 # creating the distribution for packaging.
442 # include has the following format in distfile:
444 # include <path> [<dest path>]
446 # If only source path, which may be file, directory or regular expression,
447 # is specified the path will be same in distribution. If the destination
448 # path is specified that will be the new name and/or new location of the
449 # source path. This, in effect, is a cp utility with ability to create
450 # directories if they do not exist.
452 # Arguments: ad_dist_includes <includeslist> <recursive>
456 ad_debug ">ad_dist_includes: $1 $2"
458 # By default do not expand pathnames
461 # Add : separator at the end
462 local incs="`echo "$1" | sed 's/$/ : /'`"
468 if test "$i" = ":" && test -z "$src"; then
471 if test -z "$src"; then
475 if test -z "$dst" && test "$i" != ":"; then
481 ad_debug "Including $src into $dst"
483 if test -f "$src"; then
486 if test "$src" = "$dst"; then
487 # Add to same location
488 d=`echo $src | sed 's,/[^/]*$,,'`
489 if test "$d" != "$src" && test "$d" != "." && \
490 test '!' -d $am_distdir/$d; then
491 mkdir -p $am_distdir/$d || exit 1
494 # Add to different location
495 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
496 if test "$check" != "$dst"; then
497 ad_fatal "Invalid destination in 'include $src $dst'"
500 d=`echo $dst | sed 's,/[^/]*$,,'`
501 if test "$d" != "$dst" && test "$d" != "." && \
502 test '!' -d $am_distdir/$d; then
503 mkdir -p $am_distdir/$d || exit 1
507 cp -p $src $am_distdir/$d || exit 1
509 elif test -d "$src"; then
512 if test "$src" = "$dst"; then
513 # Add to same location
514 d=`echo $src | sed 's,/[^/]*$,,'`
515 ds=`echo $src | sed 's/\/$//'`
516 if test "$ds" = "$d"; then
517 d=`echo $d | sed 's,/[^/]*$,,'`
519 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
520 mkdir -p $am_distdir/$d || exit 1
523 cp -pR $src $am_distdir/$d || exit 1
525 # Add to different location
526 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
527 if test "$check" != "$dst"; then
528 ad_fatal "Invalid destination in 'include $src $dst'"
531 d=`echo $dst | sed 's,/[^/]*$,,'`
532 ds=`echo $dst | sed 's/\/$//'`
533 if test "$ds" = "$d"; then
534 d=`echo $d | sed 's,/[^/]*$,,'`
536 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
537 mkdir -p $am_distdir/$d || exit 1
540 cp -pR $src $am_distdir/$dst || exit 1
543 elif test x$2 != xtrue; then
544 # We assume regular expression in filename
545 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
546 if test "$check" == "$src"; then
547 if test '!' -a $src; then
548 ad_fatal "Including $src: No such file or directory"
555 # Recursively call this function with expanded pathnames. The
556 # reason why we don't let sh by default expand patnames is that
557 # the include's destination is optional. If sh expands by default
558 # we don't know the destination. For this reason, we handle the
559 # expansion here ourselves.
561 # If src and dst are same, then expand the pathname as we'll copy
562 # matches to their own locations.
563 if test "$src" = "$dst"; then
564 # Expand pathnames, and format to our include format
566 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
569 # Destination is new, and it has to be a directory.
570 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
571 if test "$check" != "$dst"; then
572 ad_fatal "Invalid destination in 'include $src $dst'"
575 # Make sure dst has / at the end, as this must be a directory
576 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
579 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
581 # Expand pathnames, and format to our include format
583 srcs=`echo $src | sed -e "s/ / $dste : /g" \
584 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
588 # Include recursively
589 ad_dist_includes "$srcs" true
591 elif test '!' -a $src; then
592 ad_fatal "Including $src: No such file or directory"
601 ad_debug "<ad_dist_includes: $1 $2"
605 # Excludes files specified in the distribution for exclusion. Used when
606 # creating the distribution for packaging.
608 # exclude has the following format in distfile:
612 # The path may be file, directory or regular expression.
614 # Arguments: ad_dist_includes <excludelist>
618 ad_debug ">ad_dist_excludes: $1"
622 ad_debug "Excluding $i"
623 rm -rf $am_distdir/$i
626 ad_debug "<ad_dist_excludes: $1"
630 # Processes the entire tree for distribution. This inspects files other
631 # than source and header files, with exception of any file with .ad
632 # suffix, and performs distribution processing for the file. The original
633 # file is replaced with the processed file. This function is used when
634 # creating the distribution for packaging.
636 # Arguments: ad_process_tree <directory>
640 ad_debug ">ad_process_tree: $1"
642 # We take all files, other than *.ad, including source files, in case
643 # they use the non-C-compiler-friendly format of distdefs, which is
646 files=`find $am_distdir \! -name \*\.ad`
647 files=`echo $files | sed 's/$am_distdir//'`
649 # Take away noprocess list
650 if test -f autodist.noprocess; then
651 files=`echo $files | sh autodist.noprocess` || exit 1
656 ad_process_file $ff $ff.tmp
657 if test -f $ff.tmp; then
659 mv -f $ff.tmp $ff || exit 1
663 ad_debug "<ad_process_tree: $1"
667 # Processes the entire source tree for distribution. This inspects files
668 # in the source tree, with exception of any file with .ad suffix, and
669 # performs distribution processing for the file. The original file is
670 # replaced with the processed file. This function is used when creating
671 # the distribution for packaging.
673 # Call this before ad_process_tree().
675 # Arguments: ad_process_source_tree <directory>
677 ad_process_source_tree()
679 ad_debug ">ad_process_source_tree: $1"
681 # We take only C/C++ files since they use the C compiler friendly
682 # version of distdefs. Other files are not assumed to use them.
683 files=`find $am_distdir \! -name \*\.ad \( \
685 -name \*\.[cC][cCpP] -o \
686 -name \*\.[cC][xX][xX] -o \
687 -name \*\.[cC][pP][pP] -o \
688 -name \*\.[cC]++ -o \
693 # Take away noprocess list
694 if test -f autodist.noprocess; then
695 files=`echo $files | sh autodist.noprocess` || exit 1
700 ad_process_source_file $ff $ff.tmp
701 if test -f $ff.tmp; then
703 mv -f $ff.tmp $ff || exit 1
707 ad_debug "<ad_process_source_tree: $1"
711 # Makes distribution sane, ala modtimes. Since we modify the distribution
712 # we need to make it sane after that.
714 # Arguments: ad_makedist_makesane
716 ad_makedist_makesane()
718 ad_debug ">ad_makedist_makesane:"
720 # DO NOT change these order unless you know what you are doing.
721 if test -f $am_distdir/configure.ac; then
722 touch $am_distdir/configure.ac
725 if test -f $am_distdir/aclocal.m4; then
726 touch $am_distdir/aclocal.m4
729 if test '!' -f Makefile; then
730 ad_fatal "Makefile: No such file or directory"
733 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
734 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
736 files=`find $am_distdir -name Makefile\.in`
742 if test -f $am_distdir/configure; then
743 touch $am_distdir/configure
746 if test -f $am_distdir/config.status; then
747 touch $am_distdir/config.status
750 ad_debug "<ad_makedist_makesane:"
754 # Creates distribution of the source tree. All files in the distribution
755 # will be processed and the distribution will be packaged.
757 # Arguments: ad_makedist
761 ad_debug ">ad_makedist"
763 if test '!' -f autodist.dist; then
764 ad_fatal "Autodist has not been run yet to prepare source tree"
767 if test -z $MAKE; then
768 ad_fatal "The MAKE variable is not set in autodist.conf"
771 # Get distdir from Makefile
772 if test '!' -f Makefile; then
773 ad_fatal "The source tree is not configured, run ./configure first"
776 # Parse the requested distribution
777 distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
778 dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
779 ad_parse_distribution $distribution false
781 am_distdir="$package-$dist_version"
783 if test x$opt_no_dist = xtrue; then
784 ad_fatal "The '$distribution' distribution cannot be packaged"
787 # Create distribution directory
788 ad_debug "Creating distribution directory $am_distdir"
789 $MAKE distdir || exit 1
790 chmod -R a+r $am_distdir
792 if test '!' -d $am_distdir; then
793 ad_fatal "Distribution directory $am_distdir not created"
797 ad_run_dist_hooks "$pre_dist_hooks"
800 ad_dist_excludes "$excludes"
803 ad_dist_includes "$includes"
805 # Include specific license file if specified
806 if test "$license" != ""; then
807 cp -p $license $am_distdir/COPYING || exit 1
810 # Process noprocesses
813 # Process source files
814 ad_debug "Process distribution source tree"
815 ad_process_source_tree $am_distdir
817 # Process non-source files
818 ad_debug "Process distribution tree"
819 ad_process_tree $am_distdir
821 # Run post-dist-hooks
822 ad_run_dist_hooks "$post_dist_hooks"
824 # Make distribution sane
828 ad_debug "Packaging distribution"
829 tar chof $am_distdir.tar $am_distdir || exit 1
832 ad_debug "Compressing distribution package"
833 if test x$ad_gzip = xtrue; then
834 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
836 if test x$ad_bzip2 = xtrue; then
837 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
839 if test x$ad_compress = xtrue; then
840 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
842 if test x$ad_zip = xtrue; then
843 rm -f $am_distdir.zip
844 zip -rq $am_distdir.zip $am_distdir || exit 1
846 rm -f $am_distdir.tar
850 rm -f autodist.noprocess
852 ad_debug "<ad_makedist"
856 # Handles distribution options.
858 # option has the following format in distfile:
862 # Following options are supported:
868 # Arguments: ad_handle_options <options>
872 ad_debug ">ad_handle_options: $1"
876 if test "$i" = "template"; then
879 elif test "$i" = "no-dist"; then
882 elif test "$i" = "no-inherit"; then
888 ad_debug "<ad_handle_options: $1"
894 # Arguments: ad_clear_options
898 ad_debug ">ad_clear_options"
902 ad_debug "<ad_clear_options"
906 # Parses the distribution. Gets all distribution defines from the
907 # distribution. This also expands all inherited distributions recursively
908 # to get all inherited distribution defines. From inherited distributions
909 # their name and package name is not inherited.
911 # Arguments: ad_parse_distribution <distribution name> <inherit>
913 ad_parse_distribution()
915 ad_debug ">ad_parse_distribution: $1 $2"
917 if test '!' -f $distdir/$1; then
918 ad_fatal "Distribution '$1' is not declared"
922 local inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
923 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
926 local defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
927 | grep "define " | cut -d' ' -f2 | sort | uniq`
929 if test "$inhs" = "" && test "$defs" = ""; then
930 ad_fatal "Distribution '$1' does not define anything"
933 # Get undefined distdefs
934 local undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
935 | grep "undef " | cut -d' ' -f2 | sort | uniq`
938 local incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
939 | grep "include " | sed 's/include / : /'`
942 local excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
943 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
946 local nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
947 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
950 local opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
951 | grep "option " | cut -d' ' -f2- | sort | uniq`
954 ad_handle_options "$opts"
955 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
956 ad_fatal "Distribution '$1' cannot be inherited"
958 if test x$2 = xfalse && test x$opt_template = xtrue; then
959 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
962 ad_debug "inherits=$inhs"
963 ad_debug "distdefs=$defs"
964 ad_debug "includes=$incs"
965 ad_debug "excludes=$excs"
966 ad_debug "noprocess=$nops"
967 ad_debug "undistdefs=$undefs"
968 ad_debug "options=$opts"
970 # Expand distdefs from inherited distributions
973 if test x$1 = x$i; then
974 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
975 distribution to not have 'inherit $i' declared."
978 if test '!' -f $distdir/$i; then
979 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
982 ad_parse_distribution $i true
987 license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
988 | grep "license " | cut -d' ' -f2`
989 licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
990 | grep "license-header " | sed 's/license-header / : /'`
992 ad_debug "license=$license"
993 ad_debug "licenseh=$licenseh"
995 if test x$2 = xfalse; then
996 # Get distribution name
997 local dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
998 | grep "name " | cut -d' ' -f2-`
1000 if test "$dname"; then
1004 # Get distribution package name (optional)
1005 local dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1006 | grep "package " | cut -d' ' -f2`
1008 if test "$dpname"; then
1011 package=$distribution
1014 # Get Bug-report email address (optional)
1015 local bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1016 | grep "bug-report " | cut -d' ' -f2-`
1018 if test "$bugr"; then
1022 ad_debug "distribution=$distribution"
1023 ad_debug "package=$package"
1024 ad_debug "bug-report=$bug_report"
1026 # Get hooks (optional)
1027 local prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1028 | grep "pre-hook " | cut -d' ' -f2-`
1029 local poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1030 | grep "post-hook " | cut -d' ' -f2-`
1031 local prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1032 | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1033 local podh=`cat $distdir/$1 | grep -v "^#" \
1034 | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1036 pre_hooks="$pre_hooks $prh"
1037 post_hooks="$post_hooks $poh"
1038 pre_dist_hooks="$pre_dist_hooks $prdh"
1039 post_dist_hooks="$post_dist_hooks $podh"
1040 options="$options $opts"
1042 ad_handle_options "$options"
1043 ad_debug "options=$options"
1047 inherits="$inherits $inhs"
1048 distdefs="$distdefs $defs"
1049 includes="$includes $incs"
1050 excludes="$excludes $excs"
1051 noprocess="$noprocess $nops"
1052 undistdefs="$undistdefs $undefs"
1054 ad_debug "<ad_parse_distribution: $1 $2"
1058 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1059 # from the distdefs.
1061 # Arguments: ad_process_distdefs
1063 ad_process_distdefs()
1065 ad_debug ">ad_process_distdefs"
1067 # Remove all undefined distribution defines
1068 for i in $undistdefs
1070 ad_debug "undefining $i distdef"
1071 distdefs=`echo $distdefs | sed s/$i//`
1074 rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
1075 rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
1077 # Remove duplicate distdefs
1080 echo $i >>autodist.tmp.defs
1082 distdefs=`cat autodist.tmp.defs | sort | uniq`
1083 distdefs=`echo $distdefs`
1084 rm -f autodist.tmp.defs
1086 ad_debug "distdefs=$distdefs"
1088 ad_debug "<ad_process_distdefs"
1092 # Processes for a license header change.
1094 # Arguments: ad_process_license_header <scriptfile>
1096 ad_process_license_header()
1098 ad_debug ">ad_process_license_header"
1100 # Add : separator at the end
1101 lics=`echo "$licenseh" | sed 's/$/ : /'`
1107 if test "$i" = ":" && test -z "$src"; then
1110 if test -z "$src"; then
1114 if test -z "$dst" && test "$i" != ":"; then
1117 ad_fatal "Missing argument in 'license-header $src'"
1120 ad_debug "Replacing $src license with $dst license"
1122 if test '!' -f $src; then
1123 ad_fatal "License header $src: No such file or directory"
1126 if test '!' -f $dst; then
1127 ad_fatal "License header $dst: No such file or directory"
1130 # Awk script to replace the license header
1131 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1132 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1133 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
1134 rm -f autodist.lsrc autodist.ldst
1140 ad_debug "<ad_process_license_header"
1144 # Process specified noprocesses. This is called during makedist.
1146 # Arguments: ad_process_noprocess
1148 ad_process_noprocess()
1150 ad_debug ">ad_process_noprocess"
1158 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1160 n="$n -e 's/$am_distdir\\/$ie//'"
1164 rm -f autodist.noprocess
1165 if test x$np = xtrue; then
1166 echo $n > autodist.noprocess || exit 1
1169 ad_debug "<ad_process_noprocess"
1173 # Process a file given as argument for the distribution.
1175 # Arguments: ad_process_file <filepath> <dest_filepath>
1181 # Process only regular files
1182 if test '!' -f $1; then
1186 ad_debug ">ad_process_file: $1 $2"
1188 local f="autodist.tmp.script"
1191 # If license header is provided, replace the license header in the file.
1192 ad_process_license_header $f
1194 ad_debug "Getting #ifdef's and #ifndef's"
1196 # Get defined distribution defines
1197 local defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1198 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1200 # Get explicitly not-defined distribution defines
1201 local ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1202 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1204 ad_debug "defs=$defs"
1205 ad_debug "ndefs=$ndefs"
1207 # Create the script to include and exclude stuff in the file according
1208 # to the distribution defines
1211 ad_debug "processing ifdefs"
1217 if test x$d = x$i; then
1223 # If distribution define was not found exclude those lines from the file.
1224 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1225 if test x$found = xfalse; then
1226 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1227 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1229 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1234 ad_debug "processing ifndefs"
1240 if test x$d = x$i; then
1246 # If distribution define was found exclude those lines from the file.
1247 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1248 if test x$found = xtrue; then
1249 ad_debug "ifndef $d will be excluded (it IS defined)"
1250 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1252 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1256 # Now process the file with the script
1259 # Those distdef lines that remain in the file are removed to make
1260 # the appearance prettier
1261 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1262 echo "{ print; }" >> $f
1264 # Execute the script
1265 cp -p $1 $2 || exit 1
1266 awk -f $f $1 > $2 || exit 1
1271 ad_debug "<ad_process_file: $1 $2"
1275 # Process a source file given as argument for the distribution.
1277 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1279 ad_process_source_file()
1283 # Process only regular files
1284 if test '!' -f $1; then
1288 ad_debug ">ad_process_source_file: $1 $2"
1290 local f="autodist.tmp.script"
1293 # If license header is provided, replace the license header in the file.
1294 ad_process_license_header $f
1296 ad_debug "Getting #ifdef's and #ifndef's"
1298 # Get defined distribution defines
1299 local defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1300 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1302 # Get explicitly not-defined distribution defines
1303 local ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1304 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1306 ad_debug "defs=$defs ndefs=$ndefs"
1308 # Create the script to include and exclude stuff in the file according
1309 # to the distribution defines
1312 ad_debug "processing ifdefs"
1318 if test x$d = x$i; then
1324 # If distribution define was not found exclude those lines from the file.
1325 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1326 if test x$found = xfalse; then
1327 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1328 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1330 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1335 ad_debug "processing ifndefs"
1341 if test x$d = x$i; then
1347 # If distribution define was found exclude those lines from the file.
1348 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1349 if test x$found = xtrue; then
1350 ad_debug "ifndef $d will be excluded (it IS defined)"
1351 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1353 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1357 # Now process the file with the script
1360 # Those distdef lines that remain in the file are removed to make
1361 # the appearance prettier
1362 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1363 echo "{ print; }" >> $f
1365 # Execute the script
1366 cp -p $1 $2 || exit 1
1367 awk -f $f $1 > $2 || exit 1
1372 ad_debug "<ad_process_source_file: $1 $2"
1378 # Arguments: ad_run_hooks <hooks>
1382 ad_debug ">ad_run_hooks: $1"
1386 if test '!' -f $i; then
1387 ad_fatal "Hook script $i does not exist"
1389 sh $i $distribution $dist_version $package || exit 1
1392 ad_debug "<ad_run_hooks: $1"
1398 # Arguments: ad_run_dist_hooks <hooks>
1402 ad_debug ">ad_run_dist_hooks: $1"
1406 if test '!' -f $i; then
1407 ad_fatal "Dist hook script $i does not exist"
1409 sh $i $distribution $dist_version $package $am_distdir || exit 1
1412 ad_debug "<ad_run_dist_hooks: $1"
1415 ###############################################################################
1418 usage="Usage: autodist [options] [distribution] [version]"
1420 Autodist prepares source tree for configuration, compilation and
1421 distribution. Prepares the source tree from the \`autodist.ad'
1422 configuration file. Generates Automake.am files from Automake.ad
1423 files, configure.ac file from configure.ad file(s), generates the
1424 configure script by running Autoconf tool, and generates Makefile.in
1425 files by running Automake tool.
1428 -h, --help print this help, then exit
1429 -V, --version print version number, then exit
1430 -v, --verbose verbosely report processing
1431 -d, --distdir <dir> search distributions from <dir>
1432 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1433 -i, --init initialize Autodist environment, create default
1434 distribution directory and distribution, then exit
1435 -m, --makedist create and package distribution
1436 --gzip create package compressed with gzip (default)
1437 --bzip2 create also package compressed with bzip2
1438 --compress create also package compressed with compress
1439 --zip create also package compressed with zip"
1442 # Process command line arguments
1444 while test $# -gt 0; do
1449 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1458 if test $# -eq 0; then
1459 ad_parse_distribution $distribution false
1460 echo "Distribution: ${distribution}" 1>&2;
1462 ad_parse_distribution $1 false
1463 echo "Distribution: ${1}" 1>&2;
1466 echo "Distdefs:" 1>&2;
1499 echo "${usage}" 1>&2;
1501 echo "${help}" 1>&2;
1506 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1507 echo "Written by Pekka Riikonen" 1>&2;
1509 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1511 This is free software; see the source for copying conditions. There is NO
1512 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1520 echo "${usage}" 1>&2;
1530 # Parse the requested distribution
1532 if test $# != 0; then
1533 distribution="${1}";
1534 distfile=$distribution
1537 ad_parse_distribution $distribution false
1540 if test $# != 0; then
1541 dist_version="${1}";
1544 ad_debug "Preparing source tree for configuration and compilation..."
1545 ad_debug "Preparing $distribution distribution version $dist_version"
1548 # Create the distribution defines header file
1550 if test "$DISTDEFS"; then
1551 ad_create_distdefs_h
1553 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1559 ad_run_hooks "$pre_hooks"
1562 # Generate the Makefile.am files from Makefile.ad files
1564 ad_make_makefile_ams
1567 # Generate the configure.ac from configure.ad file(s)
1569 ad_make_configure_ac ./configure.ad
1572 # Generate configure script
1577 # Generate Makefile.in files
1579 ad_make_makefile_ins
1582 # Process all files with .ad suffix for distribution processing
1587 # Create autodist.dist
1589 ad_debug "Creating autodist.dist"
1590 echo "dist:$distfile" > autodist.dist
1591 echo "ver:$dist_version" >> autodist.dist
1592 echo "$package-$dist_version" >> autodist.dist
1597 ad_run_hooks "$post_hooks"
1599 ad_debug "Done, now run ./configure and make."