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