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