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 # Be Bourne compatible
37 if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
38 # XXX We actually may not work on zsh
41 # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
42 # is contrary to our usage. Disable this feature.
43 alias -g '${1+"$@"}'='"$@"'
45 DUALCASE=1; export DUALCASE # for MKS sh
47 # Support unset when possible.
48 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
54 # Work around bugs in pre-3.0 UWIN ksh.
55 $as_unset ENV MAIL MAILPATH
62 LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
63 LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
66 if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
67 eval $as_var=C; export $as_var
74 ###############################################################################
77 # Packaging and compressing
83 # Distribution subdirectory
87 # This current distribution
89 distfile=$distribution
94 # All inherited distributions in this distribution
97 # All distribution defines for this distribution
100 # All distribution undefines for this distribution
103 # All distribution options
126 # Distribution license and license header
130 # Whether to output ad_debug information
136 ###############################################################################
138 if test -f "$distdir/autodist.conf"; then
139 . $distdir/autodist.conf
145 ###############################################################################
149 # Print out debug information if debugging is enabled. To enable debugging
150 # set the global variable "debug" to true value.
152 # Arguments: ad_debug <ad_debug string>
156 if test x$debug = xtrue; then
164 # Prints out error message and exits the script.
166 # Arguments: ad_fatal <error message>
171 echo autodist: error: $1
177 # Prints out warning message
179 # Arguments: ad_warning <warning message>
184 echo autodist: warning: $1
189 # Initializes the Autodist environment, creates default distribution
190 # directory, and default distribution.
192 # Arguments: ad_initialize
196 ad_debug ">ad_initialize"
198 # Create default distdir
199 if test '!' -f $distdir; then
203 # Create Autodist configuration file
204 if test -f @AUTODISTDIR@/autodist.conf; then
205 cp -p @AUTODISTDIR@/autodist.conf $distdir
208 # Create default distribution
209 if test -f @AUTODISTDIR@/default; then
210 cp -p @AUTODISTDIR@/default $distdir
213 ad_debug "<ad_initialize"
217 # Creates the distdefs header file including defined distdefs
219 # Arguments: ad_create_distdefs_h
221 ad_create_distdefs_h()
223 ad_debug ">ad_create_distdefs_h"
228 echo " Automatically generated by Autodist $ver. Do not edit." >> $fname
230 echo " Generated: `date` by `whoami`" >> $fname
231 echo " Distribution: $distribution" >> $fname
232 echo " License: $license" >> $fname
235 echo "#ifndef _"$DP"_DISTDEFS_H" >> $fname
236 echo "#define _"$DP"_DISTDEFS_H" >> $fname
241 echo "#define $i 1" >>$fname
245 echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname
247 ad_debug "<ad_create_distdefs_h"
251 # Creates the main configure script for the distribution. This runs
252 # the aclocal, autoheader and autoconf tools.
254 # Arguments: ad_make_configure
258 local run_autoconf=false
260 ad_debug ">ad_make_configure"
264 if test "$ACLOCAL"; then
265 ad_debug "Running aclocal"
266 $ACLOCAL 1>/dev/null 2>/dev/null
267 if test $? != 0; then
268 ad_fatal "aclocal failed"
272 if test "$AUTOCONF"; then
273 ad_debug "Running autoconf"
275 if test $? != 0; then
276 ad_fatal "autoconf failed"
281 if test "$AUTOHEADER"; then
282 ad_debug "Running autoheader"
284 if test $? != 0; then
285 ad_fatal "autoheader failed"
289 if test "$LIBTOOLIZE"; then
290 ad_debug "Running libtoolize"
292 if test $? != 0; then
293 ad_fatal "libtoolize failed"
297 if test x$run_autoconf = xtrue; then
298 if test '!' -f configure; then
299 ad_fatal "creating configure script failed"
303 ad_debug "<ad_make_configure"
307 # Creates the configure.ac script from the configure.ad fragments in
308 # the source tree. Takes the source configure file as argument which
309 # is used to create the actual configure.ac.
311 # Arguments: ad_make_configure_ac <configure_ac_source>
313 ad_make_configure_ac()
317 ad_debug ">ad_make_configure_ac: $1"
319 if test '!' -f $1; then
320 ad_fatal "The configure file '$1' does not exist"
323 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
324 if test -z $check; then
325 rm -f configure.ad.cfs
326 rm -f $fname $fname.tmp
327 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
330 rm -f configure.ac configure.ad.cfs
332 cfs=`find . -name configure\*\.ad`
335 if test "x$i" = "x$1"; then
338 ad_debug "including $i"
339 cat $i >> configure.ad.cfs
342 if test -f configure.ad.cfs; then
343 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
344 if test -z $check; then
345 rm -f configure.ad.cfs
346 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
350 # Header for configure.ac
351 fname="configure.tmp.ac"
352 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
353 echo "# To make changes edit the configure.ad file in the source tree." >> $fname
355 echo "# Source: configure.ad" >> $fname
356 echo "# Generated: `date` by `whoami`" >> $fname
357 echo "# Distribution: $distribution" >> $fname
358 echo "# License: $license" >> $fname
361 ad_debug "creating configure.ac"
362 if test -f configure.ad.cfs; then
363 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
364 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
365 rm -f configure.ad.cfs $fname.tmp
371 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
373 # Process for distribution
375 ad_process_file $fname.tmp $fname
377 # Remove any trailing backslashes
378 if test -f "$fname"; then
379 cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
381 cp -p $fname.tmp configure.ac
383 rm -f $fname $fname.tmp
385 ad_debug "<ad_make_configure_ac: $1"
389 # Creates the Makefile.in files by running the automake tool.
391 # Arguments: ad_make_makefile_ins
393 ad_make_makefile_ins()
395 ad_debug ">ad_make_makefile_ins"
397 if test "$AUTOMAKE"; then
398 ad_debug "Running automake"
400 if test $? != 0; then
401 ad_fatal "automake failed"
405 ad_debug "<ad_make_makefile_ins"
409 # Creates the Makefile.am files from the Makefile.ad files in the
410 # source tree. This runs the distribution specific processing for the
413 # Arguments: ad_make_makefile_ams
415 ad_make_makefile_ams()
417 ad_debug ">ad_make_makefile_ams"
419 files=`find . -name Makefile\.ad`
422 fname=`echo $ff | sed s/\.ad//`
424 # Header for the Makefile.am
425 echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am
426 echo "# To make changes edit the $ff file in the source tree." >> $fname.am
428 echo "# Source: $ff" >> $fname.am
429 echo "# Generated: `date` by `whoami`" >> $fname.am
430 echo "# Distribution: $distribution" >> $fname.am
431 echo "# License: $license" >> $fname.am
434 # Run the distribution processing for this Makefile.ad
435 ad_debug "Processing $ff to be $fname.am"
436 ad_process_file $ff $fname.tmp
438 # Remove any trailing backslashes
439 if test -f "$fname.tmp"; then
440 cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
448 ad_debug "<ad_make_makefile_ams"
452 # Processes all files with .ad suffix, with exception of configure*.ad
453 # and Makefile.ad files, for distribution from the source tree.
455 # Arguments: ad_process_ads
459 ad_debug ">ad_process_ads"
461 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
464 fname=`echo $i | sed s/\.ad//`
467 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
468 echo "# To make changes edit the $i file in the source tree." >> $fname
470 echo "# Source: $i" >> $fname
471 echo "# Generated: `date` by `whoami`" >> $fname
472 echo "# Distribution: $distribution" >> $fname
473 echo "# License: $license" >> $fname
476 # Run the distribution processing for this file
477 ad_debug "Processing $i to be $fname"
478 ad_process_file $i $fname
481 ad_debug "<ad_process_ads"
485 # Includes files specified in the distribution for inclusion. Used when
486 # creating the distribution for packaging.
488 # include has the following format in distfile:
490 # include <path> [<dest path>]
492 # If only source path, which may be file, directory or regular expression,
493 # is specified the path will be same in distribution. If the destination
494 # path is specified that will be the new name and/or new location of the
495 # source path. This, in effect, is a cp utility with ability to create
496 # directories if they do not exist.
498 # Arguments: ad_dist_includes <includeslist> <recursive>
504 ad_debug ">ad_dist_includes: $1 $2"
506 # By default do not expand pathnames
509 # Add : separator at the end
510 incs="`echo "$1" | sed 's/$/ : /'`"
516 if test "$i" = ":" && test -z "$src"; then
519 if test -z "$src"; then
523 if test -z "$dst" && test "$i" != ":"; then
529 ad_debug "Including $src into $dst"
531 if test -f "$src"; then
534 if test "$src" = "$dst"; then
535 # Add to same location
536 d=`echo $src | sed 's,/[^/]*$,,'`
537 if test "$d" != "$src" && test "$d" != "." && \
538 test '!' -d $am_distdir/$d; then
539 mkdir -p $am_distdir/$d || exit 1
542 # Add to different location
543 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
544 if test "$check" != "$dst"; then
545 ad_fatal "Invalid destination in 'include $src $dst'"
548 d=`echo $dst | sed 's,/[^/]*$,,'`
549 if test "$d" != "$dst" && test "$d" != "." && \
550 test '!' -d $am_distdir/$d; then
551 mkdir -p $am_distdir/$d || exit 1
555 cp -p $src $am_distdir/$d || exit 1
557 elif test -d "$src"; then
560 if test "$src" = "$dst"; then
561 # Add to same location
562 d=`echo $src | sed 's,/[^/]*$,,'`
563 ds=`echo $src | sed 's/\/$//'`
564 if test "$ds" = "$d"; then
565 d=`echo $d | sed 's,/[^/]*$,,'`
567 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
568 mkdir -p $am_distdir/$d || exit 1
571 cp -pR $src $am_distdir/$d || exit 1
573 # Add to different location
574 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
575 if test "$check" != "$dst"; then
576 ad_fatal "Invalid destination in 'include $src $dst'"
579 d=`echo $dst | sed 's,/[^/]*$,,'`
580 ds=`echo $dst | sed 's/\/$//'`
581 if test "$ds" = "$d"; then
582 d=`echo $d | sed 's,/[^/]*$,,'`
584 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
585 mkdir -p $am_distdir/$d || exit 1
588 cp -pR $src $am_distdir/$dst || exit 1
591 elif test x$2 != xtrue; then
592 # We assume regular expression in filename
593 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
594 if test "$check" == "$src"; then
595 if test '!' -a $src; then
596 ad_fatal "Including $src: No such file or directory"
603 # Recursively call this function with expanded pathnames. The
604 # reason why we don't let sh by default expand patnames is that
605 # the include's destination is optional. If sh expands by default
606 # we don't know the destination. For this reason, we handle the
607 # expansion here ourselves.
609 # If src and dst are same, then expand the pathname as we'll copy
610 # matches to their own locations.
611 if test "$src" = "$dst"; then
612 # Expand pathnames, and format to our include format
614 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
617 # Destination is new, and it has to be a directory.
618 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
619 if test "$check" != "$dst"; then
620 ad_fatal "Invalid destination in 'include $src $dst'"
623 # Make sure dst has / at the end, as this must be a directory
624 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
627 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
629 # Expand pathnames, and format to our include format
631 srcs=`echo $src | sed -e "s/ / $dste : /g" \
632 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
636 # Include recursively
637 ad_dist_includes "$srcs" true
639 elif test '!' -a $src; then
640 ad_fatal "Including $src: No such file or directory"
649 ad_debug "<ad_dist_includes: $1 $2"
653 # Excludes files specified in the distribution for exclusion. Used when
654 # creating the distribution for packaging.
656 # exclude has the following format in distfile:
660 # The path may be file, directory or regular expression.
662 # Arguments: ad_dist_includes <excludelist>
666 ad_debug ">ad_dist_excludes: $1"
670 ad_debug "Excluding $i"
671 rm -rf $am_distdir/$i
674 ad_debug "<ad_dist_excludes: $1"
678 # Processes the entire tree for distribution. This inspects files other
679 # than source and header files, with exception of any file with .ad
680 # suffix, and performs distribution processing for the file. The original
681 # file is replaced with the processed file. This function is used when
682 # creating the distribution for packaging.
684 # Arguments: ad_process_tree <directory>
688 ad_debug ">ad_process_tree: $1"
690 # We take all files, other than *.ad, including source files, in case
691 # they use the non-C-compiler-friendly format of distdefs, which is
694 files=`find $am_distdir \! -name \*\.ad`
695 files=`echo $files | sed 's/$am_distdir//'`
697 # Take away noprocess list
698 if test -f autodist.noprocess; then
699 files=`echo $files | sh autodist.noprocess` || exit 1
704 ad_process_file $ff $ff.tmp
705 if test -f $ff.tmp; then
707 mv -f $ff.tmp $ff || exit 1
711 ad_debug "<ad_process_tree: $1"
715 # Processes the entire source tree for distribution. This inspects files
716 # in the source tree, with exception of any file with .ad suffix, and
717 # performs distribution processing for the file. The original file is
718 # replaced with the processed file. This function is used when creating
719 # the distribution for packaging.
721 # Call this before ad_process_tree().
723 # Arguments: ad_process_source_tree <directory>
725 ad_process_source_tree()
727 ad_debug ">ad_process_source_tree: $1"
729 # We take only C/C++ files since they use the C compiler friendly
730 # version of distdefs. Other files are not assumed to use them.
731 files=`find $am_distdir \! -name \*\.ad \( \
733 -name \*\.[cC][cCpP] -o \
734 -name \*\.[cC][xX][xX] -o \
735 -name \*\.[cC][pP][pP] -o \
736 -name \*\.[cC]++ -o \
741 # Take away noprocess list
742 if test -f autodist.noprocess; then
743 files=`echo $files | sh autodist.noprocess` || exit 1
748 ad_process_source_file $ff $ff.tmp
749 if test -f $ff.tmp; then
751 mv -f $ff.tmp $ff || exit 1
755 ad_debug "<ad_process_source_tree: $1"
759 # Makes distribution sane, ala modtimes. Since we modify the distribution
760 # we need to make it sane after that.
762 # Arguments: ad_makedist_makesane
764 ad_makedist_makesane()
766 ad_debug ">ad_makedist_makesane:"
768 # DO NOT change these order unless you know what you are doing.
769 if test -f $am_distdir/configure.ac; then
770 touch $am_distdir/configure.ac
773 if test -f $am_distdir/aclocal.m4; then
774 touch $am_distdir/aclocal.m4
777 if test '!' -f Makefile; then
778 ad_fatal "Makefile: No such file or directory"
781 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
782 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
784 files=`find $am_distdir -name Makefile\.in`
790 if test -f $am_distdir/configure; then
791 touch $am_distdir/configure
794 if test -f $am_distdir/config.status; then
795 touch $am_distdir/config.status
798 ad_debug "<ad_makedist_makesane:"
802 # Creates distribution of the source tree. All files in the distribution
803 # will be processed and the distribution will be packaged.
805 # Arguments: ad_makedist
809 ad_debug ">ad_makedist"
811 if test '!' -f autodist.dist; then
812 ad_fatal "Autodist has not been run yet to prepare source tree"
815 if test -z $MAKE; then
816 ad_fatal "The MAKE variable is not set in autodist.conf"
819 # Get distdir from Makefile
820 if test '!' -f Makefile; then
821 ad_fatal "The source tree is not configured, run ./configure first"
824 # Parse the requested distribution
825 distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
826 dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
827 ad_parse_distribution $distribution false
829 am_distdir="$package-$dist_version"
831 if test x$opt_no_dist = xtrue; then
832 ad_fatal "The '$distribution' distribution cannot be packaged"
836 ad_run_dist_hooks "$pre_dist_hooks"
838 # Create distribution directory
839 ad_debug "Creating distribution directory $am_distdir"
840 $MAKE distdir || exit 1
841 chmod -R a+r $am_distdir
843 if test '!' -d $am_distdir; then
844 ad_fatal "Distribution directory $am_distdir not created"
847 # Run pre-process-dist-hooks
848 ad_run_dist_hooks "$pre_p_dist_hooks"
851 ad_dist_excludes "$excludes"
854 ad_dist_includes "$includes"
856 # Include specific license file if specified
857 if test "$license" != ""; then
858 cp -p $license $am_distdir/COPYING || exit 1
861 # Process noprocesses
864 # Process source files
865 ad_debug "Process distribution source tree"
866 ad_process_source_tree $am_distdir
868 # Process non-source files
869 ad_debug "Process distribution tree"
870 ad_process_tree $am_distdir
872 # Run post-process_dist-hooks
873 ad_run_dist_hooks "$post_p_dist_hooks"
875 # Make distribution sane
879 ad_debug "Packaging distribution"
880 tar chof $am_distdir.tar $am_distdir || exit 1
883 ad_debug "Compressing distribution package"
884 if test x$ad_gzip = xtrue; then
885 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
887 if test x$ad_bzip2 = xtrue; then
888 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
890 if test x$ad_compress = xtrue; then
891 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
893 if test x$ad_zip = xtrue; then
894 rm -f $am_distdir.zip
895 zip -rq $am_distdir.zip $am_distdir || exit 1
897 rm -f $am_distdir.tar
899 # Run post-dist-hooks
900 ad_run_dist_hooks "$post_dist_hooks"
904 rm -f autodist.noprocess
906 ad_debug "<ad_makedist"
910 # Handles distribution options.
912 # option has the following format in distfile:
916 # Following options are supported:
922 # Arguments: ad_handle_options <options>
926 ad_debug ">ad_handle_options: $1"
930 if test "$i" = "template"; then
933 elif test "$i" = "no-dist"; then
936 elif test "$i" = "no-inherit"; then
942 ad_debug "<ad_handle_options: $1"
948 # Arguments: ad_clear_options
952 ad_debug ">ad_clear_options"
956 ad_debug "<ad_clear_options"
960 # Parses the distribution. Gets all distribution defines from the
961 # distribution. This also expands all inherited distributions recursively
962 # to get all inherited distribution defines. From inherited distributions
963 # their name and package name is not inherited.
965 # Arguments: ad_parse_distribution <distribution name> <inherit>
967 ad_parse_distribution()
986 ad_debug ">ad_parse_distribution: $1 $2"
988 if test '!' -f $distdir/$1; then
989 ad_fatal "Distribution '$1' is not declared"
993 inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
994 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
997 defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
998 | grep "define " | cut -d' ' -f2 | sort | uniq`
1000 if test "$inhs" = "" && test "$defs" = ""; then
1001 ad_fatal "Distribution '$1' does not define anything"
1004 # Get undefined distdefs
1005 undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1006 | grep "undef " | cut -d' ' -f2 | sort | uniq`
1009 incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1010 | grep "include " | sed 's/include / : /'`
1013 excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1014 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
1017 nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1018 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
1021 opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1022 | grep "option " | cut -d' ' -f2- | sort | uniq`
1025 ad_handle_options "$opts"
1026 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
1027 ad_fatal "Distribution '$1' cannot be inherited"
1029 if test x$2 = xfalse && test x$opt_template = xtrue; then
1030 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
1033 ad_debug "inherits=$inhs"
1034 ad_debug "distdefs=$defs"
1035 ad_debug "includes=$incs"
1036 ad_debug "excludes=$excs"
1037 ad_debug "noprocess=$nops"
1038 ad_debug "undistdefs=$undefs"
1039 ad_debug "options=$opts"
1041 # Expand distdefs from inherited distributions
1044 if test x$1 = x$i; then
1045 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1046 distribution to not have 'inherit $i' declared."
1049 if test '!' -f $distdir/$i; then
1050 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1053 ad_parse_distribution $i true
1058 license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1059 | grep "license " | cut -d' ' -f2`
1060 licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1061 | grep "license-header " | sed 's/license-header / : /'`
1063 ad_debug "license=$license"
1064 ad_debug "licenseh=$licenseh"
1066 if test x$2 = xfalse; then
1067 # Get distribution name
1068 dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1069 | grep "name " | cut -d' ' -f2-`
1071 if test "$dname"; then
1075 # Get distribution package name (optional)
1076 dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1077 | grep "package " | cut -d' ' -f2`
1079 if test "$dpname"; then
1082 package=$distribution
1085 # Get Bug-report email address (optional)
1086 bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1087 | grep "bug-report " | cut -d' ' -f2-`
1089 if test "$bugr"; then
1093 ad_debug "distribution=$distribution"
1094 ad_debug "package=$package"
1095 ad_debug "bug-report=$bug_report"
1097 # Get hooks (optional)
1098 prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1099 | grep "pre-hook " | cut -d' ' -f2-`
1100 poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1101 | grep "post-hook " | cut -d' ' -f2-`
1102 prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1103 | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1104 podh=`cat $distdir/$1 | grep -v "^#" \
1105 | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1106 prpdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1107 | grep "pre-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1108 popdh=`cat $distdir/$1 | grep -v "^#" \
1109 | grep "post-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1111 pre_hooks="$pre_hooks $prh"
1112 post_hooks="$post_hooks $poh"
1113 pre_dist_hooks="$pre_dist_hooks $prdh"
1114 post_dist_hooks="$post_dist_hooks $podh"
1115 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1116 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1117 options="$options $opts"
1119 ad_handle_options "$options"
1120 ad_debug "options=$options"
1124 inherits="$inherits $inhs"
1125 distdefs="$distdefs $defs"
1126 includes="$includes $incs"
1127 excludes="$excludes $excs"
1128 noprocess="$noprocess $nops"
1129 undistdefs="$undistdefs $undefs"
1131 ad_debug "<ad_parse_distribution: $1 $2"
1135 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1136 # from the distdefs.
1138 # Arguments: ad_process_distdefs
1140 ad_process_distdefs()
1142 ad_debug ">ad_process_distdefs"
1144 # Remove all undefined distribution defines
1145 for i in $undistdefs
1147 ad_debug "undefining $i distdef"
1148 distdefs=`echo $distdefs | sed s/$i//`
1151 rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
1152 rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
1154 # Remove duplicate distdefs
1157 echo $i >>autodist.tmp.defs
1159 distdefs=`cat autodist.tmp.defs | sort | uniq`
1160 distdefs=`echo $distdefs`
1161 rm -f autodist.tmp.defs
1163 ad_debug "distdefs=$distdefs"
1165 ad_debug "<ad_process_distdefs"
1169 # Processes for a license header change.
1171 # Arguments: ad_process_license_header <scriptfile>
1173 ad_process_license_header()
1175 ad_debug ">ad_process_license_header"
1177 # Add : separator at the end
1178 lics=`echo "$licenseh" | sed 's/$/ : /'`
1184 if test "$i" = ":" && test -z "$src"; then
1187 if test -z "$src"; then
1191 if test -z "$dst" && test "$i" != ":"; then
1194 ad_fatal "Missing argument in 'license-header $src'"
1197 ad_debug "Replacing $src license with $dst license"
1199 if test '!' -f $src; then
1200 ad_fatal "License header $src: No such file or directory"
1203 if test '!' -f $dst; then
1204 ad_fatal "License header $dst: No such file or directory"
1207 # Awk script to replace the license header
1208 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1209 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1210 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
1211 rm -f autodist.lsrc autodist.ldst
1217 ad_debug "<ad_process_license_header"
1221 # Process specified noprocesses. This is called during makedist.
1223 # Arguments: ad_process_noprocess
1225 ad_process_noprocess()
1230 ad_debug ">ad_process_noprocess"
1235 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1237 n="$n -e 's/$am_distdir\\/$ie//'"
1241 rm -f autodist.noprocess
1242 if test x$np = xtrue; then
1243 echo $n > autodist.noprocess || exit 1
1246 ad_debug "<ad_process_noprocess"
1250 # Process a file given as argument for the distribution.
1252 # Arguments: ad_process_file <filepath> <dest_filepath>
1261 # Process only regular files
1262 if test '!' -f $1; then
1266 ad_debug ">ad_process_file: $1 $2"
1268 f="autodist.tmp.script"
1271 # If license header is provided, replace the license header in the file.
1272 ad_process_license_header $f
1274 ad_debug "Getting #ifdef's and #ifndef's"
1276 # Get defined distribution defines
1277 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1278 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1280 # Get explicitly not-defined distribution defines
1281 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1282 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1284 ad_debug "defs=$defs"
1285 ad_debug "ndefs=$ndefs"
1287 # Create the script to include and exclude stuff in the file according
1288 # to the distribution defines
1291 ad_debug "processing ifdefs"
1297 if test x$d = x$i; then
1303 # If distribution define was not found exclude those lines from the file.
1304 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1305 if test x$found = xfalse; then
1306 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1307 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1309 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1314 ad_debug "processing ifndefs"
1320 if test x$d = x$i; then
1326 # If distribution define was found exclude those lines from the file.
1327 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1328 if test x$found = xtrue; then
1329 ad_debug "ifndef $d will be excluded (it IS defined)"
1330 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1332 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1336 # Now process the file with the script
1339 # Those distdef lines that remain in the file are removed to make
1340 # the appearance prettier
1341 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1342 echo "{ print; }" >> $f
1344 # Execute the script
1345 cp -p $1 $2 || exit 1
1346 awk -f $f $1 > $2 || exit 1
1351 ad_debug "<ad_process_file: $1 $2"
1355 # Process a source file given as argument for the distribution.
1357 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1359 ad_process_source_file()
1366 # Process only regular files
1367 if test '!' -f $1; then
1371 ad_debug ">ad_process_source_file: $1 $2"
1373 f="autodist.tmp.script"
1376 # If license header is provided, replace the license header in the file.
1377 ad_process_license_header $f
1379 ad_debug "Getting #ifdef's and #ifndef's"
1381 # Get defined distribution defines
1382 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1383 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1385 # Get explicitly not-defined distribution defines
1386 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1387 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1389 ad_debug "defs=$defs ndefs=$ndefs"
1391 # Create the script to include and exclude stuff in the file according
1392 # to the distribution defines
1395 ad_debug "processing ifdefs"
1401 if test x$d = x$i; then
1407 # If distribution define was not found exclude those lines from the file.
1408 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1409 if test x$found = xfalse; then
1410 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1411 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1413 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1418 ad_debug "processing ifndefs"
1424 if test x$d = x$i; then
1430 # If distribution define was found exclude those lines from the file.
1431 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1432 if test x$found = xtrue; then
1433 ad_debug "ifndef $d will be excluded (it IS defined)"
1434 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1436 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1440 # Now process the file with the script
1443 # Those distdef lines that remain in the file are removed to make
1444 # the appearance prettier
1445 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1446 echo "{ print; }" >> $f
1448 # Execute the script
1449 cp -p $1 $2 || exit 1
1450 awk -f $f $1 > $2 || exit 1
1455 ad_debug "<ad_process_source_file: $1 $2"
1461 # Arguments: ad_run_hooks <hooks>
1465 ad_debug ">ad_run_hooks: $1"
1469 if test '!' -f $i; then
1470 ad_fatal "Hook script $i does not exist"
1472 sh $i $distribution $dist_version $package || exit 1
1475 ad_debug "<ad_run_hooks: $1"
1481 # Arguments: ad_run_dist_hooks <hooks>
1485 ad_debug ">ad_run_dist_hooks: $1"
1489 if test '!' -f $i; then
1490 ad_fatal "Dist hook script $i does not exist"
1492 sh $i $distribution $dist_version $package $am_distdir || exit 1
1495 ad_debug "<ad_run_dist_hooks: $1"
1498 ###############################################################################
1501 usage="Usage: autodist [options] [distribution] [version]"
1503 Autodist prepares source tree for configuration, compilation and
1504 distribution. Prepares the source tree from the \`autodist.ad'
1505 configuration file. Generates Automake.am files from Automake.ad
1506 files, configure.ac file from configure.ad file(s), generates the
1507 configure script by running Autoconf tool, and generates Makefile.in
1508 files by running Automake tool.
1511 -h, --help print this help, then exit
1512 -V, --version print version number, then exit
1513 -v, --verbose verbosely report processing
1514 -d, --distdir <dir> search distributions from <dir>
1515 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1516 -i, --init initialize Autodist environment, create default
1517 distribution directory and distribution, then exit
1518 -m, --makedist create and package distribution
1519 --gzip create package compressed with gzip (default)
1520 --bzip2 create also package compressed with bzip2
1521 --compress create also package compressed with compress
1522 --zip create also package compressed with zip"
1525 # Process command line arguments
1527 while test $# -gt 0; do
1532 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1541 if test $# -eq 0; then
1542 ad_parse_distribution $distribution false
1543 echo "Distribution: ${distribution}" 1>&2;
1545 ad_parse_distribution $1 false
1546 echo "Distribution: ${1}" 1>&2;
1549 echo "Distdefs:" 1>&2;
1582 echo "${usage}" 1>&2;
1584 echo "${help}" 1>&2;
1589 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1590 echo "Written by Pekka Riikonen" 1>&2;
1592 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1594 This is free software; see the source for copying conditions. There is NO
1595 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1603 echo "${usage}" 1>&2;
1613 # Parse the requested distribution
1615 if test $# != 0; then
1616 distribution="${1}";
1617 distfile=$distribution
1620 ad_parse_distribution $distribution false
1623 if test $# != 0; then
1624 dist_version="${1}";
1627 ad_debug "Preparing source tree for configuration and compilation..."
1628 ad_debug "Preparing $distribution distribution version $dist_version"
1631 # Create the distribution defines header file
1633 if test "$DISTDEFS"; then
1634 ad_create_distdefs_h
1636 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1642 ad_run_hooks "$pre_hooks"
1645 # Generate the Makefile.am files from Makefile.ad files
1647 ad_make_makefile_ams
1650 # Generate the configure.ac from configure.ad file(s)
1652 ad_make_configure_ac ./configure.ad
1655 # Process all files with .ad suffix for distribution processing
1660 # Generate configure script
1665 # Generate Makefile.in files
1667 ad_make_makefile_ins
1670 # Create autodist.dist
1672 ad_debug "Creating autodist.dist"
1673 echo "dist:$distfile" > autodist.dist
1674 echo "ver:$dist_version" >> autodist.dist
1675 echo "$package-$dist_version" >> autodist.dist
1680 ad_run_hooks "$post_hooks"
1682 ad_debug "Done, now run ./configure and make."