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