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