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
137 ###############################################################################
139 if test -f "$distdir/autodist.conf"; then
140 . $distdir/autodist.conf
146 ###############################################################################
150 # Print out debug information if debugging is enabled. To enable debugging
151 # set the global variable "debug" to true value.
153 # Arguments: ad_debug <ad_debug string>
157 if test x$debug = xtrue; then
165 # Prints out error message and exits the script.
167 # Arguments: ad_fatal <error message>
173 echo autodist: error: $1
179 # Prints out warning message
181 # Arguments: ad_warning <warning message>
187 echo autodist: warning: $1
194 # Arguments: ad_log_open <logfile>
202 This file contains messages produced by the Autodist $ver.
208 # Prints to an open log file
214 if test x$nolog = xfalse; then
220 # Initializes the Autodist environment, creates default distribution
221 # directory, and default distribution.
223 # Arguments: ad_initialize
227 ad_debug "Initializing Autodist environment"
229 # Create default distdir
230 if test '!' -f $distdir; then
234 # Create Autodist configuration file
235 if test -f @AUTODISTDIR@/autodist.conf; then
236 cp -p @AUTODISTDIR@/autodist.conf $distdir
239 # Create default distribution
240 if test -f @AUTODISTDIR@/default; then
241 cp -p @AUTODISTDIR@/default $distdir
244 ad_debug "Autodist environment initialized"
248 # Creates the distdefs header file including defined distdefs
250 # Arguments: ad_create_distdefs_h
252 ad_create_distdefs_h()
254 ad_debug "Creating distdef header file"
260 Automatically generated by Autodist $ver. Do not edit.
262 Generated: `date` by `whoami`
263 Distribution: $distribution
267 #ifndef _`echo $DP`_DISTDEFS_H
268 #define _`echo $DP`_DISTDEFS_H
274 echo "#define $i 1" >>$fname
279 #endif /* _`echo $DP`_DISTDEFS_H */
282 ad_debug "Distdef header file created"
286 # Creates the main configure script for the distribution. This runs
287 # the aclocal, autoheader and autoconf tools.
289 # Arguments: ad_make_configure
293 local run_autoconf=false
295 ad_debug "Starting configure creation"
299 if test "$ACLOCAL"; then
300 ad_debug "Running aclocal"
301 if test x$debug = xtrue; then
304 $ACLOCAL 1>/dev/null 2>/dev/null
306 if test $? != 0; then
307 ad_fatal "aclocal failed"
311 if test "$AUTOCONF"; then
312 ad_debug "Running autoconf"
314 if test $? != 0; then
315 ad_fatal "autoconf failed"
320 if test "$AUTOHEADER"; then
321 ad_debug "Running autoheader"
323 if test $? != 0; then
324 ad_fatal "autoheader failed"
328 if test "$LIBTOOLIZE"; then
329 ad_debug "Running libtoolize"
331 if test $? != 0; then
332 ad_fatal "libtoolize failed"
336 if test x$run_autoconf = xtrue; then
337 if test '!' -f configure; then
338 ad_fatal "creating configure script failed"
342 ad_debug "Ending configure creation"
346 # Creates the configure.ac script from the configure.ad fragments in
347 # the source tree. Takes the source configure file as argument which
348 # is used to create the actual configure.ac.
350 # Arguments: ad_make_configure_ac <configure_ac_source>
352 ad_make_configure_ac()
356 ad_debug "Starting creating configure.ac: $1"
359 ad_log "Following configure.ad files were processed into configure.ac:"
360 ad_log "--------------------------------------------------------------"
362 if test '!' -f $1; then
363 ad_fatal "The configure file '$1' does not exist"
366 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INIT"`"
367 if test -z $check; then
368 rm -f configure.ad.cfs
369 rm -f $fname $fname.tmp
370 ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
373 rm -f configure.ac configure.ad.cfs
375 cfs=`find . -type f -name configure\*\.ad`
378 if test "x$i" = "x$1"; then
382 ad_debug "including $i"
385 cat $i >> configure.ad.cfs
388 if test -f configure.ad.cfs; then
389 check="`sed 's/^[ ]*//' < $1 | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
390 if test -z $check; then
391 rm -f configure.ad.cfs
392 ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
396 # Header for configure.ac
397 fname="configure.tmp.ac"
399 # Automatically generated by Autodist $ver. Do not edit.
400 # To make changes edit the configure.ad file in the source tree.
402 # Source: configure.ad
403 # Generated: `date` by `whoami`
404 # Distribution: $distribution
409 ad_debug "creating configure.ac"
410 if test -f configure.ad.cfs; then
411 sed '/^AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
412 sed -e "/^AD_INCLUDE_CONFIGURE/d" $fname.tmp >> $fname
413 rm -f configure.ad.cfs $fname.tmp
419 sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
421 # Remove AD_DISABLE_DEPENDENCIES
422 sed -e "/^AD_DISABLE_DEPENDENCIES/d" $fname.tmp > $fname
424 # Process for distribution
426 ad_process_file $fname $fname.tmp false
428 # Remove any trailing backslashes
429 if test -f "$fname.tmp"; then
430 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp > configure.ac
432 cp -p $fname configure.ac
434 rm -f $fname $fname.tmp
436 ad_log " ./configure.ad"
439 ad_debug "Ending creating configure.ac: $1"
443 # Creates the Makefile.in files by running the automake tool.
445 # Arguments: ad_make_makefile_ins
447 ad_make_makefile_ins()
449 ad_debug "Starting creating Makefile.in files"
451 if test "$AUTOMAKE"; then
452 ad_debug "Running automake"
454 if test $? != 0; then
455 ad_fatal "automake failed"
459 ad_debug "Ending creating Makefile.in files"
463 # Creates the Makefile.am files from the Makefile.ad files in the
464 # source tree. This runs the distribution specific processing for the
467 # Arguments: ad_make_makefile_ams
469 ad_make_makefile_ams()
471 ad_debug "Starting creating Makefile.am files"
474 ad_log "Following Makefile.ad files were processed into Makefile.am files:"
475 ad_log "------------------------------------------------------------------"
477 files=`find . -type f -name Makefile\.ad`
481 fname=`echo $ff | sed s/\.ad//`
482 ad_make_makefile_am $ff $fname.am
486 ad_debug "Ending creating Makefile.am files"
490 # Creates Makefile.am file from the Makefile.ad file.
492 # Arguments: ad_make_makefile_am <src> <dst>
494 ad_make_makefile_am()
500 # Disable dependencies if requested
501 dc=`sed 's/^[ ]*//' < configure.ad | grep -v "^#" \
502 | grep "AD_DISABLE_DEPENDENCIES"`
503 if test "$dc" = "AD_DISABLE_DEPENDENCIES"; then
507 # Header for the Makefile.am
509 # Automatically generated by Autodist $ver from Makefile.ad. Do not edit.
510 # To make changes edit the $f file in the source tree.
513 # Generated: `date` by `whoami`
514 # Distribution: $distribution
519 # Run the distribution processing for this Makefile.ad
520 ad_debug "Processing $f to be $fname"
521 ad_process_file $f $fname.tmp false
523 # Remove any trailing backslashes
524 if test -f "$fname.tmp"; then
525 sed -e :a -e '/\\$/N; s/[ ]*\\\n//; ta' < $fname.tmp >> $fname
530 # Enable dependencies if requested
531 if test x$am_deps = xtrue; then
532 # Get list of configure.ad's to get them into deps also
533 cfs=`find . -type f -name configure\*\.ad`
534 cfs=`echo $cfs | sed 's/\.\///g'`
538 # S_AD_ENABLE_DEPENDENCIES
539 \$(srcdir)/Makefile.am: Makefile.ad
540 cd \$(top_srcdir) && autodist -p makefile \$(subdir)/Makefile.ad \$(subdir)/Makefile.am && cd \$(subdir)
541 \$(srcdir)/configure.ac: $cfs
542 cd \$(top_srcdir) && autodist -p configure \$(top_srcdir)/configure.ad && cd \$(subdir)
543 # E_AD_ENABLE_DEPENDENCIES
551 # Processes all files with .ad suffix, with exception of configure*.ad
552 # and Makefile.ad files, for distribution from the source tree.
554 # Arguments: ad_process_ads false
558 ad_debug "Starting processing .ad files"
561 ad_log "Following .ad files were processed:"
562 ad_log "-----------------------------------"
564 files=`find . -type f -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
567 fname=`echo $i | sed s/\.ad//`
569 ad_debug "Processing $i to be $fname"
570 ad_log " $i into $fname"
572 # Run the distribution processing for this file
573 ad_process_file $i $fname false
574 if test -f $fname; then
575 cp -p $i $fname || exit 1
581 ad_debug "Ending processing .ad files"
585 # Includes files specified in the distribution for inclusion. Used when
586 # creating the distribution for packaging.
588 # include has the following format in distfile:
590 # include <path> [<dest path>]
592 # If only source path, which may be file, directory or regular expression,
593 # is specified the path will be same in distribution. If the destination
594 # path is specified that will be the new name and/or new location of the
595 # source path. This, in effect, is a cp utility with ability to create
596 # directories if they do not exist.
598 # Arguments: ad_dist_includes <includeslist> <recursive> <log>
604 ad_debug "Starting running includes: $1 $2"
606 if test x$3 = xtrue; then
608 ad_log "Following files and directories were included in distribution:"
609 ad_log "--------------------------------------------------------------"
612 # By default do not expand pathnames
615 # Add : separator at the end
616 incs="`echo "$1" | sed 's/$/ : /'`"
622 if test "$i" = ":" && test -z "$src"; then
625 if test -z "$src"; then
629 if test -z "$dst" && test "$i" != ":"; then
635 ad_debug "Including $src into $dst"
637 if test -f "$src"; then
640 if test "$src" = "$dst"; then
641 # Add to same location
642 d=`echo $src | sed 's,/[^/]*$,,'`
643 if test "$d" != "$src" && test "$d" != "." && \
644 test '!' -d $am_distdir/$d; then
645 mkdir -p -- $am_distdir/$d || exit 1
648 # Add to different location
649 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
650 if test "$check" != "$dst"; then
651 ad_fatal "Invalid destination in 'include $src $dst'"
654 d=`echo $dst | sed 's,/[^/]*$,,'`
655 if test "$d" != "$dst" && test "$d" != "." && \
656 test '!' -d $am_distdir/$d; then
657 mkdir -p -- $am_distdir/$d || exit 1
661 if test x$3 = xtrue; then
662 ad_log " $src into $am_distdir/$d"
664 cp -p $src $am_distdir/$d || exit 1
666 elif test -d "$src"; then
669 if test "$src" = "$dst"; then
670 # Add to same location
671 d=`echo $src | sed 's,/[^/]*$,,'`
672 ds=`echo $src | sed 's/\/$//'`
673 if test "$ds" = "$d"; then
674 d=`echo $d | sed 's,/[^/]*$,,'`
676 if test "$ds" = "$d"; then
679 if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
680 mkdir -p -- $am_distdir/$d || exit 1
683 if test x$3 = xtrue; then
684 ad_log " $src into $am_distdir/$d"
686 cp -pR $src $am_distdir/$d || exit 1
688 # Add to different location
689 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
690 if test "$check" != "$dst"; then
691 ad_fatal "Invalid destination in 'include $src $dst'"
694 d=`echo $dst | sed 's,/[^/]*$,,'`
695 ds=`echo $dst | sed 's/\/$//'`
696 if test "$ds" = "$d"; then
697 d=`echo $d | sed 's,/[^/]*$,,'`
699 if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
700 mkdir -p -- $am_distdir/$d || exit 1
703 if test x$3 = xtrue; then
704 ad_log " $src into $am_distdir/$dst"
706 cp -pR $src $am_distdir/$dst || exit 1
709 elif test x$2 != xtrue; then
710 # We assume regular expression in filename
711 check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
712 if test "$check" == "$src"; then
713 if test '!' -a $src; then
714 ad_fatal "Including $src: No such file or directory"
721 # Recursively call this function with expanded pathnames. The
722 # reason why we don't let sh by default expand pathnames is that
723 # the include's destination is optional. If sh expands by default
724 # we don't know the destination. For this reason, we handle the
725 # expansion here ourselves.
727 # If src and dst are same, then expand the pathname as we'll copy
728 # matches to their own locations.
729 if test "$src" = "$dst"; then
730 # Expand pathnames, and format to our include format
732 srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
735 # Destination is new, and it has to be a directory.
736 check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
737 if test "$check" != "$dst"; then
738 ad_fatal "Invalid destination in 'include $src $dst'"
741 # Make sure dst has / at the end, as this must be a directory
742 dst=`echo $dst | sed 's/\/$//; s/$/\//'`
745 dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
747 # Expand pathnames, and format to our include format
749 srcs=`echo $src | sed -e "s/ / $dste : /g" \
750 -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
754 # Include recursively
755 ad_dist_includes "$srcs" true
757 elif test '!' -a $src; then
758 ad_fatal "Including $src: No such file or directory"
765 if test x$3 = xtrue; then
771 ad_debug "Ending running includes: $1 $2"
775 # Excludes files specified in the distribution for exclusion. Used when
776 # creating the distribution for packaging.
778 # exclude has the following format in distfile:
782 # The path may be file, directory or regular expression.
784 # Arguments: ad_dist_includes <excludelist> <log>
788 ad_debug "Starting running excludes: $1"
790 if test x$2 = xtrue; then
792 ad_log "Following files and directories were excluded from distribution:"
793 ad_log "----------------------------------------------------------------"
797 cd $am_distdir || exit 1
800 ad_debug "Excluding $i"
801 if test x$2 = xtrue; then
808 if test x$2 = xtrue; then
812 ad_debug "Ending running excludes: $1"
816 # Processes the entire tree for distribution. This inspects files other
817 # than source and header files, with exception of any file with .ad
818 # suffix, and performs distribution processing for the file. The original
819 # file is replaced with the processed file. This function is used when
820 # creating the distribution for packaging.
822 # Arguments: ad_process_tree <directory>
826 ad_debug "Starting processing non-source files: $1"
828 # Take files, except source and .ad files.
829 files=`find $am_distdir -type f \! -name \*\.ad \( \
830 \! -name \*\.[cC] -a \
831 \! -name \*\.[cC][cCpP] -a \
832 \! -name \*\.[cC][xX][xX] -a \
833 \! -name \*\.[cC][pP][pP] -a \
834 \! -name \*\.[cC]++ -a \
836 \! -name \*\.[hH] -a \
838 \! -name \*\.[cC]\.in -a \
839 \! -name \*\.[cC][cCpP]\.in -a \
840 \! -name \*\.[cC][xX][xX]\.in -a \
841 \! -name \*\.[cC][pP][pP]\.in -a \
842 \! -name \*\.[cC]++\.in -a \
843 \! -name \*\.m\.in -a \
844 \! -name \*\.[hH]\.in -a \
845 \! -name \*\.hh\.in \)`
846 files=`echo $files | sed 's/$am_distdir//'`
850 ad_process_file $ff $ff.tmp true
851 if test -f $ff.tmp; then
853 mv -f $ff.tmp $ff || exit 1
857 ad_debug "Ending processing non-source files: $1"
861 # Processes the entire source tree for distribution. This inspects files
862 # in the source tree, with exception of any file with .ad suffix, and
863 # performs distribution processing for the file. The original file is
864 # replaced with the processed file. This function is used when creating
865 # the distribution for packaging.
867 # Call this before ad_process_tree().
869 # Arguments: ad_process_source_tree <directory>
871 ad_process_source_tree()
873 ad_debug "Starting processing source files: $1"
875 # We take only C/C++ files since they use the C compiler friendly
876 # version of distdefs. Other files are not assumed to use them.
877 files=`find $am_distdir -type f \! -name \*\.ad \( \
879 -name \*\.[cC][cCpP] -o \
880 -name \*\.[cC][xX][xX] -o \
881 -name \*\.[cC][pP][pP] -o \
882 -name \*\.[cC]++ -o \
886 -name \*\.[cC]\.in -o \
887 -name \*\.[cC][cCpP]\.in -o \
888 -name \*\.[cC][xX][xX]\.in -o \
889 -name \*\.[cC][pP][pP]\.in -o \
890 -name \*\.[cC]++\.in -o \
892 -name \*\.[hH]\.in -o \
897 ad_process_source_file $ff $ff.tmp true
898 if test -f $ff.tmp; then
900 mv -f $ff.tmp $ff || exit 1
904 ad_debug "Ending processing source files: $1"
908 # Removes Autodist dependencies, as they cannot be delivered to distribution.
910 # Arguments: ad_remove_dependencies <distdir>
912 ad_remove_dependencies()
914 ad_debug "Removing dependencies"
916 ams=`find $1 -type f -name Makefile\.\*`
919 sed -e "/^# S_AD_ENABLE_DEPENDENCIES/,/^# E_AD_ENABLE_DEPENDENCIES/d" $i > $i.tmp
925 # Makes distribution sane, ala modtimes. Since we modify the distribution
926 # we need to make it sane after that.
928 # Arguments: ad_makedist_makesane
930 ad_makedist_makesane()
932 ad_debug "Making distribution file modtimes sane"
934 # DO NOT change these order unless you know what you are doing.
935 if test -f $am_distdir/configure.ac; then
936 touch $am_distdir/configure.ac
939 if test -f $am_distdir/aclocal.m4; then
940 touch $am_distdir/aclocal.m4
943 if test '!' -f Makefile; then
944 ad_fatal "Makefile: No such file or directory"
947 configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ ]*//'`
948 touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
950 files=`find $am_distdir -type f -name Makefile\.in`
956 if test -f $am_distdir/configure; then
957 touch $am_distdir/configure
960 if test -f $am_distdir/config.status; then
961 touch $am_distdir/config.status
964 ad_debug "Distribution made sane"
968 # Creates distribution of the source tree. All files in the distribution
969 # will be processed and the distribution will be packaged.
971 # Arguments: ad_makedist
975 ad_log_open "makedist.log"
976 ad_debug "Starting distribution creation"
978 ad_log "Created distribution"
979 ad_log "--------------------"
982 if test '!' -f autodist.dist; then
983 ad_fatal "Autodist has not been run yet to prepare source tree"
986 if test -z $MAKE; then
987 ad_fatal "The MAKE variable is not set in autodist.conf"
990 # Get distdir from Makefile
991 if test '!' -f Makefile; then
992 ad_fatal "The source tree is not configured, run ./configure first"
995 # Parse the requested distribution
996 distribution=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1
997 dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1
998 am_distdir=`grep "distdir:" < autodist.dist | cut -d: -f2` || exit 1
999 ad_parse_distribution $distribution false
1000 ad_log " Distribution: $distribution $dist_version"
1001 ad_log " Destination directory: $am_distdir"
1005 if test x$opt_no_dist = xtrue; then
1006 ad_fatal "The '$distribution' distribution cannot be packaged"
1009 # Run pre-dist-hooks
1010 ad_run_dist_hooks "$pre_dist_hooks"
1012 # Create distribution directory
1013 ad_debug "Creating distribution directory $am_distdir"
1014 $MAKE distdir || exit 1
1015 chmod -R a+r $am_distdir
1017 if test '!' -d $am_distdir; then
1018 ad_fatal "Distribution directory $am_distdir not created"
1021 # Run pre-process-dist-hooks
1022 ad_run_dist_hooks "$pre_p_dist_hooks"
1025 ad_dist_excludes "$excludes" true
1028 ad_dist_includes "$includes" false true
1030 # Include specific license file if specified
1031 if test "$license" != ""; then
1033 ad_log "License file in distribution:"
1034 ad_log "-----------------------------"
1035 ad_log " $license into $am_distdir/COPYING"
1037 cp -p $license $am_distdir/COPYING || exit 1
1040 # Remove dependencies
1041 ad_remove_dependencies $am_distdir
1043 # Process noprocesses, first pass
1044 ad_process_noprocess true
1047 ad_log "Following files were not re-licensed:"
1048 ad_log "-------------------------------------"
1050 # Process source files
1051 ad_debug "Process distribution source tree"
1052 ad_process_source_tree $am_distdir
1054 # Process non-source files
1055 ad_debug "Process distribution tree"
1056 ad_process_tree $am_distdir
1060 # Process noprocesses, second pass
1061 ad_process_noprocess false
1063 # Run post-process_dist-hooks
1064 ad_run_dist_hooks "$post_p_dist_hooks"
1066 # Make distribution sane
1067 ad_makedist_makesane
1070 ad_debug "Packaging distribution"
1071 tar chof $am_distdir.tar $am_distdir || exit 1
1074 ad_debug "Compressing distribution package"
1075 if test x$ad_gzip = xtrue; then
1076 ad_debug "Compressing distribution package $am_distdir.tar.gz"
1077 gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
1079 if test x$ad_bzip2 = xtrue; then
1080 ad_debug "Compressing distribution package $am_distdir.tar.bz2"
1081 bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
1083 if test x$ad_compress = xtrue; then
1084 ad_debug "Compressing distribution package $am_distdir.tar.Z"
1085 compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
1087 if test x$ad_zip = xtrue; then
1088 rm -f $am_distdir.zip
1089 ad_debug "Compressing distribution package $am_distdir.zip"
1090 zip -rq $am_distdir.zip $am_distdir || exit 1
1092 rm -f $am_distdir.tar
1094 # Run post-dist-hooks
1095 ad_run_dist_hooks "$post_dist_hooks"
1100 ad_log "Distribution created successfully."
1102 ad_debug "Ending distribution creation"
1106 # Handles distribution options.
1108 # option has the following format in distfile:
1112 # Following options are supported:
1118 # Arguments: ad_handle_options <options>
1122 ad_debug "Handling options: $1"
1126 if test "$i" = "template"; then
1129 elif test "$i" = "no-dist"; then
1132 elif test "$i" = "no-inherit"; then
1140 # Clears set options
1142 # Arguments: ad_clear_options
1148 opt_no_inherit=false
1152 # Parses the distribution. Gets all distribution defines from the
1153 # distribution. This also expands all inherited distributions recursively
1154 # to get all inherited distribution defines. From inherited distributions
1155 # their name and package name is not inherited.
1157 # Arguments: ad_parse_distribution <distribution name> <inherit>
1159 ad_parse_distribution()
1178 ad_debug "Starting parsing distribution: $1 $2"
1180 if test '!' -f $distdir/$1; then
1181 ad_fatal "Distribution '$1' is not declared"
1185 inhs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1186 | grep "inherit " | cut -d' ' -f2 | sort | uniq`
1189 defs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1190 | grep "define " | cut -d' ' -f2 | sort | uniq`
1192 if test "$inhs" = "" && test "$defs" = ""; then
1193 ad_fatal "Distribution '$1' does not define anything"
1196 # Get undefined distdefs
1197 undefs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1198 | grep "undef " | cut -d' ' -f2 | sort | uniq`
1201 incs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1202 | grep "include " | sed 's/include / : /'`
1205 excs=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1206 | grep "exclude " | cut -d' ' -f2- | sort | uniq`
1209 nops=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1210 | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
1213 opts=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1214 | grep "option " | cut -d' ' -f2- | sort | uniq`
1217 ad_handle_options "$opts"
1218 if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
1219 ad_fatal "Distribution '$1' cannot be inherited"
1221 if test x$2 = xfalse && test x$opt_template = xtrue; then
1222 ad_fatal "Template distribution '$1' cannot be prepared or packaged"
1225 ad_debug "inherits: $inhs"
1226 ad_debug "distdefs: $defs"
1227 ad_debug "includes: $incs"
1228 ad_debug "excludes: $excs"
1229 ad_debug "noprocess: $nops"
1230 ad_debug "undistdefs: $undefs"
1231 ad_debug "options: $opts"
1233 # Expand distdefs from inherited distributions
1236 if test x$1 = x$i; then
1237 ad_fatal "Infinite recursion detected. Fix the '$distdir/$1' \
1238 distribution to not have 'inherit $i' declared."
1241 if test '!' -f $distdir/$i; then
1242 ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
1245 ad_parse_distribution $i true
1250 license=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1251 | grep "license " | cut -d' ' -f2`
1252 licenseh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1253 | grep "license-header " | sed 's/license-header / : /'`
1255 ad_debug "license: $license"
1256 ad_debug "licenseh: $licenseh"
1258 if test x$2 = xfalse; then
1259 # Take rest of the stuff from top distribution
1261 # We take precedence on defined and undefined distdefs. Remove
1262 # undefined distdefs if we have defined them.
1265 ad_debug "defining undefined $d distdef"
1266 undistdefs=`echo $undistdefs | sed s/$d//g`
1269 # Get distribution name
1270 dname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1271 | grep "name " | cut -d' ' -f2-`
1273 if test "$dname"; then
1277 # Get distribution package name (optional)
1278 dpname=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1279 | grep "package " | cut -d' ' -f2`
1281 if test "$dpname"; then
1284 package=$distribution
1287 # Get Bug-report email address (optional)
1288 bugr=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1289 | grep "bug-report " | cut -d' ' -f2-`
1291 if test "$bugr"; then
1295 ad_debug "distribution: $distribution"
1296 ad_debug "package: $package"
1297 ad_debug "bug-report: $bug_report"
1299 # Get hooks (optional)
1300 prh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1301 | grep "pre-hook " | cut -d' ' -f2-`
1302 poh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1303 | grep "post-hook " | cut -d' ' -f2-`
1304 prdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1305 | grep "pre-dist-hook " | cut -d' ' -f2-`
1306 podh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1307 | grep "post-dist-hook " | cut -d' ' -f2-`
1308 prpdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1309 | grep "pre-process-dist-hook " | cut -d' ' -f2-`
1310 popdh=`sed 's/^[ ]*//' < $distdir/$1 | grep -v "^#" \
1311 | grep "post-process-dist-hook " | cut -d' ' -f2-`
1313 pre_hooks="$pre_hooks $prh"
1314 post_hooks="$post_hooks $poh"
1315 pre_dist_hooks="$pre_dist_hooks $prdh"
1316 post_dist_hooks="$post_dist_hooks $podh"
1317 pre_p_dist_hooks="$pre_p_dist_hooks $prpdh"
1318 post_p_dist_hooks="$post_p_dist_hooks $popdh"
1319 doptions="$doptions $opts"
1321 ad_handle_options "$doptions"
1322 ad_debug "options: $doptions"
1326 inherits="$inherits $inhs"
1327 distdefs="$distdefs $defs"
1328 includes="$includes $incs"
1329 excludes="$excludes $excs"
1330 noprocess="$noprocess $nops"
1331 undistdefs="$undistdefs $undefs"
1333 ad_debug "Ending parsing distribution: $1 $2"
1337 # Processes parsed distdefs. Removes duplicates, and undefined distdefs
1338 # from the distdefs.
1340 # Arguments: ad_process_distdefs
1342 ad_process_distdefs()
1344 ad_debug "Starting processing distdefs"
1347 ad_log "Following distdefs were processed:"
1348 ad_log "----------------------------------"
1350 # Remove all undefined distribution defines
1351 for i in $undistdefs
1353 ad_debug "undefining $i distdef"
1354 distdefs=`echo $distdefs | sed s/$i//g`
1357 rm -f autodist.tmp.defs
1359 # Remove duplicate distdefs
1362 echo $i >>autodist.tmp.defs
1364 distdefs=`sort < autodist.tmp.defs | uniq`
1365 distdefs=`echo $distdefs`
1366 rm -f autodist.tmp.defs
1375 ad_debug "distdefs=$distdefs"
1377 ad_debug "Ending processing distdefs"
1381 # Processes for a license header change.
1383 # Arguments: ad_process_license_header <scriptfile> <sourcefile>
1385 ad_process_license_header()
1387 ad_debug "Starting license header processing"
1389 # Add : separator at the end
1390 lics=`echo "$licenseh" | sed 's/$/ : /'`
1396 if test "$i" = ":" && test -z "$src"; then
1399 if test -z "$src"; then
1403 if test -z "$dst" && test "$i" != ":"; then
1406 ad_fatal "Missing argument in 'license-header $src'"
1409 ad_debug "Replacing $src license with $dst license"
1411 if test '!' -f $src; then
1412 ad_fatal "License header $src: No such file or directory"
1415 if test '!' -f $dst; then
1416 ad_fatal "License header $dst: No such file or directory"
1419 # Awk script to replace the license header
1420 fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1421 ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1422 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
1423 rm -f autodist.lsrc autodist.ldst
1429 ad_debug "Ending license header processing"
1433 # Process specified noprocesses. This is called during makedist.
1434 # The noprocess first copies the noprocess files and dirs into a temp
1435 # directory, and then removes them from the distdir. This way they are
1436 # not processed by Autodist. After processing they are returned to their
1437 # correct locations from the temp dir. Dirty, yeah, but the way we do
1438 # this until better one comes along.
1440 # Arguments: ad_process_noprocess <process>
1442 # If <process> is true this excludes and if false this includes.
1444 ad_process_noprocess()
1446 ad_debug "Starting running noprocesses"
1452 if test x$1 = xtrue; then
1454 ad_log "Following files and directories were not processed:"
1455 ad_log "---------------------------------------------------"
1457 f="$cur/autodist__noprocess"
1459 mkdir -p -- $f || exit 1
1461 # First, include them to new location with correct directory structure.
1462 old_am_distdir="$am_distdir"
1463 cd $am_distdir || exit 1
1466 nops=`echo $nops | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
1467 ad_dist_includes "$nops" false false
1468 am_distdir="$old_am_distdir"
1470 # Then, remove from distdir (they are in temp dir now)
1480 # Copy from the temp dir back to distdir
1481 cd autodist__noprocess || exit 1
1482 old_am_distdir="$am_distdir"
1483 am_distdir="$cur/$old_am_distdir"
1485 nops=`echo $nops | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
1487 ad_dist_includes "$nops" false false
1489 am_distdir="$old_am_distdir"
1491 rm -rf autodist__noprocess
1496 ad_debug "Ending running noprocesses"
1500 # Process a file given as argument for the distribution.
1502 # Arguments: ad_process_file <filepath> <dest_filepath> <re-license>
1511 # Process only regular files
1512 if test '!' -f $1; then
1516 ad_debug "Starting processing file: $1 $2"
1518 f="autodist.tmp.script"
1521 # If license header is provided, replace the license header in the file.
1522 if test x$3 = xtrue; then
1523 ad_process_license_header $f $1
1526 # Get defined distribution defines
1527 defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1528 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1530 # Get explicitly not-defined distribution defines
1531 ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1532 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1534 ad_debug "defs in $1: $defs"
1535 ad_debug "ndefs in $1: $ndefs"
1537 # Create the script to include and exclude stuff in the file according
1538 # to the distribution defines
1541 ad_debug "processing ifdefs"
1547 if test x$d = x$i; then
1553 # If distribution define was not found exclude those lines from the file.
1554 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1555 if test x$found = xfalse; then
1556 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1557 echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1559 echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1564 ad_debug "processing ifndefs"
1570 if test x$d = x$i; then
1576 # If distribution define was found exclude those lines from the file.
1577 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1578 if test x$found = xtrue; then
1579 ad_debug "ifndef $d will be excluded (it IS defined)"
1580 echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1582 echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1586 # Now process the file with the script
1589 # Those distdef lines that remain in the file are removed to make
1590 # the appearance prettier
1591 echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1592 echo "{ print; }" >> $f
1594 # Execute the script
1595 cp -p $1 $2 || exit 1
1596 awk -f $f $1 > $2 || exit 1
1601 # Log if file was not relicensed
1602 if test -f "$1.norelicense"; then
1604 rm -f $1.norelicense
1607 ad_debug "Ending processing file: $1 $2"
1611 # Process a source file given as argument for the distribution.
1613 # Arguments: ad_process_source_file <filepath> <dest_filepath> <re-license>
1615 ad_process_source_file()
1622 # Process only regular files
1623 if test '!' -f $1; then
1627 ad_debug "Starting processing source file: $1 $2"
1629 f="autodist.tmp.script"
1632 # If license header is provided, replace the license header in the file.
1633 if test x$3 = xtrue; then
1634 ad_process_license_header $f $1
1637 # Get defined distribution defines
1638 defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1639 $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1641 # Get explicitly not-defined distribution defines
1642 ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1643 $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1645 ad_debug "defs in $1: $defs"
1646 ad_debug "ndefs in $1: $ndefs"
1648 # Create the script to include and exclude stuff in the file according
1649 # to the distribution defines
1652 ad_debug "processing ifdefs"
1658 if test x$d = x$i; then
1664 # If distribution define was not found exclude those lines from the file.
1665 # This also handles the #ifdef's #else (ie. #ifndef) branch.
1666 if test x$found = xfalse; then
1667 ad_debug "ifdef $d will be excluded (it is NOT defined)"
1668 echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1670 echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1675 ad_debug "processing ifndefs"
1681 if test x$d = x$i; then
1687 # If distribution define was found exclude those lines from the file.
1688 # This also handles the #ifndef's #else (ie. #ifdef) branch.
1689 if test x$found = xtrue; then
1690 ad_debug "ifndef $d will be excluded (it IS defined)"
1691 echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1693 echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1697 # Now process the file with the script
1700 # Those distdef lines that remain in the file are removed to make
1701 # the appearance prettier
1702 echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1703 echo "{ print; }" >> $f
1705 # Execute the script
1706 cp -p $1 $2 || exit 1
1707 awk -f $f $1 > $2 || exit 1
1712 # Log if file was not relicensed
1713 if test -f "$1.norelicense"; then
1715 rm -f $1.norelicense
1718 ad_debug "Ending processing source file: $1 $2"
1722 # Processes a file. This is the -p, --process option.
1724 # Arguments: ad_process <type> <src> <dst>
1728 ad_debug "Starting process: $1 $2 $3"
1732 if test '!' -f autodist.dist; then
1733 ad_fatal "Autodist has not been run yet to prepare source tree"
1736 # Parse distribution
1737 distribution=`grep "dist:" < autodist.dist | cut -d: -f2` || exit 1
1738 dist_version=`grep "ver:" < autodist.dist | cut -d: -f2` || exit 1
1739 ad_parse_distribution $distribution false
1746 ad_fatal "File type $1 requires <dst> argument"
1748 ad_make_makefile_am $2 $3
1752 ad_make_configure_ac $2
1757 ad_fatal "File type $1 requires <dst> argument"
1759 ad_process_file $2 $3 false
1764 ad_fatal "File type $1 requires <dst> argument"
1766 ad_process_source_file $2 $3 false
1770 ad_fatal "Unknown file type: $1";
1778 # Arguments: ad_run_hooks <hooks>
1782 ad_debug "Running hooks: $1"
1785 ad_log "Hooks executed:"
1786 ad_log "--------------"
1790 if test '!' -f $i; then
1791 ad_fatal "Hook script $i does not exist"
1793 ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\""
1794 sh $i "$distribution" "$dist_version" "$package" || exit 1
1798 ad_debug "Ending running hooks: $1"
1804 # Arguments: ad_run_dist_hooks <hooks>
1808 ad_debug "Starting running distributions hooks: $1"
1811 ad_log "Distribution hooks executed:"
1812 ad_log "----------------------------"
1816 if test '!' -f $i; then
1817 ad_fatal "Dist hook script $i does not exist"
1820 ad_log " sh $i \"$distribution\" \"$dist_version\" \"$package\" \"$am_distdir\""
1821 sh $i "$distribution" "$dist_version" "$package" "$am_distdir" || exit 1
1825 ad_debug "Ending running distribution hooks"
1828 ###############################################################################
1831 usage="Usage: autodist [options] [distribution] [version]"
1833 Autodist prepares source tree for configuration, compilation and
1834 distribution. Prepares the source tree from the \`autodist.ad'
1835 configuration file. Generates Automake.am files from Automake.ad
1836 files, configure.ac file from configure.ad file(s), generates the
1837 configure script by running Autoconf tool, and generates Makefile.in
1838 files by running Automake tool.
1841 -h, --help print this help, then exit
1842 -V, --version print version number, then exit
1843 -v, --verbose verbosely report processing
1844 -d, --distdir <dir> search distributions from <dir>
1845 -s, --distdefs [<dist>] print distribution defines of <dist>, then exit
1846 -i, --init initialize Autodist environment, create default
1847 distribution directory and distribution, then exit
1848 -p, --process <type> <src> [<dst>]
1849 process file <src> into <dst> for distribution,
1850 <type> is 'makefile', 'configure', 'non-source'
1851 or 'source' and defines the type of <src>
1852 -m, --makedist create and package distribution
1853 --gzip create package compressed with gzip (default)
1854 --bzip2 create also package compressed with bzip2
1855 --compress create also package compressed with compress
1856 --zip create also package compressed with zip"
1859 # Process command line arguments
1861 while test $# -gt 0; do
1866 test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1875 if test $# -eq 0; then
1876 ad_parse_distribution $distribution false
1877 echo "Distribution: ${distribution}" 1>&2;
1879 ad_parse_distribution $1 false
1880 echo "Distribution: ${1}" 1>&2;
1883 echo "Distdefs:" 1>&2;
1896 if test $# -ge 2; then
1899 echo "${usage}" 1>&2;
1928 echo "${usage}" 1>&2;
1930 echo "${help}" 1>&2;
1935 echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1936 echo "Written by Pekka Riikonen" 1>&2;
1938 echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1940 This is free software; see the source for copying conditions. There is NO
1941 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1949 echo "${usage}" 1>&2;
1959 ad_log_open "autodist.log"
1961 ad_log "Processing source tree for compilation and configuration"
1962 ad_log "--------------------------------------------------------"
1966 # Parse the requested distribution
1968 if test $# != 0; then
1969 distribution="${1}";
1970 distfile=$distribution
1974 ad_parse_distribution $distribution false
1976 if test $# != 0; then
1977 dist_version="${1}";
1980 ad_log " Distribution: $distribution $dist_version"
1985 ad_debug "Preparing source tree for configuration and compilation..."
1986 ad_debug "Preparing $distribution distribution version $dist_version"
1989 # Create the distribution defines header file
1991 if test "$DISTDEFS"; then
1992 ad_create_distdefs_h
1994 ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
2000 ad_run_hooks "$pre_hooks"
2003 # Generate the Makefile.am files from Makefile.ad files
2005 ad_make_makefile_ams
2008 # Generate the configure.ac from configure.ad file(s)
2010 ad_make_configure_ac ./configure.ad
2013 # Process all files with .ad suffix for distribution processing
2018 # Generate configure script
2023 # Generate Makefile.in files
2025 ad_make_makefile_ins
2028 # Create autodist.dist
2030 ad_debug "Creating autodist.dist"
2031 echo "dist:$distfile" > autodist.dist
2032 echo "ver:$dist_version" >> autodist.dist
2033 echo "distdir:$package-$dist_version" >> autodist.dist
2038 ad_run_hooks "$post_hooks"
2040 ad_log "Source tree processed successfully."
2041 ad_debug "Done, now run ./configure and make."