gnome-autogen: Do not use sed to get the AC_CONFIG_MACRO_DIR directory
[platform/upstream/gnome-common.git] / macros2 / gnome-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.4.3
12 test "$REQUIRED_GETTEXT_VERSION" || REQUIRED_GETTEXT_VERSION=0.10.40
13 test "$REQUIRED_GLIB_GETTEXT_VERSION" || REQUIRED_GLIB_GETTEXT_VERSION=2.2.0
14 test "$REQUIRED_INTLTOOL_VERSION" || REQUIRED_INTLTOOL_VERSION=0.25
15 test "$REQUIRED_PKG_CONFIG_VERSION" || REQUIRED_PKG_CONFIG_VERSION=0.14.0
16 test "$REQUIRED_GTK_DOC_VERSION" || REQUIRED_GTK_DOC_VERSION=1.0
17 test "$REQUIRED_DOC_COMMON_VERSION" || REQUIRED_DOC_COMMON_VERSION=2.3.0
18 test "$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 test "$REQUIRED_M4MACROS" || REQUIRED_M4MACROS=
22 test "$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 AUTOMAKE was defined, no version was detected.
178     if [ -z "$AUTOMAKE_VERSION" ] || compare_versions 1.7 $AUTOMAKE_VERSION && [ -s $cm_macrodirs/dirlist ]; then
179         cm_dirlist=`sed 's/[    ]*#.*//;/^$/d' $cm_macrodirs/dirlist`
180         if [ -n "$cm_dirlist" ] ; then
181             for cm_dir in $cm_dirlist; do
182                 if [ -d $cm_dir ]; then
183                     add_to_cm_macrodirs $cm_dir
184                 fi
185             done
186         fi
187     fi
188
189     # Parse $ACLOCAL_FLAGS
190     set - $ACLOCAL_FLAGS
191     while [ $# -gt 0 ]; do
192         if [ "$1" = "-I" ]; then
193             add_to_cm_macrodirs "$2"
194             shift
195         fi
196         shift
197     done
198
199     cm_status=0
200     if [ -n "$REQUIRED_M4MACROS" ]; then
201         printbold "Checking for required M4 macros..."
202         # check that each macro file is in one of the macro dirs
203         for cm_macro in $REQUIRED_M4MACROS; do
204             cm_macrofound=false
205             for cm_dir in $cm_macrodirs; do
206                 if [ -f "$cm_dir/$cm_macro" ]; then
207                     cm_macrofound=true
208                     break
209                 fi
210                 # The macro dir in Cygwin environments may contain a file
211                 # called dirlist containing other directories to look in.
212                 if [ -f "$cm_dir/dirlist" ]; then
213                     for cm_otherdir in `cat $cm_dir/dirlist`; do
214                         if [ -f "$cm_otherdir/$cm_macro" ]; then
215                             cm_macrofound=true
216                             break
217                         fi
218                     done
219                 fi
220             done
221             if $cm_macrofound; then
222                 :
223             else
224                 printerr "  $cm_macro not found"
225                 cm_status=1
226             fi
227         done
228     fi
229     if [ "$cm_status" != 0 ]; then
230         print_m4macros_error
231         exit $cm_status
232     fi
233     if [ -n "$FORBIDDEN_M4MACROS" ]; then
234         printbold "Checking for forbidden M4 macros..."
235         # check that each macro file is in one of the macro dirs
236         for cm_macro in $FORBIDDEN_M4MACROS; do
237             cm_macrofound=false
238             for cm_dir in $cm_macrodirs; do
239                 if [ -f "$cm_dir/$cm_macro" ]; then
240                     cm_macrofound=true
241                     break
242                 fi
243             done
244             if $cm_macrofound; then
245                 printerr "  $cm_macro found (should be cleared from macros dir)"
246                 cm_status=1
247             fi
248         done
249     fi
250     if [ "$cm_status" != 0 ]; then
251         print_m4macros_error
252         exit $cm_status
253     fi
254 }
255
256 # try to catch the case where the macros2/ directory hasn't been cleared out.
257 forbid_m4macro gnome-cxx-check.m4
258
259 want_libtool=false
260 want_gettext=false
261 want_glib_gettext=false
262 want_intltool=false
263 want_pkg_config=false
264 want_gtk_doc=false
265 want_gnome_doc_utils=false
266 want_maintainer_mode=false
267
268 #tell Mandrake autoconf wrapper we want autoconf 2.5x, not 2.13
269 WANT_AUTOCONF_2_5=1
270 export WANT_AUTOCONF_2_5
271 version_check autoconf AUTOCONF 'autoconf2.50 autoconf autoconf-2.53' $REQUIRED_AUTOCONF_VERSION \
272     "http://ftp.gnu.org/pub/gnu/autoconf/autoconf-$REQUIRED_AUTOCONF_VERSION.tar.gz"
273 AUTOHEADER=`echo $AUTOCONF | sed s/autoconf/autoheader/`
274
275 find_configure_files() {
276     configure_ac=
277     if test -f "$1/configure.ac"; then
278         configure_ac="$1/configure.ac"
279     elif test -f "$1/configure.in"; then
280         configure_ac="$1/configure.in"
281     fi
282     if test "x$configure_ac" != x; then
283         echo "$configure_ac"
284         $AUTOCONF -t 'AC_CONFIG_SUBDIRS:$1' "$configure_ac" | while read dir; do
285             find_configure_files "$1/$dir"
286         done
287     fi
288 }
289
290 configure_files="`find_configure_files $srcdir`"
291
292 for configure_ac in $configure_files; do
293     dirname=`dirname $configure_ac`
294     if [ -f $dirname/NO-AUTO-GEN ]; then
295         echo skipping $dirname -- flagged as no auto-gen
296         continue
297     fi
298     if grep "^A[CM]_PROG_LIBTOOL" $configure_ac >/dev/null ||
299        grep "^LT_INIT" $configure_ac >/dev/null; then
300         want_libtool=true
301     fi
302     if grep "^AM_GNU_GETTEXT" $configure_ac >/dev/null; then
303         want_gettext=true
304     fi
305     if grep "^AM_GLIB_GNU_GETTEXT" $configure_ac >/dev/null; then
306         want_glib_gettext=true
307     fi
308     if grep "^AC_PROG_INTLTOOL" $configure_ac >/dev/null ||
309        grep "^IT_PROG_INTLTOOL" $configure_ac >/dev/null; then
310         want_intltool=true
311     fi
312     if grep "^PKG_CHECK_MODULES" $configure_ac >/dev/null; then
313         want_pkg_config=true
314     fi
315     if grep "^GTK_DOC_CHECK" $configure_ac >/dev/null; then
316         want_gtk_doc=true
317     fi
318     if grep "^GNOME_DOC_INIT" $configure_ac >/dev/null; then
319         want_gnome_doc_utils=true
320     fi
321
322     # check that AM_MAINTAINER_MODE is used
323     if grep "^AM_MAINTAINER_MODE" $configure_ac >/dev/null; then
324         want_maintainer_mode=true
325     fi
326
327     if grep "^YELP_HELP_INIT" $configure_ac >/dev/null; then
328         require_m4macro yelp.m4
329     fi
330
331     # check to make sure gnome-common macros can be found ...
332     if grep "^GNOME_COMMON_INIT" $configure_ac >/dev/null ||
333        grep "^GNOME_DEBUG_CHECK" $configure_ac >/dev/null ||
334        grep "^GNOME_MAINTAINER_MODE_DEFINES" $configure_ac >/dev/null; then
335         require_m4macro gnome-common.m4
336     fi
337     if grep "^GNOME_COMPILE_WARNINGS" $configure_ac >/dev/null ||
338        grep "^GNOME_CXX_WARNINGS" $configure_ac >/dev/null; then
339         require_m4macro gnome-compiler-flags.m4
340     fi
341     if grep "^GNOME_CODE_COVERAGE" $configure_ac >/dev/null; then
342         require_m4macro gnome-code-coverage.m4
343     fi
344 done
345
346 case $REQUIRED_AUTOMAKE_VERSION in
347     1.4*) automake_progs="automake-1.4" ;;
348     1.5*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10 automake-1.9 automake-1.8 automake-1.7 automake-1.6 automake-1.5" ;;
349     1.6*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10 automake-1.9 automake-1.8 automake-1.7 automake-1.6" ;;
350     1.7*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10 automake-1.9 automake-1.8 automake-1.7" ;;
351     1.8*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10 automake-1.9 automake-1.8" ;;
352     1.9*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10 automake-1.9" ;;
353     1.10*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11 automake-1.10" ;;
354     1.11*) automake_progs="automake-1.14 automake-1.13 automake-1.12 automake-1.11" ;;
355     1.12*) automake_progs="automake-1.14 automake-1.13 automake-1.12" ;;
356     1.13*) automake_progs="automake-1.14 automake-1.13" ;;
357     1.14*) automake_progs="automake-1.14" ;;
358 esac
359 version_check automake AUTOMAKE "$automake_progs" $REQUIRED_AUTOMAKE_VERSION \
360     "http://ftp.gnu.org/pub/gnu/automake/automake-$REQUIRED_AUTOMAKE_VERSION.tar.gz"
361 ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
362
363 if $want_libtool; then
364     version_check libtool LIBTOOLIZE "libtoolize glibtoolize" $REQUIRED_LIBTOOL_VERSION \
365         "http://ftp.gnu.org/pub/gnu/libtool/libtool-$REQUIRED_LIBTOOL_VERSION.tar.gz"
366     require_m4macro libtool.m4
367 fi
368
369 if $want_gettext; then
370     version_check gettext GETTEXTIZE gettextize $REQUIRED_GETTEXT_VERSION \
371         "http://ftp.gnu.org/pub/gnu/gettext/gettext-$REQUIRED_GETTEXT_VERSION.tar.gz"
372     require_m4macro gettext.m4
373 fi
374
375 if $want_glib_gettext; then
376     version_check glib-gettext GLIB_GETTEXTIZE glib-gettextize $REQUIRED_GLIB_GETTEXT_VERSION \
377         "ftp://ftp.gtk.org/pub/gtk/v2.2/glib-$REQUIRED_GLIB_GETTEXT_VERSION.tar.gz"
378     require_m4macro glib-gettext.m4
379 fi
380
381 if $want_intltool; then
382     version_check intltool INTLTOOLIZE intltoolize $REQUIRED_INTLTOOL_VERSION \
383         "http://ftp.gnome.org/pub/GNOME/sources/intltool/"
384     require_m4macro intltool.m4
385 fi
386
387 if $want_pkg_config; then
388     version_check pkg-config PKG_CONFIG pkg-config $REQUIRED_PKG_CONFIG_VERSION \
389         "'http://www.freedesktop.org/software/pkgconfig/releases/pkgconfig-$REQUIRED_PKG_CONFIG_VERSION.tar.gz"
390     require_m4macro pkg.m4
391 fi
392
393 if $want_gtk_doc; then
394     version_check gtk-doc GTKDOCIZE gtkdocize $REQUIRED_GTK_DOC_VERSION \
395         "http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/"
396     require_m4macro gtk-doc.m4
397 fi
398
399 if $want_gnome_doc_utils; then
400     version_check gnome-doc-utils GNOME_DOC_PREPARE gnome-doc-prepare $REQUIRED_GNOME_DOC_UTILS_VERSION \
401         "http://ftp.gnome.org/pub/GNOME/sources/gnome-doc-utils/"
402 fi
403
404 if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
405     version_check gnome-common DOC_COMMON gnome-doc-common \
406         $REQUIRED_DOC_COMMON_VERSION " "
407 fi
408
409 check_m4macros
410
411 if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
412   printerr "**Warning**: I am going to run \`configure' with no arguments."
413   printerr "If you wish to pass any to it, please specify them on the"
414   printerr \`$0\'" command line."
415   printerr
416 fi
417
418 topdir=`pwd`
419 for configure_ac in $configure_files; do 
420     dirname=`dirname $configure_ac`
421     basename=`basename $configure_ac`
422     if [ -f $dirname/NO-AUTO-GEN ]; then
423         echo skipping $dirname -- flagged as no auto-gen
424     elif [ ! -w $dirname ]; then
425         echo skipping $dirname -- directory is read only
426     else
427         printbold "Processing $configure_ac"
428         cd $dirname
429
430         # if the AC_CONFIG_MACRO_DIR() macro is used, create that directory
431         # This is a automake bug fixed in automake 1.13.2
432         # See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13514
433         m4dir=`autoconf --trace 'AC_CONFIG_MACRO_DIR:$1'`
434         if [ -n "$m4dir" ]; then
435             mkdir -p $m4dir
436         fi
437
438         if grep "^GTK_DOC_CHECK" $basename >/dev/null; then
439             printbold "Running $GTKDOCIZE..."
440             $GTKDOCIZE --copy || exit 1
441         fi
442
443         if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
444             printbold "Running gnome-doc-common..."
445             gnome-doc-common --copy || exit 1
446         fi
447         if grep "^GNOME_DOC_INIT" $basename >/dev/null; then
448             printbold "Running $GNOME_DOC_PREPARE..."
449             $GNOME_DOC_PREPARE --force --copy || exit 1
450         fi
451
452         # Now that all the macros are sorted, run autoreconf ...
453         printbold "Running autoreconf..."
454         autoreconf --verbose --force --install -Wno-portability || exit 1
455
456         if grep "^AC_PROG_INTLTOOL" $basename >/dev/null ||
457            grep "^IT_PROG_INTLTOOL" $basename >/dev/null; then
458             printbold "Running $INTLTOOLIZE..."
459             $INTLTOOLIZE --force --copy --automake || exit 1
460         fi
461
462         cd "$topdir"
463     fi
464 done
465
466 conf_flags=""
467
468 if $want_maintainer_mode; then
469     conf_flags="--enable-maintainer-mode"
470 fi
471
472 if test x$NOCONFIGURE = x; then
473     printbold Running $srcdir/configure $conf_flags "$@" ...
474     $srcdir/configure $conf_flags "$@" \
475         && echo Now type \`make\' to compile $PKG_NAME || exit 1
476 else
477     echo Skipping configure process.
478 fi