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