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 local run_autoconf=false
219 ad_debug ">ad_make_configure"
223 if test "$ACLOCAL"; then
224 ad_debug "Running aclocal"
225 $ACLOCAL 1>/dev/null 2>/dev/null
226 if test $? != 0; then
227 ad_fatal "aclocal failed"
231 if test "$AUTOCONF"; then
232 ad_debug "Running autoconf"
234 if test $? != 0; then
235 ad_fatal "autoconf failed"
240 if test "$AUTOHEADER"; then
241 ad_debug "Running autoheader"
243 if test $? != 0; then
244 ad_fatal "autoheader failed"
248 if test "$LIBTOOLIZE"; then
249 ad_debug "Running libtoolize"
251 if test $? != 0; then
252 ad_fatal "libtoolize failed"
256 if test x$run_autoconf = xtrue; then
257 if test '!' -f configure; then
258 ad_fatal "creating configure script failed"
262 ad_debug "<ad_make_configure"
266 # Creates the configure.ac script from the configure.ad fragments in
267 # the source tree. Takes the source configure file as argument which
268 # is used to create the actual configure.ac.
270 # Arguments: ad_make_configure_ac <configure_ac_source>
272 ad_make_configure_ac()
276 ad_debug ">ad_make_configure_ac: $1"
278 if test '!' -f $1; then
279 ad_fatal "The configure file '$1' does not exist"
282 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
283 if test -z $check; then
284 rm -f configure.ad.cfs
285 rm -f $fname $fname.tmp
286 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
289 rm -f configure.ac configure.ad.cfs
291 cfs=`find . -name configure\*\.ad`
294 if test "x$i" = "x$1"; then
297 ad_debug "including $i"
298 cat $i >> configure.ad.cfs
301 if test -f configure.ad.cfs; then
302 check="`cat $1 | sed 's/^[ ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
303 if test -z $check; then
304 rm -f configure.ad.cfs
305 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
309 # Header for configure.ac
310 fname="configure.tmp.ac"
311 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
312 echo "# To make changes edit the configure.ad file in the source tree." >> $fname
314 echo "# Source: configure.ad" >> $fname
315 echo "# Generated: `date` by `whoami`" >> $fname
316 echo "# Distribution: $distribution" >> $fname
317 echo "# License: $license" >> $fname
320 ad_debug "creating configure.ac"
321 if test -f configure.ad.cfs; then
322 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
323 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
324 rm -f configure.ad.cfs $fname.tmp
330 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
332 # Process for distribution
334 ad_process_file $fname.tmp $fname
336 # Remove any trailing backslashes
337 if test -f "$fname"; then
338 cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
340 cp -p $fname.tmp configure.ac
342 rm -f $fname $fname.tmp
344 ad_debug "<ad_make_configure_ac: $1"
348 # Creates the Makefile.in files by running the automake tool.
350 # Arguments: ad_make_makefile_ins
352 ad_make_makefile_ins()
354 ad_debug ">ad_make_makefile_ins"
356 if test "$AUTOMAKE"; then
357 ad_debug "Running automake"
359 if test $? != 0; then
360 ad_fatal "automake failed"
364 ad_debug "<ad_make_makefile_ins"
368 # Creates the Makefile.am files from the Makefile.ad files in the
369 # source tree. This runs the distribution specific processing for the
372 # Arguments: ad_make_makefile_ams
374 ad_make_makefile_ams()
376 ad_debug ">ad_make_makefile_ams"
378 files=`find . -name Makefile\.ad`
381 fname=`echo $ff | sed s/\.ad//`
383 # Header for the Makefile.am
384 echo "# Automatically generated by Autodist $ver from Makefile.ad. Do not edit." > $fname.am
385 echo "# To make changes edit the $ff file in the source tree." >> $fname.am
387 echo "# Source: $ff" >> $fname.am
388 echo "# Generated: `date` by `whoami`" >> $fname.am
389 echo "# Distribution: $distribution" >> $fname.am
390 echo "# License: $license" >> $fname.am
393 # Run the distribution processing for this Makefile.ad
394 ad_debug "Processing $ff to be $fname.am"
395 ad_process_file $ff $fname.tmp
397 # Remove any trailing backslashes
398 if test -f "$fname.tmp"; then
399 cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
407 ad_debug "<ad_make_makefile_ams"
411 # Processes all files with .ad suffix, with exception of configure*.ad
412 # and Makefile.ad files, for distribution from the source tree.
414 # Arguments: ad_process_ads
418 ad_debug ">ad_process_ads"
420 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
423 fname=`echo $i | sed s/\.ad//`
426 echo "# Automatically generated by Autodist $ver. Do not edit." > $fname
427 echo "# To make changes edit the $i file in the source tree." >> $fname
429 echo "# Source: $i" >> $fname
430 echo "# Generated: `date` by `whoami`" >> $fname
431 echo "# Distribution: $distribution" >> $fname
432 echo "# License: $license" >> $fname
435 # Run the distribution processing for this file
436 ad_debug "Processing $i to be $fname"
437 ad_process_file $i $fname
440 ad_debug "<ad_process_ads"
444 # Includes files specified in the distribution for inclusion. Used when
445 # creating the distribution for packaging.
447 # include has the following format in distfile:
449 # include <path> [<dest path>]
451 # If only source path, which may be file, directory or regular expression,
452 # is specified the path will be same in distribution. If the destination
453 # path is specified that will be the new name and/or new location of the
454 # source path. This, in effect, is a cp utility with ability to create
455 # directories if they do not exist.
457 # Arguments: ad_dist_includes <includeslist> <recursive>
463 ad_debug ">ad_dist_includes: $1 $2"
465 # By default do not expand pathnames
468 # Add : separator at the end
469 incs="`echo "$1" | sed 's/$/ : /'`"
475 if test "$i" = ":" && test -z "$src"; then
478 if test -z "$src"; then
482 if test -z "$dst" && test "$i" != ":"; then
488 ad_debug "Including $src into $dst"
490 if test -f "$src"; then
493 if test "$src" = "$dst"; then
494 # Add to same location
495 d=`echo $src | sed 's,/[^/]*$,,'`
496 if test "$d" != "$src" && test "$d" != "." && \
497 test '!' -d $am_distdir/$d; then
498 mkdir -p $am_distdir/$d || exit 1
501 # Add to different location
502 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
503 if test "$check" != "$dst"; then
504 ad_fatal "Invalid destination in 'include $src $dst'"
507 d=`echo $dst | sed 's,/[^/]*$,,'`
508 if test "$d" != "$dst" && test "$d" != "." && \
509 test '!' -d $am_distdir/$d; then
510 mkdir -p $am_distdir/$d || exit 1
514 cp -p $src $am_distdir/$d || exit 1
516 elif test -d "$src"; then
519 if test "$src" = "$dst"; then
520 # Add to same location
521 d=`echo $src | sed 's,/[^/]*$,,'`
522 ds=`echo $src | sed 's/\/$//'`
523 if test "$ds" = "$d"; then
524 d=`echo $d | sed 's,/[^/]*$,,'`
526 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
527 mkdir -p $am_distdir/$d || exit 1
530 cp -pR $src $am_distdir/$d || exit 1
532 # Add to different location
533 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
534 if test "$check" != "$dst"; then
535 ad_fatal "Invalid destination in 'include $src $dst'"
538 d=`echo $dst | sed 's,/[^/]*$,,'`
539 ds=`echo $dst | sed 's/\/$//'`
540 if test "$ds" = "$d"; then
541 d=`echo $d | sed 's,/[^/]*$,,'`
543 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
544 mkdir -p $am_distdir/$d || exit 1
547 cp -pR $src $am_distdir/$dst || exit 1
550 elif test x$2 != xtrue; then
551 # We assume regular expression in filename
552 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
553 if test "$check" == "$src"; then
554 if test '!' -a $src; then
555 ad_fatal "Including $src: No such file or directory"
562 # Recursively call this function with expanded pathnames. The
563 # reason why we don't let sh by default expand patnames is that
564 # the include's destination is optional. If sh expands by default
565 # we don't know the destination. For this reason, we handle the
566 # expansion here ourselves.
568 # If src and dst are same, then expand the pathname as we'll copy
569 # matches to their own locations.
570 if test "$src" = "$dst"; then
571 # Expand pathnames, and format to our include format
573 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
576 # Destination is new, and it has to be a directory.
577 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
578 if test "$check" != "$dst"; then
579 ad_fatal "Invalid destination in 'include $src $dst'"
582 # Make sure dst has / at the end, as this must be a directory
583 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
586 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
588 # Expand pathnames, and format to our include format
590 srcs=`echo $src | sed -e "s/ / $dste : /g" \
591 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
595 # Include recursively
596 ad_dist_includes "$srcs" true
598 elif test '!' -a $src; then
599 ad_fatal "Including $src: No such file or directory"
608 ad_debug "<ad_dist_includes: $1 $2"
612 # Excludes files specified in the distribution for exclusion. Used when
613 # creating the distribution for packaging.
615 # exclude has the following format in distfile:
619 # The path may be file, directory or regular expression.
621 # Arguments: ad_dist_includes <excludelist>
625 ad_debug ">ad_dist_excludes: $1"
629 ad_debug "Excluding $i"
630 rm -rf $am_distdir/$i
633 ad_debug "<ad_dist_excludes: $1"
637 # Processes the entire tree for distribution. This inspects files other
638 # than source and header files, with exception of any file with .ad
639 # suffix, and performs distribution processing for the file. The original
640 # file is replaced with the processed file. This function is used when
641 # creating the distribution for packaging.
643 # Arguments: ad_process_tree <directory>
647 ad_debug ">ad_process_tree: $1"
649 # We take all files, other than *.ad, including source files, in case
650 # they use the non-C-compiler-friendly format of distdefs, which is
653 files=`find $am_distdir \! -name \*\.ad`
654 files=`echo $files | sed 's/$am_distdir//'`
656 # Take away noprocess list
657 if test -f autodist.noprocess; then
658 files=`echo $files | sh autodist.noprocess` || exit 1
663 ad_process_file $ff $ff.tmp
664 if test -f $ff.tmp; then
666 mv -f $ff.tmp $ff || exit 1
670 ad_debug "<ad_process_tree: $1"
674 # Processes the entire source tree for distribution. This inspects files
675 # in the source tree, with exception of any file with .ad suffix, and
676 # performs distribution processing for the file. The original file is
677 # replaced with the processed file. This function is used when creating
678 # the distribution for packaging.
680 # Call this before ad_process_tree().
682 # Arguments: ad_process_source_tree <directory>
684 ad_process_source_tree()
686 ad_debug ">ad_process_source_tree: $1"
688 # We take only C/C++ files since they use the C compiler friendly
689 # version of distdefs. Other files are not assumed to use them.
690 files=`find $am_distdir \! -name \*\.ad \( \
692 -name \*\.[cC][cCpP] -o \
693 -name \*\.[cC][xX][xX] -o \
694 -name \*\.[cC][pP][pP] -o \
695 -name \*\.[cC]++ -o \
700 # Take away noprocess list
701 if test -f autodist.noprocess; then
702 files=`echo $files | sh autodist.noprocess` || exit 1
707 ad_process_source_file $ff $ff.tmp
708 if test -f $ff.tmp; then
710 mv -f $ff.tmp $ff || exit 1
714 ad_debug "<ad_process_source_tree: $1"
718 # Makes distribution sane, ala modtimes. Since we modify the distribution
719 # we need to make it sane after that.
721 # Arguments: ad_makedist_makesane
723 ad_makedist_makesane()
725 ad_debug ">ad_makedist_makesane:"
727 # DO NOT change these order unless you know what you are doing.
728 if test -f $am_distdir/configure.ac; then
729 touch $am_distdir/configure.ac
732 if test -f $am_distdir/aclocal.m4; then
733 touch $am_distdir/aclocal.m4
736 if test '!' -f Makefile; then
737 ad_fatal "Makefile: No such file or directory"
740 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
741 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
743 files=`find $am_distdir -name Makefile\.in`
749 if test -f $am_distdir/configure; then
750 touch $am_distdir/configure
753 if test -f $am_distdir/config.status; then
754 touch $am_distdir/config.status
757 ad_debug "<ad_makedist_makesane:"
761 # Creates distribution of the source tree. All files in the distribution
762 # will be processed and the distribution will be packaged.
764 # Arguments: ad_makedist
768 ad_debug ">ad_makedist"
770 if test '!' -f autodist.dist; then
771 ad_fatal "Autodist has not been run yet to prepare source tree"
774 if test -z $MAKE; then
775 ad_fatal "The MAKE variable is not set in autodist.conf"
778 # Get distdir from Makefile
779 if test '!' -f Makefile; then
780 ad_fatal "The source tree is not configured, run ./configure first"
783 # Parse the requested distribution
784 distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
785 dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
786 ad_parse_distribution $distribution false
788 am_distdir="$package-$dist_version"
790 if test x$opt_no_dist = xtrue; then
791 ad_fatal "The '$distribution' distribution cannot be packaged"
795 ad_run_dist_hooks "$pre_dist_hooks"
797 # Create distribution directory
798 ad_debug "Creating distribution directory $am_distdir"
799 $MAKE distdir || exit 1
800 chmod -R a+r $am_distdir
802 if test '!' -d $am_distdir; then
803 ad_fatal "Distribution directory $am_distdir not created"
806 # Run pre-process-dist-hooks
807 ad_run_dist_hooks "$pre_p_dist_hooks"
810 ad_dist_excludes "$excludes"
813 ad_dist_includes "$includes"
815 # Include specific license file if specified
816 if test "$license" != ""; then
817 cp -p $license $am_distdir/COPYING || exit 1
820 # Process noprocesses
823 # Process source files
824 ad_debug "Process distribution source tree"
825 ad_process_source_tree $am_distdir
827 # Process non-source files
828 ad_debug "Process distribution tree"
829 ad_process_tree $am_distdir
831 # Run post-process_dist-hooks
832 ad_run_dist_hooks "$post_p_dist_hooks"
834 # Make distribution sane
838 ad_debug "Packaging distribution"
839 tar chof $am_distdir.tar $am_distdir || exit 1
842 ad_debug "Compressing distribution package"
843 if test x$ad_gzip = xtrue; then
844 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
846 if test x$ad_bzip2 = xtrue; then
847 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
849 if test x$ad_compress = xtrue; then
850 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
852 if test x$ad_zip = xtrue; then
853 rm -f $am_distdir.zip
854 zip -rq $am_distdir.zip $am_distdir || exit 1
856 rm -f $am_distdir.tar
858 # Run post-dist-hooks
859 ad_run_dist_hooks "$post_dist_hooks"
863 rm -f autodist.noprocess
865 ad_debug "<ad_makedist"
869 # Handles distribution options.
871 # option has the following format in distfile:
875 # Following options are supported:
881 # Arguments: ad_handle_options <options>
885 ad_debug ">ad_handle_options: $1"
889 if test "$i" = "template"; then
892 elif test "$i" = "no-dist"; then
895 elif test "$i" = "no-inherit"; then
901 ad_debug "<ad_handle_options: $1"
907 # Arguments: ad_clear_options
911 ad_debug ">ad_clear_options"
915 ad_debug "<ad_clear_options"
919 # Parses the distribution. Gets all distribution defines from the
920 # distribution. This also expands all inherited distributions recursively
921 # to get all inherited distribution defines. From inherited distributions
922 # their name and package name is not inherited.
924 # Arguments: ad_parse_distribution <distribution name> <inherit>
926 ad_parse_distribution()
945 ad_debug ">ad_parse_distribution: $1 $2"
947 if test '!' -f $distdir/$1; then
948 ad_fatal "Distribution '$1' is not declared"
952 inhs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
953 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
956 defs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
957 | grep "define " | cut -d' ' -f2 | sort | uniq`
959 if test "$inhs" = "" && test "$defs" = ""; then
960 ad_fatal "Distribution '$1' does not define anything"
963 # Get undefined distdefs
964 undefs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
965 | grep "undef " | cut -d' ' -f2 | sort | uniq`
968 incs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
969 | grep "include " | sed 's/include / : /'`
972 excs=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
973 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
976 nops=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
977 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
980 opts=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
981 | grep "option " | cut -d' ' -f2- | sort | uniq`
984 ad_handle_options "$opts"
985 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
986 ad_fatal "Distribution '$1' cannot be inherited"
988 if test x$2 = xfalse && test x$opt_template = xtrue; then
989 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
992 ad_debug "inherits=$inhs"
993 ad_debug "distdefs=$defs"
994 ad_debug "includes=$incs"
995 ad_debug "excludes=$excs"
996 ad_debug "noprocess=$nops"
997 ad_debug "undistdefs=$undefs"
998 ad_debug "options=$opts"
1000 # Expand distdefs from inherited distributions
1003 if test x$1 = x$i; then
1004 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1005 distribution to not have 'inherit $i' declared."
1008 if test '!' -f $distdir/$i; then
1009 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1012 ad_parse_distribution $i true
1017 license=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1018 | grep "license " | cut -d' ' -f2`
1019 licenseh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1020 | grep "license-header " | sed 's/license-header / : /'`
1022 ad_debug "license=$license"
1023 ad_debug "licenseh=$licenseh"
1025 if test x$2 = xfalse; then
1026 # Get distribution name
1027 dname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1028 | grep "name " | cut -d' ' -f2-`
1030 if test "$dname"; then
1034 # Get distribution package name (optional)
1035 dpname=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1036 | grep "package " | cut -d' ' -f2`
1038 if test "$dpname"; then
1041 package=$distribution
1044 # Get Bug-report email address (optional)
1045 bugr=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1046 | grep "bug-report " | cut -d' ' -f2-`
1048 if test "$bugr"; then
1052 ad_debug "distribution=$distribution"
1053 ad_debug "package=$package"
1054 ad_debug "bug-report=$bug_report"
1056 # Get hooks (optional)
1057 prh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1058 | grep "pre-hook " | cut -d' ' -f2-`
1059 poh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1060 | grep "post-hook " | cut -d' ' -f2-`
1061 prdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1062 | grep "pre-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1063 podh=`cat $distdir/$1 | grep -v "^#" \
1064 | grep "post-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1065 prpdh=`cat $distdir/$1 | sed 's/^[ ]*//' | grep -v "^#" \
1066 | grep "pre-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1067 popdh=`cat $distdir/$1 | grep -v "^#" \
1068 | grep "post-process-dist-hook " | sed 's/^[ ]*//' | cut -d' ' -f2-`
1070 pre_hooks="$pre_hooks $prh"
1071 post_hooks="$post_hooks $poh"
1072 pre_dist_hooks="$pre_dist_hooks $prdh"
1073 post_dist_hooks="$post_dist_hooks $podh"
1074 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1075 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1076 options="$options $opts"
1078 ad_handle_options "$options"
1079 ad_debug "options=$options"
1083 inherits="$inherits $inhs"
1084 distdefs="$distdefs $defs"
1085 includes="$includes $incs"
1086 excludes="$excludes $excs"
1087 noprocess="$noprocess $nops"
1088 undistdefs="$undistdefs $undefs"
1090 ad_debug "<ad_parse_distribution: $1 $2"
1094 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1095 # from the distdefs.
1097 # Arguments: ad_process_distdefs
1099 ad_process_distdefs()
1101 ad_debug ">ad_process_distdefs"
1103 # Remove all undefined distribution defines
1104 for i in $undistdefs
1106 ad_debug "undefining $i distdef"
1107 distdefs=`echo $distdefs | sed s/$i//`
1110 rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
1111 rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
1113 # Remove duplicate distdefs
1116 echo $i >>autodist.tmp.defs
1118 distdefs=`cat autodist.tmp.defs | sort | uniq`
1119 distdefs=`echo $distdefs`
1120 rm -f autodist.tmp.defs
1122 ad_debug "distdefs=$distdefs"
1124 ad_debug "<ad_process_distdefs"
1128 # Processes for a license header change.
1130 # Arguments: ad_process_license_header <scriptfile>
1132 ad_process_license_header()
1134 ad_debug ">ad_process_license_header"
1136 # Add : separator at the end
1137 lics=`echo "$licenseh" | sed 's/$/ : /'`
1143 if test "$i" = ":" && test -z "$src"; then
1146 if test -z "$src"; then
1150 if test -z "$dst" && test "$i" != ":"; then
1153 ad_fatal "Missing argument in 'license-header $src'"
1156 ad_debug "Replacing $src license with $dst license"
1158 if test '!' -f $src; then
1159 ad_fatal "License header $src: No such file or directory"
1162 if test '!' -f $dst; then
1163 ad_fatal "License header $dst: No such file or directory"
1166 # Awk script to replace the license header
1167 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1168 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1169 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
1170 rm -f autodist.lsrc autodist.ldst
1176 ad_debug "<ad_process_license_header"
1180 # Process specified noprocesses. This is called during makedist.
1182 # Arguments: ad_process_noprocess
1184 ad_process_noprocess()
1189 ad_debug ">ad_process_noprocess"
1194 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1196 n="$n -e 's/$am_distdir\\/$ie//'"
1200 rm -f autodist.noprocess
1201 if test x$np = xtrue; then
1202 echo $n > autodist.noprocess || exit 1
1205 ad_debug "<ad_process_noprocess"
1209 # Process a file given as argument for the distribution.
1211 # Arguments: ad_process_file <filepath> <dest_filepath>
1220 # Process only regular files
1221 if test '!' -f $1; then
1225 ad_debug ">ad_process_file: $1 $2"
1227 f="autodist.tmp.script"
1230 # If license header is provided, replace the license header in the file.
1231 ad_process_license_header $f
1233 ad_debug "Getting #ifdef's and #ifndef's"
1235 # Get defined distribution defines
1236 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1237 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1239 # Get explicitly not-defined distribution defines
1240 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1241 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1243 ad_debug "defs=$defs"
1244 ad_debug "ndefs=$ndefs"
1246 # Create the script to include and exclude stuff in the file according
1247 # to the distribution defines
1250 ad_debug "processing ifdefs"
1256 if test x$d = x$i; then
1262 # If distribution define was not found exclude those lines from the file.
1263 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1264 if test x$found = xfalse; then
1265 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1266 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1268 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1273 ad_debug "processing ifndefs"
1279 if test x$d = x$i; then
1285 # If distribution define was found exclude those lines from the file.
1286 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1287 if test x$found = xtrue; then
1288 ad_debug "ifndef $d will be excluded (it IS defined)"
1289 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1291 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1295 # Now process the file with the script
1298 # Those distdef lines that remain in the file are removed to make
1299 # the appearance prettier
1300 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1301 echo "{ print; }" >> $f
1303 # Execute the script
1304 cp -p $1 $2 || exit 1
1305 awk -f $f $1 > $2 || exit 1
1310 ad_debug "<ad_process_file: $1 $2"
1314 # Process a source file given as argument for the distribution.
1316 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1318 ad_process_source_file()
1325 # Process only regular files
1326 if test '!' -f $1; then
1330 ad_debug ">ad_process_source_file: $1 $2"
1332 f="autodist.tmp.script"
1335 # If license header is provided, replace the license header in the file.
1336 ad_process_license_header $f
1338 ad_debug "Getting #ifdef's and #ifndef's"
1340 # Get defined distribution defines
1341 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1342 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1344 # Get explicitly not-defined distribution defines
1345 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1346 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1348 ad_debug "defs=$defs ndefs=$ndefs"
1350 # Create the script to include and exclude stuff in the file according
1351 # to the distribution defines
1354 ad_debug "processing ifdefs"
1360 if test x$d = x$i; then
1366 # If distribution define was not found exclude those lines from the file.
1367 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1368 if test x$found = xfalse; then
1369 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1370 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1372 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1377 ad_debug "processing ifndefs"
1383 if test x$d = x$i; then
1389 # If distribution define was found exclude those lines from the file.
1390 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1391 if test x$found = xtrue; then
1392 ad_debug "ifndef $d will be excluded (it IS defined)"
1393 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1395 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1399 # Now process the file with the script
1402 # Those distdef lines that remain in the file are removed to make
1403 # the appearance prettier
1404 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1405 echo "{ print; }" >> $f
1407 # Execute the script
1408 cp -p $1 $2 || exit 1
1409 awk -f $f $1 > $2 || exit 1
1414 ad_debug "<ad_process_source_file: $1 $2"
1420 # Arguments: ad_run_hooks <hooks>
1424 ad_debug ">ad_run_hooks: $1"
1428 if test '!' -f $i; then
1429 ad_fatal "Hook script $i does not exist"
1431 sh $i $distribution $dist_version $package || exit 1
1434 ad_debug "<ad_run_hooks: $1"
1440 # Arguments: ad_run_dist_hooks <hooks>
1444 ad_debug ">ad_run_dist_hooks: $1"
1448 if test '!' -f $i; then
1449 ad_fatal "Dist hook script $i does not exist"
1451 sh $i $distribution $dist_version $package $am_distdir || exit 1
1454 ad_debug "<ad_run_dist_hooks: $1"
1457 ###############################################################################
1460 usage="Usage: autodist [options] [distribution] [version]"
1462 Autodist prepares source tree for configuration, compilation and
1463 distribution. Prepares the source tree from the \`autodist.ad'
1464 configuration file. Generates Automake.am files from Automake.ad
1465 files, configure.ac file from configure.ad file(s), generates the
1466 configure script by running Autoconf tool, and generates Makefile.in
1467 files by running Automake tool.
1470 -h, --help print this help, then exit
1471 -V, --version print version number, then exit
1472 -v, --verbose verbosely report processing
1473 -d, --distdir <dir> search distributions from <dir>
1474 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1475 -i, --init initialize Autodist environment, create default
1476 distribution directory and distribution, then exit
1477 -m, --makedist create and package distribution
1478 --gzip create package compressed with gzip (default)
1479 --bzip2 create also package compressed with bzip2
1480 --compress create also package compressed with compress
1481 --zip create also package compressed with zip"
1484 # Process command line arguments
1486 while test $# -gt 0; do
1491 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1500 if test $# -eq 0; then
1501 ad_parse_distribution $distribution false
1502 echo "Distribution: ${distribution}" 1>&2;
1504 ad_parse_distribution $1 false
1505 echo "Distribution: ${1}" 1>&2;
1508 echo "Distdefs:" 1>&2;
1541 echo "${usage}" 1>&2;
1543 echo "${help}" 1>&2;
1548 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1549 echo "Written by Pekka Riikonen" 1>&2;
1551 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1553 This is free software; see the source for copying conditions. There is NO
1554 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1562 echo "${usage}" 1>&2;
1572 # Parse the requested distribution
1574 if test $# != 0; then
1575 distribution="${1}";
1576 distfile=$distribution
1579 ad_parse_distribution $distribution false
1582 if test $# != 0; then
1583 dist_version="${1}";
1586 ad_debug "Preparing source tree for configuration and compilation..."
1587 ad_debug "Preparing $distribution distribution version $dist_version"
1590 # Create the distribution defines header file
1592 if test "$DISTDEFS"; then
1593 ad_create_distdefs_h
1595 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1601 ad_run_hooks "$pre_hooks"
1604 # Generate the Makefile.am files from Makefile.ad files
1606 ad_make_makefile_ams
1609 # Generate the configure.ac from configure.ad file(s)
1611 ad_make_configure_ac ./configure.ad
1614 # Process all files with .ad suffix for distribution processing
1619 # Generate configure script
1624 # Generate Makefile.in files
1626 ad_make_makefile_ins
1629 # Create autodist.dist
1631 ad_debug "Creating autodist.dist"
1632 echo "dist:$distfile" > autodist.dist
1633 echo "ver:$dist_version" >> autodist.dist
1634 echo "$package-$dist_version" >> autodist.dist
1639 ad_run_hooks "$post_hooks"
1641 ad_debug "Done, now run ./configure and make."