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"
229 Automatically generated by Autodist $ver. Do not edit.
231 Generated: `date` by `whoami`
232 Distribution: $distribution
236 #ifndef _`echo $DP`_DISTDEFS_H
237 #define _`echo $DP`_DISTDEFS_H
243 echo "#define $i 1" >>$fname
248 #endif /* _`echo $DP`_DISTDEFS_H */
250 ad_debug "<ad_create_distdefs_h"
254 # Creates the main configure script for the distribution. This runs
255 # the aclocal, autoheader and autoconf tools.
257 # Arguments: ad_make_configure
261 local run_autoconf=false
263 ad_debug ">ad_make_configure"
267 if test "$ACLOCAL"; then
268 ad_debug "Running aclocal"
269 if test x$debug = xtrue; then
272 $ACLOCAL 1>/dev/null 2>/dev/null
274 if test $? != 0; then
275 ad_fatal "aclocal failed"
279 if test "$AUTOCONF"; then
280 ad_debug "Running autoconf"
282 if test $? != 0; then
283 ad_fatal "autoconf failed"
288 if test "$AUTOHEADER"; then
289 ad_debug "Running autoheader"
291 if test $? != 0; then
292 ad_fatal "autoheader failed"
296 if test "$LIBTOOLIZE"; then
297 ad_debug "Running libtoolize"
299 if test $? != 0; then
300 ad_fatal "libtoolize failed"
304 if test x$run_autoconf = xtrue; then
305 if test '!' -f configure; then
306 ad_fatal "creating configure script failed"
310 ad_debug "<ad_make_configure"
314 # Creates the configure.ac script from the configure.ad fragments in
315 # the source tree. Takes the source configure file as argument which
316 # is used to create the actual configure.ac.
318 # Arguments: ad_make_configure_ac <configure_ac_source>
320 ad_make_configure_ac()
324 ad_debug ">ad_make_configure_ac: $1"
326 if test '!' -f $1; then
327 ad_fatal "The configure file '$1' does not exist"
330 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INIT"`"
331 if test -z $check; then
332 rm -f configure.ad.cfs
333 rm -f $fname $fname.tmp
334 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
337 rm -f configure.ac configure.ad.cfs
339 cfs=`find . -name configure\*\.ad`
342 if test "x$i" = "x$1"; then
345 ad_debug "including $i"
346 cat $i >> configure.ad.cfs
349 if test -f configure.ad.cfs; then
350 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
351 if test -z $check; then
352 rm -f configure.ad.cfs
353 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
357 # Header for configure.ac
358 fname="configure.tmp.ac"
360 # Automatically generated by Autodist $ver. Do not edit.
361 # To make changes edit the configure.ad file in the source tree.
363 # Source: configure.ad
364 # Generated: `date` by `whoami`
365 # Distribution: $distribution
370 ad_debug "creating configure.ac"
371 if test -f configure.ad.cfs; then
372 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
373 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
374 rm -f configure.ad.cfs $fname.tmp
380 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
382 # Process for distribution
384 ad_process_file $fname.tmp $fname
386 # Remove any trailing backslashes
387 if test -f "$fname"; then
388 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname > configure.ac
390 cp -p $fname.tmp configure.ac
392 rm -f $fname $fname.tmp
394 ad_debug "<ad_make_configure_ac: $1"
398 # Creates the Makefile.in files by running the automake tool.
400 # Arguments: ad_make_makefile_ins
402 ad_make_makefile_ins()
404 ad_debug ">ad_make_makefile_ins"
406 if test "$AUTOMAKE"; then
407 ad_debug "Running automake"
409 if test $? != 0; then
410 ad_fatal "automake failed"
414 ad_debug "<ad_make_makefile_ins"
418 # Creates the Makefile.am files from the Makefile.ad files in the
419 # source tree. This runs the distribution specific processing for the
422 # Arguments: ad_make_makefile_ams
424 ad_make_makefile_ams()
426 ad_debug ">ad_make_makefile_ams"
428 files=`find . -name Makefile\.ad`
431 fname=`echo $ff | sed s/\.ad//`
433 # Header for the Makefile.am
434 cat > $fname.am <<EOF
435 # Automatically generated by Autodist $ver from Makefile.ad. Do not edit.
436 # To make changes edit the $ff file in the source tree.
439 # Generated: `date` by `whoami`
440 # Distribution: $distribution
445 # Run the distribution processing for this Makefile.ad
446 ad_debug "Processing $ff to be $fname.am"
447 ad_process_file $ff $fname.tmp
449 # Remove any trailing backslashes
450 if test -f "$fname.tmp"; then
451 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp >> $fname.am
459 ad_debug "<ad_make_makefile_ams"
463 # Processes all files with .ad suffix, with exception of configure*.ad
464 # and Makefile.ad files, for distribution from the source tree.
466 # Arguments: ad_process_ads
470 ad_debug ">ad_process_ads"
472 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
475 fname=`echo $i | sed s/\.ad//`
477 # Run the distribution processing for this file
478 ad_debug "Processing $i to be $fname"
479 ad_process_file $i $fname
482 ad_debug "<ad_process_ads"
486 # Includes files specified in the distribution for inclusion. Used when
487 # creating the distribution for packaging.
489 # include has the following format in distfile:
491 # include <path> [<dest path>]
493 # If only source path, which may be file, directory or regular expression,
494 # is specified the path will be same in distribution. If the destination
495 # path is specified that will be the new name and/or new location of the
496 # source path. This, in effect, is a cp utility with ability to create
497 # directories if they do not exist.
499 # Arguments: ad_dist_includes <includeslist> <recursive>
505 ad_debug ">ad_dist_includes: $1 $2"
507 # By default do not expand pathnames
510 # Add : separator at the end
511 incs="`echo "$1" | sed 's/$/ : /'`"
517 if test "$i" = ":" && test -z "$src"; then
520 if test -z "$src"; then
524 if test -z "$dst" && test "$i" != ":"; then
530 ad_debug "Including $src into $dst"
532 if test -f "$src"; then
535 if test "$src" = "$dst"; then
536 # Add to same location
537 d=`echo $src | sed 's,/[^/]*$,,'`
538 if test "$d" != "$src" && test "$d" != "." && \
539 test '!' -d $am_distdir/$d; then
540 mkdir -p $am_distdir/$d || exit 1
543 # Add to different location
544 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
545 if test "$check" != "$dst"; then
546 ad_fatal "Invalid destination in 'include $src $dst'"
549 d=`echo $dst | sed 's,/[^/]*$,,'`
550 if test "$d" != "$dst" && test "$d" != "." && \
551 test '!' -d $am_distdir/$d; then
552 mkdir -p $am_distdir/$d || exit 1
556 cp -p $src $am_distdir/$d || exit 1
558 elif test -d "$src"; then
561 if test "$src" = "$dst"; then
562 # Add to same location
563 d=`echo $src | sed 's,/[^/]*$,,'`
564 ds=`echo $src | sed 's/\/$//'`
565 if test "$ds" = "$d"; then
566 d=`echo $d | sed 's,/[^/]*$,,'`
568 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
569 mkdir -p $am_distdir/$d || exit 1
572 cp -pR $src $am_distdir/$d || exit 1
574 # Add to different location
575 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
576 if test "$check" != "$dst"; then
577 ad_fatal "Invalid destination in 'include $src $dst'"
580 d=`echo $dst | sed 's,/[^/]*$,,'`
581 ds=`echo $dst | sed 's/\/$//'`
582 if test "$ds" = "$d"; then
583 d=`echo $d | sed 's,/[^/]*$,,'`
585 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
586 mkdir -p $am_distdir/$d || exit 1
589 cp -pR $src $am_distdir/$dst || exit 1
592 elif test x$2 != xtrue; then
593 # We assume regular expression in filename
594 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
595 if test "$check" == "$src"; then
596 if test '!' -a $src; then
597 ad_fatal "Including $src: No such file or directory"
604 # Recursively call this function with expanded pathnames. The
605 # reason why we don't let sh by default expand pathnames is that
606 # the include's destination is optional. If sh expands by default
607 # we don't know the destination. For this reason, we handle the
608 # expansion here ourselves.
610 # If src and dst are same, then expand the pathname as we'll copy
611 # matches to their own locations.
612 if test "$src" = "$dst"; then
613 # Expand pathnames, and format to our include format
615 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
618 # Destination is new, and it has to be a directory.
619 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
620 if test "$check" != "$dst"; then
621 ad_fatal "Invalid destination in 'include $src $dst'"
624 # Make sure dst has / at the end, as this must be a directory
625 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
628 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
630 # Expand pathnames, and format to our include format
632 srcs=`echo $src | sed -e "s/ / $dste : /g" \
633 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
637 # Include recursively
638 ad_dist_includes "$srcs" true
640 elif test '!' -a $src; then
641 ad_fatal "Including $src: No such file or directory"
650 ad_debug "<ad_dist_includes: $1 $2"
654 # Excludes files specified in the distribution for exclusion. Used when
655 # creating the distribution for packaging.
657 # exclude has the following format in distfile:
661 # The path may be file, directory or regular expression.
663 # Arguments: ad_dist_includes <excludelist>
667 ad_debug ">ad_dist_excludes: $1"
671 ad_debug "Excluding $i"
672 rm -rf $am_distdir/$i
675 ad_debug "<ad_dist_excludes: $1"
679 # Processes the entire tree for distribution. This inspects files other
680 # than source and header files, with exception of any file with .ad
681 # suffix, and performs distribution processing for the file. The original
682 # file is replaced with the processed file. This function is used when
683 # creating the distribution for packaging.
685 # Arguments: ad_process_tree <directory>
689 ad_debug ">ad_process_tree: $1"
691 # Take files, except source and .ad files.
692 files=`find $am_distdir \! -name \*\.ad \( \
693 \! -name \*\.[cC] -a \
694 \! -name \*\.[cC][cCpP] -a \
695 \! -name \*\.[cC][xX][xX] -a \
696 \! -name \*\.[cC][pP][pP] -a \
697 \! -name \*\.[cC]++ -a \
699 \! -name \*\.[hH] -a \
701 \! -name \*\.[cC]\.in -a \
702 \! -name \*\.[cC][cCpP]\.in -a \
703 \! -name \*\.[cC][xX][xX]\.in -a \
704 \! -name \*\.[cC][pP][pP]\.in -a \
705 \! -name \*\.[cC]++\.in -a \
706 \! -name \*\.m\.in -a \
707 \! -name \*\.[hH]\.in -a \
708 \! -name \*\.hh\.in \)`
709 files=`echo $files | sed 's/$am_distdir//'`
711 # Take away noprocess list
712 if test -f autodist.noprocess; then
713 files=`echo $files" " | sh autodist.noprocess` || exit 1
718 ad_process_file $ff $ff.tmp
719 if test -f $ff.tmp; then
721 mv -f $ff.tmp $ff || exit 1
725 ad_debug "<ad_process_tree: $1"
729 # Processes the entire source tree for distribution. This inspects files
730 # in the source tree, with exception of any file with .ad suffix, and
731 # performs distribution processing for the file. The original file is
732 # replaced with the processed file. This function is used when creating
733 # the distribution for packaging.
735 # Call this before ad_process_tree().
737 # Arguments: ad_process_source_tree <directory>
739 ad_process_source_tree()
741 ad_debug ">ad_process_source_tree: $1"
743 # We take only C/C++ files since they use the C compiler friendly
744 # version of distdefs. Other files are not assumed to use them.
745 files=`find $am_distdir \! -name \*\.ad \( \
747 -name \*\.[cC][cCpP] -o \
748 -name \*\.[cC][xX][xX] -o \
749 -name \*\.[cC][pP][pP] -o \
750 -name \*\.[cC]++ -o \
754 -name \*\.[cC]\.in -o \
755 -name \*\.[cC][cCpP]\.in -o \
756 -name \*\.[cC][xX][xX]\.in -o \
757 -name \*\.[cC][pP][pP]\.in -o \
758 -name \*\.[cC]++\.in -o \
760 -name \*\.[hH]\.in -o \
763 # Take away noprocess list
764 if test -f autodist.noprocess; then
765 files=`echo $files" " | sh autodist.noprocess` || exit 1
770 ad_process_source_file $ff $ff.tmp
771 if test -f $ff.tmp; then
773 mv -f $ff.tmp $ff || exit 1
777 ad_debug "<ad_process_source_tree: $1"
781 # Makes distribution sane, ala modtimes. Since we modify the distribution
782 # we need to make it sane after that.
784 # Arguments: ad_makedist_makesane
786 ad_makedist_makesane()
788 ad_debug ">ad_makedist_makesane:"
790 # DO NOT change these order unless you know what you are doing.
791 if test -f $am_distdir/configure.ac; then
792 touch $am_distdir/configure.ac
795 if test -f $am_distdir/aclocal.m4; then
796 touch $am_distdir/aclocal.m4
799 if test '!' -f Makefile; then
800 ad_fatal "Makefile: No such file or directory"
803 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ ]*//'`
804 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
806 files=`find $am_distdir -name Makefile\.in`
812 if test -f $am_distdir/configure; then
813 touch $am_distdir/configure
816 if test -f $am_distdir/config.status; then
817 touch $am_distdir/config.status
820 ad_debug "<ad_makedist_makesane:"
824 # Creates distribution of the source tree. All files in the distribution
825 # will be processed and the distribution will be packaged.
827 # Arguments: ad_makedist
831 ad_debug ">ad_makedist"
833 if test '!' -f autodist.dist; then
834 ad_fatal "Autodist has not been run yet to prepare source tree"
837 if test -z $MAKE; then
838 ad_fatal "The MAKE variable is not set in autodist.conf"
841 # Get distdir from Makefile
842 if test '!' -f Makefile; then
843 ad_fatal "The source tree is not configured, run ./configure first"
846 # Parse the requested distribution
847 distribution=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1
848 dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1
849 am_distdir=`grep "distdir:" < autodist.dist | cut -d: -f2` || exit 1
850 ad_parse_distribution $distribution false
853 if test x$opt_no_dist = xtrue; then
854 ad_fatal "The '$distribution' distribution cannot be packaged"
858 ad_run_dist_hooks "$pre_dist_hooks"
860 # Create distribution directory
861 ad_debug "Creating distribution directory $am_distdir"
862 $MAKE distdir || exit 1
863 chmod -R a+r $am_distdir
865 if test '!' -d $am_distdir; then
866 ad_fatal "Distribution directory $am_distdir not created"
869 # Run pre-process-dist-hooks
870 ad_run_dist_hooks "$pre_p_dist_hooks"
873 ad_dist_excludes "$excludes"
876 ad_dist_includes "$includes"
878 # Include specific license file if specified
879 if test "$license" != ""; then
880 cp -p $license $am_distdir/COPYING || exit 1
883 # Process noprocesses
886 # Process source files
887 ad_debug "Process distribution source tree"
888 ad_process_source_tree $am_distdir
890 # Process non-source files
891 ad_debug "Process distribution tree"
892 ad_process_tree $am_distdir
894 # Run post-process_dist-hooks
895 ad_run_dist_hooks "$post_p_dist_hooks"
897 # Make distribution sane
901 ad_debug "Packaging distribution"
902 tar chof $am_distdir.tar $am_distdir || exit 1
905 ad_debug "Compressing distribution package"
906 if test x$ad_gzip = xtrue; then
907 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
909 if test x$ad_bzip2 = xtrue; then
910 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
912 if test x$ad_compress = xtrue; then
913 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
915 if test x$ad_zip = xtrue; then
916 rm -f $am_distdir.zip
917 zip -rq $am_distdir.zip $am_distdir || exit 1
919 rm -f $am_distdir.tar
921 # Run post-dist-hooks
922 ad_run_dist_hooks "$post_dist_hooks"
926 rm -f autodist.noprocess
928 ad_debug "<ad_makedist"
932 # Handles distribution options.
934 # option has the following format in distfile:
938 # Following options are supported:
944 # Arguments: ad_handle_options <options>
948 ad_debug ">ad_handle_options: $1"
952 if test "$i" = "template"; then
955 elif test "$i" = "no-dist"; then
958 elif test "$i" = "no-inherit"; then
964 ad_debug "<ad_handle_options: $1"
970 # Arguments: ad_clear_options
974 ad_debug ">ad_clear_options"
978 ad_debug "<ad_clear_options"
982 # Parses the distribution. Gets all distribution defines from the
983 # distribution. This also expands all inherited distributions recursively
984 # to get all inherited distribution defines. From inherited distributions
985 # their name and package name is not inherited.
987 # Arguments: ad_parse_distribution <distribution name> <inherit>
989 ad_parse_distribution()
1008 ad_debug ">ad_parse_distribution: $1 $2"
1010 if test '!' -f $distdir/$1; then
1011 ad_fatal "Distribution '$1' is not declared"
1015 inhs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1016 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
1019 defs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1020 | grep "define " | cut -d' ' -f2 | sort | uniq`
1022 if test "$inhs" = "" && test "$defs" = ""; then
1023 ad_fatal "Distribution '$1' does not define anything"
1026 # Get undefined distdefs
1027 undefs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1028 | grep "undef " | cut -d' ' -f2 | sort | uniq`
1031 incs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1032 | grep "include " | sed 's/include / : /'`
1035 excs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1036 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
1039 nops=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1040 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
1043 opts=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1044 | grep "option " | cut -d' ' -f2- | sort | uniq`
1047 ad_handle_options "$opts"
1048 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
1049 ad_fatal "Distribution '$1' cannot be inherited"
1051 if test x$2 = xfalse && test x$opt_template = xtrue; then
1052 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
1055 ad_debug "inherits: $inhs"
1056 ad_debug "distdefs: $defs"
1057 ad_debug "includes: $incs"
1058 ad_debug "excludes: $excs"
1059 ad_debug "noprocess: $nops"
1060 ad_debug "undistdefs: $undefs"
1061 ad_debug "options: $opts"
1063 # Expand distdefs from inherited distributions
1066 if test x$1 = x$i; then
1067 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1068 distribution to not have 'inherit $i' declared."
1071 if test '!' -f $distdir/$i; then
1072 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1075 ad_parse_distribution $i true
1080 license=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1081 | grep "license " | cut -d' ' -f2`
1082 licenseh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1083 | grep "license-header " | sed 's/license-header / : /'`
1085 ad_debug "license: $license"
1086 ad_debug "licenseh: $licenseh"
1088 if test x$2 = xfalse; then
1089 # Take rest of the stuff from top distribution
1091 # We take precedence on defined and undefined distdefs. Remove
1092 # undefined distdefs if we have defined them.
1095 ad_debug "defining undefined $d distdef"
1096 undistdefs=`echo $undistdefs | sed s/$d//g`
1099 # Get distribution name
1100 dname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1101 | grep "name " | cut -d' ' -f2-`
1103 if test "$dname"; then
1107 # Get distribution package name (optional)
1108 dpname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1109 | grep "package " | cut -d' ' -f2`
1111 if test "$dpname"; then
1114 package=$distribution
1117 # Get Bug-report email address (optional)
1118 bugr=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1119 | grep "bug-report " | cut -d' ' -f2-`
1121 if test "$bugr"; then
1125 ad_debug "distribution: $distribution"
1126 ad_debug "package: $package"
1127 ad_debug "bug-report: $bug_report"
1129 # Get hooks (optional)
1130 prh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1131 | grep "pre-hook " | cut -d' ' -f2-`
1132 poh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1133 | grep "post-hook " | cut -d' ' -f2-`
1134 prdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1135 | grep "pre-dist-hook " | cut -d' ' -f2-`
1136 podh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1137 | grep "post-dist-hook " | cut -d' ' -f2-`
1138 prpdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1139 | grep "pre-process-dist-hook " | cut -d' ' -f2-`
1140 popdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1141 | grep "post-process-dist-hook " | cut -d' ' -f2-`
1143 pre_hooks="$pre_hooks $prh"
1144 post_hooks="$post_hooks $poh"
1145 pre_dist_hooks="$pre_dist_hooks $prdh"
1146 post_dist_hooks="$post_dist_hooks $podh"
1147 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1148 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1149 doptions="$doptions $opts"
1151 ad_handle_options "$doptions"
1152 ad_debug "options: $doptions"
1156 inherits="$inherits $inhs"
1157 distdefs="$distdefs $defs"
1158 includes="$includes $incs"
1159 excludes="$excludes $excs"
1160 noprocess="$noprocess $nops"
1161 undistdefs="$undistdefs $undefs"
1163 ad_debug "<ad_parse_distribution: $1 $2"
1167 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1168 # from the distdefs.
1170 # Arguments: ad_process_distdefs
1172 ad_process_distdefs()
1174 ad_debug ">ad_process_distdefs"
1176 # Remove all undefined distribution defines
1177 for i in $undistdefs
1179 ad_debug "undefining $i distdef"
1180 distdefs=`echo $distdefs | sed s/$i//g`
1183 rm -f autodist.tmp.defs
1185 # Remove duplicate distdefs
1188 echo $i >>autodist.tmp.defs
1190 distdefs=`sort < autodist.tmp.defs | uniq`
1191 distdefs=`echo $distdefs`
1192 rm -f autodist.tmp.defs
1194 ad_debug "distdefs=$distdefs"
1196 ad_debug "<ad_process_distdefs"
1200 # Processes for a license header change.
1202 # Arguments: ad_process_license_header <scriptfile>
1204 ad_process_license_header()
1206 ad_debug ">ad_process_license_header"
1208 # Add : separator at the end
1209 lics=`echo "$licenseh" | sed 's/$/ : /'`
1215 if test "$i" = ":" && test -z "$src"; then
1218 if test -z "$src"; then
1222 if test -z "$dst" && test "$i" != ":"; then
1225 ad_fatal "Missing argument in 'license-header $src'"
1228 ad_debug "Replacing $src license with $dst license"
1230 if test '!' -f $src; then
1231 ad_fatal "License header $src: No such file or directory"
1234 if test '!' -f $dst; then
1235 ad_fatal "License header $dst: No such file or directory"
1238 # Awk script to replace the license header
1239 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1240 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1241 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
1242 rm -f autodist.lsrc autodist.ldst
1248 ad_debug "<ad_process_license_header"
1252 # Process specified noprocesses. This is called during makedist.
1254 # Arguments: ad_process_noprocess
1256 ad_process_noprocess()
1261 ad_debug ">ad_process_noprocess"
1264 cd $am_distdir || exit 1
1268 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1270 n="$n -e 's/$am_distdir\\/$ie //'"
1275 rm -f autodist.noprocess
1276 if test x$np = xtrue; then
1277 echo $n > autodist.noprocess || exit 1
1280 ad_debug "<ad_process_noprocess"
1284 # Process a file given as argument for the distribution.
1286 # Arguments: ad_process_file <filepath> <dest_filepath>
1295 # Process only regular files
1296 if test '!' -f $1; then
1300 ad_debug ">ad_process_file: $1 $2"
1302 f="autodist.tmp.script"
1305 # If license header is provided, replace the license header in the file.
1306 ad_process_license_header $f
1308 ad_debug "Getting #ifdef's and #ifndef's"
1310 # Get defined distribution defines
1311 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1312 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1314 # Get explicitly not-defined distribution defines
1315 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1316 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1318 ad_debug "defs in $1: $defs"
1319 ad_debug "ndefs in $1: $ndefs"
1321 # Create the script to include and exclude stuff in the file according
1322 # to the distribution defines
1325 ad_debug "processing ifdefs"
1331 if test x$d = x$i; then
1337 # If distribution define was not found exclude those lines from the file.
1338 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1339 if test x$found = xfalse; then
1340 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1341 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1343 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1348 ad_debug "processing ifndefs"
1354 if test x$d = x$i; then
1360 # If distribution define was found exclude those lines from the file.
1361 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1362 if test x$found = xtrue; then
1363 ad_debug "ifndef $d will be excluded (it IS defined)"
1364 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1366 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1370 # Now process the file with the script
1373 # Those distdef lines that remain in the file are removed to make
1374 # the appearance prettier
1375 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1376 echo "{ print; }" >> $f
1378 # Execute the script
1379 cp -p $1 $2 || exit 1
1380 awk -f $f $1 > $2 || exit 1
1385 ad_debug "<ad_process_file: $1 $2"
1389 # Process a source file given as argument for the distribution.
1391 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1393 ad_process_source_file()
1400 # Process only regular files
1401 if test '!' -f $1; then
1405 ad_debug ">ad_process_source_file: $1 $2"
1407 f="autodist.tmp.script"
1410 # If license header is provided, replace the license header in the file.
1411 ad_process_license_header $f
1413 ad_debug "Getting #ifdef's and #ifndef's"
1415 # Get defined distribution defines
1416 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1417 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1419 # Get explicitly not-defined distribution defines
1420 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1421 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1423 ad_debug "defs in $1: $defs"
1424 ad_debug "ndefs in $1: $ndefs"
1426 # Create the script to include and exclude stuff in the file according
1427 # to the distribution defines
1430 ad_debug "processing ifdefs"
1436 if test x$d = x$i; then
1442 # If distribution define was not found exclude those lines from the file.
1443 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1444 if test x$found = xfalse; then
1445 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1446 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1448 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1453 ad_debug "processing ifndefs"
1459 if test x$d = x$i; then
1465 # If distribution define was found exclude those lines from the file.
1466 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1467 if test x$found = xtrue; then
1468 ad_debug "ifndef $d will be excluded (it IS defined)"
1469 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1471 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1475 # Now process the file with the script
1478 # Those distdef lines that remain in the file are removed to make
1479 # the appearance prettier
1480 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1481 echo "{ print; }" >> $f
1483 # Execute the script
1484 cp -p $1 $2 || exit 1
1485 awk -f $f $1 > $2 || exit 1
1490 ad_debug "<ad_process_source_file: $1 $2"
1496 # Arguments: ad_run_hooks <hooks>
1500 ad_debug ">ad_run_hooks: $1"
1504 if test '!' -f $i; then
1505 ad_fatal "Hook script $i does not exist"
1507 sh $i "$distribution" "$dist_version" "$package" || exit 1
1510 ad_debug "<ad_run_hooks: $1"
1516 # Arguments: ad_run_dist_hooks <hooks>
1520 ad_debug ">ad_run_dist_hooks: $1"
1524 if test '!' -f $i; then
1525 ad_fatal "Dist hook script $i does not exist"
1527 sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1
1530 ad_debug "<ad_run_dist_hooks: $1"
1533 ###############################################################################
1536 usage="Usage: autodist [options] [distribution] [version]"
1538 Autodist prepares source tree for configuration, compilation and
1539 distribution. Prepares the source tree from the \`autodist.ad'
1540 configuration file. Generates Automake.am files from Automake.ad
1541 files, configure.ac file from configure.ad file(s), generates the
1542 configure script by running Autoconf tool, and generates Makefile.in
1543 files by running Automake tool.
1546 -h, --help print this help, then exit
1547 -V, --version print version number, then exit
1548 -v, --verbose verbosely report processing
1549 -d, --distdir <dir> search distributions from <dir>
1550 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1551 -i, --init initialize Autodist environment, create default
1552 distribution directory and distribution, then exit
1553 -m, --makedist create and package distribution
1554 --gzip create package compressed with gzip (default)
1555 --bzip2 create also package compressed with bzip2
1556 --compress create also package compressed with compress
1557 --zip create also package compressed with zip"
1560 # Process command line arguments
1562 while test $# -gt 0; do
1567 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1576 if test $# -eq 0; then
1577 ad_parse_distribution $distribution false
1578 echo "Distribution: ${distribution}" 1>&2;
1580 ad_parse_distribution $1 false
1581 echo "Distribution: ${1}" 1>&2;
1584 echo "Distdefs:" 1>&2;
1620 echo "${usage}" 1>&2;
1622 echo "${help}" 1>&2;
1627 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1628 echo "Written by Pekka Riikonen" 1>&2;
1630 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1632 This is free software; see the source for copying conditions. There is NO
1633 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1641 echo "${usage}" 1>&2;
1651 # Parse the requested distribution
1653 if test $# != 0; then
1654 distribution="${1}";
1655 distfile=$distribution
1658 ad_parse_distribution $distribution false
1661 if test $# != 0; then
1662 dist_version="${1}";
1665 ad_debug "Preparing source tree for configuration and compilation..."
1666 ad_debug "Preparing $distribution distribution version $dist_version"
1669 # Create the distribution defines header file
1671 if test "$DISTDEFS"; then
1672 ad_create_distdefs_h
1674 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1680 ad_run_hooks "$pre_hooks"
1683 # Generate the Makefile.am files from Makefile.ad files
1685 ad_make_makefile_ams
1688 # Generate the configure.ac from configure.ad file(s)
1690 ad_make_configure_ac ./configure.ad
1693 # Process all files with .ad suffix for distribution processing
1698 # Generate configure script
1703 # Generate Makefile.in files
1705 ad_make_makefile_ins
1708 # Create autodist.dist
1710 ad_debug "Creating autodist.dist"
1711 echo "dist:$distfile" > autodist.dist
1712 echo "ver:$dist_version" >> autodist.dist
1713 echo "distdir:$package-$dist_version" >> autodist.dist
1718 ad_run_hooks "$post_hooks"
1720 ad_debug "Done, now run ./configure and make."