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