7a9c5ef78a3db01c8c592c201254863e2e8da4ae
[platform/core/uifw/at-spi2-atk.git] / autogen.sh
1 #!/bin/sh
2 #                        a u t o g e n . s h
3 #
4 # Copyright (c) 2005-2007 United States Government as represented by
5 # the U.S. Army Research Laboratory.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 #
14 # 2. Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 #
19 # 3. The name of the author may not be used to endorse or promote
20 # products derived from this software without specific prior written
21 # permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #
35 ###
36 #
37 # Script for automatically preparing the sources for compilation by
38 # performing the myrid of necessary steps.  The script attempts to
39 # detect proper version support, and outputs warnings about particular
40 # systems that have autotool peculiarities.
41 #
42 # Basically, if everything is set up and installed correctly, the
43 # script will validate that minimum versions of the GNU Build System
44 # tools are installed, account for several common configuration
45 # issues, and then simply run autoreconf for you.
46 #
47 # If autoreconf fails, which can happen for many valid configurations,
48 # this script proceeds to run manual preparation steps effectively
49 # providing a POSIX shell script (mostly complete) reimplementation of
50 # autoreconf.
51 #
52 # The AUTORECONF, AUTOCONF, AUTOMAKE, LIBTOOLIZE, ACLOCAL, AUTOHEADER
53 # environment variables and corresponding _OPTIONS variables (e.g.
54 # AUTORECONF_OPTIONS) may be used to override the default automatic
55 # detection behaviors.  Similarly the _VERSION variables will override
56 # the minimum required version numbers.
57 #
58 # Examples:
59 #
60 #   To obtain help on usage:
61 #     ./autogen.sh --help
62 #
63 #   To obtain verbose output:
64 #     ./autogen.sh --verbose
65 #
66 #   To skip autoreconf and prepare manually:
67 #     AUTORECONF=false ./autogen.sh
68 #
69 #   To verbosely try running with an older (unsupported) autoconf:
70 #     AUTOCONF_VERSION=2.50 ./autogen.sh --verbose
71 #
72 # Author: Christopher Sean Morrison <morrison@brlcad.org>
73 #
74 ######################################################################
75
76 # set to minimum acceptible version of autoconf
77 if [ "x$AUTOCONF_VERSION" = "x" ] ; then
78     AUTOCONF_VERSION=2.52
79 fi
80 # set to minimum acceptible version of automake
81 if [ "x$AUTOMAKE_VERSION" = "x" ] ; then
82     AUTOMAKE_VERSION=1.6.0
83 fi
84 # set to minimum acceptible version of libtool
85 if [ "x$LIBTOOL_VERSION" = "x" ] ; then
86     LIBTOOL_VERSION=1.4.2
87 fi
88
89
90 ##################
91 # ident function #
92 ##################
93 ident ( ) {
94     # extract copyright from header
95     __copyright="`grep Copyright $AUTOGEN_SH | head -${HEAD_N}1 | awk '{print $4}'`"
96     if [ "x$__copyright" = "x" ] ; then
97         __copyright="`date +%Y`"
98     fi
99
100     # extract version from CVS Id string
101     __id="$Id: autogen.sh,v 14.97 2007/06/18 22:25:02 brlcad Exp $"
102     __version="`echo $__id | sed 's/.*\([0-9][0-9][0-9][0-9]\)[-\/]\([0-9][0-9]\)[-\/]\([0-9][0-9]\).*/\1\2\3/'`"
103     if [ "x$__version" = "x" ] ; then
104         __version=""
105     fi
106
107     echo "autogen.sh build preparation script by Christopher Sean Morrison"
108     echo "revised 3-clause BSD-style license, copyright (c) $__copyright"
109     echo "script version $__version, ISO/IEC 9945 POSIX shell script"
110 }
111
112
113 ##################
114 # USAGE FUNCTION #
115 ##################
116 usage ( ) {
117     echo "Usage: $AUTOGEN_SH [-h|--help] [-v|--verbose] [-q|--quiet] [--version]"
118     echo "    --help     Help on $NAME_OF_AUTOGEN usage"
119     echo "    --verbose  Verbose progress output"
120     echo "    --quiet    Quiet suppressed progress output"
121     echo "    --version  Only perform GNU Build System version checks"
122     echo
123     echo "Description: This script will validate that minimum versions of the"
124     echo "GNU Build System tools are installed and then run autoreconf for you."
125     echo "Should autoreconf fail, manual preparation steps will be run"
126     echo "potentially accounting for several common preparation issues.  The"
127
128     echo "AUTORECONF, AUTOCONF, AUTOMAKE, LIBTOOLIZE, ACLOCAL, AUTOHEADER,"
129     echo "PROJECT, & CONFIGURE environment variables and corresponding _OPTIONS"
130     echo "variables (e.g. AUTORECONF_OPTIONS) may be used to override the"
131     echo "default automatic detection behavior."
132     echo
133
134     ident
135
136     return 0
137 }
138
139
140 ##########################
141 # VERSION_ERROR FUNCTION #
142 ##########################
143 version_error ( ) {
144     if [ "x$1" = "x" ] ; then
145         echo "INTERNAL ERROR: version_error was not provided a version"
146         exit 1
147     fi
148     if [ "x$2" = "x" ] ; then
149         echo "INTERNAL ERROR: version_error was not provided an application name"
150         exit 1
151     fi
152     $ECHO
153     $ECHO "ERROR:  To prepare the ${PROJECT} build system from scratch,"
154     $ECHO "        at least version $1 of $2 must be installed."
155     $ECHO
156     $ECHO "$NAME_OF_AUTOGEN does not need to be run on the same machine that will"
157     $ECHO "run configure or make.  Either the GNU Autotools will need to be installed"
158     $ECHO "or upgraded on this system, or $NAME_OF_AUTOGEN must be run on the source"
159     $ECHO "code on another system and then transferred to here. -- Cheers!"
160     $ECHO
161 }
162
163 ##########################
164 # VERSION_CHECK FUNCTION #
165 ##########################
166 version_check ( ) {
167     if [ "x$1" = "x" ] ; then
168         echo "INTERNAL ERROR: version_check was not provided a minimum version"
169         exit 1
170     fi
171     _min="$1"
172     if [ "x$2" = "x" ] ; then
173         echo "INTERNAL ERROR: version check was not provided a comparison version"
174         exit 1
175     fi
176     _cur="$2"
177
178     # needed to handle versions like 1.10 and 1.4-p6
179     _min="`echo ${_min}. | sed 's/[^0-9]/./g' | sed 's/\.\././g'`"
180     _cur="`echo ${_cur}. | sed 's/[^0-9]/./g' | sed 's/\.\././g'`"
181
182     _min_major="`echo $_min | cut -d. -f1`"
183     _min_minor="`echo $_min | cut -d. -f2`"
184     _min_patch="`echo $_min | cut -d. -f3`"
185
186     _cur_major="`echo $_cur | cut -d. -f1`"
187     _cur_minor="`echo $_cur | cut -d. -f2`"
188     _cur_patch="`echo $_cur | cut -d. -f3`"
189
190     if [ "x$_min_major" = "x" ] ; then
191         _min_major=0
192     fi
193     if [ "x$_min_minor" = "x" ] ; then
194         _min_minor=0
195     fi
196     if [ "x$_min_patch" = "x" ] ; then
197         _min_patch=0
198     fi
199     if [ "x$_cur_minor" = "x" ] ; then
200         _cur_major=0
201     fi
202     if [ "x$_cur_minor" = "x" ] ; then
203         _cur_minor=0
204     fi
205     if [ "x$_cur_patch" = "x" ] ; then
206         _cur_patch=0
207     fi
208
209     $VERBOSE_ECHO "Checking if ${_cur_major}.${_cur_minor}.${_cur_patch} is greater than ${_min_major}.${_min_minor}.${_min_patch}"
210
211     if [ $_min_major -lt $_cur_major ] ; then
212         return 0
213     elif [ $_min_major -eq $_cur_major ] ; then
214         if [ $_min_minor -lt $_cur_minor ] ; then
215             return 0
216         elif [ $_min_minor -eq $_cur_minor ] ; then
217             if [ $_min_patch -lt $_cur_patch ] ; then
218                 return 0
219             elif [ $_min_patch -eq $_cur_patch ] ; then
220                 return 0
221             fi
222         fi
223     fi
224     return 1
225 }
226
227
228 ######################################
229 # LOCATE_CONFIGURE_TEMPLATE FUNCTION #
230 ######################################
231 locate_configure_template ( ) {
232     _pwd="`pwd`"
233     if test -f "./configure.ac" ; then
234         echo "./configure.ac"
235     elif test -f "./configure.in" ; then
236         echo "./configure.in"
237     elif test -f "$_pwd/configure.ac" ; then
238         echo "$_pwd/configure.ac"
239     elif test -f "$_pwd/configure.in" ; then
240         echo "$_pwd/configure.in"
241     elif test -f "$PATH_TO_AUTOGEN/configure.ac" ; then
242         echo "$PATH_TO_AUTOGEN/configure.ac"
243     elif test -f "$PATH_TO_AUTOGEN/configure.in" ; then
244         echo "$PATH_TO_AUTOGEN/configure.in"
245     fi
246 }
247
248
249 ##################
250 # argument check #
251 ##################
252 ARGS="$*"
253 PATH_TO_AUTOGEN="`dirname $0`"
254 NAME_OF_AUTOGEN="`basename $0`"
255 AUTOGEN_SH="$PATH_TO_AUTOGEN/$NAME_OF_AUTOGEN"
256
257 LIBTOOL_M4="${PATH_TO_AUTOGEN}/misc/libtool.m4"
258
259 if [ "x$HELP" = "x" ] ; then
260     HELP=no
261 fi
262 if [ "x$QUIET" = "x" ] ; then
263     QUIET=no
264 fi
265 if [ "x$VERBOSE" = "x" ] ; then
266     VERBOSE=no
267 fi
268 if [ "x$VERSION_ONLY" = "x" ] ; then
269     VERSION_ONLY=no
270 fi
271 if [ "x$AUTORECONF_OPTIONS" = "x" ] ; then
272     AUTORECONF_OPTIONS="-i -f"
273 fi
274 if [ "x$AUTOCONF_OPTIONS" = "x" ] ; then
275     AUTOCONF_OPTIONS="-f"
276 fi
277 if [ "x$AUTOMAKE_OPTIONS" = "x" ] ; then
278     AUTOMAKE_OPTIONS="-a -c -f"
279 fi
280 ALT_AUTOMAKE_OPTIONS="-a -c"
281 if [ "x$LIBTOOLIZE_OPTIONS" = "x" ] ; then
282     LIBTOOLIZE_OPTIONS="--automake -c -f"
283 fi
284 ALT_LIBTOOLIZE_OPTIONS="--automake --copy --force"
285 if [ "x$ACLOCAL_OPTIONS" = "x" ] ; then
286     ACLOCAL_OPTIONS=""
287 fi
288 if [ "x$AUTOHEADER_OPTIONS" = "x" ] ; then
289     AUTOHEADER_OPTIONS=""
290 fi
291 for arg in $ARGS ; do
292     case "x$arg" in
293         x--help) HELP=yes ;;
294         x-[hH]) HELP=yes ;;
295         x--quiet) QUIET=yes ;;
296         x-[qQ]) QUIET=yes ;;
297         x--verbose) VERBOSE=yes ;;
298         x-[vV]) VERBOSE=yes ;;
299         x--version) VERSION_ONLY=yes ;;
300         *)
301             echo "Unknown option: $arg"
302             echo
303             usage
304             exit 1
305             ;;
306     esac
307 done
308
309
310 #####################
311 # environment check #
312 #####################
313
314 # sanity check before recursions potentially begin
315 if [ ! -f "$AUTOGEN_SH" ] ; then
316     echo "INTERNAL ERROR: $AUTOGEN_SH does not exist"
317     if [ ! "x$0" = "x$AUTOGEN_SH" ] ; then
318         echo "INTERNAL ERROR: dirname/basename inconsistency: $0 != $AUTOGEN_SH"
319     fi
320     exit 1
321 fi
322
323 # force locale setting to C so things like date output as expected
324 LC_ALL=C
325
326 # commands that this script expects
327 for __cmd in echo head tail pwd ; do
328     echo "test" | $__cmd > /dev/null 2>&1
329     if [ $? != 0 ] ; then
330         echo "INTERNAL ERROR: '${__cmd}' command is required"
331         exit 2
332     fi
333 done
334 echo "test" | grep "test" > /dev/null 2>&1
335 if test ! x$? = x0 ; then
336     echo "INTERNAL ERROR: grep command is required"
337     exit 1
338 fi
339 echo "test" | sed "s/test/test/" > /dev/null 2>&1
340 if test ! x$? = x0 ; then
341     echo "INTERNAL ERROR: sed command is required"
342     exit 1
343 fi
344
345
346 # determine the behavior of echo
347 case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
348     *c*,-n*) ECHO_N= ECHO_C='
349 ' ECHO_T='      ' ;;
350     *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
351     *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
352 esac
353
354 # determine the behavior of head
355 case "x`echo 'head' | head -n 1 2>&1`" in
356     *xhead*) HEAD_N="n " ;;
357     *) HEAD_N="" ;;
358 esac
359
360 # determine the behavior of tail
361 case "x`echo 'tail' | tail -n 1 2>&1`" in
362     *xtail*) TAIL_N="n " ;;
363     *) TAIL_N="" ;;
364 esac
365
366 VERBOSE_ECHO=:
367 ECHO=:
368 if [ "x$QUIET" = "xyes" ] ; then
369     if [ "x$VERBOSE" = "xyes" ] ; then
370         echo "Verbose output quelled by quiet option.  Further output disabled."
371     fi
372 else
373     ECHO=echo
374     if [ "x$VERBOSE" = "xyes" ] ; then
375         echo "Verbose output enabled"
376         VERBOSE_ECHO=echo
377     fi
378 fi
379
380
381 # allow a recursive run to disable further recursions
382 if [ "x$RUN_RECURSIVE" = "x" ] ; then
383     RUN_RECURSIVE=yes
384 fi
385
386
387 ################################################
388 # check for help arg and bypass version checks #
389 ################################################
390 if [ "x`echo $ARGS | sed 's/.*[hH][eE][lL][pP].*/help/'`" = "xhelp" ] ; then
391     HELP=yes
392 fi
393 if [ "x$HELP" = "xyes" ] ; then
394     usage
395     $ECHO "---"
396     $ECHO "Help was requested.  No preparation or configuration will be performed."
397     exit 0
398 fi
399
400
401 #######################
402 # set up signal traps #
403 #######################
404 untrap_abnormal ( ) {
405     for sig in 1 2 13 15; do
406         trap - $sig
407     done
408 }
409
410 # do this cleanup whenever we exit.
411 trap '
412     # start from the root
413     if test -d "$START_PATH" ; then
414         cd "$START_PATH"
415     fi
416
417     # restore/delete backup files
418     if test "x$PFC_INIT" = "x1" ; then
419         recursive_restore
420     fi
421 ' 0
422
423 # trap SIGHUP (1), SIGINT (2), SIGPIPE (13), SIGTERM (15)
424 for sig in 1 2 13 15; do
425     trap '
426         $ECHO ""
427         $ECHO "Aborting $NAME_OF_AUTOGEN: caught signal '$sig'"
428
429         # start from the root
430         if test -d "$START_PATH" ; then
431             cd "$START_PATH"
432         fi
433
434         # clean up on abnormal exit
435         $VERBOSE_ECHO "rm -rf autom4te.cache"
436         rm -rf autom4te.cache
437
438         if test -f "acinclude.m4.$$.backup" ; then
439             $VERBOSE_ECHO "cat acinclude.m4.$$.backup > acinclude.m4"
440             chmod u+w acinclude.m4
441             cat acinclude.m4.$$.backup > acinclude.m4
442
443             $VERBOSE_ECHO "rm -f acinclude.m4.$$.backup"
444             rm -f acinclude.m4.$$.backup
445         fi
446
447         { (exit 1); exit 1; }
448 ' $sig
449 done
450
451
452 #############################
453 # look for a configure file #
454 #############################
455 if [ "x$CONFIGURE" = "x" ] ; then
456     CONFIGURE="`locate_configure_template`"
457     if [ ! "x$CONFIGURE" = "x" ] ; then
458         $VERBOSE_ECHO "Found a configure template: $CONFIGURE"
459     fi
460 else
461     $ECHO "Using CONFIGURE environment variable override: $CONFIGURE"
462 fi
463 if [ "x$CONFIGURE" = "x" ] ; then
464     if [ "x$VERSION_ONLY" = "xyes" ] ; then
465         CONFIGURE=/dev/null
466     else
467         $ECHO
468         $ECHO "A configure.ac or configure.in file could not be located implying"
469         $ECHO "that the GNU Build System is at least not used in this directory.  In"
470         $ECHO "any case, there is nothing to do here without one of those files."
471         $ECHO
472         $ECHO "ERROR: No configure.in or configure.ac file found in `pwd`"
473         exit 1
474     fi
475 fi
476
477 ####################
478 # get project name #
479 ####################
480 if [ "x$PROJECT" = "x" ] ; then
481     PROJECT="`grep AC_INIT $CONFIGURE | grep -v '.*#.*AC_INIT' | tail -${TAIL_N}1 | sed 's/^[   ]*AC_INIT(\([^,)]*\).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
482     if [ "x$PROJECT" = "xAC_INIT" ] ; then
483         # projects might be using the older/deprecated arg-less AC_INIT .. look for AM_INIT_AUTOMAKE instead
484         PROJECT="`grep AM_INIT_AUTOMAKE $CONFIGURE | grep -v '.*#.*AM_INIT_AUTOMAKE' | tail -${TAIL_N}1 | sed 's/^[     ]*AM_INIT_AUTOMAKE(\([^,)]*\).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
485     fi
486     if [ "x$PROJECT" = "xAM_INIT_AUTOMAKE" ] ; then
487         PROJECT="project"
488     fi
489     if [ "x$PROJECT" = "x" ] ; then
490         PROJECT="project"
491     fi
492 else
493     $ECHO "Using PROJECT environment variable override: $PROJECT"
494 fi
495 $ECHO "Preparing the $PROJECT build system...please wait"
496 $ECHO
497
498
499 ########################
500 # check for autoreconf #
501 ########################
502 HAVE_AUTORECONF=no
503 if [ "x$AUTORECONF" = "x" ] ; then
504     for AUTORECONF in autoreconf ; do
505         $VERBOSE_ECHO "Checking autoreconf version: $AUTORECONF --version"
506         $AUTORECONF --version > /dev/null 2>&1
507         if [ $? = 0 ] ; then
508             HAVE_AUTORECONF=yes
509             break
510         fi
511     done
512 else
513     HAVE_AUTORECONF=yes
514     $ECHO "Using AUTORECONF environment variable override: $AUTORECONF"
515 fi
516
517
518 ##########################
519 # autoconf version check #
520 ##########################
521 _acfound=no
522 if [ "x$AUTOCONF" = "x" ] ; then
523     for AUTOCONF in autoconf ; do
524         $VERBOSE_ECHO "Checking autoconf version: $AUTOCONF --version"
525         $AUTOCONF --version > /dev/null 2>&1
526         if [ $? = 0 ] ; then
527             _acfound=yes
528             break
529         fi
530     done
531 else
532     _acfound=yes
533     $ECHO "Using AUTOCONF environment variable override: $AUTOCONF"
534 fi
535
536 _report_error=no
537 if [ ! "x$_acfound" = "xyes" ] ; then
538     $ECHO "ERROR:  Unable to locate GNU Autoconf."
539     _report_error=yes
540 else
541     _version="`$AUTOCONF --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`"
542     if [ "x$_version" = "x" ] ; then
543         _version="0.0.0"
544     fi
545     $ECHO "Found GNU Autoconf version $_version"
546     version_check "$AUTOCONF_VERSION" "$_version"
547     if [ $? -ne 0 ] ; then
548         _report_error=yes
549     fi
550 fi
551 if [ "x$_report_error" = "xyes" ] ; then
552     version_error "$AUTOCONF_VERSION" "GNU Autoconf"
553     exit 1
554 fi
555
556
557 ##########################
558 # automake version check #
559 ##########################
560 _amfound=no
561 if [ "x$AUTOMAKE" = "x" ] ; then
562     for AUTOMAKE in automake ; do
563         $VERBOSE_ECHO "Checking automake version: $AUTOMAKE --version"
564         $AUTOMAKE --version > /dev/null 2>&1
565         if [ $? = 0 ] ; then
566             _amfound=yes
567             break
568         fi
569     done
570 else
571     _amfound=yes
572     $ECHO "Using AUTOMAKE environment variable override: $AUTOMAKE"
573 fi
574
575
576 _report_error=no
577 if [ ! "x$_amfound" = "xyes" ] ; then
578     $ECHO
579     $ECHO "ERROR: Unable to locate GNU Automake."
580     _report_error=yes
581 else
582     _version="`$AUTOMAKE --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`"
583     if [ "x$_version" = "x" ] ; then
584         _version="0.0.0"
585     fi
586     $ECHO "Found GNU Automake version $_version"
587     version_check "$AUTOMAKE_VERSION" "$_version" 
588     if [ $? -ne 0 ] ; then
589         _report_error=yes
590     fi
591 fi
592 if [ "x$_report_error" = "xyes" ] ; then
593     version_error "$AUTOMAKE_VERSION" "GNU Automake"
594     exit 1
595 fi
596
597
598 ########################
599 # check for libtoolize #
600 ########################
601 HAVE_LIBTOOLIZE=yes
602 HAVE_ALT_LIBTOOLIZE=no
603 _ltfound=no
604 if [ "x$LIBTOOLIZE" = "x" ] ; then
605     LIBTOOLIZE=libtoolize
606     $VERBOSE_ECHO "Checking libtoolize version: $LIBTOOLIZE --version"
607     $LIBTOOLIZE --version > /dev/null 2>&1
608     if [ ! $? = 0 ] ; then
609         HAVE_LIBTOOLIZE=no
610         $ECHO
611         if [ "x$HAVE_AUTORECONF" = "xno" ] ; then
612             $ECHO "Warning:  libtoolize does not appear to be available."
613         else
614             $ECHO "Warning:  libtoolize does not appear to be available.  This means that"
615             $ECHO "the automatic build preparation via autoreconf will probably not work."
616             $ECHO "Preparing the build by running each step individually, however, should"
617             $ECHO "work and will be done automatically for you if autoreconf fails."
618         fi
619
620         # look for some alternates
621         for tool in glibtoolize libtoolize15 libtoolize14 libtoolize13 ; do
622             $VERBOSE_ECHO "Checking libtoolize alternate: $tool --version"
623             _glibtoolize="`$tool --version > /dev/null 2>&1`"
624             if [ $? = 0 ] ; then
625                 $VERBOSE_ECHO "Found $tool --version"
626                 _glti="`which $tool`"
627                 if [ "x$_glti" = "x" ] ; then
628                     $VERBOSE_ECHO "Cannot find $tool with which"
629                     continue;
630                 fi
631                 if test ! -f "$_glti" ; then
632                     $VERBOSE_ECHO "Cannot use $tool, $_glti is not a file"
633                     continue;
634                 fi
635                 _gltidir="`dirname $_glti`"
636                 if [ "x$_gltidir" = "x" ] ; then
637                     $VERBOSE_ECHO "Cannot find $tool path with dirname of $_glti"
638                     continue;
639                 fi
640                 if test ! -d "$_gltidir" ; then
641                     $VERBOSE_ECHO "Cannot use $tool, $_gltidir is not a directory"
642                     continue;
643                 fi
644                 HAVE_ALT_LIBTOOLIZE=yes
645                 LIBTOOLIZE="$tool"
646                 $ECHO
647                 $ECHO "Fortunately, $tool was found which means that your system may simply"
648                 $ECHO "have a non-standard or incomplete GNU Autotools install.  If you have"
649                 $ECHO "sufficient system access, it may be possible to quell this warning by"
650                 $ECHO "running:"
651                 $ECHO
652                 sudo -V > /dev/null 2>&1
653                 if [ $? = 0 ] ; then
654                     $ECHO "   sudo ln -s $_glti $_gltidir/libtoolize"
655                     $ECHO
656                 else
657                     $ECHO "   ln -s $_glti $_gltidir/libtoolize"
658                     $ECHO
659                     $ECHO "Run that as root or with proper permissions to the $_gltidir directory"
660                     $ECHO
661                 fi
662                 _ltfound=yes
663                 break
664             fi
665         done
666     else
667         _ltfound=yes
668     fi
669 else
670     _ltfound=yes
671     $ECHO "Using LIBTOOLIZE environment variable override: $LIBTOOLIZE"
672 fi
673
674
675 ############################
676 # libtoolize version check #
677 ############################
678 _report_error=no
679 if [ ! "x$_ltfound" = "xyes" ] ; then
680     $ECHO
681     $ECHO "ERROR: Unable to locate GNU Libtool."
682     _report_error=yes
683 else
684     _version="`$LIBTOOLIZE --version | head -${HEAD_N}1 | sed 's/[^0-9]*\([0-9\.][0-9\.]*\)/\1/'`"
685     if [ "x$_version" = "x" ] ; then
686         _version="0.0.0"
687     fi
688     $ECHO "Found GNU Libtool version $_version"
689     version_check "$LIBTOOL_VERSION" "$_version" 
690     if [ $? -ne 0 ] ; then
691         _report_error=yes
692     fi
693 fi
694 if [ "x$_report_error" = "xyes" ] ; then
695     version_error "$LIBTOOL_VERSION" "GNU Libtool"
696     exit 1
697 fi
698
699
700 #####################
701 # check for aclocal #
702 #####################
703 if [ "x$ACLOCAL" = "x" ] ; then
704     for ACLOCAL in aclocal ; do
705         $VERBOSE_ECHO "Checking aclocal version: $ACLOCAL --version"
706         $ACLOCAL --version > /dev/null 2>&1
707         if [ $? = 0 ] ; then
708             break
709         fi
710     done
711 else
712     $ECHO "Using ACLOCAL environment variable override: $ACLOCAL"
713 fi
714
715
716 ########################
717 # check for autoheader #
718 ########################
719 if [ "x$AUTOHEADER" = "x" ] ; then
720     for AUTOHEADER in autoheader ; do
721         $VERBOSE_ECHO "Checking autoheader version: $AUTOHEADER --version"
722         $AUTOHEADER --version > /dev/null 2>&1
723         if [ $? = 0 ] ; then
724             break
725         fi
726     done
727 else
728     $ECHO "Using AUTOHEADER environment variable override: $AUTOHEADER"
729 fi
730
731
732 #########################
733 # check if version only #
734 #########################
735 $VERBOSE_ECHO "Checking whether to only output version information"
736 if [ "x$VERSION_ONLY" = "xyes" ] ; then
737     $ECHO
738     ident
739     $ECHO "---"
740     $ECHO "Version requested.  No preparation or configuration will be performed."
741     exit 0
742 fi
743
744
745 #################################
746 # PROTECT_FROM_CLOBBER FUNCTION #
747 #################################
748 protect_from_clobber ( ) {
749     PFC_INIT=1
750
751     # protect COPYING & INSTALL from overwrite by automake.  the
752     # automake force option will (inappropriately) ignore the existing
753     # contents of a COPYING and/or INSTALL files (depending on the
754     # version) instead of just forcing *missing* files like it does
755     # for AUTHORS, NEWS, and README. this is broken but extremely
756     # prevalent behavior, so we protect against it by keeping a backup
757     # of the file that can later be restored.
758
759     if test -f COPYING ; then
760         if test -f COPYING.$$.protect_from_automake.backup ; then
761             $VERBOSE_ECHO "Already backed up COPYING in `pwd`"
762         else
763             $VERBOSE_ECHO "Backing up COPYING in `pwd`"
764             $VERBOSE_ECHO "cp -p COPYING COPYING.$$.protect_from_automake.backup"
765             cp -p COPYING COPYING.$$.protect_from_automake.backup
766         fi
767     fi
768     if test -f INSTALL ; then
769         if test -f INSTALL.$$.protect_from_automake.backup ; then
770             $VERBOSE_ECHO "Already backed up INSTALL in `pwd`"
771         else
772             $VERBOSE_ECHO "Backing up INSTALL in `pwd`"
773             $VERBOSE_ECHO "cp -p INSTALL INSTALL.$$.protect_from_automake.backup"
774             cp -p INSTALL INSTALL.$$.protect_from_automake.backup
775         fi
776     fi
777 }
778
779
780 ##############################
781 # RECURSIVE_PROTECT FUNCTION #
782 ##############################
783 recursive_protect ( ) {
784
785     # for projects using recursive configure, run the build
786     # preparation steps for the subdirectories.  this function assumes
787     # START_PATH was set to pwd before recursion begins so that
788     # relative paths work.
789
790     # git 'r done, protect COPYING and INSTALL from being clobbered
791     protect_from_clobber
792
793     if test -d autom4te.cache ; then
794         $VERBOSE_ECHO "Found an autom4te.cache directory, deleting it"
795         $VERBOSE_ECHO "rm -rf autom4te.cache"
796         rm -rf autom4te.cache
797     fi
798
799     # find configure template
800     _configure="`locate_configure_template`"
801     if [ "x$_configure" = "x" ] ; then
802         return
803     fi
804     # $VERBOSE_ECHO "Looking for configure template found `pwd`/$_configure"
805
806     # look for subdirs
807     # $VERBOSE_ECHO "Looking for subdirs in `pwd`"
808     _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $_configure | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[     ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
809     CHECK_DIRS=""
810     for dir in $_det_config_subdirs ; do
811         if test -d "`pwd`/$dir" ; then
812             CHECK_DIRS="$CHECK_DIRS \"`pwd`/$dir\""
813         fi
814     done
815
816     # process subdirs
817     if [ ! "x$CHECK_DIRS" = "x" ] ; then
818         $VERBOSE_ECHO "Recursively scanning the following directories:"
819         $VERBOSE_ECHO "  $CHECK_DIRS"
820         for dir in $CHECK_DIRS ; do
821             $VERBOSE_ECHO "Protecting files from automake in $dir"
822             cd "$START_PATH"
823             eval "cd $dir"
824
825             # recursively git 'r done
826             recursive_protect
827         done
828     fi
829 } # end of recursive_protect
830
831
832 #############################
833 # RESTORE_CLOBBERED FUNCION #
834 #############################
835 restore_clobbered ( ) {
836
837     # The automake (and autoreconf by extension) -f/--force-missing
838     # option may overwrite COPYING and INSTALL even if they do exist.
839     # Here we restore the files if necessary.
840
841     spacer=no
842
843     # COPYING
844     if test -f COPYING.$$.protect_from_automake.backup ; then
845         if test -f COPYING ; then
846             # compare entire content, restore if needed
847             if test "x`cat COPYING`" != "x`cat COPYING.$$.protect_from_automake.backup`" ; then
848                 if test "x$spacer" = "xno" ; then
849                     $VERBOSE_ECHO
850                     spacer=yes
851                 fi
852                 # restore the backup
853                 $VERBOSE_ECHO "Restoring COPYING from backup (automake -f likely clobbered it)"
854                 $VERBOSE_ECHO "rm -f COPYING"
855                 rm -f COPYING
856                 $VERBOSE_ECHO "mv COPYING.$$.protect_from_automake.backup COPYING"
857                 mv COPYING.$$.protect_from_automake.backup COPYING
858             fi # check contents
859         elif test -f COPYING.$$.protect_from_automake.backup ; then
860             $VERBOSE_ECHO "mv COPYING.$$.protect_from_automake.backup COPYING"
861             mv COPYING.$$.protect_from_automake.backup COPYING
862         fi # -f COPYING
863
864         # just in case
865         $VERBOSE_ECHO "rm -f COPYING.$$.protect_from_automake.backup"
866         rm -f COPYING.$$.protect_from_automake.backup
867     fi # -f COPYING.$$.protect_from_automake.backup
868
869     # INSTALL
870     if test -f INSTALL.$$.protect_from_automake.backup ; then
871         if test -f INSTALL ; then
872             # compare entire content, restore if needed
873             if test "x`cat INSTALL`" != "x`cat INSTALL.$$.protect_from_automake.backup`" ; then
874                 if test "x$spacer" = "xno" ; then
875                     $VERBOSE_ECHO
876                     spacer=yes
877                 fi
878                 # restore the backup
879                 $VERBOSE_ECHO "Restoring INSTALL from backup (automake -f likely clobbered it)"
880                 $VERBOSE_ECHO "rm -f INSTALL"
881                 rm -f INSTALL
882                 $VERBOSE_ECHO "mv INSTALL.$$.protect_from_automake.backup INSTALL"
883                 mv INSTALL.$$.protect_from_automake.backup INSTALL
884             fi # check contents
885         elif test -f INSTALL.$$.protect_from_automake.backup ; then
886             $VERBOSE_ECHO "mv INSTALL.$$.protect_from_automake.backup INSTALL"
887             mv INSTALL.$$.protect_from_automake.backup INSTALL
888         fi # -f INSTALL
889
890         # just in case
891         $VERBOSE_ECHO "rm -f INSTALL.$$.protect_from_automake.backup"
892         rm -f INSTALL.$$.protect_from_automake.backup
893     fi # -f INSTALL.$$.protect_from_automake.backup
894
895     CONFIGURE="`locate_configure_template`"
896     if [ "x$CONFIGURE" = "x" ] ; then
897         return
898     fi
899
900     _aux_dir="`grep AC_CONFIG_AUX_DIR $CONFIGURE | grep -v '.*#.*AC_CONFIG_AUX_DIR' | tail -${TAIL_N}1 | sed 's/^[      ]*AC_CONFIG_AUX_DIR(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
901     if test ! -d "$_aux_dir" ; then
902         _aux_dir=.
903     fi
904
905     for file in config.guess config.sub ltmain.sh ; do
906         if test -f "${_aux_dir}/${file}" ; then
907             $VERBOSE_ECHO "rm -f \"${_aux_dir}/${file}.backup\""
908             rm -f "${_aux_dir}/${file}.backup"
909         fi
910     done
911 } # end of restore_clobbered
912
913
914 ##############################
915 # RECURSIVE_RESTORE FUNCTION #
916 ##############################
917 recursive_restore ( ) {
918
919     # restore COPYING and INSTALL from backup if they were clobbered
920     # for each directory recursively.
921
922     # git 'r undone
923     restore_clobbered
924
925     # find configure template
926     _configure="`locate_configure_template`"
927     if [ "x$_configure" = "x" ] ; then
928         return
929     fi
930
931     # look for subdirs
932     _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $_configure | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[     ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
933     CHECK_DIRS=""
934     for dir in $_det_config_subdirs ; do
935         if test -d "`pwd`/$dir" ; then
936             CHECK_DIRS="$CHECK_DIRS \"`pwd`/$dir\""
937         fi
938     done
939
940     # process subdirs
941     if [ ! "x$CHECK_DIRS" = "x" ] ; then
942         $VERBOSE_ECHO "Recursively scanning the following directories:"
943         $VERBOSE_ECHO "  $CHECK_DIRS"
944         for dir in $CHECK_DIRS ; do
945             $VERBOSE_ECHO "Checking files for automake damage in $dir"
946             cd "$START_PATH"
947             eval "cd $dir"
948
949             # recursively git 'r undone
950             recursive_restore
951         done
952     fi
953 } # end of recursive_restore
954
955
956 #######################
957 # INITIALIZE FUNCTION #
958 #######################
959 initialize ( ) {
960
961     # this routine performs a variety of directory-specific
962     # initializations.  some are sanity checks, some are preventive,
963     # and some are necessary setup detection.
964     #
965     # this function sets:
966     #   CONFIGURE
967     #   SEARCH_DIRS
968     #   CONFIG_SUBDIRS
969
970     ##################################
971     # check for a configure template #
972     ##################################
973     CONFIGURE="`locate_configure_template`"
974     if [ "x$CONFIGURE" = "x" ] ; then
975         $ECHO
976         $ECHO "A configure.ac or configure.in file could not be located implying"
977         $ECHO "that the GNU Build System is at least not used in this directory.  In"
978         $ECHO "any case, there is nothing to do here without one of those files."
979         $ECHO
980         $ECHO "ERROR: No configure.in or configure.ac file found in `pwd`"
981         exit 1
982     fi
983
984     #####################
985     # detect an aux dir #
986     #####################
987     _aux_dir="`grep AC_CONFIG_AUX_DIR $CONFIGURE | grep -v '.*#.*AC_CONFIG_AUX_DIR' | tail -${TAIL_N}1 | sed 's/^[      ]*AC_CONFIG_AUX_DIR(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
988     if test ! -d "$_aux_dir" ; then
989         _aux_dir=.
990     else
991         $VERBOSE_ECHO "Detected auxillary directory: $_aux_dir"
992     fi
993
994     ################################
995     # detect a recursive configure #
996     ################################
997     CONFIG_SUBDIRS=""
998     _det_config_subdirs="`grep AC_CONFIG_SUBDIRS $CONFIGURE | grep -v '.*#.*AC_CONFIG_SUBDIRS' | sed 's/^[      ]*AC_CONFIG_SUBDIRS(\(.*\)).*/\1/' | sed 's/.*\[\(.*\)\].*/\1/'`"
999     for dir in $_det_config_subdirs ; do
1000         if test -d "`pwd`/$dir" ; then
1001             $VERBOSE_ECHO "Detected recursive configure directory: `pwd`/$dir"
1002             CONFIG_SUBDIRS="$CONFIG_SUBDIRS `pwd`/$dir"
1003         fi
1004     done
1005
1006     ##########################################
1007     # make sure certain required files exist #
1008     ##########################################
1009     for file in AUTHORS COPYING ChangeLog INSTALL NEWS README ; do
1010         if test ! -f $file ; then
1011             $VERBOSE_ECHO "Touching ${file} since it does not exist"
1012             touch $file
1013         fi
1014     done
1015
1016     ##################################################
1017     # make sure certain generated files do not exist #
1018     ##################################################
1019     for file in config.guess config.sub ltmain.sh ; do
1020         if test -f "${_aux_dir}/${file}" ; then
1021             $VERBOSE_ECHO "mv -f \"${_aux_dir}/${file}\" \"${_aux_dir}/${file}.backup\""
1022             mv -f "${_aux_dir}/${file}" "${_aux_dir}/${file}.backup"
1023         fi
1024     done
1025
1026     ############################
1027     # search alternate m4 dirs #
1028     ############################
1029     SEARCH_DIRS=""
1030     for dir in m4 ; do
1031         if [ -d $dir ] ; then
1032             $VERBOSE_ECHO "Found extra aclocal search directory: $dir"
1033             SEARCH_DIRS="$SEARCH_DIRS -I $dir"
1034         fi
1035     done
1036
1037     ######################################
1038     # remove any previous build products #
1039     ######################################
1040     if test -d autom4te.cache ; then
1041         $VERBOSE_ECHO "Found an autom4te.cache directory, deleting it"
1042         $VERBOSE_ECHO "rm -rf autom4te.cache"
1043         rm -rf autom4te.cache
1044     fi
1045 # tcl/tk (and probably others) have a customized aclocal.m4, so can't delete it
1046 #     if test -f aclocal.m4 ; then
1047 #       $VERBOSE_ECHO "Found an aclocal.m4 file, deleting it"
1048 #       $VERBOSE_ECHO "rm -f aclocal.m4"
1049 #       rm -f aclocal.m4
1050 #     fi
1051
1052 } # end of initialize()
1053
1054
1055 ##############
1056 # initialize #
1057 ##############
1058
1059 # stash path
1060 START_PATH="`pwd`"
1061
1062 # Before running autoreconf or manual steps, some prep detection work
1063 # is necessary or useful.  Only needs to occur once per directory, but
1064 # does need to traverse the entire subconfigure hierarchy to protect
1065 # files from being clobbered even by autoreconf.
1066 recursive_protect
1067
1068 # start from where we started
1069 cd "$START_PATH"
1070
1071 # get ready to process
1072 initialize
1073
1074
1075 ############################################
1076 # prepare build via autoreconf or manually #
1077 ############################################
1078 reconfigure_manually=no
1079 if [ "x$HAVE_AUTORECONF" = "xyes" ] ; then
1080     $ECHO
1081     $ECHO $ECHO_N "Automatically preparing build ... $ECHO_C"
1082
1083     $VERBOSE_ECHO "$AUTORECONF $SEARCH_DIRS $AUTORECONF_OPTIONS"
1084     autoreconf_output="`$AUTORECONF $SEARCH_DIRS $AUTORECONF_OPTIONS 2>&1`"
1085     ret=$?
1086     $VERBOSE_ECHO "$autoreconf_output"
1087
1088     if [ ! $ret = 0 ] ; then
1089         if [ "x$HAVE_ALT_LIBTOOLIZE" = "xyes" ] ; then
1090             if [ ! "x`echo \"$autoreconf_output\" | grep libtoolize | grep \"No such file or directory\"`" = "x" ] ; then
1091                 $ECHO
1092                 $ECHO "Warning: autoreconf failed but due to what is usually a common libtool"
1093                 $ECHO "misconfiguration issue.  This problem is encountered on systems that"
1094                 $ECHO "have installed libtoolize under a different name without providing a"
1095                 $ECHO "symbolic link or without setting the LIBTOOLIZE environment variable."
1096                 $ECHO
1097                 $ECHO "Restarting the preparation steps with LIBTOOLIZE set to $LIBTOOLIZE"
1098
1099                 export LIBTOOLIZE
1100                 RUN_RECURSIVE=no
1101                 export RUN_RECURSIVE
1102                 untrap_abnormal
1103
1104                 $VERBOSE_ECHO sh $AUTOGEN_SH "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
1105                 sh "$AUTOGEN_SH" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
1106                 exit $?
1107             fi
1108         fi
1109
1110         $ECHO "Warning: $AUTORECONF failed"
1111
1112         if test -f ltmain.sh ; then
1113             $ECHO "libtoolize being run by autoreconf is not creating ltmain.sh in the auxillary directory like it should"
1114         fi
1115
1116         $ECHO "Attempting to run the preparation steps individually"
1117         reconfigure_manually=yes
1118     fi
1119 else
1120     reconfigure_manually=yes
1121 fi
1122
1123
1124 ############################
1125 # LIBTOOL_FAILURE FUNCTION #
1126 ############################
1127 libtool_failure ( ) {
1128
1129     # libtool is rather error-prone in comparison to the other
1130     # autotools and this routine attempts to compensate for some
1131     # common failures.  the output after a libtoolize failure is
1132     # parsed for an error related to AC_PROG_LIBTOOL and if found, we
1133     # attempt to inject a project-provided libtool.m4 file.
1134
1135     _autoconf_output="$1"
1136
1137     if [ "x$RUN_RECURSIVE" = "xno" ] ; then
1138         # we already tried the libtool.m4, don't try again
1139         return 1
1140     fi
1141
1142     if test -f "$LIBTOOL_M4" ; then
1143         found_libtool="`$ECHO $_autoconf_output | grep AC_PROG_LIBTOOL`"
1144         if test ! "x$found_libtool" = "x" ; then
1145             if test -f acinclude.m4 ; then
1146                 rm -f acinclude.m4.$$.backup
1147                 $VERBOSE_ECHO "cat acinclude.m4 > acinclude.m4.$$.backup"
1148                 cat acinclude.m4 > acinclude.m4.$$.backup
1149             fi
1150             $VERBOSE_ECHO "cat \"$LIBTOOL_M4\" >> acinclude.m4"
1151             chmod u+w acinclude.m4
1152             cat "$LIBTOOL_M4" >> acinclude.m4
1153
1154             # don't keep doing this
1155             RUN_RECURSIVE=no
1156             export RUN_RECURSIVE
1157             untrap_abnormal
1158
1159             $ECHO
1160             $ECHO "Restarting the preparation steps with libtool macros in acinclude.m4"
1161             $VERBOSE_ECHO sh $AUTOGEN_SH "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
1162             sh "$AUTOGEN_SH" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
1163             exit $?
1164         fi
1165     fi
1166 }
1167
1168
1169 ###########################
1170 # MANUAL_AUTOGEN FUNCTION #
1171 ###########################
1172 manual_autogen ( ) {
1173
1174     ##################################################
1175     # Manual preparation steps taken are as follows: #
1176     #   aclocal [-I m4]                              #
1177     #   libtoolize --automake -c -f                  #
1178     #   aclocal [-I m4]                              #
1179     #   autoconf -f                                  #
1180     #   autoheader                                   #
1181     #   automake -a -c -f                            #
1182     ##################################################
1183
1184     ###########
1185     # aclocal #
1186     ###########
1187     $VERBOSE_ECHO "$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS"
1188     aclocal_output="`$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS 2>&1`"
1189     ret=$?
1190     $VERBOSE_ECHO "$aclocal_output"
1191     if [ ! $ret = 0 ] ; then $ECHO "ERROR: $ACLOCAL failed" && exit 2 ; fi
1192
1193     ##############
1194     # libtoolize #
1195     ##############
1196     need_libtoolize=no
1197     for feature in AC_PROG_LIBTOOL LT_INIT ; do
1198         $VERBOSE_ECHO "Searching for $feature in $CONFIGURE"
1199         found="`grep \"^$feature.*\" $CONFIGURE`"
1200         if [ ! "x$found" = "x" ] ; then
1201             need_libtoolize=yes
1202             break
1203         fi
1204     done
1205     if [ "x$need_libtoolize" = "xyes" ] ; then
1206         if [ "x$HAVE_LIBTOOLIZE" = "xyes" ] ; then
1207             $VERBOSE_ECHO "$LIBTOOLIZE $LIBTOOLIZE_OPTIONS"
1208             libtoolize_output="`$LIBTOOLIZE $LIBTOOLIZE_OPTIONS 2>&1`"
1209             ret=$?
1210             $VERBOSE_ECHO "$libtoolize_output"
1211             
1212             if [ ! $ret = 0 ] ; then $ECHO "ERROR: $LIBTOOLIZE failed" && exit 2 ; fi
1213         else
1214             if [ "x$HAVE_ALT_LIBTOOLIZE" = "xyes" ] ; then
1215                 $VERBOSE_ECHO "$LIBTOOLIZE $ALT_LIBTOOLIZE_OPTIONS"
1216                 libtoolize_output="`$LIBTOOLIZE $ALT_LIBTOOLIZE_OPTIONS 2>&1`"
1217                 ret=$?
1218                 $VERBOSE_ECHO "$libtoolize_output"
1219                 
1220                 if [ ! $ret = 0 ] ; then $ECHO "ERROR: $LIBTOOLIZE failed" && exit 2 ; fi
1221             fi
1222         fi
1223
1224         ###########
1225         # aclocal #
1226         ###########
1227         # re-run again as instructed by libtoolize
1228         $VERBOSE_ECHO "$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS"
1229         aclocal_output="`$ACLOCAL $SEARCH_DIRS $ACLOCAL_OPTIONS 2>&1`"
1230         ret=$?
1231         $VERBOSE_ECHO "$aclocal_output"
1232
1233         # libtoolize might put ltmain.sh in the wrong place
1234         if test -f ltmain.sh ; then
1235             if test ! -f "${_aux_dir}/ltmain.sh" ; then
1236                 $ECHO
1237                 $ECHO "Warning:  $LIBTOOLIZE is creating ltmain.sh in the wrong directory"
1238                 $ECHO
1239                 $ECHO "Fortunately, the problem can be worked around by simply copying the"
1240                 $ECHO "file to the appropriate location (${_aux_dir}/).  This has been done for you."
1241                 $ECHO
1242                 $VERBOSE_ECHO "cp -p ltmain.sh \"${_aux_dir}/ltmain.sh\""
1243                 cp -p ltmain.sh "${_aux_dir}/ltmain.sh"
1244                 $ECHO $ECHO_N "Continuing build preparation ... $ECHO_C"
1245             fi
1246         fi # ltmain.sh
1247     fi # need_libtoolize
1248
1249     ############
1250     # autoconf #
1251     ############
1252     $VERBOSE_ECHO
1253     $VERBOSE_ECHO "$AUTOCONF $AUTOCONF_OPTIONS"
1254     autoconf_output="`$AUTOCONF $AUTOCONF_OPTIONS 2>&1`"
1255     ret=$?
1256     $VERBOSE_ECHO "$autoconf_output"
1257
1258     if [ ! $ret = 0 ] ; then
1259         # retry without the -f and check for usage of macros that are too new
1260         ac2_59_macros="AC_C_RESTRICT AC_INCLUDES_DEFAULT AC_LANG_ASSERT AC_LANG_WERROR AS_SET_CATFILE"
1261         ac2_55_macros="AC_COMPILER_IFELSE AC_FUNC_MBRTOWC AC_HEADER_STDBOOL AC_LANG_CONFTEST AC_LANG_SOURCE AC_LANG_PROGRAM AC_LANG_CALL AC_LANG_FUNC_TRY_LINK AC_MSG_FAILURE AC_PREPROC_IFELSE"
1262         ac2_54_macros="AC_C_BACKSLASH_A AC_CONFIG_LIBOBJ_DIR AC_GNU_SOURCE AC_PROG_EGREP AC_PROG_FGREP AC_REPLACE_FNMATCH AC_FUNC_FNMATCH_GNU AC_FUNC_REALLOC AC_TYPE_MBSTATE_T"
1263
1264         macros_to_search=""
1265         ac_major="`echo ${AUTOCONF_VERSION}. | cut -d. -f1 | sed 's/[^0-9]//g'`"
1266         ac_minor="`echo ${AUTOCONF_VERSION}. | cut -d. -f2 | sed 's/[^0-9]//g'`"
1267         
1268         if [ $ac_major -lt 2 ] ; then
1269             macros_to_search="$ac2_59_macros $ac2_55_macros $ac2_54_macros"
1270         else
1271             if [ $ac_minor -lt 54 ] ; then
1272                 macros_to_search="$ac2_59_macros $ac2_55_macros $ac2_54_macros"
1273             elif [ $ac_minor -lt 55 ] ; then
1274                 macros_to_search="$ac2_59_macros $ac2_55_macros"
1275             elif [ $ac_minor -lt 59 ] ; then
1276                 macros_to_search="$ac2_59_macros"
1277             fi
1278         fi
1279
1280         configure_ac_macros=__none__
1281         for feature in $macros_to_search ; do
1282             $VERBOSE_ECHO "Searching for $feature in $CONFIGURE"
1283             found="`grep \"^$feature.*\" $CONFIGURE`"
1284             if [ ! "x$found" = "x" ] ; then
1285                 if [ "x$configure_ac_macros" = "x__none__" ] ; then
1286                     configure_ac_macros="$feature"
1287                 else
1288                     configure_ac_macros="$feature $configure_ac_macros"
1289                 fi
1290             fi
1291         done
1292         if [ ! "x$configure_ac_macros" = "x__none__" ] ; then
1293             $ECHO
1294             $ECHO "Warning:  Unsupported macros were found in $CONFIGURE"
1295             $ECHO
1296             $ECHO "The `echo $CONFIGURE | basename` file was scanned in order to determine if any"
1297             $ECHO "unsupported macros are used that exceed the minimum version"
1298             $ECHO "settings specified within this file.  As such, the following macros"
1299             $ECHO "should be removed from configure.ac or the version numbers in this"
1300             $ECHO "file should be increased:"
1301             $ECHO
1302             $ECHO "$configure_ac_macros"
1303             $ECHO
1304             $ECHO $ECHO_N "Ignorantly continuing build preparation ... $ECHO_C"
1305         fi
1306
1307         ###################
1308         # autoconf, retry #
1309         ###################
1310         $VERBOSE_ECHO
1311         $VERBOSE_ECHO "$AUTOCONF"
1312         autoconf_output="`$AUTOCONF 2>&1`"
1313         ret=$?
1314         $VERBOSE_ECHO "$autoconf_output"
1315
1316         if [ ! $ret = 0 ] ; then
1317             # test if libtool is busted
1318             libtool_failure "$autoconf_output"
1319
1320             # let the user know what went wrong
1321             cat <<EOF
1322 $autoconf_output
1323 EOF
1324             $ECHO "ERROR: $AUTOCONF failed"
1325             exit 2
1326         else
1327             # autoconf sans -f and possibly sans unsupported options succeed so warn verbosely
1328             $ECHO
1329             $ECHO "Warning: autoconf seems to have succeeded by removing the following options:"
1330             $ECHO "     AUTOCONF_OPTIONS=\"$AUTOCONF_OPTIONS\""
1331             $ECHO
1332             $ECHO "Removing those options should not be necessary and indicate some other"
1333             $ECHO "problem with the build system.  The build preparation is highly suspect"
1334             $ECHO "and may result in configuration or compilation errors.  Consider"
1335             if [ "x$VERBOSE_ECHO" = "x:" ] ; then
1336                 $ECHO "rerunning the build preparation with verbose output enabled."
1337                 $ECHO " $AUTOGEN_SH --verbose"
1338             else
1339                 $ECHO "reviewing the minimum GNU Autotools version settings contained in"
1340                 $ECHO "this script along with the macros being used in your `echo $CONFIGURE | basename` file."
1341             fi
1342             $ECHO
1343             $ECHO $ECHO_N "Continuing build preparation ... $ECHO_C"
1344         fi # autoconf ret = 0
1345     fi # autoconf ret = 0
1346
1347     ##############
1348     # autoheader #
1349     ##############
1350     need_autoheader=no
1351     for feature in AM_CONFIG_HEADER AC_CONFIG_HEADER ; do
1352         $VERBOSE_ECHO "Searching for $feature in $CONFIGURE"
1353         found="`grep \"^$feature.*\" $CONFIGURE`"
1354         if [ ! "x$found" = "x" ] ; then
1355             need_autoheader=yes
1356             break
1357         fi
1358     done
1359     if [ "x$need_autoheader" = "xyes" ] ; then
1360         $VERBOSE_ECHO "$AUTOHEADER $AUTOHEADER_OPTIONS"
1361         autoheader_output="`$AUTOHEADER $AUTOHEADER_OPTIONS 2>&1`"
1362         ret=$?
1363         $VERBOSE_ECHO "$autoheader_output"
1364         if [ ! $ret = 0 ] ; then $ECHO "ERROR: $AUTOHEADER failed" && exit 2 ; fi
1365     fi # need_autoheader
1366
1367     ############
1368     # automake #
1369     ############
1370     need_automake=no
1371     for feature in AM_INIT_AUTOMAKE ; do
1372         $VERBOSE_ECHO "Searching for $feature in $CONFIGURE"
1373         found="`grep \"^$feature.*\" $CONFIGURE`"
1374         if [ ! "x$found" = "x" ] ; then
1375             need_automake=yes
1376             break
1377         fi
1378     done
1379
1380     if [ "x$need_automake" = "xyes" ] ; then
1381         $VERBOSE_ECHO "$AUTOMAKE $AUTOMAKE_OPTIONS"
1382         automake_output="`$AUTOMAKE $AUTOMAKE_OPTIONS 2>&1`"
1383         ret=$?
1384         $VERBOSE_ECHO "$automake_output"
1385         
1386         if [ ! $ret = 0 ] ; then
1387
1388             ###################
1389             # automake, retry #
1390             ###################
1391             $VERBOSE_ECHO
1392             $VERBOSE_ECHO "$AUTOMAKE $ALT_AUTOMAKE_OPTIONS"
1393             # retry without the -f
1394             automake_output="`$AUTOMAKE $ALT_AUTOMAKE_OPTIONS 2>&1`"
1395             ret=$?
1396             $VERBOSE_ECHO "$automake_output"
1397             
1398             if [ ! $ret = 0 ] ; then
1399                 # test if libtool is busted
1400                 libtool_failure "$automake_output"
1401
1402                 # let the user know what went wrong
1403                 cat <<EOF
1404 $automake_output
1405 EOF
1406                 $ECHO "ERROR: $AUTOMAKE failed"
1407                 exit 2
1408             fi # automake retry
1409         fi # automake ret = 0
1410     fi # need_automake
1411 } # end of manual_autogen
1412
1413
1414 #####################################
1415 # RECURSIVE_MANUAL_AUTOGEN FUNCTION #
1416 #####################################
1417 recursive_manual_autogen ( ) {
1418
1419     # run the build preparation steps manually for this directory
1420     manual_autogen
1421
1422     # for projects using recursive configure, run the build
1423     # preparation steps for the subdirectories.
1424     if [ ! "x$CONFIG_SUBDIRS" = "x" ] ; then
1425         $VERBOSE_ECHO "Recursively configuring the following directories:"
1426         $VERBOSE_ECHO "  $CONFIG_SUBDIRS"
1427         for dir in $CONFIG_SUBDIRS ; do
1428             $VERBOSE_ECHO "Processing recursive configure in $dir"
1429             cd "$START_PATH"
1430             cd "$dir"
1431
1432             # new directory, prepare
1433             initialize
1434
1435             # run manual steps for the subdir and any others below
1436             recursive_manual_autogen
1437         done
1438     fi
1439 }
1440
1441
1442 ################################
1443 # run manual preparation steps #
1444 ################################
1445 if [ "x$reconfigure_manually" = "xyes" ] ; then
1446     $ECHO
1447     $ECHO $ECHO_N "Preparing build ... $ECHO_C"
1448
1449     recursive_manual_autogen
1450 fi
1451
1452
1453 #########################
1454 # restore and summarize #
1455 #########################
1456 cd "$START_PATH"
1457
1458 # restore COPYING and INSTALL from backup if necessary
1459 recursive_restore
1460
1461 # make sure we end up with a configure script
1462 config_ac="`locate_configure_template`"
1463 config="`echo $config_ac | sed 's/\.ac$//' | sed 's/\.in$//'`"
1464 if [ "x$config" = "x" ] ; then
1465     $VERBOSE_ECHO "Could not locate the configure template (from `pwd`)"
1466 fi
1467
1468 # summarize
1469 $ECHO "done"
1470 $ECHO
1471 if test "x$config" = "x" -o ! -f "$config" ; then
1472     $ECHO "WARNING: The $PROJECT build system should now be prepared but there"
1473     $ECHO "does not seem to be a resulting configure file.  This is unexpected"
1474     $ECHO "and likely the result of an error.  You should run $NAME_OF_AUTOGEN"
1475     $ECHO "with the --verbose option to get more details on a potential"
1476     $ECHO "misconfiguration."
1477 else
1478     $ECHO "The $PROJECT build system is now prepared.  To build here, run:"
1479     $ECHO "  $config"
1480     $ECHO "  make"
1481 fi
1482
1483
1484 # Local Variables:
1485 # mode: sh
1486 # tab-width: 8
1487 # sh-basic-offset: 4
1488 # sh-indentation: 4
1489 # indent-tabs-mode: t
1490 # End:
1491 # ex: shiftwidth=4 tabstop=8