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 # Despite of this, we have managed to segfault some zsh's.
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 if test x$debug = xtrue; then
269 $ACLOCAL 1>/dev/null 2>/dev/null
271 if test $? != 0; then
272 ad_fatal "aclocal failed"
276 if test "$AUTOCONF"; then
277 ad_debug "Running autoconf"
279 if test $? != 0; then
280 ad_fatal "autoconf failed"
285 if test "$AUTOHEADER"; then
286 ad_debug "Running autoheader"
288 if test $? != 0; then
289 ad_fatal "autoheader failed"
293 if test "$LIBTOOLIZE"; then
294 ad_debug "Running libtoolize"
296 if test $? != 0; then
297 ad_fatal "libtoolize failed"
301 if test x$run_autoconf = xtrue; then
302 if test '!' -f configure; then
303 ad_fatal "creating configure script failed"
307 ad_debug "<ad_make_configure"
311 # Creates the configure.ac script from the configure.ad fragments in
312 # the source tree. Takes the source configure file as argument which
313 # is used to create the actual configure.ac.
315 # Arguments: ad_make_configure_ac <configure_ac_source>
317 ad_make_configure_ac()
321 ad_debug ">ad_make_configure_ac: $1"
323 if test '!' -f $1; then
324 ad_fatal "The configure file '$1' does not exist"
327 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
328 if test -z $check; then
329 rm -f configure.ad.cfs
330 rm -f $fname $fname.tmp
331 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
334 rm -f configure.ac configure.ad.cfs
336 cfs=`find . -name configure\*\.ad`
339 if test "x$i" = "x$1"; then
342 ad_debug "including $i"
343 cat $i >> configure.ad.cfs
346 if test -f configure.ad.cfs; then
347 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
348 if test -z $check; then
349 rm -f configure.ad.cfs
350 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
354 # Header for configure.ac
355 fname="configure.tmp.ac"
356 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
357 echo "# To make changes edit the configure.ad file in the source tree." >> $fname
359 echo "# Source: configure.ad" >> $fname
360 echo "# Generated: `date` by `whoami`" >> $fname
361 echo "# Distribution: $distribution" >> $fname
362 echo "# License: $license" >> $fname
365 ad_debug "creating configure.ac"
366 if test -f configure.ad.cfs; then
367 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
368 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
369 rm -f configure.ad.cfs $fname.tmp
375 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
377 # Process for distribution
379 ad_process_file $fname.tmp $fname
381 # Remove any trailing backslashes
382 if test -f "$fname"; then
383 cat $fname | sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' > configure.ac
385 cp -p $fname.tmp configure.ac
387 rm -f $fname $fname.tmp
389 ad_debug "<ad_make_configure_ac: $1"
393 # Creates the Makefile.in files by running the automake tool.
395 # Arguments: ad_make_makefile_ins
397 ad_make_makefile_ins()
399 ad_debug ">ad_make_makefile_ins"
401 if test "$AUTOMAKE"; then
402 ad_debug "Running automake"
404 if test $? != 0; then
405 ad_fatal "automake failed"
409 ad_debug "<ad_make_makefile_ins"
413 # Creates the Makefile.am files from the Makefile.ad files in the
414 # source tree. This runs the distribution specific processing for the
417 # Arguments: ad_make_makefile_ams
419 ad_make_makefile_ams()
421 ad_debug ">ad_make_makefile_ams"
423 files=`find . -name Makefile\.ad`
426 fname=`echo $ff | sed s/\.ad//`
428 # Header for the Makefile.am
429 echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am
430 echo "# To make changes edit the $ff file in the source tree." >> $fname.am
432 echo "# Source: $ff" >> $fname.am
433 echo "# Generated: `date` by `whoami`" >> $fname.am
434 echo "# Distribution: $distribution" >> $fname.am
435 echo "# License: $license" >> $fname.am
438 # Run the distribution processing for this Makefile.ad
439 ad_debug "Processing $ff to be $fname.am"
440 ad_process_file $ff $fname.tmp
442 # Remove any trailing backslashes
443 if test -f "$fname.tmp"; then
444 cat $fname.tmp | sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' >> $fname.am
452 ad_debug "<ad_make_makefile_ams"
456 # Processes all files with .ad suffix, with exception of configure*.ad
457 # and Makefile.ad files, for distribution from the source tree.
459 # Arguments: ad_process_ads
463 ad_debug ">ad_process_ads"
465 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
468 fname=`echo $i | sed s/\.ad//`
471 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
472 echo "# To make changes edit the $i file in the source tree." >> $fname
474 echo "# Source: $i" >> $fname
475 echo "# Generated: `date` by `whoami`" >> $fname
476 echo "# Distribution: $distribution" >> $fname
477 echo "# License: $license" >> $fname
480 # Run the distribution processing for this file
481 ad_debug "Processing $i to be $fname"
482 ad_process_file $i $fname
485 ad_debug "<ad_process_ads"
489 # Includes files specified in the distribution for inclusion. Used when
490 # creating the distribution for packaging.
492 # include has the following format in distfile:
494 # include <path> [<dest path>]
496 # If only source path, which may be file, directory or regular expression,
497 # is specified the path will be same in distribution. If the destination
498 # path is specified that will be the new name and/or new location of the
499 # source path. This, in effect, is a cp utility with ability to create
500 # directories if they do not exist.
502 # Arguments: ad_dist_includes <includeslist> <recursive>
508 ad_debug ">ad_dist_includes: $1 $2"
510 # By default do not expand pathnames
513 # Add : separator at the end
514 incs="`echo "$1" | sed 's/$/ : /'`"
520 if test "$i" = ":" && test -z "$src"; then
523 if test -z "$src"; then
527 if test -z "$dst" && test "$i" != ":"; then
533 ad_debug "Including $src into $dst"
535 if test -f "$src"; then
538 if test "$src" = "$dst"; then
539 # Add to same location
540 d=`echo $src | sed 's,/[^/]*$,,'`
541 if test "$d" != "$src" && test "$d" != "." && \
542 test '!' -d $am_distdir/$d; then
543 mkdir -p $am_distdir/$d || exit 1
546 # Add to different location
547 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
548 if test "$check" != "$dst"; then
549 ad_fatal "Invalid destination in 'include $src $dst'"
552 d=`echo $dst | sed 's,/[^/]*$,,'`
553 if test "$d" != "$dst" && test "$d" != "." && \
554 test '!' -d $am_distdir/$d; then
555 mkdir -p $am_distdir/$d || exit 1
559 cp -p $src $am_distdir/$d || exit 1
561 elif test -d "$src"; then
564 if test "$src" = "$dst"; then
565 # Add to same location
566 d=`echo $src | sed 's,/[^/]*$,,'`
567 ds=`echo $src | sed 's/\/$//'`
568 if test "$ds" = "$d"; then
569 d=`echo $d | sed 's,/[^/]*$,,'`
571 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
572 mkdir -p $am_distdir/$d || exit 1
575 cp -pR $src $am_distdir/$d || exit 1
577 # Add to different location
578 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
579 if test "$check" != "$dst"; then
580 ad_fatal "Invalid destination in 'include $src $dst'"
583 d=`echo $dst | sed 's,/[^/]*$,,'`
584 ds=`echo $dst | sed 's/\/$//'`
585 if test "$ds" = "$d"; then
586 d=`echo $d | sed 's,/[^/]*$,,'`
588 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
589 mkdir -p $am_distdir/$d || exit 1
592 cp -pR $src $am_distdir/$dst || exit 1
595 elif test x$2 != xtrue; then
596 # We assume regular expression in filename
597 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
598 if test "$check" == "$src"; then
599 if test '!' -a $src; then
600 ad_fatal "Including $src: No such file or directory"
607 # Recursively call this function with expanded pathnames. The
608 # reason why we don't let sh by default expand patnames is that
609 # the include's destination is optional. If sh expands by default
610 # we don't know the destination. For this reason, we handle the
611 # expansion here ourselves.
613 # If src and dst are same, then expand the pathname as we'll copy
614 # matches to their own locations.
615 if test "$src" = "$dst"; then
616 # Expand pathnames, and format to our include format
618 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
621 # Destination is new, and it has to be a directory.
622 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
623 if test "$check" != "$dst"; then
624 ad_fatal "Invalid destination in 'include $src $dst'"
627 # Make sure dst has / at the end, as this must be a directory
628 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
631 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
633 # Expand pathnames, and format to our include format
635 srcs=`echo $src | sed -e "s/ / $dste : /g" \
636 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
640 # Include recursively
641 ad_dist_includes "$srcs" true
643 elif test '!' -a $src; then
644 ad_fatal "Including $src: No such file or directory"
653 ad_debug "<ad_dist_includes: $1 $2"
657 # Excludes files specified in the distribution for exclusion. Used when
658 # creating the distribution for packaging.
660 # exclude has the following format in distfile:
664 # The path may be file, directory or regular expression.
666 # Arguments: ad_dist_includes <excludelist>
670 ad_debug ">ad_dist_excludes: $1"
674 ad_debug "Excluding $i"
675 rm -rf $am_distdir/$i
678 ad_debug "<ad_dist_excludes: $1"
682 # Processes the entire tree for distribution. This inspects files other
683 # than source and header files, with exception of any file with .ad
684 # suffix, and performs distribution processing for the file. The original
685 # file is replaced with the processed file. This function is used when
686 # creating the distribution for packaging.
688 # Arguments: ad_process_tree <directory>
692 ad_debug ">ad_process_tree: $1"
694 # We take all files, other than *.ad, including source files, in case
695 # they use the non-C-compiler-friendly format of distdefs, which is
698 files=`find $am_distdir \! -name \*\.ad`
699 files=`echo $files | sed 's/$am_distdir//'`
701 # Take away noprocess list
702 if test -f autodist.noprocess; then
703 files=`echo $files | sh autodist.noprocess` || exit 1
708 ad_process_file $ff $ff.tmp
709 if test -f $ff.tmp; then
711 mv -f $ff.tmp $ff || exit 1
715 ad_debug "<ad_process_tree: $1"
719 # Processes the entire source tree for distribution. This inspects files
720 # in the source tree, with exception of any file with .ad suffix, and
721 # performs distribution processing for the file. The original file is
722 # replaced with the processed file. This function is used when creating
723 # the distribution for packaging.
725 # Call this before ad_process_tree().
727 # Arguments: ad_process_source_tree <directory>
729 ad_process_source_tree()
731 ad_debug ">ad_process_source_tree: $1"
733 # We take only C/C++ files since they use the C compiler friendly
734 # version of distdefs. Other files are not assumed to use them.
735 files=`find $am_distdir \! -name \*\.ad \( \
737 -name \*\.[cC][cCpP] -o \
738 -name \*\.[cC][xX][xX] -o \
739 -name \*\.[cC][pP][pP] -o \
740 -name \*\.[cC]++ -o \
745 # Take away noprocess list
746 if test -f autodist.noprocess; then
747 files=`echo $files | sh autodist.noprocess` || exit 1
752 ad_process_source_file $ff $ff.tmp
753 if test -f $ff.tmp; then
755 mv -f $ff.tmp $ff || exit 1
759 ad_debug "<ad_process_source_tree: $1"
763 # Makes distribution sane, ala modtimes. Since we modify the distribution
764 # we need to make it sane after that.
766 # Arguments: ad_makedist_makesane
768 ad_makedist_makesane()
770 ad_debug ">ad_makedist_makesane:"
772 # DO NOT change these order unless you know what you are doing.
773 if test -f $am_distdir/configure.ac; then
774 touch $am_distdir/configure.ac
777 if test -f $am_distdir/aclocal.m4; then
778 touch $am_distdir/aclocal.m4
781 if test '!' -f Makefile; then
782 ad_fatal "Makefile: No such file or directory"
785 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ ]*//'`
786 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
788 files=`find $am_distdir -name Makefile\.in`
794 if test -f $am_distdir/configure; then
795 touch $am_distdir/configure
798 if test -f $am_distdir/config.status; then
799 touch $am_distdir/config.status
802 ad_debug "<ad_makedist_makesane:"
806 # Creates distribution of the source tree. All files in the distribution
807 # will be processed and the distribution will be packaged.
809 # Arguments: ad_makedist
813 ad_debug ">ad_makedist"
815 if test '!' -f autodist.dist; then
816 ad_fatal "Autodist has not been run yet to prepare source tree"
819 if test -z $MAKE; then
820 ad_fatal "The MAKE variable is not set in autodist.conf"
823 # Get distdir from Makefile
824 if test '!' -f Makefile; then
825 ad_fatal "The source tree is not configured, run ./configure first"
828 # Parse the requested distribution
829 distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2` || exit 1
830 dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2` || exit 1
831 am_distdir=`cat autodist.dist | grep "distdir:" | cut -d: -f2` || exit 1
832 ad_parse_distribution $distribution false
835 if test x$opt_no_dist = xtrue; then
836 ad_fatal "The '$distribution' distribution cannot be packaged"
840 ad_run_dist_hooks "$pre_dist_hooks"
842 # Create distribution directory
843 ad_debug "Creating distribution directory $am_distdir"
844 $MAKE distdir || exit 1
845 chmod -R a+r $am_distdir
847 if test '!' -d $am_distdir; then
848 ad_fatal "Distribution directory $am_distdir not created"
851 # Run pre-process-dist-hooks
852 ad_run_dist_hooks "$pre_p_dist_hooks"
855 ad_dist_excludes "$excludes"
858 ad_dist_includes "$includes"
860 # Include specific license file if specified
861 if test "$license" != ""; then
862 cp -p $license $am_distdir/COPYING || exit 1
865 # Process noprocesses
868 # Process source files
869 ad_debug "Process distribution source tree"
870 ad_process_source_tree $am_distdir
872 # Process non-source files
873 ad_debug "Process distribution tree"
874 ad_process_tree $am_distdir
876 # Run post-process_dist-hooks
877 ad_run_dist_hooks "$post_p_dist_hooks"
879 # Make distribution sane
883 ad_debug "Packaging distribution"
884 tar chof $am_distdir.tar $am_distdir || exit 1
887 ad_debug "Compressing distribution package"
888 if test x$ad_gzip = xtrue; then
889 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
891 if test x$ad_bzip2 = xtrue; then
892 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
894 if test x$ad_compress = xtrue; then
895 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
897 if test x$ad_zip = xtrue; then
898 rm -f $am_distdir.zip
899 zip -rq $am_distdir.zip $am_distdir || exit 1
901 rm -f $am_distdir.tar
903 # Run post-dist-hooks
904 ad_run_dist_hooks "$post_dist_hooks"
908 rm -f autodist.noprocess
910 ad_debug "<ad_makedist"
914 # Handles distribution options.
916 # option has the following format in distfile:
920 # Following options are supported:
926 # Arguments: ad_handle_options <options>
930 ad_debug ">ad_handle_options: $1"
934 if test "$i" = "template"; then
937 elif test "$i" = "no-dist"; then
940 elif test "$i" = "no-inherit"; then
946 ad_debug "<ad_handle_options: $1"
952 # Arguments: ad_clear_options
956 ad_debug ">ad_clear_options"
960 ad_debug "<ad_clear_options"
964 # Parses the distribution. Gets all distribution defines from the
965 # distribution. This also expands all inherited distributions recursively
966 # to get all inherited distribution defines. From inherited distributions
967 # their name and package name is not inherited.
969 # Arguments: ad_parse_distribution <distribution name> <inherit>
971 ad_parse_distribution()
990 ad_debug ">ad_parse_distribution: $1 $2"
992 if test '!' -f $distdir/$1; then
993 ad_fatal "Distribution '$1' is not declared"
997 inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
998 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
1001 defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1002 | grep "define " | cut -d' ' -f2 | sort | uniq`
1004 if test "$inhs" = "" && test "$defs" = ""; then
1005 ad_fatal "Distribution '$1' does not define anything"
1008 # Get undefined distdefs
1009 undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1010 | grep "undef " | cut -d' ' -f2 | sort | uniq`
1013 incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1014 | grep "include " | sed 's/include / : /'`
1017 excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1018 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
1021 nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1022 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
1025 opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1026 | grep "option " | cut -d' ' -f2- | sort | uniq`
1029 ad_handle_options "$opts"
1030 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
1031 ad_fatal "Distribution '$1' cannot be inherited"
1033 if test x$2 = xfalse && test x$opt_template = xtrue; then
1034 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
1037 ad_debug "inherits: $inhs"
1038 ad_debug "distdefs: $defs"
1039 ad_debug "includes: $incs"
1040 ad_debug "excludes: $excs"
1041 ad_debug "noprocess: $nops"
1042 ad_debug "undistdefs: $undefs"
1043 ad_debug "options: $opts"
1045 # Expand distdefs from inherited distributions
1048 if test x$1 = x$i; then
1049 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1050 distribution to not have 'inherit $i' declared."
1053 if test '!' -f $distdir/$i; then
1054 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1057 ad_parse_distribution $i true
1062 license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1063 | grep "license " | cut -d' ' -f2`
1064 licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1065 | grep "license-header " | sed 's/license-header / : /'`
1067 ad_debug "license: $license"
1068 ad_debug "licenseh: $licenseh"
1070 if test x$2 = xfalse; then
1071 # Get distribution name
1072 dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1073 | grep "name " | cut -d' ' -f2-`
1075 if test "$dname"; then
1079 # Get distribution package name (optional)
1080 dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1081 | grep "package " | cut -d' ' -f2`
1083 if test "$dpname"; then
1086 package=$distribution
1089 # Get Bug-report email address (optional)
1090 bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1091 | grep "bug-report " | cut -d' ' -f2-`
1093 if test "$bugr"; then
1097 ad_debug "distribution: $distribution"
1098 ad_debug "package: $package"
1099 ad_debug "bug-report: $bug_report"
1101 # Get hooks (optional)
1102 prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1103 | grep "pre-hook " | cut -d' ' -f2-`
1104 poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1105 | grep "post-hook " | cut -d' ' -f2-`
1106 prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1107 | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1108 podh=`cat $distdir/$1 | grep -v "^#" \
1109 | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1110 prpdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1111 | grep "pre-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1112 popdh=`cat $distdir/$1 | grep -v "^#" \
1113 | grep "post-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1115 pre_hooks="$pre_hooks $prh"
1116 post_hooks="$post_hooks $poh"
1117 pre_dist_hooks="$pre_dist_hooks $prdh"
1118 post_dist_hooks="$post_dist_hooks $podh"
1119 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1120 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1121 doptions="$doptions $opts"
1123 ad_handle_options "$doptions"
1124 ad_debug "options: $doptions"
1128 inherits="$inherits $inhs"
1129 distdefs="$distdefs $defs"
1130 includes="$includes $incs"
1131 excludes="$excludes $excs"
1132 noprocess="$noprocess $nops"
1133 undistdefs="$undistdefs $undefs"
1135 ad_debug "<ad_parse_distribution: $1 $2"
1139 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1140 # from the distdefs.
1142 # Arguments: ad_process_distdefs
1144 ad_process_distdefs()
1146 ad_debug ">ad_process_distdefs"
1148 # Remove all undefined distribution defines
1149 for i in $undistdefs
1151 ad_debug "undefining $i distdef"
1152 distdefs=`echo $distdefs | sed s/$i//`
1155 rm -f autodist.tmp.defs
1157 # Remove duplicate distdefs
1160 echo $i >>autodist.tmp.defs
1162 distdefs=`cat autodist.tmp.defs | sort | uniq`
1163 distdefs=`echo $distdefs`
1164 rm -f autodist.tmp.defs
1166 ad_debug "distdefs=$distdefs"
1168 ad_debug "<ad_process_distdefs"
1172 # Processes for a license header change.
1174 # Arguments: ad_process_license_header <scriptfile>
1176 ad_process_license_header()
1178 ad_debug ">ad_process_license_header"
1180 # Add : separator at the end
1181 lics=`echo "$licenseh" | sed 's/$/ : /'`
1187 if test "$i" = ":" && test -z "$src"; then
1190 if test -z "$src"; then
1194 if test -z "$dst" && test "$i" != ":"; then
1197 ad_fatal "Missing argument in 'license-header $src'"
1200 ad_debug "Replacing $src license with $dst license"
1202 if test '!' -f $src; then
1203 ad_fatal "License header $src: No such file or directory"
1206 if test '!' -f $dst; then
1207 ad_fatal "License header $dst: No such file or directory"
1210 # Awk script to replace the license header
1211 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1212 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1213 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
1214 rm -f autodist.lsrc autodist.ldst
1220 ad_debug "<ad_process_license_header"
1224 # Process specified noprocesses. This is called during makedist.
1226 # Arguments: ad_process_noprocess
1228 ad_process_noprocess()
1233 ad_debug ">ad_process_noprocess"
1238 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1240 n="$n -e 's/$am_distdir\\/$ie//'"
1244 rm -f autodist.noprocess
1245 if test x$np = xtrue; then
1246 echo $n > autodist.noprocess || exit 1
1249 ad_debug "<ad_process_noprocess"
1253 # Process a file given as argument for the distribution.
1255 # Arguments: ad_process_file <filepath> <dest_filepath>
1264 # Process only regular files
1265 if test '!' -f $1; then
1269 ad_debug ">ad_process_file: $1 $2"
1271 f="autodist.tmp.script"
1274 # If license header is provided, replace the license header in the file.
1275 ad_process_license_header $f
1277 ad_debug "Getting #ifdef's and #ifndef's"
1279 # Get defined distribution defines
1280 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1281 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1283 # Get explicitly not-defined distribution defines
1284 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1285 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1287 ad_debug "defs in $1: $defs"
1288 ad_debug "ndefs in $1: $ndefs"
1290 # Create the script to include and exclude stuff in the file according
1291 # to the distribution defines
1294 ad_debug "processing ifdefs"
1300 if test x$d = x$i; then
1306 # If distribution define was not found exclude those lines from the file.
1307 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1308 if test x$found = xfalse; then
1309 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1310 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1312 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1317 ad_debug "processing ifndefs"
1323 if test x$d = x$i; then
1329 # If distribution define was found exclude those lines from the file.
1330 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1331 if test x$found = xtrue; then
1332 ad_debug "ifndef $d will be excluded (it IS defined)"
1333 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1335 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1339 # Now process the file with the script
1342 # Those distdef lines that remain in the file are removed to make
1343 # the appearance prettier
1344 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1345 echo "{ print; }" >> $f
1347 # Execute the script
1348 cp -p $1 $2 || exit 1
1349 awk -f $f $1 > $2 || exit 1
1354 ad_debug "<ad_process_file: $1 $2"
1358 # Process a source file given as argument for the distribution.
1360 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1362 ad_process_source_file()
1369 # Process only regular files
1370 if test '!' -f $1; then
1374 ad_debug ">ad_process_source_file: $1 $2"
1376 f="autodist.tmp.script"
1379 # If license header is provided, replace the license header in the file.
1380 ad_process_license_header $f
1382 ad_debug "Getting #ifdef's and #ifndef's"
1384 # Get defined distribution defines
1385 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1386 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1388 # Get explicitly not-defined distribution defines
1389 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1390 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1392 ad_debug "defs in $1: $defs"
1393 ad_debug "ndefs in $1: $ndefs"
1395 # Create the script to include and exclude stuff in the file according
1396 # to the distribution defines
1399 ad_debug "processing ifdefs"
1405 if test x$d = x$i; then
1411 # If distribution define was not found exclude those lines from the file.
1412 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1413 if test x$found = xfalse; then
1414 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1415 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1417 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1422 ad_debug "processing ifndefs"
1428 if test x$d = x$i; then
1434 # If distribution define was found exclude those lines from the file.
1435 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1436 if test x$found = xtrue; then
1437 ad_debug "ifndef $d will be excluded (it IS defined)"
1438 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1440 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1444 # Now process the file with the script
1447 # Those distdef lines that remain in the file are removed to make
1448 # the appearance prettier
1449 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1450 echo "{ print; }" >> $f
1452 # Execute the script
1453 cp -p $1 $2 || exit 1
1454 awk -f $f $1 > $2 || exit 1
1459 ad_debug "<ad_process_source_file: $1 $2"
1465 # Arguments: ad_run_hooks <hooks>
1469 ad_debug ">ad_run_hooks: $1"
1473 if test '!' -f $i; then
1474 ad_fatal "Hook script $i does not exist"
1476 sh $i "$distribution" "$dist_version" "$package" || exit 1
1479 ad_debug "<ad_run_hooks: $1"
1485 # Arguments: ad_run_dist_hooks <hooks>
1489 ad_debug ">ad_run_dist_hooks: $1"
1493 if test '!' -f $i; then
1494 ad_fatal "Dist hook script $i does not exist"
1496 sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1
1499 ad_debug "<ad_run_dist_hooks: $1"
1502 ###############################################################################
1505 usage="Usage: autodist [options] [distribution] [version]"
1507 Autodist prepares source tree for configuration, compilation and
1508 distribution. Prepares the source tree from the \`autodist.ad'
1509 configuration file. Generates Automake.am files from Automake.ad
1510 files, configure.ac file from configure.ad file(s), generates the
1511 configure script by running Autoconf tool, and generates Makefile.in
1512 files by running Automake tool.
1515 -h, --help print this help, then exit
1516 -V, --version print version number, then exit
1517 -v, --verbose verbosely report processing
1518 -d, --distdir <dir> search distributions from <dir>
1519 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1520 -i, --init initialize Autodist environment, create default
1521 distribution directory and distribution, then exit
1522 -m, --makedist create and package distribution
1523 --gzip create package compressed with gzip (default)
1524 --bzip2 create also package compressed with bzip2
1525 --compress create also package compressed with compress
1526 --zip create also package compressed with zip"
1529 # Process command line arguments
1531 while test $# -gt 0; do
1536 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1545 if test $# -eq 0; then
1546 ad_parse_distribution $distribution false
1547 echo "Distribution: ${distribution}" 1>&2;
1549 ad_parse_distribution $1 false
1550 echo "Distribution: ${1}" 1>&2;
1553 echo "Distdefs:" 1>&2;
1586 echo "${usage}" 1>&2;
1588 echo "${help}" 1>&2;
1593 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1594 echo "Written by Pekka Riikonen" 1>&2;
1596 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1598 This is free software; see the source for copying conditions. There is NO
1599 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1607 echo "${usage}" 1>&2;
1617 # Parse the requested distribution
1619 if test $# != 0; then
1620 distribution="${1}";
1621 distfile=$distribution
1624 ad_parse_distribution $distribution false
1627 if test $# != 0; then
1628 dist_version="${1}";
1631 ad_debug "Preparing source tree for configuration and compilation..."
1632 ad_debug "Preparing $distribution distribution version $dist_version"
1635 # Create the distribution defines header file
1637 if test "$DISTDEFS"; then
1638 ad_create_distdefs_h
1640 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1646 ad_run_hooks "$pre_hooks"
1649 # Generate the Makefile.am files from Makefile.ad files
1651 ad_make_makefile_ams
1654 # Generate the configure.ac from configure.ad file(s)
1656 ad_make_configure_ac ./configure.ad
1659 # Process all files with .ad suffix for distribution processing
1664 # Generate configure script
1669 # Generate Makefile.in files
1671 ad_make_makefile_ins
1674 # Create autodist.dist
1676 ad_debug "Creating autodist.dist"
1677 echo "dist:$distfile" > autodist.dist
1678 echo "ver:$dist_version" >> autodist.dist
1679 echo "distdir:$package-$dist_version" >> autodist.dist
1684 ad_run_hooks "$post_hooks"
1686 ad_debug "Done, now run ./configure and make."