2009-06-20 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/upstream/at-spi2-core.git] / autogen.sh
1 #!/bin/sh
2 # Run this to generate all the initial makefiles, etc.
3
4 #name of package
5 test "$PKG_NAME" || PKG_NAME=Package
6 test "$srcdir" || srcdir=.
7
8 # default version requirements ...
9 test "$REQUIRED_AUTOCONF_VERSION" || REQUIRED_AUTOCONF_VERSION=2.53
10 test "$REQUIRED_AUTOMAKE_VERSION" || REQUIRED_AUTOMAKE_VERSION=1.9
11 test "$REQUIRED_LIBTOOL_VERSION" || REQUIRED_LIBTOOL_VERSION=1.5
12 test "$REQUIRED_PKG_CONFIG_VERSION" || REQUIRED_PKG_CONFIG_VERSION=0.14.0
13 test "$REQUIRED_GTK_DOC_VERSION" || REQUIRED_GTK_DOC_VERSION=1.0
14 test "$REQUIRED_DOC_COMMON_VERSION" || REQUIRED_DOC_COMMON_VERSION=2.3.0
15 test "$REQUIRED_GNOME_DOC_UTILS_VERSION" || REQUIRED_GNOME_DOC_UTILS_VERSION=0.4.2
16
17 # a list of required m4 macros.  Package can set an initial value
18 test "$REQUIRED_M4MACROS" || REQUIRED_M4MACROS=
19 test "$FORBIDDEN_M4MACROS" || FORBIDDEN_M4MACROS=
20
21 # Not all echo versions allow -n, so we check what is possible. This test is
22 # based on the one in autoconf.
23 ECHO_C=
24 ECHO_N=
25 case `echo -n x` in
26 -n*)
27   case `echo 'x\c'` in
28   *c*) ;;
29   *)   ECHO_C='\c';;
30   esac;;
31 *)
32   ECHO_N='-n';;
33 esac
34
35 # some terminal codes ...
36 boldface="`tput bold 2>/dev/null`"
37 normal="`tput sgr0 2>/dev/null`"
38 printbold() {
39     echo $ECHO_N "$boldface" $ECHO_C
40     echo "$@"
41     echo $ECHO_N "$normal" $ECHO_C
42 }    
43 printerr() {
44     echo "$@" >&2
45 }
46
47 # Usage:
48 #     compare_versions MIN_VERSION ACTUAL_VERSION
49 # returns true if ACTUAL_VERSION >= MIN_VERSION
50 compare_versions() {
51     ch_min_version=$1
52     ch_actual_version=$2
53     ch_status=0
54     IFS="${IFS=         }"; ch_save_IFS="$IFS"; IFS="."
55     set $ch_actual_version
56     for ch_min in $ch_min_version; do
57         ch_cur=`echo $1 | sed 's/[^0-9].*$//'`; shift # remove letter suffixes
58         if [ -z "$ch_min" ]; then break; fi
59         if [ -z "$ch_cur" ]; then ch_status=1; break; fi
60         if [ $ch_cur -gt $ch_min ]; then break; fi
61         if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
62     done
63     IFS="$ch_save_IFS"
64     return $ch_status
65 }
66
67 # Usage:
68 #     version_check PACKAGE VARIABLE CHECKPROGS MIN_VERSION SOURCE
69 # checks to see if the package is available
70 version_check() {
71     vc_package=$1
72     vc_variable=$2
73     vc_checkprogs=$3
74     vc_min_version=$4
75     vc_source=$5
76     vc_status=1
77
78     vc_checkprog=`eval echo "\\$$vc_variable"`
79     if [ -n "$vc_checkprog" ]; then
80         printbold "using $vc_checkprog for $vc_package"
81         return 0
82     fi
83
84     if test "x$vc_package" = "xautomake" -a "x$vc_min_version" = "x1.4"; then
85         vc_comparator="="
86     else
87         vc_comparator=">="
88     fi
89     printbold "checking for $vc_package $vc_comparator $vc_min_version..."
90     for vc_checkprog in $vc_checkprogs; do
91         echo $ECHO_N "  testing $vc_checkprog... " $ECHO_C
92         if $vc_checkprog --version < /dev/null > /dev/null 2>&1; then
93             vc_actual_version=`$vc_checkprog --version | head -n 1 | \
94                                sed 's/^.*[      ]\([0-9.]*[a-z]*\).*$/\1/'`
95             if compare_versions $vc_min_version $vc_actual_version; then
96                 echo "found $vc_actual_version"
97                 # set variables
98                 eval "$vc_variable=$vc_checkprog; \
99                         ${vc_variable}_VERSION=$vc_actual_version"
100                 vc_status=0
101                 break
102             else
103                 echo "too old (found version $vc_actual_version)"
104             fi
105         else
106             echo "not found."
107         fi
108     done
109     if [ "$vc_status" != 0 ]; then
110         printerr "***Error***: You must have $vc_package $vc_comparator $vc_min_version installed"
111         printerr "  to build $PKG_NAME.  Download the appropriate package for"
112         printerr "  from your distribution or get the source tarball at"
113         printerr "    $vc_source"
114         printerr
115         exit $vc_status
116     fi
117     return $vc_status
118 }
119
120 # Usage:
121 #     require_m4macro filename.m4
122 # adds filename.m4 to the list of required macros
123 require_m4macro() {
124     case "$REQUIRED_M4MACROS" in
125         $1\ * | *\ $1\ * | *\ $1) ;;
126         *) REQUIRED_M4MACROS="$REQUIRED_M4MACROS $1" ;;
127     esac
128 }
129
130 forbid_m4macro() {
131     case "$FORBIDDEN_M4MACROS" in
132         $1\ * | *\ $1\ * | *\ $1) ;;
133         *) FORBIDDEN_M4MACROS="$FORBIDDEN_M4MACROS $1" ;;
134     esac
135 }
136
137 # Usage:
138 #     add_to_cm_macrodirs dirname
139 # Adds the dir to $cm_macrodirs, if it's not there yet.
140 add_to_cm_macrodirs() {
141     case $cm_macrodirs in
142     "$1 "* | *" $1 "* | *" $1") ;;
143     *) cm_macrodirs="$cm_macrodirs $1";;
144     esac
145 }
146
147 # Usage:
148 #     print_m4macros_error
149 # Prints an error message saying that autoconf macros were misused
150 print_m4macros_error() {
151     printerr "***Error***: some autoconf macros required to build $PKG_NAME"
152     printerr "  were not found in your aclocal path, or some forbidden"
153     printerr "  macros were found.  Perhaps you need to adjust your"
154     printerr "  ACLOCAL_FLAGS?"
155     printerr
156 }
157
158 # Usage:
159 #     check_m4macros
160 # Checks that all the requested macro files are in the aclocal macro path
161 # Uses REQUIRED_M4MACROS and ACLOCAL variables.
162 check_m4macros() {
163     # construct list of macro directories
164     cm_macrodirs=`$ACLOCAL --print-ac-dir`
165     # aclocal also searches a version specific dir, eg. /usr/share/aclocal-1.9
166     # but it contains only Automake's own macros, so we can ignore it.
167
168     # Read the dirlist file, supported by Automake >= 1.7.
169     # If AUTOMAKE was defined, no version was detected.
170     if [ -z "$AUTOMAKE_VERSION" ] || compare_versions 1.7 $AUTOMAKE_VERSION && [ -s $cm_macrodirs/dirlist ]; then
171         cm_dirlist=`sed 's/[    ]*#.*//;/^$/d' $cm_macrodirs/dirlist`
172         if [ -n "$cm_dirlist" ] ; then
173             for cm_dir in $cm_dirlist; do
174                 if [ -d $cm_dir ]; then
175                     add_to_cm_macrodirs $cm_dir
176                 fi
177             done
178         fi
179     fi
180
181     # Parse $ACLOCAL_FLAGS
182     set - $ACLOCAL_FLAGS
183     while [ $# -gt 0 ]; do
184         if [ "$1" = "-I" ]; then
185             add_to_cm_macrodirs "$2"
186             shift
187         fi
188         shift
189     done
190
191     cm_status=0
192     if [ -n "$REQUIRED_M4MACROS" ]; then
193         printbold "Checking for required M4 macros..."
194         # check that each macro file is in one of the macro dirs
195         for cm_macro in $REQUIRED_M4MACROS; do
196             cm_macrofound=false
197             for cm_dir in $cm_macrodirs; do
198                 if [ -f "$cm_dir/$cm_macro" ]; then
199                     cm_macrofound=true
200                     break
201                 fi
202                 # The macro dir in Cygwin environments may contain a file
203                 # called dirlist containing other directories to look in.
204                 if [ -f "$cm_dir/dirlist" ]; then
205                     for cm_otherdir in `cat $cm_dir/dirlist`; do
206                         if [ -f "$cm_otherdir/$cm_macro" ]; then
207                             cm_macrofound=true
208                             break
209                         fi
210                     done
211                 fi
212             done
213             if $cm_macrofound; then
214                 :
215             else
216                 printerr "  $cm_macro not found"
217                 cm_status=1
218             fi
219         done
220     fi
221     if [ "$cm_status" != 0 ]; then
222         print_m4macros_error
223         exit $cm_status
224     fi
225     if [ -n "$FORBIDDEN_M4MACROS" ]; then
226         printbold "Checking for forbidden M4 macros..."
227         # check that each macro file is in one of the macro dirs
228         for cm_macro in $FORBIDDEN_M4MACROS; do
229             cm_macrofound=false
230             for cm_dir in $cm_macrodirs; do
231                 if [ -f "$cm_dir/$cm_macro" ]; then
232                     cm_macrofound=true
233                     break
234                 fi
235             done
236             if $cm_macrofound; then
237                 printerr "  $cm_macro found (should be cleared from macros dir)"
238                 cm_status=1
239             fi
240         done
241     fi
242     if [ "$cm_status" != 0 ]; then
243         print_m4macros_error
244         exit $cm_status
245     fi
246 }
247
248 # try to catch the case where the macros2/ directory hasn't been cleared out.
249 forbid_m4macro gnome-cxx-check.m4
250
251 want_libtool=false
252 want_gettext=false
253 want_glib_gettext=false
254 want_intltool=false
255 want_pkg_config=false
256 want_gtk_doc=false
257 want_gnome_doc_utils=false
258
259 configure_files="`find $srcdir -name '{arch}' -prune -o -name '_darcs' -prune -o -name '.??*' -prune -o -name configure.ac -print -o -name configure.in -print`"
260 for configure_ac in $configure_files; do
261     dirname=`dirname $configure_ac`
262     if [ -f $dirname/NO-AUTO-GEN ]; then
263         echo skipping $dirname -- flagged as no auto-gen
264         continue
265     fi
266     if grep "^A[CM]_PROG_LIBTOOL" $configure_ac >/dev/null ||
267        grep "^LT_INIT" $configure_ac >/dev/null; then
268         want_libtool=true
269     fi
270     if grep "^AM_GNU_GETTEXT" $configure_ac >/dev/null; then
271         want_gettext=true
272     fi
273     if grep "^AM_GLIB_GNU_GETTEXT" $configure_ac >/dev/null; then
274         want_glib_gettext=true
275     fi
276     if grep "^AC_PROG_INTLTOOL" $configure_ac >/dev/null ||
277        grep "^IT_PROG_INTLTOOL" $configure_ac >/dev/null; then
278         want_intltool=true
279     fi
280     if grep "^PKG_CHECK_MODULES" $configure_ac >/dev/null; then
281         want_pkg_config=true
282     fi
283     if grep "^GTK_DOC_CHECK" $configure_ac >/dev/null; then
284         want_gtk_doc=true
285     fi
286     if grep "^GNOME_DOC_INIT" $configure_ac >/dev/null; then
287         want_gnome_doc_utils=true
288     fi
289
290     # check to make sure gnome-common macros can be found ...
291     if grep "^GNOME_COMMON_INIT" $configure_ac >/dev/null ||
292        grep "^GNOME_DEBUG_CHECK" $configure_ac >/dev/null ||
293        grep "^GNOME_MAINTAINER_MODE_DEFINES" $configure_ac >/dev/null; then
294         require_m4macro gnome-common.m4
295     fi
296     if grep "^GNOME_COMPILE_WARNINGS" $configure_ac >/dev/null ||
297        grep "^GNOME_CXX_WARNINGS" $configure_ac >/dev/null; then
298         require_m4macro gnome-compiler-flags.m4
299     fi
300 done
301
302 #tell Mandrake autoconf wrapper we want autoconf 2.5x, not 2.13
303 WANT_AUTOCONF_2_5=1
304 export WANT_AUTOCONF_2_5
305 version_check autoconf AUTOCONF 'autoconf2.50 autoconf autoconf-2.53' $REQUIRED_AUTOCONF_VERSION \
306     "http://ftp.gnu.org/pub/gnu/autoconf/autoconf-$REQUIRED_AUTOCONF_VERSION.tar.gz"
307 AUTOHEADER=`echo $AUTOCONF | sed s/autoconf/autoheader/`
308
309 case $REQUIRED_AUTOMAKE_VERSION in
310     1.4*) automake_progs="automake-1.4" ;;
311     1.5*) automake_progs="automake-1.10 automake-1.9 automake-1.8 automake-1.7 automake-1.6 automake-1.5" ;;
312     1.6*) automake_progs="automake-1.10 automake-1.9 automake-1.8 automake-1.7 automake-1.6" ;;
313     1.7*) automake_progs="automake-1.10 automake-1.9 automake-1.8 automake-1.7" ;;
314     1.8*) automake_progs="automake-1.10 automake-1.9 automake-1.8" ;;
315     1.9*) automake_progs="automake-1.10 automake-1.9" ;;
316     1.10*) automake_progs="automake-1.10" ;;
317 esac
318 version_check automake AUTOMAKE "$automake_progs" $REQUIRED_AUTOMAKE_VERSION \
319     "http://ftp.gnu.org/pub/gnu/automake/automake-$REQUIRED_AUTOMAKE_VERSION.tar.gz"
320 ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
321
322 if $want_libtool; then
323     version_check libtool LIBTOOLIZE libtoolize $REQUIRED_LIBTOOL_VERSION \
324         "http://ftp.gnu.org/pub/gnu/libtool/libtool-$REQUIRED_LIBTOOL_VERSION.tar.gz"
325     require_m4macro libtool.m4
326 fi
327
328 if $want_pkg_config; then
329     version_check pkg-config PKG_CONFIG pkg-config $REQUIRED_PKG_CONFIG_VERSION \
330         "'http://www.freedesktop.org/software/pkgconfig/releases/pkgconfig-$REQUIRED_PKG_CONFIG_VERSION.tar.gz"
331     require_m4macro pkg.m4
332 fi
333
334 if $want_gtk_doc; then
335     version_check gtk-doc GTKDOCIZE gtkdocize $REQUIRED_GTK_DOC_VERSION \
336         "http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/"
337     require_m4macro gtk-doc.m4
338 fi
339
340 if $want_gnome_doc_utils; then
341     version_check gnome-doc-utils GNOME_DOC_PREPARE gnome-doc-prepare $REQUIRED_GNOME_DOC_UTILS_VERSION \
342         "http://ftp.gnome.org/pub/GNOME/sources/gnome-doc-utils/"
343 fi
344
345 if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
346     version_check gnome-common DOC_COMMON gnome-doc-common \
347         $REQUIRED_DOC_COMMON_VERSION " "
348 fi
349
350 check_m4macros
351
352 if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
353   printerr "**Warning**: I am going to run \`configure' with no arguments."
354   printerr "If you wish to pass any to it, please specify them on the"
355   printerr \`$0\'" command line."
356   printerr
357 fi
358
359 topdir=`pwd`
360 for configure_ac in $configure_files; do 
361     dirname=`dirname $configure_ac`
362     basename=`basename $configure_ac`
363     if [ -f $dirname/NO-AUTO-GEN ]; then
364         echo skipping $dirname -- flagged as no auto-gen
365     elif [ ! -w $dirname ]; then
366         echo skipping $dirname -- directory is read only
367     else
368         printbold "Processing $configure_ac"
369         cd $dirname
370
371         # Note that the order these tools are called should match what
372         # autoconf's "autoupdate" package does.  See bug 138584 for
373         # details.
374
375         # programs that might install new macros get run before aclocal
376         if grep "^A[CM]_PROG_LIBTOOL" $basename >/dev/null ||
377            grep "^LT_INIT" $basename >/dev/null; then
378             printbold "Running $LIBTOOLIZE..."
379             $LIBTOOLIZE --force --copy || exit 1
380         fi
381
382         if grep "^AM_GLIB_GNU_GETTEXT" $basename >/dev/null; then
383             printbold "Running $GLIB_GETTEXTIZE... Ignore non-fatal messages."
384             echo "no" | $GLIB_GETTEXTIZE --force --copy || exit 1
385         elif grep "^AM_GNU_GETTEXT" $basename >/dev/null; then
386            if grep "^AM_GNU_GETTEXT_VERSION" $basename > /dev/null; then
387                 printbold "Running autopoint..."
388                 autopoint --force || exit 1
389            else
390                 printbold "Running $GETTEXTIZE... Ignore non-fatal messages."
391                 echo "no" | $GETTEXTIZE --force --copy || exit 1
392            fi
393         fi
394
395         if grep "^AC_PROG_INTLTOOL" $basename >/dev/null ||
396            grep "^IT_PROG_INTLTOOL" $basename >/dev/null; then
397             printbold "Running $INTLTOOLIZE..."
398             $INTLTOOLIZE --force --copy --automake || exit 1
399         fi
400         if grep "^GTK_DOC_CHECK" $basename >/dev/null; then
401             printbold "Running $GTKDOCIZE..."
402             $GTKDOCIZE --copy || exit 1
403         fi
404
405         if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
406             printbold "Running gnome-doc-common..."
407             gnome-doc-common --copy || exit 1
408         fi
409         if grep "^GNOME_DOC_INIT" $basename >/dev/null; then
410             printbold "Running $GNOME_DOC_PREPARE..."
411             $GNOME_DOC_PREPARE --force --copy || exit 1
412         fi
413
414         # Now run aclocal to pull in any additional macros needed
415
416         # if the AC_CONFIG_MACRO_DIR() macro is used, pass that
417         # directory to aclocal.
418         m4dir=`cat "$basename" | grep '^AC_CONFIG_MACRO_DIR' | sed -n -e 's/AC_CONFIG_MACRO_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
419         if [ -n "$m4dir" ]; then
420             m4dir="-I $m4dir"
421         fi
422         printbold "Running $ACLOCAL..."
423         $ACLOCAL $m4dir $ACLOCAL_FLAGS || exit 1
424
425         if grep "GNOME_AUTOGEN_OBSOLETE" aclocal.m4 >/dev/null; then
426             printerr "*** obsolete gnome macros were used in $configure_ac"
427         fi
428
429         # Now that all the macros are sorted, run autoconf and autoheader ...
430         printbold "Running $AUTOCONF..."
431         $AUTOCONF || exit 1
432         if grep "^A[CM]_CONFIG_HEADER" $basename >/dev/null; then
433             printbold "Running $AUTOHEADER..."
434             $AUTOHEADER || exit 1
435             # this prevents automake from thinking config.h.in is out of
436             # date, since autoheader doesn't touch the file if it doesn't
437             # change.
438             test -f config.h.in && touch config.h.in
439         fi
440
441         # Finally, run automake to create the makefiles ...
442         printbold "Running $AUTOMAKE..."
443         if [ -f COPYING ]; then
444           cp -pf COPYING COPYING.autogen_bak
445         fi
446         if [ -f INSTALL ]; then
447           cp -pf INSTALL INSTALL.autogen_bak
448         fi
449         if [ $REQUIRED_AUTOMAKE_VERSION != 1.4 ]; then
450             $AUTOMAKE --gnu --add-missing --force --copy || exit 1
451         else
452             $AUTOMAKE --gnu --add-missing --copy || exit 1
453         fi
454         if [ -f COPYING.autogen_bak ]; then
455           cmp COPYING COPYING.autogen_bak > /dev/null || cp -pf COPYING.autogen_bak COPYING
456           rm -f COPYING.autogen_bak
457         fi
458         if [ -f INSTALL.autogen_bak ]; then
459           cmp INSTALL INSTALL.autogen_bak > /dev/null || cp -pf INSTALL.autogen_bak INSTALL
460           rm -f INSTALL.autogen_bak
461         fi
462
463         cd "$topdir"
464     fi
465 done
466
467 conf_flags=
468
469 if test x$NOCONFIGURE = x; then
470     printbold Running $srcdir/configure $conf_flags "$@" ...
471     $srcdir/configure $conf_flags "$@" \
472         && echo Now type \`make\' to compile $PKG_NAME || exit 1
473 else
474     echo Skipping configure process.
475 fi