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>
172 echo autodist: error: $1
178 # Prints out warning message
180 # Arguments: ad_warning <warning message>
186 echo autodist: warning: $1
193 # Arguments: ad_log_open <logfile>
201 This file contains messages produced by the Autodist $ver.
207 # Prints to an open log file
217 # Initializes the Autodist environment, creates default distribution
218 # directory, and default distribution.
220 # Arguments: ad_initialize
224 ad_debug "Initializing Autodist environment"
226 # Create default distdir
227 if test '!' -f $distdir; then
231 # Create Autodist configuration file
232 if test -f @AUTODISTDIR@/autodist.conf; then
233 cp -p @AUTODISTDIR@/autodist.conf $distdir
236 # Create default distribution
237 if test -f @AUTODISTDIR@/default; then
238 cp -p @AUTODISTDIR@/default $distdir
241 ad_debug "Autodist environment initialized"
245 # Creates the distdefs header file including defined distdefs
247 # Arguments: ad_create_distdefs_h
249 ad_create_distdefs_h()
251 ad_debug "Creating distdef header file"
257 Automatically generated by Autodist $ver. Do not edit.
259 Generated: `date` by `whoami`
260 Distribution: $distribution
264 #ifndef _`echo $DP`_DISTDEFS_H
265 #define _`echo $DP`_DISTDEFS_H
271 echo "#define $i 1" >>$fname
276 #endif /* _`echo $DP`_DISTDEFS_H */
279 ad_debug "Distdef header file created"
283 # Creates the main configure script for the distribution. This runs
284 # the aclocal, autoheader and autoconf tools.
286 # Arguments: ad_make_configure
290 local run_autoconf=false
292 ad_debug "Starting configure creation"
296 if test "$ACLOCAL"; then
297 ad_debug "Running aclocal"
298 if test x$debug = xtrue; then
301 $ACLOCAL 1>/dev/null 2>/dev/null
303 if test $? != 0; then
304 ad_fatal "aclocal failed"
308 if test "$AUTOCONF"; then
309 ad_debug "Running autoconf"
311 if test $? != 0; then
312 ad_fatal "autoconf failed"
317 if test "$AUTOHEADER"; then
318 ad_debug "Running autoheader"
320 if test $? != 0; then
321 ad_fatal "autoheader failed"
325 if test "$LIBTOOLIZE"; then
326 ad_debug "Running libtoolize"
328 if test $? != 0; then
329 ad_fatal "libtoolize failed"
333 if test x$run_autoconf = xtrue; then
334 if test '!' -f configure; then
335 ad_fatal "creating configure script failed"
339 ad_debug "Ending configure creation"
343 # Creates the configure.ac script from the configure.ad fragments in
344 # the source tree. Takes the source configure file as argument which
345 # is used to create the actual configure.ac.
347 # Arguments: ad_make_configure_ac <configure_ac_source>
349 ad_make_configure_ac()
353 ad_debug "Starting creating configure.ac: $1"
356 ad_log "Following configure.ad files were processed into configure.ac:"
357 ad_log "--------------------------------------------------------------"
359 if test '!' -f $1; then
360 ad_fatal "The configure file '$1' does not exist"
363 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INIT"`"
364 if test -z $check; then
365 rm -f configure.ad.cfs
366 rm -f $fname $fname.tmp
367 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
370 rm -f configure.ac configure.ad.cfs
372 cfs=`find . -name configure\*\.ad`
375 if test "x$i" = "x$1"; then
379 ad_debug "including $i"
382 cat $i >> configure.ad.cfs
385 if test -f configure.ad.cfs; then
386 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
387 if test -z $check; then
388 rm -f configure.ad.cfs
389 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
393 # Header for configure.ac
394 fname="configure.tmp.ac"
396 # Automatically generated by Autodist $ver. Do not edit.
397 # To make changes edit the configure.ad file in the source tree.
399 # Source: configure.ad
400 # Generated: `date` by `whoami`
401 # Distribution: $distribution
406 ad_debug "creating configure.ac"
407 if test -f configure.ad.cfs; then
408 sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
409 sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
410 rm -f configure.ad.cfs $fname.tmp
416 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
418 # Process for distribution
420 ad_process_file $fname.tmp $fname false
422 # Remove any trailing backslashes
423 if test -f "$fname"; then
424 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname > configure.ac
426 cp -p $fname.tmp configure.ac
428 rm -f $fname $fname.tmp
430 ad_log " ./configure.ad"
433 ad_debug "Ending creating configure.ac: $1"
437 # Creates the Makefile.in files by running the automake tool.
439 # Arguments: ad_make_makefile_ins
441 ad_make_makefile_ins()
443 ad_debug "Starting creating Makefile.in files"
445 if test "$AUTOMAKE"; then
446 ad_debug "Running automake"
448 if test $? != 0; then
449 ad_fatal "automake failed"
453 ad_debug "Ending creating Makefile.in files"
457 # Creates the Makefile.am files from the Makefile.ad files in the
458 # source tree. This runs the distribution specific processing for the
461 # Arguments: ad_make_makefile_ams
463 ad_make_makefile_ams()
465 ad_debug "Starting creating Makefile.am files"
468 ad_log "Following Makefile.ad files were processed into Makefile.am files:"
469 ad_log "------------------------------------------------------------------"
471 files=`find . -name Makefile\.ad`
475 fname=`echo $ff | sed s/\.ad//`
477 # Header for the Makefile.am
478 cat > $fname.am <<EOF
479 # Automatically generated by Autodist $ver from Makefile.ad. Do not edit.
480 # To make changes edit the $ff file in the source tree.
483 # Generated: `date` by `whoami`
484 # Distribution: $distribution
489 # Run the distribution processing for this Makefile.ad
490 ad_debug "Processing $ff to be $fname.am"
491 ad_process_file $ff $fname.tmp false
493 # Remove any trailing backslashes
494 if test -f "$fname.tmp"; then
495 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp >> $fname.am
504 ad_debug "Ending creating Makefile.am files"
508 # Processes all files with .ad suffix, with exception of configure*.ad
509 # and Makefile.ad files, for distribution from the source tree.
511 # Arguments: ad_process_ads false
515 ad_debug "Starting processing .ad files"
518 ad_log "Following .ad files were processed:"
519 ad_log "-----------------------------------"
521 files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
524 fname=`echo $i | sed s/\.ad//`
526 ad_debug "Processing $i to be $fname"
527 ad_log " $i into $fname"
529 # Run the distribution processing for this file
530 ad_process_file $i $fname false
531 if test -f $fname; then
532 cp -p $i $fname || exit 1
538 ad_debug "Ending processing .ad files"
542 # Includes files specified in the distribution for inclusion. Used when
543 # creating the distribution for packaging.
545 # include has the following format in distfile:
547 # include <path> [<dest path>]
549 # If only source path, which may be file, directory or regular expression,
550 # is specified the path will be same in distribution. If the destination
551 # path is specified that will be the new name and/or new location of the
552 # source path. This, in effect, is a cp utility with ability to create
553 # directories if they do not exist.
555 # Arguments: ad_dist_includes <includeslist> <recursive>
561 ad_debug "Starting running includes: $1 $2"
564 ad_log "Following files and directories were included in distribution:"
565 ad_log "--------------------------------------------------------------"
567 # By default do not expand pathnames
570 # Add : separator at the end
571 incs="`echo "$1" | sed 's/$/ : /'`"
577 if test "$i" = ":" && test -z "$src"; then
580 if test -z "$src"; then
584 if test -z "$dst" && test "$i" != ":"; then
590 ad_debug "Including $src into $dst"
592 if test -f "$src"; then
595 if test "$src" = "$dst"; then
596 # Add to same location
597 d=`echo $src | sed 's,/[^/]*$,,'`
598 if test "$d" != "$src" && test "$d" != "." && \
599 test '!' -d $am_distdir/$d; then
600 mkdir -p $am_distdir/$d || exit 1
603 # Add to different location
604 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
605 if test "$check" != "$dst"; then
606 ad_fatal "Invalid destination in 'include $src $dst'"
609 d=`echo $dst | sed 's,/[^/]*$,,'`
610 if test "$d" != "$dst" && test "$d" != "." && \
611 test '!' -d $am_distdir/$d; then
612 mkdir -p $am_distdir/$d || exit 1
616 ad_log " $src into $am_distdir/$d"
617 cp -p $src $am_distdir/$d || exit 1
619 elif test -d "$src"; then
622 if test "$src" = "$dst"; then
623 # Add to same location
624 d=`echo $src | sed 's,/[^/]*$,,'`
625 ds=`echo $src | sed 's/\/$//'`
626 if test "$ds" = "$d"; then
627 d=`echo $d | sed 's,/[^/]*$,,'`
629 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
630 mkdir -p $am_distdir/$d || exit 1
633 ad_log " $src into $am_distdir/$d"
634 cp -pR $src $am_distdir/$d || exit 1
636 # Add to different location
637 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
638 if test "$check" != "$dst"; then
639 ad_fatal "Invalid destination in 'include $src $dst'"
642 d=`echo $dst | sed 's,/[^/]*$,,'`
643 ds=`echo $dst | sed 's/\/$//'`
644 if test "$ds" = "$d"; then
645 d=`echo $d | sed 's,/[^/]*$,,'`
647 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
648 mkdir -p $am_distdir/$d || exit 1
651 ad_log " $src into $am_distdir/$dst"
652 cp -pR $src $am_distdir/$dst || exit 1
655 elif test x$2 != xtrue; then
656 # We assume regular expression in filename
657 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
658 if test "$check" == "$src"; then
659 if test '!' -a $src; then
660 ad_fatal "Including $src: No such file or directory"
667 # Recursively call this function with expanded pathnames. The
668 # reason why we don't let sh by default expand pathnames is that
669 # the include's destination is optional. If sh expands by default
670 # we don't know the destination. For this reason, we handle the
671 # expansion here ourselves.
673 # If src and dst are same, then expand the pathname as we'll copy
674 # matches to their own locations.
675 if test "$src" = "$dst"; then
676 # Expand pathnames, and format to our include format
678 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
681 # Destination is new, and it has to be a directory.
682 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
683 if test "$check" != "$dst"; then
684 ad_fatal "Invalid destination in 'include $src $dst'"
687 # Make sure dst has / at the end, as this must be a directory
688 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
691 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
693 # Expand pathnames, and format to our include format
695 srcs=`echo $src | sed -e "s/ / $dste : /g" \
696 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
700 # Include recursively
701 ad_dist_includes "$srcs" true
703 elif test '!' -a $src; then
704 ad_fatal "Including $src: No such file or directory"
714 ad_debug "Ending running includes: $1 $2"
718 # Excludes files specified in the distribution for exclusion. Used when
719 # creating the distribution for packaging.
721 # exclude has the following format in distfile:
725 # The path may be file, directory or regular expression.
727 # Arguments: ad_dist_includes <excludelist>
731 ad_debug "Starting running excludes: $1"
734 ad_log "Following files and directories were excluded from distribution:"
735 ad_log "----------------------------------------------------------------"
739 ad_debug "Excluding $i"
741 rm -rf $am_distdir/$i
745 ad_debug "Ending running excludes: $1"
749 # Processes the entire tree for distribution. This inspects files other
750 # than source and header files, with exception of any file with .ad
751 # suffix, and performs distribution processing for the file. The original
752 # file is replaced with the processed file. This function is used when
753 # creating the distribution for packaging.
755 # Arguments: ad_process_tree <directory>
759 ad_debug "Starting processing non-source files: $1"
761 # Take files, except source and .ad files.
762 files=`find $am_distdir \! -name \*\.ad \( \
763 \! -name \*\.[cC] -a \
764 \! -name \*\.[cC][cCpP] -a \
765 \! -name \*\.[cC][xX][xX] -a \
766 \! -name \*\.[cC][pP][pP] -a \
767 \! -name \*\.[cC]++ -a \
769 \! -name \*\.[hH] -a \
771 \! -name \*\.[cC]\.in -a \
772 \! -name \*\.[cC][cCpP]\.in -a \
773 \! -name \*\.[cC][xX][xX]\.in -a \
774 \! -name \*\.[cC][pP][pP]\.in -a \
775 \! -name \*\.[cC]++\.in -a \
776 \! -name \*\.m\.in -a \
777 \! -name \*\.[hH]\.in -a \
778 \! -name \*\.hh\.in \)`
779 files=`echo $files | sed 's/$am_distdir//'`
781 # Take away noprocess list
782 if test -f autodist.noprocess; then
783 files=`echo $files" " | sh autodist.noprocess` || exit 1
788 ad_process_file $ff $ff.tmp true
789 if test -f $ff.tmp; then
791 mv -f $ff.tmp $ff || exit 1
795 ad_debug "Ending processing non-source files: $1"
799 # Processes the entire source tree for distribution. This inspects files
800 # in the source tree, with exception of any file with .ad suffix, and
801 # performs distribution processing for the file. The original file is
802 # replaced with the processed file. This function is used when creating
803 # the distribution for packaging.
805 # Call this before ad_process_tree().
807 # Arguments: ad_process_source_tree <directory>
809 ad_process_source_tree()
811 ad_debug "Starting processing source files: $1"
813 # We take only C/C++ files since they use the C compiler friendly
814 # version of distdefs. Other files are not assumed to use them.
815 files=`find $am_distdir \! -name \*\.ad \( \
817 -name \*\.[cC][cCpP] -o \
818 -name \*\.[cC][xX][xX] -o \
819 -name \*\.[cC][pP][pP] -o \
820 -name \*\.[cC]++ -o \
824 -name \*\.[cC]\.in -o \
825 -name \*\.[cC][cCpP]\.in -o \
826 -name \*\.[cC][xX][xX]\.in -o \
827 -name \*\.[cC][pP][pP]\.in -o \
828 -name \*\.[cC]++\.in -o \
830 -name \*\.[hH]\.in -o \
833 # Take away noprocess list
834 if test -f autodist.noprocess; then
835 files=`echo $files" " | sh autodist.noprocess` || exit 1
840 ad_process_source_file $ff $ff.tmp true
841 if test -f $ff.tmp; then
843 mv -f $ff.tmp $ff || exit 1
847 ad_debug "Ending processing source files: $1"
851 # Makes distribution sane, ala modtimes. Since we modify the distribution
852 # we need to make it sane after that.
854 # Arguments: ad_makedist_makesane
856 ad_makedist_makesane()
858 ad_debug "Making distribution file modtimes sane"
860 # DO NOT change these order unless you know what you are doing.
861 if test -f $am_distdir/configure.ac; then
862 touch $am_distdir/configure.ac
865 if test -f $am_distdir/aclocal.m4; then
866 touch $am_distdir/aclocal.m4
869 if test '!' -f Makefile; then
870 ad_fatal "Makefile: No such file or directory"
873 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ ]*//'`
874 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
876 files=`find $am_distdir -name Makefile\.in`
882 if test -f $am_distdir/configure; then
883 touch $am_distdir/configure
886 if test -f $am_distdir/config.status; then
887 touch $am_distdir/config.status
890 ad_debug "Distribution made sane"
894 # Creates distribution of the source tree. All files in the distribution
895 # will be processed and the distribution will be packaged.
897 # Arguments: ad_makedist
901 ad_log_open "makedist.log"
902 ad_debug "Starting distribution creation"
904 ad_log "Starting distribution creation"
905 ad_log "------------------------------"
908 if test '!' -f autodist.dist; then
909 ad_fatal "Autodist has not been run yet to prepare source tree"
912 if test -z $MAKE; then
913 ad_fatal "The MAKE variable is not set in autodist.conf"
916 # Get distdir from Makefile
917 if test '!' -f Makefile; then
918 ad_fatal "The source tree is not configured, run ./configure first"
921 # Parse the requested distribution
922 distribution=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1
923 dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1
924 am_distdir=`grep "distdir:" < autodist.dist | cut -d: -f2` || exit 1
925 ad_parse_distribution $distribution false
926 ad_log " Distribution: $distribution $dist_version"
927 ad_log " Destination directory: $am_distdir"
930 if test x$opt_no_dist = xtrue; then
931 ad_fatal "The '$distribution' distribution cannot be packaged"
935 ad_run_dist_hooks "$pre_dist_hooks"
937 # Create distribution directory
938 ad_debug "Creating distribution directory $am_distdir"
939 $MAKE distdir || exit 1
940 chmod -R a+r $am_distdir
942 if test '!' -d $am_distdir; then
943 ad_fatal "Distribution directory $am_distdir not created"
946 # Run pre-process-dist-hooks
947 ad_run_dist_hooks "$pre_p_dist_hooks"
950 ad_dist_excludes "$excludes"
953 ad_dist_includes "$includes"
955 # Include specific license file if specified
956 if test "$license" != ""; then
957 ad_log "License file in distribution is $am_distdir/COPYING"
958 cp -p $license $am_distdir/COPYING || exit 1
961 # Process noprocesses
965 ad_log "Following files were not re-licensed:"
966 ad_log "-------------------------------------"
968 # Process source files
969 ad_debug "Process distribution source tree"
970 ad_process_source_tree $am_distdir
972 # Process non-source files
973 ad_debug "Process distribution tree"
974 ad_process_tree $am_distdir
976 # Run post-process_dist-hooks
977 ad_run_dist_hooks "$post_p_dist_hooks"
979 # Make distribution sane
983 ad_debug "Packaging distribution"
984 tar chof $am_distdir.tar $am_distdir || exit 1
987 ad_debug "Compressing distribution package"
988 if test x$ad_gzip = xtrue; then
989 ad_debug "Compressing distribution package $am_distdir.tar.gz"
990 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
992 if test x$ad_bzip2 = xtrue; then
993 ad_debug "Compressing distribution package $am_distdir.tar.bz2"
994 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
996 if test x$ad_compress = xtrue; then
997 ad_debug "Compressing distribution package $am_distdir.tar.Z"
998 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
1000 if test x$ad_zip = xtrue; then
1001 rm -f $am_distdir.zip
1002 ad_debug "Compressing distribution package $am_distdir.zip"
1003 zip -rq $am_distdir.zip $am_distdir || exit 1
1005 rm -f $am_distdir.tar
1007 # Run post-dist-hooks
1008 ad_run_dist_hooks "$post_dist_hooks"
1012 rm -f autodist.noprocess
1014 ad_log "Distribution created successfully."
1016 ad_debug "Ending distribution creation"
1020 # Handles distribution options.
1022 # option has the following format in distfile:
1026 # Following options are supported:
1032 # Arguments: ad_handle_options <options>
1036 ad_debug "Handling options: $1"
1040 if test "$i" = "template"; then
1043 elif test "$i" = "no-dist"; then
1046 elif test "$i" = "no-inherit"; then
1054 # Clears set options
1056 # Arguments: ad_clear_options
1062 opt_no_inherit=false
1066 # Parses the distribution. Gets all distribution defines from the
1067 # distribution. This also expands all inherited distributions recursively
1068 # to get all inherited distribution defines. From inherited distributions
1069 # their name and package name is not inherited.
1071 # Arguments: ad_parse_distribution <distribution name> <inherit>
1073 ad_parse_distribution()
1092 ad_debug "Starting parsing distribution: $1 $2"
1094 if test '!' -f $distdir/$1; then
1095 ad_fatal "Distribution '$1' is not declared"
1099 inhs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1100 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
1103 defs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1104 | grep "define " | cut -d' ' -f2 | sort | uniq`
1106 if test "$inhs" = "" && test "$defs" = ""; then
1107 ad_fatal "Distribution '$1' does not define anything"
1110 # Get undefined distdefs
1111 undefs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1112 | grep "undef " | cut -d' ' -f2 | sort | uniq`
1115 incs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1116 | grep "include " | sed 's/include / : /'`
1119 excs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1120 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
1123 nops=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1124 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
1127 opts=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1128 | grep "option " | cut -d' ' -f2- | sort | uniq`
1131 ad_handle_options "$opts"
1132 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
1133 ad_fatal "Distribution '$1' cannot be inherited"
1135 if test x$2 = xfalse && test x$opt_template = xtrue; then
1136 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
1139 ad_debug "inherits: $inhs"
1140 ad_debug "distdefs: $defs"
1141 ad_debug "includes: $incs"
1142 ad_debug "excludes: $excs"
1143 ad_debug "noprocess: $nops"
1144 ad_debug "undistdefs: $undefs"
1145 ad_debug "options: $opts"
1147 # Expand distdefs from inherited distributions
1150 if test x$1 = x$i; then
1151 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1152 distribution to not have 'inherit $i' declared."
1155 if test '!' -f $distdir/$i; then
1156 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1159 ad_parse_distribution $i true
1164 license=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1165 | grep "license " | cut -d' ' -f2`
1166 licenseh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1167 | grep "license-header " | sed 's/license-header / : /'`
1169 ad_debug "license: $license"
1170 ad_debug "licenseh: $licenseh"
1172 if test x$2 = xfalse; then
1173 # Take rest of the stuff from top distribution
1175 # We take precedence on defined and undefined distdefs. Remove
1176 # undefined distdefs if we have defined them.
1179 ad_debug "defining undefined $d distdef"
1180 undistdefs=`echo $undistdefs | sed s/$d//g`
1183 # Get distribution name
1184 dname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1185 | grep "name " | cut -d' ' -f2-`
1187 if test "$dname"; then
1191 # Get distribution package name (optional)
1192 dpname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1193 | grep "package " | cut -d' ' -f2`
1195 if test "$dpname"; then
1198 package=$distribution
1201 # Get Bug-report email address (optional)
1202 bugr=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1203 | grep "bug-report " | cut -d' ' -f2-`
1205 if test "$bugr"; then
1209 ad_debug "distribution: $distribution"
1210 ad_debug "package: $package"
1211 ad_debug "bug-report: $bug_report"
1213 # Get hooks (optional)
1214 prh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1215 | grep "pre-hook " | cut -d' ' -f2-`
1216 poh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1217 | grep "post-hook " | cut -d' ' -f2-`
1218 prdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1219 | grep "pre-dist-hook " | cut -d' ' -f2-`
1220 podh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1221 | grep "post-dist-hook " | cut -d' ' -f2-`
1222 prpdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1223 | grep "pre-process-dist-hook " | cut -d' ' -f2-`
1224 popdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1225 | grep "post-process-dist-hook " | cut -d' ' -f2-`
1227 pre_hooks="$pre_hooks $prh"
1228 post_hooks="$post_hooks $poh"
1229 pre_dist_hooks="$pre_dist_hooks $prdh"
1230 post_dist_hooks="$post_dist_hooks $podh"
1231 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1232 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1233 doptions="$doptions $opts"
1235 ad_handle_options "$doptions"
1236 ad_debug "options: $doptions"
1240 inherits="$inherits $inhs"
1241 distdefs="$distdefs $defs"
1242 includes="$includes $incs"
1243 excludes="$excludes $excs"
1244 noprocess="$noprocess $nops"
1245 undistdefs="$undistdefs $undefs"
1247 ad_debug "Ending parsing distribution: $1 $2"
1251 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1252 # from the distdefs.
1254 # Arguments: ad_process_distdefs
1256 ad_process_distdefs()
1258 ad_debug "Starting processing distdefs"
1261 ad_log "Following distdefs were processed:"
1262 ad_log "----------------------------------"
1264 # Remove all undefined distribution defines
1265 for i in $undistdefs
1267 ad_debug "undefining $i distdef"
1268 distdefs=`echo $distdefs | sed s/$i//g`
1271 rm -f autodist.tmp.defs
1273 # Remove duplicate distdefs
1276 echo $i >>autodist.tmp.defs
1278 distdefs=`sort < autodist.tmp.defs | uniq`
1279 distdefs=`echo $distdefs`
1280 rm -f autodist.tmp.defs
1289 ad_debug "distdefs=$distdefs"
1291 ad_debug "Ending processing distdefs"
1295 # Processes for a license header change.
1297 # Arguments: ad_process_license_header <scriptfile> <sourcefile>
1299 ad_process_license_header()
1301 ad_debug "Starting license header processing"
1303 # Add : separator at the end
1304 lics=`echo "$licenseh" | sed 's/$/ : /'`
1310 if test "$i" = ":" && test -z "$src"; then
1313 if test -z "$src"; then
1317 if test -z "$dst" && test "$i" != ":"; then
1320 ad_fatal "Missing argument in 'license-header $src'"
1323 ad_debug "Replacing $src license with $dst license"
1325 if test '!' -f $src; then
1326 ad_fatal "License header $src: No such file or directory"
1329 if test '!' -f $dst; then
1330 ad_fatal "License header $dst: No such file or directory"
1333 # Awk script to replace the license header
1334 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1335 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1336 echo "BEGIN { N=0; } /`cat autodist.lsrc`/,/`cat autodist.ldst`/ { FILE1=\"$src\"; FILE2=\"$dst\"; getline F1 < FILE1; getline F2 < FILE2; if (F1) { N=sub(F1, F2); } else { F1=\"\$\"; N=sub(F1, F2); } if (N == 0) print 0 > \"$2.norelicense\"; } END { if (N == 0) print 0 > \"$2.norelicense\"; }" >> $1
1337 rm -f autodist.lsrc autodist.ldst
1343 ad_debug "Ending license header processing"
1347 # Process specified noprocesses. This is called during makedist.
1349 # Arguments: ad_process_noprocess
1351 ad_process_noprocess()
1356 ad_debug "Starting running noprocesses"
1359 ad_log "Autodist did not process the following files:"
1360 ad_log "---------------------------------------------"
1363 cd $am_distdir || exit 1
1369 ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1371 n="$n -e 's/$am_distdir\\/$ie //'"
1376 rm -f autodist.noprocess
1377 if test x$np = xtrue; then
1378 echo $n > autodist.noprocess || exit 1
1382 ad_debug "Ending running noprocesses"
1386 # Process a file given as argument for the distribution.
1388 # Arguments: ad_process_file <filepath> <dest_filepath> <re-license>
1397 # Process only regular files
1398 if test '!' -f $1; then
1402 ad_debug "Starting processing file: $1 $2"
1404 f="autodist.tmp.script"
1407 # If license header is provided, replace the license header in the file.
1408 if test x$3 = xtrue; then
1409 ad_process_license_header $f $1
1412 ad_debug "Getting #ifdef's and #ifndef's"
1414 # Get defined distribution defines
1415 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1416 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1418 # Get explicitly not-defined distribution defines
1419 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1420 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1422 ad_debug "defs in $1: $defs"
1423 ad_debug "ndefs in $1: $ndefs"
1425 # Create the script to include and exclude stuff in the file according
1426 # to the distribution defines
1429 ad_debug "processing ifdefs"
1435 if test x$d = x$i; then
1441 # If distribution define was not found exclude those lines from the file.
1442 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1443 if test x$found = xfalse; then
1444 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1445 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1447 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1452 ad_debug "processing ifndefs"
1458 if test x$d = x$i; then
1464 # If distribution define was found exclude those lines from the file.
1465 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1466 if test x$found = xtrue; then
1467 ad_debug "ifndef $d will be excluded (it IS defined)"
1468 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1470 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1474 # Now process the file with the script
1477 # Those distdef lines that remain in the file are removed to make
1478 # the appearance prettier
1479 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1480 echo "{ print; }" >> $f
1482 # Execute the script
1483 cp -p $1 $2 || exit 1
1484 awk -f $f $1 > $2 || exit 1
1489 # Log if file was not relicensed
1490 if test -f "$1.norelicense"; then
1492 rm -f $1.norelicense
1495 ad_debug "Ending processing file: $1 $2"
1499 # Process a source file given as argument for the distribution.
1501 # Arguments: ad_process_source_file <filepath> <dest_filepath> <re-license>
1503 ad_process_source_file()
1510 # Process only regular files
1511 if test '!' -f $1; then
1515 ad_debug "Starting processing source file: $1 $2"
1517 f="autodist.tmp.script"
1520 # If license header is provided, replace the license header in the file.
1521 if test x$3 = xtrue; then
1522 ad_process_license_header $f $1
1525 ad_debug "Getting #ifdef's and #ifndef's"
1527 # Get defined distribution defines
1528 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1529 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1531 # Get explicitly not-defined distribution defines
1532 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1533 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1535 ad_debug "defs in $1: $defs"
1536 ad_debug "ndefs in $1: $ndefs"
1538 # Create the script to include and exclude stuff in the file according
1539 # to the distribution defines
1542 ad_debug "processing ifdefs"
1548 if test x$d = x$i; then
1554 # If distribution define was not found exclude those lines from the file.
1555 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1556 if test x$found = xfalse; then
1557 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1558 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1560 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1565 ad_debug "processing ifndefs"
1571 if test x$d = x$i; then
1577 # If distribution define was found exclude those lines from the file.
1578 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1579 if test x$found = xtrue; then
1580 ad_debug "ifndef $d will be excluded (it IS defined)"
1581 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1583 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1587 # Now process the file with the script
1590 # Those distdef lines that remain in the file are removed to make
1591 # the appearance prettier
1592 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1593 echo "{ print; }" >> $f
1595 # Execute the script
1596 cp -p $1 $2 || exit 1
1597 awk -f $f $1 > $2 || exit 1
1602 # Log if file was not relicensed
1603 if test -f "$1.norelicense"; then
1605 rm -f $1.norelicense
1608 ad_debug "Ending processing source file: $1 $2"
1614 # Arguments: ad_run_hooks <hooks>
1618 ad_debug "Running hooks: $1"
1621 ad_log "Running hooks:"
1622 ad_log "--------------"
1626 if test '!' -f $i; then
1627 ad_fatal "Hook script $i does not exist"
1629 ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\""
1630 sh $i "$distribution" "$dist_version" "$package" || exit 1
1634 ad_debug "Ending running hooks: $1"
1640 # Arguments: ad_run_dist_hooks <hooks>
1644 ad_debug "Starting running distributions hooks: $1"
1647 ad_log "Running distribution hooks:"
1648 ad_log "---------------------------"
1652 if test '!' -f $i; then
1653 ad_fatal "Dist hook script $i does not exist"
1656 ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\" \"$am_distdir\""
1657 sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1
1661 ad_debug "Ending running distribution hooks"
1664 ###############################################################################
1667 usage="Usage: autodist [options] [distribution] [version]"
1669 Autodist prepares source tree for configuration, compilation and
1670 distribution. Prepares the source tree from the \`autodist.ad'
1671 configuration file. Generates Automake.am files from Automake.ad
1672 files, configure.ac file from configure.ad file(s), generates the
1673 configure script by running Autoconf tool, and generates Makefile.in
1674 files by running Automake tool.
1677 -h, --help print this help, then exit
1678 -V, --version print version number, then exit
1679 -v, --verbose verbosely report processing
1680 -d, --distdir <dir> search distributions from <dir>
1681 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1682 -i, --init initialize Autodist environment, create default
1683 distribution directory and distribution, then exit
1684 -m, --makedist create and package distribution
1685 --gzip create package compressed with gzip (default)
1686 --bzip2 create also package compressed with bzip2
1687 --compress create also package compressed with compress
1688 --zip create also package compressed with zip"
1691 # Process command line arguments
1693 while test $# -gt 0; do
1698 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1707 if test $# -eq 0; then
1708 ad_parse_distribution $distribution false
1709 echo "Distribution: ${distribution}" 1>&2;
1711 ad_parse_distribution $1 false
1712 echo "Distribution: ${1}" 1>&2;
1715 echo "Distdefs:" 1>&2;
1751 echo "${usage}" 1>&2;
1753 echo "${help}" 1>&2;
1758 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1759 echo "Written by Pekka Riikonen" 1>&2;
1761 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1763 This is free software; see the source for copying conditions. There is NO
1764 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1772 echo "${usage}" 1>&2;
1782 ad_log_open "autodist.log"
1784 ad_log "Processing source tree for compilation and configuration"
1785 ad_log "--------------------------------------------------------"
1789 # Parse the requested distribution
1791 if test $# != 0; then
1792 distribution="${1}";
1793 distfile=$distribution
1796 ad_parse_distribution $distribution false
1797 ad_log " Distribution: $distribution $dist_version"
1800 if test $# != 0; then
1801 dist_version="${1}";
1804 ad_debug "Preparing source tree for configuration and compilation..."
1805 ad_debug "Preparing $distribution distribution version $dist_version"
1808 # Create the distribution defines header file
1810 if test "$DISTDEFS"; then
1811 ad_create_distdefs_h
1813 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1819 ad_run_hooks "$pre_hooks"
1822 # Generate the Makefile.am files from Makefile.ad files
1824 ad_make_makefile_ams
1827 # Generate the configure.ac from configure.ad file(s)
1829 ad_make_configure_ac ./configure.ad
1832 # Process all files with .ad suffix for distribution processing
1837 # Generate configure script
1842 # Generate Makefile.in files
1844 ad_make_makefile_ins
1847 # Create autodist.dist
1849 ad_debug "Creating autodist.dist"
1850 echo "dist:$distfile" > autodist.dist
1851 echo "ver:$dist_version" >> autodist.dist
1852 echo "distdir:$package-$dist_version" >> autodist.dist
1857 ad_run_hooks "$post_hooks"
1859 ad_log "Source tree processed successfully."
1860 ad_debug "Done, now run ./configure and make."