Merged silc_1_0_branch to trunk.
[silc.git] / apps / autodist / autodist.in
1 #!/bin/sh
2 #
3 # Author: Pekka Riikonen <priikone@silcnet.org>
4 #
5 # Copyright (C) 2005 Pekka Riikonen
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are
10 # met:
11 #
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
19 #      permission.
20 #
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.
31 #
32
33 ###############################################################################
34 # Global variables
35
36 # Packaging and compressing
37 ad_gzip=true
38 ad_bzip2=false
39 ad_compress=false
40 ad_zip=false
41
42 # Distribution subdirectory
43 distdir="distdir"
44 am_distdir=
45
46 # This current distribution
47 distribution=default
48 distfile=$distribution
49 dist_version=0.0
50 package=
51 bug_report=
52
53 # All inherited distributions in this distribution
54 inherits=
55
56 # All distribution defines for this distribution
57 distdefs=
58
59 # All distribution undefines for this distribution
60 undistdefs=
61
62 # All distribution options
63 options=
64 opt_template=false
65 opt_no_dist=false
66 opt_no_inherit=false
67
68 # All includes
69 includes=
70
71 # All excludes
72 excludes=
73
74 # All noprocesses
75 noprocess=
76
77 # All pre, post pre-dist and post-dist hooks
78 pre_hooks=
79 post_hooks=
80 pre_dist_hooks=
81 post_dist_hooks=
82
83 # Distribution license and license header
84 license=
85 licenseh=
86
87 # Whether to output ad_debug information
88 debug=false
89
90 # Autodist version
91 ver=@VERSION@
92
93 ###############################################################################
94 # Configuration file
95 if test -f "$distdir/autodist.conf"; then
96   . $distdir/autodist.conf
97 fi
98
99 DP=$DISTPREFIX
100
101
102 ###############################################################################
103 # Functions
104
105 #
106 # Print out debug information if debugging is enabled.  To enable debugging
107 # set the global variable "debug" to true value.
108 #
109 # Arguments: ad_debug <ad_debug string>
110 #
111 ad_debug()
112 {
113   if test x$debug = xtrue; then
114     set -f
115     echo autodist: $1
116     set +f
117   fi
118 }
119
120 #
121 # Prints out error message and exits the script.
122 #
123 # Arguments: ad_fatal <error message>
124 #
125 ad_fatal()
126 {
127   set -f
128   echo autodist: error: $1
129   set +f
130   exit 1
131 }
132
133 #
134 # Prints out warning message
135 #
136 # Arguments: ad_warning <warning message>
137 #
138 ad_warning()
139 {
140   set -f
141   echo autodist: warning: $1
142   set +f
143 }
144
145 #
146 # Initializes the Autodist environment, creates default distribution
147 # directory, and default distribution.
148 #
149 # Arguments: ad_initialize
150 #
151 ad_initialize()
152 {
153   ad_debug ">ad_initialize"
154
155   # Create default distdir
156   if test '!' -f $distdir; then
157     mkdir -p $distdir
158   fi
159
160   # Create Autodist configuration file
161   if test -f @AUTODISTDIR@/autodist.conf; then
162     cp -p @AUTODISTDIR@/autodist.conf $distdir
163   fi
164
165   # Create default distribution
166   if test -f @AUTODISTDIR@/default; then
167     cp -p @AUTODISTDIR@/default $distdir
168   fi
169
170   ad_debug "<ad_initialize"
171 }
172
173 #
174 # Creates the distdefs header file including defined distdefs
175 #
176 # Arguments: ad_create_distdefs_h
177 #
178 ad_create_distdefs_h()
179 {
180   ad_debug ">ad_create_distdefs_h"
181
182   fname=$DISTDEFS
183   rm -f $fname
184   echo "/*" > $fname
185   echo "  Automatically generated by Autodist $ver.  Do not edit." >> $fname
186   echo >> $fname
187   echo "  Generated: `date` by `whoami`" >> $fname
188   echo "  Distribution: $distribution" >> $fname
189   echo "  License: $license" >> $fname
190   echo "*/" >> $fname
191   echo >> $fname
192   echo "#ifndef _"$DP"_DISTDEFS_H" >> $fname
193   echo "#define _"$DP"_DISTDEFS_H" >> $fname
194   echo >> $fname
195
196   for i in $distdefs
197   do
198     echo "#define $i 1" >>$fname
199   done
200
201   echo >> $fname
202   echo "#endif /* _"$DP"_DISTDEFS_H */" >> $fname
203
204   ad_debug "<ad_create_distdefs_h"
205 }
206
207 #
208 # Creates the main configure script for the distribution.  This runs
209 # the aclocal, autoheader and autoconf tools.
210 #
211 # Arguments: ad_make_configure
212 #
213 ad_make_configure()
214 {
215   ad_debug ">ad_make_configure"
216   local run_autoconf=false
217
218   rm -f configure
219
220   if test "$ACLOCAL"; then
221     ad_debug "Running aclocal"
222     $ACLOCAL 1>/dev/null 2>/dev/null
223     if test $? != 0; then
224       ad_fatal "aclocal failed"
225     fi
226   fi
227
228   if test "$AUTOCONF"; then
229     ad_debug "Running autoconf"
230     $AUTOCONF
231     if test $? != 0; then
232       ad_fatal "autoconf failed"
233     fi
234     run_autoconf=true
235   fi
236
237   if test "$AUTOHEADER"; then
238     ad_debug "Running autoheader"
239     $AUTOHEADER
240     if test $? != 0; then
241       ad_fatal "autoheader failed"
242     fi
243   fi
244
245   if test "$LIBTOOLIZE"; then
246     ad_debug "Running libtoolize"
247     $LIBTOOLIZE
248     if test $? != 0; then
249       ad_fatal "libtoolize failed"
250     fi
251   fi
252
253   if test x$run_autoconf = xtrue; then
254     if test '!' -f configure; then
255       ad_fatal "creating configure script failed"
256     fi
257   fi
258
259   ad_debug "<ad_make_configure"
260 }
261
262 #
263 # Creates the configure.ac script from the configure.ad fragments in
264 # the source tree.  Takes the source configure file as argument which
265 # is used to create the actual configure.ac.
266 #
267 # Arguments: ad_make_configure_ac <configure_ac_source>
268 #
269 ad_make_configure_ac()
270 {
271   ad_debug ">ad_make_configure_ac: $1"
272
273   if test '!' -f $1; then
274     ad_fatal "The configure file '$1' does not exist"
275   fi
276
277   local check="`cat $1 | sed 's/^[      ]*//' | grep -v "^#" | grep -e "AD_INIT"`"
278   if test -z $check; then
279     rm -f configure.ad.cfs
280     rm -f $fname $fname.tmp
281     ad_fatal "The 'AD_INIT' macro has not been set in configure.ac"
282   fi
283
284   rm -f configure.ac configure.ad.cfs
285
286   cfs=`find . -name configure\*\.ad`
287   for i in $cfs
288   do
289     if test "x$i" = "x$1"; then
290       continue
291     fi
292     ad_debug "including $i"
293     cat $i >> configure.ad.cfs
294   done
295
296   if test -f configure.ad.cfs; then
297     local check="`cat $1 | sed 's/^[    ]*//' | grep -v "^#" | grep -e "AD_INCLUDE_CONFIGURE"`"
298     if test -z $check; then
299       rm -f configure.ad.cfs
300       ad_warning "configure.ad fragments found but 'AD_INCLUDE_CONFIGURE' is not set"
301     fi
302   fi
303
304   # Header for configure.ac
305   fname="configure.tmp.ac"
306   echo "# Automatically generated by Autodist $ver.  Do not edit." > $fname
307   echo "# To make changes edit the $i file in the source tree." >> $fname
308   echo >> $fname
309   echo "# Source: $i" >> $fname
310   echo "# Generated: `date` by `whoami`" >> $fname
311   echo "# Distribution: $distribution" >> $fname
312   echo "# License: $license" >> $fname
313   echo >> $fname
314
315   ad_debug "creating configure.ac"
316   if test -f configure.ad.cfs; then
317     sed '/AD_INCLUDE_CONFIGURE/ r configure.ad.cfs' $1 > $fname.tmp
318     sed -e "/AD_INCLUDE_CONFIGURE/s///" $fname.tmp >> $fname
319     rm -f configure.ad.cfs $fname.tmp
320   else
321     cat $1 >> $fname.tmp
322   fi
323
324   # Process AD_INIT
325   sed -e "/AD_INIT/s//AC_INIT([$distribution], [$dist_version], [$bug_report], [$package])/" $fname > $fname.tmp
326
327   # Process for distribution
328   rm -f $fname
329   ad_process_file $fname.tmp $fname
330
331   # Remove any trailing backslashes
332   if test -f "$fname"; then
333     cat $fname | sed -e :a -e '/\\$/N; s/\\\n//; ta' > configure.ac
334   else
335     cp -p $fname.tmp configure.ac
336   fi
337   rm -f $fname $fname.tmp
338
339   ad_debug "<ad_make_configure_ac: $1"
340 }
341
342 #
343 # Creates the Makefile.in files by running the automake tool.
344 #
345 # Arguments: ad_make_makefile_ins
346 #
347 ad_make_makefile_ins()
348 {
349   ad_debug ">ad_make_makefile_ins"
350
351   if test "$AUTOMAKE"; then
352     ad_debug "Running automake"
353     $AUTOMAKE
354     if test $? != 0; then
355       ad_fatal "automake failed"
356     fi
357   fi
358
359   ad_debug "<ad_make_makefile_ins"
360 }
361
362 #
363 # Creates the Makefile.am files from the Makefile.ad files in the
364 # source tree.  This runs the distribution specific processing for the
365 # Makefile.ad files.
366 #
367 # Arguments: ad_make_makefile_ams
368 #
369 ad_make_makefile_ams()
370 {
371   ad_debug ">ad_make_makefile_ams"
372
373   files=`find . -name Makefile\.ad`
374   for ff in $files
375   do
376     fname=`echo $ff | sed s/\.ad//`
377
378     # Header for the Makefile.am
379     echo "# Automatically generated by Autodist $ver from Makefile.ad.  Do not edit." > $fname.am
380     echo "# To make changes edit the $ff file in the source tree." >> $fname.am
381     echo >> $fname.am
382     echo "# Source: $ff" >> $fname.am
383     echo "# Generated: `date` by `whoami`" >> $fname.am
384     echo "# Distribution: $distribution" >> $fname.am
385     echo "# License: $license" >> $fname.am
386     echo >> $fname.am
387
388     # Run the distribution processing for this Makefile.ad
389     ad_debug "Processing $ff to be $fname.am"
390     ad_process_file $ff $fname.tmp
391
392     # Remove any trailing backslashes
393     if test -f "$fname.tmp"; then
394       cat $fname.tmp | sed -e :a -e '/\\$/N; s/\\\n//; ta' >> $fname.am
395     else
396       cat $ff >> $fname.am
397     fi
398
399     rm -f $fname.tmp
400   done
401
402   ad_debug "<ad_make_makefile_ams"
403 }
404
405 #
406 # Processes all files with .ad suffix, with exception of configure*.ad
407 # and Makefile.ad files, for distribution from the source tree.
408 #
409 # Arguments: ad_process_ads
410 #
411 ad_process_ads()
412 {
413   ad_debug ">ad_process_ads"
414
415   files=`find . -name \*\.ad \! -name configure\*\.ad \! -name Makefile\.ad`
416   for i in $files
417   do
418     fname=`echo $i | sed s/\.ad//`
419
420     # Header
421     echo "# Automatically generated by Autodist $ver.  Do not edit." > $fname
422     echo "# To make changes edit the $i file in the source tree." >> $fname
423     echo >> $fname
424     echo "# Source: $i" >> $fname
425     echo "# Generated: `date` by `whoami`" >> $fname
426     echo "# Distribution: $distribution" >> $fname
427     echo "# License: $license" >> $fname
428     echo >> $fname
429
430     # Run the distribution processing for this file
431     ad_debug "Processing $i to be $fname"
432     ad_process_file $i $fname
433   done
434
435   ad_debug "<ad_process_ads"
436 }
437
438 #
439 # Includes files specified in the distribution for inclusion.  Used when
440 # creating the distribution for packaging.
441 #
442 # include has the following format in distfile:
443 #
444 #   include <path> [<dest path>]
445 #
446 # If only source path, which may be file, directory or regular expression,
447 # is specified the path will be same in distribution.  If the destination
448 # path is specified that will be the new name and/or new location of the
449 # source path.  This, in effect, is a cp utility with ability to create
450 # directories if they do not exist.
451 #
452 # Arguments: ad_dist_includes <includeslist> <recursive>
453 #
454 ad_dist_includes()
455 {
456   ad_debug ">ad_dist_includes: $1 $2"
457
458   # By default do not expand pathnames
459   set -f
460
461   # Add : separator at the end
462   local incs="`echo "$1" | sed 's/$/ : /'`"
463
464   src=
465   dst=
466   for i in $incs
467   do
468     if test "$i" = ":" && test -z "$src"; then
469       continue
470     fi
471     if test -z "$src"; then
472       src=$i
473       continue
474     fi
475     if test -z "$dst" && test "$i" != ":"; then
476       dst=$i
477     else
478       dst=$src
479     fi
480
481     ad_debug "Including $src into $dst"
482
483     if test -f "$src"; then
484       # Add file
485
486       if test "$src" = "$dst"; then
487         # Add to same location
488         d=`echo $src | sed 's,/[^/]*$,,'`
489         if test "$d" != "$src" && test "$d" != "." && \
490            test '!' -d $am_distdir/$d; then
491           mkdir -p $am_distdir/$d || exit 1
492         fi
493       else
494         # Add to different location
495         check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
496         if test "$check" != "$dst"; then
497           ad_fatal "Invalid destination in 'include $src $dst'"
498         fi
499
500         d=`echo $dst | sed 's,/[^/]*$,,'`
501         if test "$d" != "$dst" && test "$d" != "." && \
502            test '!' -d $am_distdir/$d; then
503           mkdir -p $am_distdir/$d || exit 1
504         fi
505       fi
506
507       cp -p $src $am_distdir/$d || exit 1
508
509     elif test -d "$src"; then
510       # Add directory
511
512       if test "$src" = "$dst"; then
513         # Add to same location
514         d=`echo $src | sed 's,/[^/]*$,,'`
515         ds=`echo $src | sed 's/\/$//'`
516         if test "$ds" = "$d"; then
517           d=`echo $d | sed 's,/[^/]*$,,'`
518         fi
519         if test '!' -d $am_distdir/$d && test "$ds" != "$d"; then
520           mkdir -p $am_distdir/$d || exit 1
521         fi
522
523         cp -pR $src $am_distdir/$d || exit 1
524       else
525         # Add to different location
526         check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
527         if test "$check" != "$dst"; then
528           ad_fatal "Invalid destination in 'include $src $dst'"
529         fi
530
531         d=`echo $dst | sed 's,/[^/]*$,,'`
532         ds=`echo $dst | sed 's/\/$//'`
533         if test "$ds" = "$d"; then
534           d=`echo $d | sed 's,/[^/]*$,,'`
535         fi
536         if test '!' -d $am_distdir/$d && test "$dst" != "$d"; then
537           mkdir -p $am_distdir/$d || exit 1
538         fi
539
540         cp -pR $src $am_distdir/$dst || exit 1
541       fi
542
543     elif test x$2 != xtrue; then
544       # We assume regular expression in filename
545       check=`echo "$src" | sed 's/?//; s/*//; s/\[//; s/\]//'`
546       if test "$check" == "$src"; then
547         if test '!' -a $src; then
548           ad_fatal "Including $src: No such file or directory"
549         fi
550         src=
551         dst=
552         continue
553       fi
554
555       # Recursively call this function with expanded pathnames.  The
556       # reason why we don't let sh by default expand patnames is that
557       # the include's destination is optional.  If sh expands by default
558       # we don't know the destination.  For this reason, we handle the
559       # expansion here ourselves.
560
561       # If src and dst are same, then expand the pathname as we'll copy
562       # matches to their own locations.
563       if test "$src" = "$dst"; then
564         # Expand pathnames, and format to our include format
565         set +f
566         srcs=`echo $src | sed -e 's/ / : /g' -e 's/^/ : /'` || exit 1
567         set -f
568       else
569         # Destination is new, and it has to be a directory.
570         check=`echo "$dst" | sed 's/?//; s/*//; s/\[//; s/\]//'`
571         if test "$check" != "$dst"; then
572           ad_fatal "Invalid destination in 'include $src $dst'"
573         fi
574
575         # Make sure dst has / at the end, as this must be a directory
576         dst=`echo $dst | sed 's/\/$//; s/$/\//'`
577
578         # Escape dst for sed
579         dste=`echo $dst | sed 's/\\//\\\\\//g'` || exit 1
580
581         # Expand pathnames, and format to our include format
582         set +f
583         srcs=`echo $src | sed -e "s/ / $dste : /g" \
584           -e 's/^/ : /' -e "s/$/ $dste/"` || exit 1
585         set -f
586       fi
587
588       # Include recursively
589       ad_dist_includes "$srcs" true
590
591     elif test '!' -a $src; then
592       ad_fatal "Including $src: No such file or directory"
593     fi
594
595     src=
596     dst=
597   done
598
599   set +f
600
601   ad_debug "<ad_dist_includes: $1 $2"
602 }
603
604 #
605 # Excludes files specified in the distribution for exclusion.  Used when
606 # creating the distribution for packaging.
607 #
608 # exclude has the following format in distfile:
609 #
610 #  exclude <path>
611 #
612 # The path may be file, directory or regular expression.
613 #
614 # Arguments: ad_dist_includes <excludelist>
615 #
616 ad_dist_excludes()
617 {
618   ad_debug ">ad_dist_excludes: $1"
619
620   for i in $1
621   do
622     ad_debug "Excluding $i"
623     rm -rf $am_distdir/$i
624   done
625
626   ad_debug "<ad_dist_excludes: $1"
627 }
628
629 #
630 # Processes the entire tree for distribution.  This inspects files other
631 # than source and header files, with exception of any file with .ad
632 # suffix, and performs distribution processing for the file.  The original
633 # file is replaced with the processed file.  This function is used when
634 # creating the distribution for packaging.
635 #
636 # Arguments: ad_process_tree <directory>
637 #
638 ad_process_tree()
639 {
640   ad_debug ">ad_process_tree: $1"
641
642   # We take all files, other than *.ad, including source files, in case
643   # they use the non-C-compiler-friendly format of distdefs, which is
644   # possible.
645
646   files=`find $am_distdir \! -name \*\.ad`
647   files=`echo $files | sed 's/$am_distdir//'`
648
649   # Take away noprocess list
650   if test -f autodist.noprocess; then
651     files=`echo $files | sh autodist.noprocess` || exit 1
652   fi
653
654   for ff in $files
655   do
656     ad_process_file $ff $ff.tmp
657     if test -f $ff.tmp; then
658       rm -f $ff || exit 1
659       mv -f $ff.tmp $ff || exit 1
660     fi
661   done
662
663   ad_debug "<ad_process_tree: $1"
664 }
665
666 #
667 # Processes the entire source tree for distribution.  This inspects files
668 # in the source tree, with exception of any file with .ad suffix, and
669 # performs distribution processing for the file.  The original file is
670 # replaced with the processed file.  This function is used when creating
671 # the distribution for packaging.
672 #
673 # Call this before ad_process_tree().
674 #
675 # Arguments: ad_process_source_tree <directory>
676 #
677 ad_process_source_tree()
678 {
679   ad_debug ">ad_process_source_tree: $1"
680
681   # We take only C/C++ files since they use the C compiler friendly
682   # version of distdefs.  Other files are not assumed to use them.
683   files=`find $am_distdir \! -name \*\.ad \( \
684         -name \*\.[cC] -o \
685         -name \*\.[cC][cCpP] -o \
686         -name \*\.[cC][xX][xX] -o \
687         -name \*\.[cC][pP][pP] -o \
688         -name \*\.[cC]++ -o \
689         -name \*\.m -o \
690         -name \*\.[hH] -o \
691         -name \*\.hh \)`
692
693   # Take away noprocess list
694   if test -f autodist.noprocess; then
695     files=`echo $files | sh autodist.noprocess` || exit 1
696   fi
697
698   for ff in $files
699   do
700     ad_process_source_file $ff $ff.tmp
701     if test -f $ff.tmp; then
702       rm -f $ff || exit 1
703       mv -f $ff.tmp $ff || exit 1
704     fi
705   done
706
707   ad_debug "<ad_process_source_tree: $1"
708 }
709
710 #
711 # Makes distribution sane, ala modtimes.  Since we modify the distribution
712 # we need to make it sane after that.
713 #
714 # Arguments: ad_makedist_makesane
715 #
716 ad_makedist_makesane()
717 {
718   ad_debug ">ad_makedist_makesane:"
719
720   # DO NOT change these order unless you know what you are doing.
721   if test -f $am_distdir/configure.ac; then
722     touch $am_distdir/configure.ac
723   fi
724
725   if test -f $am_distdir/aclocal.m4; then
726     touch $am_distdir/aclocal.m4
727   fi
728
729   if test '!' -f Makefile; then
730     ad_fatal "Makefile: No such file or directory"
731   fi
732
733   configh=`grep "^CONFIG_HEADER" Makefile | cut -d= -f2 | sed 's/^[ \t]//'`
734   touch $am_distdir/$configh.in 1>/dev/null 2>/dev/null
735
736   files=`find $am_distdir -name Makefile\.in`
737   for i in $files
738   do
739     touch $i
740   done
741
742   if test -f $am_distdir/configure; then
743     touch $am_distdir/configure
744   fi
745
746   if test -f $am_distdir/config.status; then
747     touch $am_distdir/config.status
748   fi
749
750   ad_debug "<ad_makedist_makesane:"
751 }
752
753 #
754 # Creates distribution of the source tree.  All files in the distribution
755 # will be processed and the distribution will be packaged.
756 #
757 # Arguments: ad_makedist
758 #
759 ad_makedist()
760 {
761   ad_debug ">ad_makedist"
762
763   if test '!' -f autodist.dist; then
764     ad_fatal "Autodist has not been run yet to prepare source tree"
765   fi
766
767   if test -z $MAKE; then
768     ad_fatal "The MAKE variable is not set in autodist.conf"
769   fi
770
771   # Get distdir from Makefile
772   if test '!' -f Makefile; then
773     ad_fatal "The source tree is not configured, run ./configure first"
774   fi
775
776   # Parse the requested distribution
777   distribution=`cat autodist.dist | grep "dist:" | cut -d: -f2`
778   dist_version=`cat autodist.dist | grep "ver:" | cut -d: -f2`
779   ad_parse_distribution $distribution false
780   ad_process_distdefs
781   am_distdir="$package-$dist_version"
782
783   if test x$opt_no_dist = xtrue; then
784     ad_fatal "The '$distribution' distribution cannot be packaged"
785   fi
786
787   # Create distribution directory
788   ad_debug "Creating distribution directory $am_distdir"
789   $MAKE distdir || exit 1
790   chmod -R a+r $am_distdir
791
792   if test '!' -d $am_distdir; then
793     ad_fatal "Distribution directory $am_distdir not created"
794   fi
795
796   # Run pre-dist-hooks
797   ad_run_dist_hooks "$pre_dist_hooks"
798
799   # Run excludes
800   ad_dist_excludes "$excludes"
801
802   # Run includes
803   ad_dist_includes "$includes"
804
805   # Include specific license file if specified
806   if test "$license" != ""; then
807     cp -p $license $am_distdir/COPYING || exit 1
808   fi
809
810   # Process noprocesses
811   ad_process_noprocess
812
813   # Process source files
814   ad_debug "Process distribution source tree"
815   ad_process_source_tree $am_distdir
816
817   # Process non-source files
818   ad_debug "Process distribution tree"
819   ad_process_tree $am_distdir
820
821   # Run post-dist-hooks
822   ad_run_dist_hooks "$post_dist_hooks"
823
824   # Make distribution sane
825   ad_makedist_makesane
826
827   # Package
828   ad_debug "Packaging distribution"
829   tar chof $am_distdir.tar $am_distdir || exit 1
830
831   # Compress
832   ad_debug "Compressing distribution package"
833   if test x$ad_gzip = xtrue; then
834     gzip -9 -c $am_distdir.tar > $am_distdir.tar.gz || exit 1
835   fi
836   if test x$ad_bzip2 = xtrue; then
837     bzip2 -9 -c $am_distdir.tar > $am_distdir.tar.bz2 || exit 1
838   fi
839   if test x$ad_compress = xtrue; then
840     compress -c $am_distdir.tar > $am_distdir.tar.Z || exit 1
841   fi
842   if test x$ad_zip = xtrue; then
843     rm -f $am_distdir.zip
844     zip -rq $am_distdir.zip $am_distdir || exit 1
845   fi
846   rm -f $am_distdir.tar
847
848   # Cleanup
849   rm -rf $am_distdir
850   rm -f autodist.noprocess
851
852   ad_debug "<ad_makedist"
853 }
854
855 #
856 # Handles distribution options.
857 #
858 # option has the following format in distfile:
859 #
860 #   option <option>
861 #
862 # Following options are supported:
863 #
864 #   template
865 #   no-dist
866 #   no-inherit
867 #
868 # Arguments: ad_handle_options <options>
869 #
870 ad_handle_options()
871 {
872   ad_debug ">ad_handle_options: $1"
873
874   for i in $1
875   do
876     if test "$i" = "template"; then
877       opt_template=true
878       continue
879     elif test "$i" = "no-dist"; then
880       opt_no_dist=true
881       continue
882     elif test "$i" = "no-inherit"; then
883       opt_no_inherit=true
884       continue
885     fi
886   done
887
888   ad_debug "<ad_handle_options: $1"
889 }
890
891 #
892 # Clears set options
893 #
894 # Arguments: ad_clear_options
895 #
896 ad_clear_options()
897 {
898   ad_debug ">ad_clear_options"
899   opt_template=false
900   opt_no_dist=false
901   opt_no_inherit=false
902   ad_debug "<ad_clear_options"
903 }
904
905 #
906 # Parses the distribution.  Gets all distribution defines from the
907 # distribution.  This also expands all inherited distributions recursively
908 # to get all inherited distribution defines.  From inherited distributions
909 # their name and package name is not inherited.
910 #
911 # Arguments: ad_parse_distribution <distribution name> <inherit>
912 #
913 ad_parse_distribution()
914 {
915   ad_debug ">ad_parse_distribution: $1 $2"
916
917   if test '!' -f $distdir/$1; then
918     ad_fatal "Distribution '$1' is not declared"
919   fi
920
921   # Get inherited
922   local inhs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
923     | grep "inherit " | cut -d' ' -f2 | sort | uniq`
924
925   # Get distdefs
926   local defs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
927    | grep "define " | cut -d' ' -f2 | sort | uniq`
928
929   if test "$inhs" = "" && test "$defs" = ""; then
930     ad_fatal "Distribution '$1' does not define anything"
931   fi
932
933   # Get undefined distdefs
934   local undefs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
935    | grep "undef " | cut -d' ' -f2 | sort | uniq`
936
937   # Get includes
938   local incs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
939     | grep "include " | sed 's/include / : /'`
940
941   # Get excludes
942   local excs=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
943     | grep "exclude " | cut -d' ' -f2- | sort | uniq`
944
945   # Get noprocesses
946   local nops=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
947     | grep "noprocess " | cut -d' ' -f2- | sort | uniq`
948
949   # Get options
950   local opts=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
951     | grep "option " | cut -d' ' -f2- | sort | uniq`
952
953   # Check options
954   ad_handle_options "$opts"
955   if test x$2 = xtrue && test x$opt_no_inherit = xtrue; then
956     ad_fatal "Distribution '$1' cannot be inherited"
957   fi
958   if test x$2 = xfalse && test x$opt_template = xtrue; then
959     ad_fatal "Template distribution '$1' cannot be prepared or packaged"
960   fi
961
962   ad_debug "inherits=$inhs"
963   ad_debug "distdefs=$defs"
964   ad_debug "includes=$incs"
965   ad_debug "excludes=$excs"
966   ad_debug "noprocess=$nops"
967   ad_debug "undistdefs=$undefs"
968   ad_debug "options=$opts"
969
970   # Expand distdefs from inherited distributions
971   for i in $inhs
972   do
973     if test x$1 = x$i; then
974       ad_fatal "Infinite recursion detected.  Fix the '$distdir/$1' \
975             distribution to not have 'inherit $i' declared."
976     fi
977
978     if test '!' -f $distdir/$i; then
979       ad_fatal "Distribution '$i' is not declared (inherited from '$1')"
980     fi
981
982     ad_parse_distribution $i true
983     ad_clear_options
984   done
985
986   # Get license
987   license=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
988     | grep "license " | cut -d' ' -f2`
989   licenseh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
990     | grep "license-header " | sed 's/license-header / : /'`
991
992   ad_debug "license=$license"
993   ad_debug "licenseh=$licenseh"
994
995   if test x$2 = xfalse; then
996     # Get distribution name
997     local dname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
998       | grep "name " | cut -d' ' -f2-`
999
1000     if test "$dname"; then
1001       distribution=$dname
1002     fi
1003
1004     # Get distribution package name (optional)
1005     local dpname=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
1006      | grep "package " | cut -d' ' -f2`
1007
1008     if test "$dpname"; then
1009       package=$dpname
1010     else
1011       package=$distribution
1012     fi
1013
1014     # Get Bug-report email address (optional)
1015     local bugr=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
1016      | grep "bug-report " | cut -d' ' -f2-`
1017
1018     if test "$bugr"; then
1019       bug_report=$bugr
1020     fi
1021
1022     ad_debug "distribution=$distribution"
1023     ad_debug "package=$package"
1024     ad_debug "bug-report=$bug_report"
1025
1026     # Get hooks (optional)
1027     local prh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
1028      | grep "pre-hook " | cut -d' ' -f2-`
1029     local poh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
1030      | grep "post-hook " | cut -d' ' -f2-`
1031     local prdh=`cat $distdir/$1 | sed 's/^[       ]*//' | grep -v "^#" \
1032      | grep "pre-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
1033     local podh=`cat $distdir/$1 | grep -v "^#" \
1034      | grep "post-dist-hook " | sed 's/^[       ]*//' | cut -d' ' -f2-`
1035
1036     pre_hooks="$pre_hooks $prh"
1037     post_hooks="$post_hooks $poh"
1038     pre_dist_hooks="$pre_dist_hooks $prdh"
1039     post_dist_hooks="$post_dist_hooks $podh"
1040     options="$options $opts"
1041
1042     ad_handle_options "$options"
1043     ad_debug "options=$options"
1044   fi
1045
1046   # Return to caller
1047   inherits="$inherits $inhs"
1048   distdefs="$distdefs $defs"
1049   includes="$includes $incs"
1050   excludes="$excludes $excs"
1051   noprocess="$noprocess $nops"
1052   undistdefs="$undistdefs $undefs"
1053
1054   ad_debug "<ad_parse_distribution: $1 $2"
1055 }
1056
1057 #
1058 # Processes parsed distdefs.  Removes duplicates, and undefined distdefs
1059 # from the distdefs.
1060 #
1061 # Arguments: ad_process_distdefs
1062 #
1063 ad_process_distdefs()
1064 {
1065   ad_debug ">ad_process_distdefs"
1066
1067   # Remove all undefined distribution defines
1068   for i in $undistdefs
1069   do
1070     ad_debug "undefining $i distdef"
1071     distdefs=`echo $distdefs | sed s/$i//`
1072   done
1073
1074   rm -f autodist.tmp.defs autodist.pre.hooks autodist.post.hooks
1075   rm -f autodist.pre.dist.hooks autodist.post.dist.hooks
1076
1077   # Remove duplicate distdefs
1078   for i in $distdefs
1079   do
1080     echo $i >>autodist.tmp.defs
1081   done
1082   distdefs=`cat autodist.tmp.defs | sort | uniq`
1083   distdefs=`echo $distdefs`
1084   rm -f autodist.tmp.defs
1085
1086   ad_debug "distdefs=$distdefs"
1087
1088   ad_debug "<ad_process_distdefs"
1089 }
1090
1091 #
1092 # Processes for a license header change.
1093 #
1094 # Arguments: ad_process_license_header <scriptfile>
1095 #
1096 ad_process_license_header()
1097 {
1098   ad_debug ">ad_process_license_header"
1099
1100   # Add : separator at the end
1101   lics=`echo "$licenseh" | sed 's/$/ : /'`
1102
1103   src=
1104   dst=
1105   for i in $lics
1106   do
1107     if test "$i" = ":" && test -z "$src"; then
1108       continue
1109     fi
1110     if test -z "$src"; then
1111       src=$i
1112       continue
1113     fi
1114     if test -z "$dst" && test "$i" != ":"; then
1115       dst=$i
1116     else
1117       ad_fatal "Missing argument in 'license-header $src'"
1118     fi
1119
1120     ad_debug "Replacing $src license with $dst license"
1121
1122     if test '!' -f $src; then
1123       ad_fatal "License header $src: No such file or directory"
1124     fi
1125
1126     if test '!' -f $dst; then
1127       ad_fatal "License header $dst: No such file or directory"
1128     fi
1129
1130     # Awk script to replace the license header
1131     fl=`sed q $src | sed 's/\\//\\\\\//g' > autodist.lsrc` || exit 1
1132     ll=`sed -n '$p' $src | sed 's/\\//\\\\\//g' > autodist.ldst` || exit 1
1133     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
1134     rm -f autodist.lsrc autodist.ldst
1135
1136     src=
1137     dst=
1138   done
1139
1140   ad_debug "<ad_process_license_header"
1141 }
1142
1143 #
1144 # Process specified noprocesses.  This is called during makedist.
1145 #
1146 # Arguments: ad_process_noprocess
1147 #
1148 ad_process_noprocess()
1149 {
1150   ad_debug ">ad_process_noprocess"
1151   local np=false
1152
1153   local n="sed "
1154
1155   for i in $noprocess
1156   do
1157     # Escape
1158     ie=`echo $i | sed 's/\\//\\\\\//g'` || exit 1
1159
1160     n="$n -e 's/$am_distdir\\/$ie//'"
1161     np=true
1162   done
1163
1164   rm -f autodist.noprocess
1165   if test x$np = xtrue; then
1166     echo $n > autodist.noprocess || exit 1
1167   fi
1168
1169   ad_debug "<ad_process_noprocess"
1170 }
1171
1172 #
1173 # Process a file given as argument for the distribution.
1174 #
1175 # Arguments: ad_process_file <filepath> <dest_filepath>
1176 #
1177 ad_process_file()
1178 {
1179   local found=false
1180
1181   # Process only regular files
1182   if test '!' -f $1; then
1183     return
1184   fi
1185
1186   ad_debug ">ad_process_file: $1 $2"
1187
1188   local f="autodist.tmp.script"
1189   rm -f $f
1190
1191   # If license header is provided, replace the license header in the file.
1192   ad_process_license_header $f
1193
1194   ad_debug "Getting #ifdef's and #ifndef's"
1195
1196   # Get defined distribution defines
1197   local defs=`awk "/^#ifdef "$DP"_DIST_|^#else "$DP"_DIST_/ { print; }" \
1198     $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1199
1200   # Get explicitly not-defined distribution defines
1201   local ndefs=`awk "/^#ifndef "$DP"_DIST_|^#else !"$DP"_DIST_/ { print; }" \
1202     $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1203
1204   ad_debug "defs=$defs"
1205   ad_debug "ndefs=$ndefs"
1206
1207   # Create the script to include and exclude stuff in the file according
1208   # to the distribution defines
1209
1210   # ifdefs
1211   ad_debug "processing ifdefs"
1212   for d in $defs
1213   do
1214     found=false
1215     for i in $distdefs
1216     do
1217       if test x$d = x$i; then
1218         found=true
1219         break
1220       fi
1221     done
1222
1223     # If distribution define was not found exclude those lines from the file.
1224     # This also handles the #ifdef's #else (ie. #ifndef) branch.
1225     if test x$found = xfalse; then
1226       ad_debug "ifdef $d will be excluded (it is NOT defined)"
1227       echo "/^#ifdef $d/,/^#else !$d|^#endif $d/ { next; }" >> $f
1228     else
1229       echo "/^#else !$d/,/^#endif $d/ { next; }" >> $f
1230     fi
1231   done
1232
1233   # ifndefs
1234   ad_debug "processing ifndefs"
1235   for d in $ndefs
1236   do
1237     found=false
1238     for i in $distdefs
1239     do
1240       if test x$d = x$i; then
1241         found=true
1242         break
1243       fi
1244     done
1245
1246     # If distribution define was found exclude those lines from the file.
1247     # This also handles the #ifndef's #else (ie. #ifdef) branch.
1248     if test x$found = xtrue; then
1249       ad_debug "ifndef $d will be excluded (it IS defined)"
1250       echo "/^#ifndef $d/,/^#else $d|^#endif $d/ { next; }" >> $f
1251     else
1252       echo "/^#else $d/,/^#endif $d/ { next; }" >> $f
1253     fi
1254   done
1255
1256   # Now process the file with the script
1257   if test -f $f; then
1258
1259     # Those distdef lines that remain in the file are removed to make
1260     # the appearance prettier
1261     echo "/^#ifdef "$DP"_DIST_|^#endif "$DP"_DIST_|^#else "$DP"_DIST_|^#else !"$DP"_DIST_|^#ifndef "$DP"_DIST_/ { next; }" >> $f
1262     echo "{ print; }" >> $f
1263
1264     # Execute the script
1265     cp -p $1 $2 || exit 1
1266     awk -f $f $1 > $2 || exit 1
1267   fi
1268
1269   rm -f $f
1270
1271   ad_debug "<ad_process_file: $1 $2"
1272 }
1273
1274 #
1275 # Process a source file given as argument for the distribution.
1276 #
1277 # Arguments: ad_process_source_file <filepath> <dest_filepath>
1278 #
1279 ad_process_source_file()
1280 {
1281   local found=false
1282
1283   # Process only regular files
1284   if test '!' -f $1; then
1285     return
1286   fi
1287
1288   ad_debug ">ad_process_source_file: $1 $2"
1289
1290   local f="autodist.tmp.script"
1291   rm -f $f
1292
1293   # If license header is provided, replace the license header in the file.
1294   ad_process_license_header $f
1295
1296   ad_debug "Getting #ifdef's and #ifndef's"
1297
1298   # Get defined distribution defines
1299   local defs=`awk '/^#ifdef SILC_DIST_|^#else \/\* SILC_DIST_/ { print; }' \
1300     $1 |cut -d'*' -f2 |cut -d' ' -f2 | sort | uniq`
1301
1302   # Get explicitly not-defined distribution defines
1303   local ndefs=`awk '/^#ifndef SILC_DIST_|^#else \/\* \!SILC_DIST_/ { print; }' \
1304     $1 |cut -d'*' -f2 |cut -d' ' -f2 | cut -d'!' -f2 | sort | uniq`
1305
1306   ad_debug "defs=$defs ndefs=$ndefs"
1307
1308   # Create the script to include and exclude stuff in the file according
1309   # to the distribution defines
1310
1311   # ifdefs
1312   ad_debug "processing ifdefs"
1313   for d in $defs
1314   do
1315     found=false
1316     for i in $distdefs
1317     do
1318       if test x$d = x$i; then
1319         found=true
1320         break
1321       fi
1322     done
1323
1324     # If distribution define was not found exclude those lines from the file.
1325     # This also handles the #ifdef's #else (ie. #ifndef) branch.
1326     if test x$found = xfalse; then
1327       ad_debug "ifdef $d will be excluded (it is NOT defined)"
1328       echo "/^#ifdef $d/,/^#else \/\* \!$d|^#endif \/\* $d/ { next; }" >> $f
1329     else
1330       echo "/^#else \/\* \!$d/,/^#endif \/\* $d/ { next; }" >> $f
1331     fi
1332   done
1333
1334   # ifndefs
1335   ad_debug "processing ifndefs"
1336   for d in $ndefs
1337   do
1338     found=false
1339     for i in $distdefs
1340     do
1341       if test x$d = x$i; then
1342         found=true
1343         break
1344       fi
1345     done
1346
1347     # If distribution define was found exclude those lines from the file.
1348     # This also handles the #ifndef's #else (ie. #ifdef) branch.
1349     if test x$found = xtrue; then
1350       ad_debug "ifndef $d will be excluded (it IS defined)"
1351       echo "/^#ifndef $d/,/^#else \/\* $d|^#endif \/\* $d/ { next; }" >> $f
1352     else
1353       echo "/^#else \/\* $d/,/^#endif \/\* $d/ { next; }" >> $f
1354     fi
1355   done
1356
1357   # Now process the file with the script
1358   if test -f $f; then
1359
1360     # Those distdef lines that remain in the file are removed to make
1361     # the appearance prettier
1362     echo "/^#ifdef SILC_DIST_|^#endif \/\* SILC_DIST_|^#else \/\* SILC_DIST_|^#else \/\* \!SILC_DIST_|^#ifndef SILC_DIST_/ { next; }" >> $f
1363     echo "{ print; }" >> $f
1364
1365     # Execute the script
1366     cp -p $1 $2 || exit 1
1367     awk -f $f $1 > $2 || exit 1
1368   fi
1369
1370   rm -f $f
1371
1372   ad_debug "<ad_process_source_file: $1 $2"
1373 }
1374
1375 #
1376 # Run hooks
1377 #
1378 # Arguments: ad_run_hooks <hooks>
1379 #
1380 ad_run_hooks()
1381 {
1382   ad_debug ">ad_run_hooks: $1"
1383
1384   for i in $1
1385   do
1386     if test '!' -f $i; then
1387       ad_fatal "Hook script $i does not exist"
1388     fi
1389     sh $i $distribution $dist_version $package || exit 1
1390   done
1391
1392   ad_debug "<ad_run_hooks: $1"
1393 }
1394
1395 #
1396 # Run dist hooks
1397 #
1398 # Arguments: ad_run_dist_hooks <hooks>
1399 #
1400 ad_run_dist_hooks()
1401 {
1402   ad_debug ">ad_run_dist_hooks: $1"
1403
1404   for i in $1
1405   do
1406     if test '!' -f $i; then
1407       ad_fatal "Dist hook script $i does not exist"
1408     fi
1409     sh $i $distribution $dist_version $package $am_distdir || exit 1
1410   done
1411
1412   ad_debug "<ad_run_dist_hooks: $1"
1413 }
1414
1415 ###############################################################################
1416 # Autodist code
1417
1418 usage="Usage: autodist [options] [distribution] [version]"
1419 help="\
1420 Autodist prepares source tree for configuration, compilation and
1421 distribution.  Prepares the source tree from the \`autodist.ad'
1422 configuration file.  Generates Automake.am files from Automake.ad
1423 files, configure.ac file from configure.ad file(s), generates the
1424 configure script by running Autoconf tool, and generates Makefile.in
1425 files by running Automake tool.
1426
1427 Operation modes:
1428   -h, --help                print this help, then exit
1429   -V, --version             print version number, then exit
1430   -v, --verbose             verbosely report processing
1431   -d, --distdir <dir>       search distributions from <dir>
1432   -s, --distdefs [<dist>]   print distribution defines of <dist>, then exit
1433   -i, --init                initialize Autodist environment, create default
1434                             distribution directory and distribution, then exit
1435   -m, --makedist            create and package distribution
1436       --gzip                create package compressed with gzip (default)
1437       --bzip2               create also package compressed with bzip2
1438       --compress            create also package compressed with compress
1439       --zip                 create also package compressed with zip"
1440
1441 #
1442 # Process command line arguments
1443 #
1444 while test $# -gt 0; do
1445   case "${1}" in
1446
1447   -d |--distdir)
1448     shift;
1449     test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
1450     distdir="${1}";
1451     shift;;
1452
1453   --list)
1454     exit 0;;
1455
1456   -s | --distdefs)
1457     shift;
1458     if test $# -eq 0; then
1459       ad_parse_distribution $distribution false
1460       echo "Distribution: ${distribution}" 1>&2;
1461     else
1462       ad_parse_distribution $1 false
1463       echo "Distribution: ${1}" 1>&2;
1464     fi
1465     ad_process_distdefs
1466     echo "Distdefs:" 1>&2;
1467     echo "${distdefs}";
1468     exit 0;;
1469
1470   -i | --init)
1471     ad_initialize;
1472     exit 0;;
1473
1474   -m | --makedist)
1475     ad_makedist
1476     exit 0;;
1477
1478   --gzip)
1479     ad_gzip=true
1480     shift;;
1481
1482   --bzip2)
1483     ad_bzip2=true
1484     shift;;
1485
1486   --compress)
1487     ad_compress=true
1488     shift;;
1489
1490   --zip)
1491     ad_zip=true
1492     shift;;
1493
1494   -v | --verbose)
1495     debug=true
1496     shift;;
1497
1498   -h | --help | --h*)
1499     echo "${usage}" 1>&2;
1500     echo 1>&2;
1501     echo "${help}" 1>&2;
1502     echo 1>&2;
1503     exit 0;;
1504
1505   -V | --version)
1506     echo "@PACKAGE@ (@PACKAGE_NAME@) $ver" 1>&2;
1507     echo "Written by Pekka Riikonen" 1>&2;
1508     echo 1>&2;
1509     echo "Copyright (C) 2004 - 2005 SILC Project" 1>&2;
1510     echo "\
1511 This is free software; see the source for copying conditions.  There is NO
1512 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " 1>&2;
1513     exit 0;;
1514
1515   --)
1516     shift;
1517     break;;
1518
1519   -*)
1520     echo "${usage}" 1>&2;
1521     exit 1;;
1522
1523   *)
1524     break;;
1525
1526   esac
1527 done
1528
1529 #
1530 # Parse the requested distribution
1531 #
1532 if test $# != 0; then
1533   distribution="${1}";
1534   distfile=$distribution
1535   shift
1536 fi
1537 ad_parse_distribution $distribution false
1538 ad_process_distdefs
1539
1540 if test $# != 0; then
1541   dist_version="${1}";
1542 fi
1543
1544 ad_debug "Preparing source tree for configuration and compilation..."
1545 ad_debug "Preparing $distribution distribution version $dist_version"
1546
1547 #
1548 # Create the distribution defines header file
1549 #
1550 if test "$DISTDEFS"; then
1551   ad_create_distdefs_h
1552 else
1553   ad_fatal "DISTDEFS not defined in $distdir/autodist.conf"
1554 fi
1555
1556 #
1557 # Run pre-hooks
1558 #
1559 ad_run_hooks "$pre_hooks"
1560
1561 #
1562 # Generate the Makefile.am files from Makefile.ad files
1563 #
1564 ad_make_makefile_ams
1565
1566 #
1567 # Generate the configure.ac from configure.ad file(s)
1568 #
1569 ad_make_configure_ac ./configure.ad
1570
1571 #
1572 # Generate configure script
1573 #
1574 ad_make_configure
1575
1576 #
1577 # Generate Makefile.in files
1578 #
1579 ad_make_makefile_ins
1580
1581 #
1582 # Process all files with .ad suffix for distribution processing
1583 #
1584 ad_process_ads
1585
1586 #
1587 # Create autodist.dist
1588 #
1589 ad_debug "Creating autodist.dist"
1590 echo "dist:$distfile" > autodist.dist
1591 echo "ver:$dist_version" >> autodist.dist
1592 echo "$package-$dist_version" >> autodist.dist
1593
1594 #
1595 # Run post-hooks
1596 #
1597 ad_run_hooks "$post_hooks"
1598
1599 ad_debug "Done, now run ./configure and make."
1600 exit 0