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
85 # Distribution license and license header
89 # Whether to output ad_debug information
95 ###############################################################################
97 if test -f "$distdir/autodist.conf"; then
98 . $distdir/autodist.conf
104 ###############################################################################
108 # Print out debug information if debugging is enabled. To enable debugging
109 # set the global variable "debug" to true value.
111 # Arguments: ad_debug <ad_debug string>
115 if test x$debug = xtrue; then
123 # Prints out error message and exits the script.
125 # Arguments: ad_fatal <error message>
130 echo autodist: error: $1
136 # Prints out warning message
138 # Arguments: ad_warning <warning message>
143 echo autodist: warning: $1
148 # Initializes the Autodist environment, creates default distribution
149 # directory, and default distribution.
151 # Arguments: ad_initialize
155 ad_debug ">ad_initialize"
157 # Create default distdir
158 if test '!' -f $distdir; then
162 # Create Autodist configuration file
163 if test -f @AUTODISTDIR@/autodist.conf; then
164 cp -p @AUTODISTDIR@/autodist.conf $distdir
167 # Create default distribution
168 if test -f @AUTODISTDIR@/default; then
169 cp -p @AUTODISTDIR@/default $distdir
172 ad_debug "<ad_initialize"
176 # Creates the distdefs header file including defined distdefs
178 # Arguments: ad_create_distdefs_h
180 ad_create_distdefs_h()
182 ad_debug ">ad_create_distdefs_h"
187 echo " Automatically generated by Autodist $ver. Do not edit." >> $fname
189 echo " Generated: `date` by `whoami`" >> $fname
190 echo " Distribution: $distribution" >> $fname
191 echo " License: $license" >> $fname
194 echo "#ifndef _"$DP"_DISTDEFS_H" >> $fname
195 echo "#define _"$DP"_DISTDEFS_H" >> $fname
200 echo "#define $i 1" >>$fname
204 echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname
206 ad_debug "<ad_create_distdefs_h"
210 # Creates the main configure script for the distribution. This runs
211 # the aclocal, autoheader and autoconf tools.
213 # Arguments: ad_make_configure
217 ad_debug ">ad_make_configure"
218 local run_autoconf=false
222 if test "$ACLOCAL"; then
223 ad_debug "Running aclocal"
224 $ACLOCAL 1>/dev/null 2>/dev/null
225 if test $? != 0; then
226 ad_fatal "aclocal failed"
230 if test "$AUTOCONF"; then
231 ad_debug "Running autoconf"
233 if test $? != 0; then
234 ad_fatal "autoconf failed"
239 if test "$AUTOHEADER"; then
240 ad_debug "Running autoheader"
242 if test $? != 0; then
243 ad_fatal "autoheader failed"
247 if test "$LIBTOOLIZE"; then
248 ad_debug "Running libtoolize"
250 if test $? != 0; then
251 ad_fatal "libtoolize failed"
255 if test x$run_autoconf = xtrue; then
256 if test '!' -f configure; then
257 ad_fatal "creating configure script failed"
261 ad_debug "<ad_make_configure"
265 # Creates the configure.ac script from the configure.ad fragments in
266 # the source tree. Takes the source configure file as argument which
267 # is used to create the actual configure.ac.
269 # Arguments: ad_make_configure_ac <configure_ac_source>
271 ad_make_configure_ac()
273 ad_debug ">ad_make_configure_ac: $1"
275 if test '!' -f $1; then
276 ad_fatal "The configure file '$1' does not exist"
279 local check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
280 if test -z $check; then
281 rm -f configure.ad.cfs
282 rm -f $fname $fname.tmp
283 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
286 rm -f configure.ac configure.ad.cfs
288 cfs=`find . -name configure\*\.ad`
291 if test "x$i" = "x$1"; then
294 ad_debug "including $i"
295 cat $i >> configure.ad.cfs
298 if test -f configure.ad.cfs; then
299 local check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
300 if test -z $check; then
301 rm -f configure.ad.cfs
302 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
306 # Header for configure.ac
307 fname="configure.tmp.ac"
308 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
309 echo "# To make changes edit the configure.ad file in the source tree." >> $fname
311 echo "# Source: configure.ad" >> $fname
312 echo "# Generated: `date` by `whoami`" >> $fname
313 echo "# Distribution: $distribution" >> $fname
314 echo "# License: $license" >> $fname
317 ad_debug "creating configure.ac"
318 if test -f configure.ad.cfs; then
319 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
320 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
321 rm -f configure.ad.cfs $fname.tmp
327 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
329 # Process for distribution
331 ad_process_file $fname.tmp $fname
333 # Remove any trailing backslashes
334 if test -f "$fname"; then
335 cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
337 cp -p $fname.tmp configure.ac
339 rm -f $fname $fname.tmp
341 ad_debug "<ad_make_configure_ac: $1"
345 # Creates the Makefile.in files by running the automake tool.
347 # Arguments: ad_make_makefile_ins
349 ad_make_makefile_ins()
351 ad_debug ">ad_make_makefile_ins"
353 if test "$AUTOMAKE"; then
354 ad_debug "Running automake"
356 if test $? != 0; then
357 ad_fatal "automake failed"
361 ad_debug "<ad_make_makefile_ins"
365 # Creates the Makefile.am files from the Makefile.ad files in the
366 # source tree. This runs the distribution specific processing for the
369 # Arguments: ad_make_makefile_ams
371 ad_make_makefile_ams()
373 ad_debug ">ad_make_makefile_ams"
375 files=`find . -name Makefile\.ad`
378 fname=`echo $ff | sed s/\.ad//`
380 # Header for the Makefile.am
381 echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am
382 echo "# To make changes edit the $ff file in the source tree." >> $fname.am
384 echo "# Source: $ff" >> $fname.am
385 echo "# Generated: `date` by `whoami`" >> $fname.am
386 echo "# Distribution: $distribution" >> $fname.am
387 echo "# License: $license" >> $fname.am
390 # Run the distribution processing for this Makefile.ad
391 ad_debug "Processing $ff to be $fname.am"
392 ad_process_file $ff $fname.tmp
394 # Remove any trailing backslashes
395 if test -f "$fname.tmp"; then
396 cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
404 ad_debug "<ad_make_makefile_ams"
408 # Processes all files with .ad suffix, with exception of configure*.ad
409 # and Makefile.ad files, for distribution from the source tree.
411 # Arguments: ad_process_ads
415 ad_debug ">ad_process_ads"
417 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
420 fname=`echo $i | sed s/\.ad//`
423 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
424 echo "# To make changes edit the $i file in the source tree." >> $fname
426 echo "# Source: $i" >> $fname
427 echo "# Generated: `date` by `whoami`" >> $fname
428 echo "# Distribution: $distribution" >> $fname
429 echo "# License: $license" >> $fname
432 # Run the distribution processing for this file
433 ad_debug "Processing $i to be $fname"
434 ad_process_file $i $fname
437 ad_debug "<ad_process_ads"
441 # Includes files specified in the distribution for inclusion. Used when
442 # creating the distribution for packaging.
444 # include has the following format in distfile:
446 # include <path> [<dest path>]
448 # If only source path, which may be file, directory or regular expression,
449 # is specified the path will be same in distribution. If the destination
450 # path is specified that will be the new name and/or new location of the
451 # source path. This, in effect, is a cp utility with ability to create
452 # directories if they do not exist.
454 # Arguments: ad_dist_includes <includeslist> <recursive>
458 ad_debug ">ad_dist_includes: $1 $2"
460 # By default do not expand pathnames
463 # Add : separator at the end
464 local incs="`echo "$1" | sed 's/$/ : /'`"
470 if test "$i" = ":" && test -z "$src"; then
473 if test -z "$src"; then
477 if test -z "$dst" && test "$i" != ":"; then
483 ad_debug "Including $src into $dst"
485 if test -f "$src"; then
488 if test "$src" = "$dst"; then
489 # Add to same location
490 d=`echo $src | sed 's,/[^/]*$,,'`
491 if test "$d" != "$src" && test "$d" != "." && \
492 test '!' -d $am_distdir/$d; then
493 mkdir -p $am_distdir/$d || exit 1
496 # Add to different location
497 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
498 if test "$check" != "$dst"; then
499 ad_fatal "Invalid destination in 'include $src $dst'"
502 d=`echo $dst | sed 's,/[^/]*$,,'`
503 if test "$d" != "$dst" && test "$d" != "." && \
504 test '!' -d $am_distdir/$d; then
505 mkdir -p $am_distdir/$d || exit 1
509 cp -p $src $am_distdir/$d || exit 1
511 elif test -d "$src"; then
514 if test "$src" = "$dst"; then
515 # Add to same location
516 d=`echo $src | sed 's,/[^/]*$,,'`
517 ds=`echo $src | sed 's/\/$//'`
518 if test "$ds" = "$d"; then
519 d=`echo $d | sed 's,/[^/]*$,,'`
521 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
522 mkdir -p $am_distdir/$d || exit 1
525 cp -pR $src $am_distdir/$d || exit 1
527 # Add to different location
528 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
529 if test "$check" != "$dst"; then
530 ad_fatal "Invalid destination in 'include $src $dst'"
533 d=`echo $dst | sed 's,/[^/]*$,,'`
534 ds=`echo $dst | sed 's/\/$//'`
535 if test "$ds" = "$d"; then
536 d=`echo $d | sed 's,/[^/]*$,,'`
538 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
539 mkdir -p $am_distdir/$d || exit 1
542 cp -pR $src $am_distdir/$dst || exit 1
545 elif test x$2 != xtrue; then
546 # We assume regular expression in filename
547 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
548 if test "$check" == "$src"; then
549 if test '!' -a $src; then
550 ad_fatal "Including $src: No such file or directory"
557 # Recursively call this function with expanded pathnames. The
558 # reason why we don't let sh by default expand patnames is that
559 # the include's destination is optional. If sh expands by default
560 # we don't know the destination. For this reason, we handle the
561 # expansion here ourselves.
563 # If src and dst are same, then expand the pathname as we'll copy
564 # matches to their own locations.
565 if test "$src" = "$dst"; then
566 # Expand pathnames, and format to our include format
568 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
571 # Destination is new, and it has to be a directory.
572 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
573 if test "$check" != "$dst"; then
574 ad_fatal "Invalid destination in 'include $src $dst'"
577 # Make sure dst has / at the end, as this must be a directory
578 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
581 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
583 # Expand pathnames, and format to our include format
585 srcs=`echo $src | sed -e "s/ / $dste : /g" \
586 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
590 # Include recursively
591 ad_dist_includes "$srcs" true
593 elif test '!' -a $src; then
594 ad_fatal "Including $src: No such file or directory"
603 ad_debug "<ad_dist_includes: $1 $2"
607 # Excludes files specified in the distribution for exclusion. Used when
608 # creating the distribution for packaging.
610 # exclude has the following format in distfile:
614 # The path may be file, directory or regular expression.
616 # Arguments: ad_dist_includes <excludelist>
620 ad_debug ">ad_dist_excludes: $1"
624 ad_debug "Excluding $i"
625 rm -rf $am_distdir/$i
628 ad_debug "<ad_dist_excludes: $1"
632 # Processes the entire tree for distribution. This inspects files other
633 # than source and header files, with exception of any file with .ad
634 # suffix, and performs distribution processing for the file. The original
635 # file is replaced with the processed file. This function is used when
636 # creating the distribution for packaging.
638 # Arguments: ad_process_tree <directory>
642 ad_debug ">ad_process_tree: $1"
644 # We take all files, other than *.ad, including source files, in case
645 # they use the non-C-compiler-friendly format of distdefs, which is
648 files=`find $am_distdir \! -name \*\.ad`
649 files=`echo $files | sed 's/$am_distdir//'`
651 # Take away noprocess list
652 if test -f autodist.noprocess; then
653 files=`echo $files | sh autodist.noprocess` || exit 1
658 ad_process_file $ff $ff.tmp
659 if test -f $ff.tmp; then
661 mv -f $ff.tmp $ff || exit 1
665 ad_debug "<ad_process_tree: $1"
669 # Processes the entire source tree for distribution. This inspects files
670 # in the source tree, with exception of any file with .ad suffix, and
671 # performs distribution processing for the file. The original file is
672 # replaced with the processed file. This function is used when creating
673 # the distribution for packaging.
675 # Call this before ad_process_tree().
677 # Arguments: ad_process_source_tree <directory>
679 ad_process_source_tree()
681 ad_debug ">ad_process_source_tree: $1"
683 # We take only C/C++ files since they use the C compiler friendly
684 # version of distdefs. Other files are not assumed to use them.
685 files=`find $am_distdir \! -name \*\.ad \( \
687 -name \*\.[cC][cCpP] -o \
688 -name \*\.[cC][xX][xX] -o \
689 -name \*\.[cC][pP][pP] -o \
690 -name \*\.[cC]++ -o \
695 # Take away noprocess list
696 if test -f autodist.noprocess; then
697 files=`echo $files | sh autodist.noprocess` || exit 1
702 ad_process_source_file $ff $ff.tmp
703 if test -f $ff.tmp; then
705 mv -f $ff.tmp $ff || exit 1
709 ad_debug "<ad_process_source_tree: $1"
713 # Makes distribution sane, ala modtimes. Since we modify the distribution
714 # we need to make it sane after that.
716 # Arguments: ad_makedist_makesane
718 ad_makedist_makesane()
720 ad_debug ">ad_makedist_makesane:"
722 # DO NOT change these order unless you know what you are doing.
723 if test -f $am_distdir/configure.ac; then
724 touch $am_distdir/configure.ac
727 if test -f $am_distdir/aclocal.m4; then
728 touch $am_distdir/aclocal.m4
731 if test '!' -f Makefile; then
732 ad_fatal "Makefile: No such file or directory"
735 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
736 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
738 files=`find $am_distdir -name Makefile\.in`
744 if test -f $am_distdir/configure; then
745 touch $am_distdir/configure
748 if test -f $am_distdir/config.status; then
749 touch $am_distdir/config.status
752 ad_debug "<ad_makedist_makesane:"
756 # Creates distribution of the source tree. All files in the distribution
757 # will be processed and the distribution will be packaged.
759 # Arguments: ad_makedist
763 ad_debug ">ad_makedist"
765 if test '!' -f autodist.dist; then
766 ad_fatal "Autodist has not been run yet to prepare source tree"
769 if test -z $MAKE; then
770 ad_fatal "The MAKE variable is not set in autodist.conf"
773 # Get distdir from Makefile
774 if test '!' -f Makefile; then
775 ad_fatal "The source tree is not configured, run ./configure first"
778 # Parse the requested distribution
779 distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
780 dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
781 ad_parse_distribution $distribution false
783 am_distdir="$package-$dist_version"
785 if test x$opt_no_dist = xtrue; then
786 ad_fatal "The '$distribution' distribution cannot be packaged"
790 ad_run_dist_hooks "$pre_dist_hooks"
792 # Create distribution directory
793 ad_debug "Creating distribution directory $am_distdir"
794 $MAKE distdir || exit 1
795 chmod -R a+r $am_distdir
797 if test '!' -d $am_distdir; then
798 ad_fatal "Distribution directory $am_distdir not created"
801 # Run pre-process-dist-hooks
802 ad_run_dist_hooks "$pre_p_dist_hooks"
805 ad_dist_excludes "$excludes"
808 ad_dist_includes "$includes"
810 # Include specific license file if specified
811 if test "$license" != ""; then
812 cp -p $license $am_distdir/COPYING || exit 1
815 # Process noprocesses
818 # Process source files
819 ad_debug "Process distribution source tree"
820 ad_process_source_tree $am_distdir
822 # Process non-source files
823 ad_debug "Process distribution tree"
824 ad_process_tree $am_distdir
826 # Run post-process_dist-hooks
827 ad_run_dist_hooks "$post_p_dist_hooks"
829 # Make distribution sane
833 ad_debug "Packaging distribution"
834 tar chof $am_distdir.tar $am_distdir || exit 1
837 ad_debug "Compressing distribution package"
838 if test x$ad_gzip = xtrue; then
839 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
841 if test x$ad_bzip2 = xtrue; then
842 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
844 if test x$ad_compress = xtrue; then
845 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
847 if test x$ad_zip = xtrue; then
848 rm -f $am_distdir.zip
849 zip -rq $am_distdir.zip $am_distdir || exit 1
851 rm -f $am_distdir.tar
853 # Run post-dist-hooks
854 ad_run_dist_hooks "$post_dist_hooks"
858 rm -f autodist.noprocess
860 ad_debug "<ad_makedist"
864 # Handles distribution options.
866 # option has the following format in distfile:
870 # Following options are supported:
876 # Arguments: ad_handle_options <options>
880 ad_debug ">ad_handle_options: $1"
884 if test "$i" = "template"; then
887 elif test "$i" = "no-dist"; then
890 elif test "$i" = "no-inherit"; then
896 ad_debug "<ad_handle_options: $1"
902 # Arguments: ad_clear_options
906 ad_debug ">ad_clear_options"
910 ad_debug "<ad_clear_options"
914 # Parses the distribution. Gets all distribution defines from the
915 # distribution. This also expands all inherited distributions recursively
916 # to get all inherited distribution defines. From inherited distributions
917 # their name and package name is not inherited.
919 # Arguments: ad_parse_distribution <distribution name> <inherit>
921 ad_parse_distribution()
923 ad_debug ">ad_parse_distribution: $1 $2"
925 if test '!' -f $distdir/$1; then
926 ad_fatal "Distribution '$1' is not declared"
930 local inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
931 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
934 local defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
935 | grep "define " | cut -d' ' -f2 | sort | uniq`
937 if test "$inhs" = "" && test "$defs" = ""; then
938 ad_fatal "Distribution '$1' does not define anything"
941 # Get undefined distdefs
942 local undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
943 | grep "undef " | cut -d' ' -f2 | sort | uniq`
946 local incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
947 | grep "include " | sed 's/include / : /'`
950 local excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
951 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
954 local nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
955 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
958 local opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
959 | grep "option " | cut -d' ' -f2- | sort | uniq`
962 ad_handle_options "$opts"
963 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
964 ad_fatal "Distribution '$1' cannot be inherited"
966 if test x$2 = xfalse && test x$opt_template = xtrue; then
967 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
970 ad_debug "inherits=$inhs"
971 ad_debug "distdefs=$defs"
972 ad_debug "includes=$incs"
973 ad_debug "excludes=$excs"
974 ad_debug "noprocess=$nops"
975 ad_debug "undistdefs=$undefs"
976 ad_debug "options=$opts"
978 # Expand distdefs from inherited distributions
981 if test x$1 = x$i; then
982 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
983 distribution to not have 'inherit $i' declared."
986 if test '!' -f $distdir/$i; then
987 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
990 ad_parse_distribution $i true
995 license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
996 | grep "license " | cut -d' ' -f2`
997 licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
998 | grep "license-header " | sed 's/license-header / : /'`
1000 ad_debug "license=$license"
1001 ad_debug "licenseh=$licenseh"
1003 if test x$2 = xfalse; then
1004 # Get distribution name
1005 local dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1006 | grep "name " | cut -d' ' -f2-`
1008 if test "$dname"; then
1012 # Get distribution package name (optional)
1013 local dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1014 | grep "package " | cut -d' ' -f2`
1016 if test "$dpname"; then
1019 package=$distribution
1022 # Get Bug-report email address (optional)
1023 local bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1024 | grep "bug-report " | cut -d' ' -f2-`
1026 if test "$bugr"; then
1030 ad_debug "distribution=$distribution"
1031 ad_debug "package=$package"
1032 ad_debug "bug-report=$bug_report"
1034 # Get hooks (optional)
1035 local prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1036 | grep "pre-hook " | cut -d' ' -f2-`
1037 local poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1038 | grep "post-hook " | cut -d' ' -f2-`
1039 local prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1040 | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1041 local podh=`cat $distdir/$1 | grep -v "^#" \
1042 | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1043 local prpdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1044 | grep "pre-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1045 local popdh=`cat $distdir/$1 | grep -v "^#" \
1046 | grep "post-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1048 pre_hooks="$pre_hooks $prh"
1049 post_hooks="$post_hooks $poh"
1050 pre_dist_hooks="$pre_dist_hooks $prdh"
1051 post_dist_hooks="$post_dist_hooks $podh"
1052 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1053 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1054 options="$options $opts"
1056 ad_handle_options "$options"
1057 ad_debug "options=$options"
1061 inherits="$inherits $inhs"
1062 distdefs="$distdefs $defs"
1063 includes="$includes $incs"
1064 excludes="$excludes $excs"
1065 noprocess="$noprocess $nops"
1066 undistdefs="$undistdefs $undefs"
1068 ad_debug "<ad_parse_distribution: $1 $2"
1072 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1073 # from the distdefs.
1075 # Arguments: ad_process_distdefs
1077 ad_process_distdefs()
1079 ad_debug ">ad_process_distdefs"
1081 # Remove all undefined distribution defines
1082 for i in $undistdefs
1084 ad_debug "undefining $i distdef"
1085 distdefs=`echo $distdefs | sed s/$i//`
1088 rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
1089 rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
1091 # Remove duplicate distdefs
1094 echo $i >>autodist.tmp.defs
1096 distdefs=`cat autodist.tmp.defs | sort | uniq`
1097 distdefs=`echo $distdefs`
1098 rm -f autodist.tmp.defs
1100 ad_debug "distdefs=$distdefs"
1102 ad_debug "<ad_process_distdefs"
1106 # Processes for a license header change.
1108 # Arguments: ad_process_license_header <scriptfile>
1110 ad_process_license_header()
1112 ad_debug ">ad_process_license_header"
1114 # Add : separator at the end
1115 lics=`echo "$licenseh" | sed 's/$/ : /'`
1121 if test "$i" = ":" && test -z "$src"; then
1124 if test -z "$src"; then
1128 if test -z "$dst" && test "$i" != ":"; then
1131 ad_fatal "Missing argument in 'license-header $src'"
1134 ad_debug "Replacing $src license with $dst license"
1136 if test '!' -f $src; then
1137 ad_fatal "License header $src: No such file or directory"
1140 if test '!' -f $dst; then
1141 ad_fatal "License header $dst: No such file or directory"
1144 # Awk script to replace the license header
1145 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1146 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1147 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
1148 rm -f autodist.lsrc autodist.ldst
1154 ad_debug "<ad_process_license_header"
1158 # Process specified noprocesses. This is called during makedist.
1160 # Arguments: ad_process_noprocess
1162 ad_process_noprocess()
1164 ad_debug ">ad_process_noprocess"
1172 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1174 n="$n -e 's/$am_distdir\\/$ie//'"
1178 rm -f autodist.noprocess
1179 if test x$np = xtrue; then
1180 echo $n > autodist.noprocess || exit 1
1183 ad_debug "<ad_process_noprocess"
1187 # Process a file given as argument for the distribution.
1189 # Arguments: ad_process_file <filepath> <dest_filepath>
1195 # Process only regular files
1196 if test '!' -f $1; then
1200 ad_debug ">ad_process_file: $1 $2"
1202 local f="autodist.tmp.script"
1205 # If license header is provided, replace the license header in the file.
1206 ad_process_license_header $f
1208 ad_debug "Getting #ifdef's and #ifndef's"
1210 # Get defined distribution defines
1211 local defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1212 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1214 # Get explicitly not-defined distribution defines
1215 local ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1216 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1218 ad_debug "defs=$defs"
1219 ad_debug "ndefs=$ndefs"
1221 # Create the script to include and exclude stuff in the file according
1222 # to the distribution defines
1225 ad_debug "processing ifdefs"
1231 if test x$d = x$i; then
1237 # If distribution define was not found exclude those lines from the file.
1238 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1239 if test x$found = xfalse; then
1240 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1241 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1243 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1248 ad_debug "processing ifndefs"
1254 if test x$d = x$i; then
1260 # If distribution define was found exclude those lines from the file.
1261 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1262 if test x$found = xtrue; then
1263 ad_debug "ifndef $d will be excluded (it IS defined)"
1264 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1266 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1270 # Now process the file with the script
1273 # Those distdef lines that remain in the file are removed to make
1274 # the appearance prettier
1275 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1276 echo "{ print; }" >> $f
1278 # Execute the script
1279 cp -p $1 $2 || exit 1
1280 awk -f $f $1 > $2 || exit 1
1285 ad_debug "<ad_process_file: $1 $2"
1289 # Process a source file given as argument for the distribution.
1291 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1293 ad_process_source_file()
1297 # Process only regular files
1298 if test '!' -f $1; then
1302 ad_debug ">ad_process_source_file: $1 $2"
1304 local f="autodist.tmp.script"
1307 # If license header is provided, replace the license header in the file.
1308 ad_process_license_header $f
1310 ad_debug "Getting #ifdef's and #ifndef's"
1312 # Get defined distribution defines
1313 local defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1314 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1316 # Get explicitly not-defined distribution defines
1317 local ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1318 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1320 ad_debug "defs=$defs ndefs=$ndefs"
1322 # Create the script to include and exclude stuff in the file according
1323 # to the distribution defines
1326 ad_debug "processing ifdefs"
1332 if test x$d = x$i; then
1338 # If distribution define was not found exclude those lines from the file.
1339 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1340 if test x$found = xfalse; then
1341 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1342 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1344 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1349 ad_debug "processing ifndefs"
1355 if test x$d = x$i; then
1361 # If distribution define was found exclude those lines from the file.
1362 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1363 if test x$found = xtrue; then
1364 ad_debug "ifndef $d will be excluded (it IS defined)"
1365 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1367 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1371 # Now process the file with the script
1374 # Those distdef lines that remain in the file are removed to make
1375 # the appearance prettier
1376 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1377 echo "{ print; }" >> $f
1379 # Execute the script
1380 cp -p $1 $2 || exit 1
1381 awk -f $f $1 > $2 || exit 1
1386 ad_debug "<ad_process_source_file: $1 $2"
1392 # Arguments: ad_run_hooks <hooks>
1396 ad_debug ">ad_run_hooks: $1"
1400 if test '!' -f $i; then
1401 ad_fatal "Hook script $i does not exist"
1403 sh $i $distribution $dist_version $package || exit 1
1406 ad_debug "<ad_run_hooks: $1"
1412 # Arguments: ad_run_dist_hooks <hooks>
1416 ad_debug ">ad_run_dist_hooks: $1"
1420 if test '!' -f $i; then
1421 ad_fatal "Dist hook script $i does not exist"
1423 sh $i $distribution $dist_version $package $am_distdir || exit 1
1426 ad_debug "<ad_run_dist_hooks: $1"
1429 ###############################################################################
1432 usage="Usage: autodist [options] [distribution] [version]"
1434 Autodist prepares source tree for configuration, compilation and
1435 distribution. Prepares the source tree from the \`autodist.ad'
1436 configuration file. Generates Automake.am files from Automake.ad
1437 files, configure.ac file from configure.ad file(s), generates the
1438 configure script by running Autoconf tool, and generates Makefile.in
1439 files by running Automake tool.
1442 -h, --help print this help, then exit
1443 -V, --version print version number, then exit
1444 -v, --verbose verbosely report processing
1445 -d, --distdir <dir> search distributions from <dir>
1446 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1447 -i, --init initialize Autodist environment, create default
1448 distribution directory and distribution, then exit
1449 -m, --makedist create and package distribution
1450 --gzip create package compressed with gzip (default)
1451 --bzip2 create also package compressed with bzip2
1452 --compress create also package compressed with compress
1453 --zip create also package compressed with zip"
1456 # Process command line arguments
1458 while test $# -gt 0; do
1463 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1472 if test $# -eq 0; then
1473 ad_parse_distribution $distribution false
1474 echo "Distribution: ${distribution}" 1>&2;
1476 ad_parse_distribution $1 false
1477 echo "Distribution: ${1}" 1>&2;
1480 echo "Distdefs:" 1>&2;
1513 echo "${usage}" 1>&2;
1515 echo "${help}" 1>&2;
1520 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1521 echo "Written by Pekka Riikonen" 1>&2;
1523 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1525 This is free software; see the source for copying conditions. There is NO
1526 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1534 echo "${usage}" 1>&2;
1544 # Parse the requested distribution
1546 if test $# != 0; then
1547 distribution="${1}";
1548 distfile=$distribution
1551 ad_parse_distribution $distribution false
1554 if test $# != 0; then
1555 dist_version="${1}";
1558 ad_debug "Preparing source tree for configuration and compilation..."
1559 ad_debug "Preparing $distribution distribution version $dist_version"
1562 # Create the distribution defines header file
1564 if test "$DISTDEFS"; then
1565 ad_create_distdefs_h
1567 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1573 ad_run_hooks "$pre_hooks"
1576 # Generate the Makefile.am files from Makefile.ad files
1578 ad_make_makefile_ams
1581 # Generate the configure.ac from configure.ad file(s)
1583 ad_make_configure_ac ./configure.ad
1586 # Generate configure script
1591 # Generate Makefile.in files
1593 ad_make_makefile_ins
1596 # Process all files with .ad suffix for distribution processing
1601 # Create autodist.dist
1603 ad_debug "Creating autodist.dist"
1604 echo "dist:$distfile" > autodist.dist
1605 echo "ver:$dist_version" >> autodist.dist
1606 echo "$package-$dist_version" >> autodist.dist
1611 ad_run_hooks "$post_hooks"
1613 ad_debug "Done, now run ./configure and make."