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