Set $variable_VERSION to the actual version number of the tool.
[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.4}
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.3.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 #     check_m4macros
135 # Checks that all the requested macro files are in the aclocal macro path
136 # Uses REQUIRED_M4MACROS and ACLOCAL variables.
137 check_m4macros() {
138     # construct list of macro directories
139     cm_macrodirs="`$ACLOCAL --print-ac-dir`"
140     set - $ACLOCAL_FLAGS
141     while [ $# -gt 0 ]; do
142         if [ "$1" = "-I" ]; then
143             cm_macrodirs="$cm_macrodirs $2"
144             shift
145         fi
146         shift
147     done
148
149     cm_status=0
150     if [ -n "$REQUIRED_M4MACROS" ]; then
151         printbold "Checking for required M4 macros..."
152         # check that each macro file is in one of the macro dirs
153         for cm_macro in $REQUIRED_M4MACROS; do
154             cm_macrofound=false
155             for cm_dir in $cm_macrodirs; do
156                 if [ -f "$cm_dir/$cm_macro" ]; then
157                     cm_macrofound=true
158                     break
159                 fi
160                 # The macro dir in Cygwin environments may contain a file
161                 # called dirlist containing other directories to look in.
162                 if [ -f "$cm_dir/dirlist" ]; then
163                     for cm_otherdir in `cat $cm_dir/dirlist`; do
164                         if [ -f "$cm_otherdir/$cm_macro" ]; then
165                             cm_macrofound=true
166                             break
167                         fi
168                     done
169                 fi
170             done
171             if $cm_macrofound; then
172                 :
173             else
174                 printerr "  $cm_macro not found"
175                 cm_status=1
176             fi
177         done
178     fi
179     if [ -n "$FORBIDDEN_M4MACROS" ]; then
180         printbold "Checking for forbidden M4 macros..."
181         # check that each macro file is in one of the macro dirs
182         for cm_macro in $FORBIDDEN_M4MACROS; do
183             cm_macrofound=false
184             for cm_dir in $cm_macrodirs; do
185                 if [ -f "$cm_dir/$cm_macro" ]; then
186                     cm_macrofound=true
187                     break
188                 fi
189             done
190             if $cm_macrofound; then
191                 printerr "  $cm_macro found (should be cleared from macros dir)"
192                 cm_status=1
193             fi
194         done
195     fi
196     if [ "$cm_status" != 0 ]; then
197         printerr "***Error***: some autoconf macros required to build $PKG_NAME"
198         printerr "  were not found in your aclocal path, or some forbidden"
199         printerr "  macros were found.  Perhaps you need to adjust your"
200         printerr "  ACLOCAL_FLAGS?"
201         printerr
202     fi
203     return $cm_status
204 }
205
206 # try to catch the case where the macros2/ directory hasn't been cleared out.
207 forbid_m4macro gnome-cxx-check.m4
208
209 want_libtool=false
210 want_gettext=false
211 want_glib_gettext=false
212 want_intltool=false
213 want_pkg_config=false
214 want_gtk_doc=false
215 want_gnome_doc_utils=false
216
217 configure_files="`find $srcdir -name '{arch}' -prune -o -name configure.ac -print -o -name configure.in -print`"
218 for configure_ac in $configure_files; do
219     if grep "^A[CM]_PROG_LIBTOOL" $configure_ac >/dev/null ||
220        grep "^LT_INIT" $configure_ac >/dev/null; then
221         want_libtool=true
222     fi
223     if grep "^AM_GNU_GETTEXT" $configure_ac >/dev/null; then
224         want_gettext=true
225     fi
226     if grep "^AM_GLIB_GNU_GETTEXT" $configure_ac >/dev/null; then
227         want_glib_gettext=true
228     fi
229     if grep "^AC_PROG_INTLTOOL" $configure_ac >/dev/null ||
230        grep "^IT_PROG_INTLTOOL" $configure_ac >/dev/null; then
231         want_intltool=true
232     fi
233     if grep "^PKG_CHECK_MODULES" $configure_ac >/dev/null; then
234         want_pkg_config=true
235     fi
236     if grep "^GTK_DOC_CHECK" $configure_ac >/dev/null; then
237         want_gtk_doc=true
238     fi
239     if grep "^GNOME_DOC_INIT" $configure_ac >/dev/null; then
240         want_gnome_doc_utils=true
241     fi
242
243     # check to make sure gnome-common macros can be found ...
244     if grep "^GNOME_COMMON_INIT" $configure_ac >/dev/null ||
245        grep "^GNOME_DEBUG_CHECK" $configure_ac >/dev/null ||
246        grep "^GNOME_MAINTAINER_MODE_DEFINES" $configure_ac >/dev/null; then
247         require_m4macro gnome-common.m4
248     fi
249     if grep "^GNOME_COMPILE_WARNINGS" $configure_ac >/dev/null ||
250        grep "^GNOME_CXX_WARNINGS" $configure_ac >/dev/null; then
251         require_m4macro gnome-compiler-flags.m4
252     fi
253 done
254
255 DIE=0
256
257 #tell Mandrake autoconf wrapper we want autoconf 2.5x, not 2.13
258 WANT_AUTOCONF_2_5=1
259 export WANT_AUTOCONF_2_5
260 version_check autoconf AUTOCONF 'autoconf2.50 autoconf autoconf-2.53' $REQUIRED_AUTOCONF_VERSION \
261     "http://ftp.gnu.org/pub/gnu/autoconf/autoconf-$REQUIRED_AUTOCONF_VERSION.tar.gz" || DIE=1
262 AUTOHEADER=`echo $AUTOCONF | sed s/autoconf/autoheader/`
263
264 case $REQUIRED_AUTOMAKE_VERSION in
265     1.4*) automake_progs="automake-1.4" ;;
266     1.5*) automake_progs="automake-1.5 automake-1.6 automake-1.7 automake-1.8 automake-1.9" ;;
267     1.6*) automake_progs="automake-1.6 automake-1.7 automake-1.8 automake-1.9" ;;
268     1.7*) automake_progs="automake-1.7 automake-1.8 automake-1.9" ;;
269     1.8*) automake_progs="automake-1.8 automake-1.9" ;;
270     1.9*) automake_progs="automake-1.9" ;;
271 esac
272 version_check automake AUTOMAKE "$automake_progs" $REQUIRED_AUTOMAKE_VERSION \
273     "http://ftp.gnu.org/pub/gnu/automake/automake-$REQUIRED_AUTOMAKE_VERSION.tar.gz" || DIE=1
274 ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
275
276 if $want_libtool; then
277     version_check libtool LIBTOOLIZE libtoolize $REQUIRED_LIBTOOL_VERSION \
278         "http://ftp.gnu.org/pub/gnu/libtool/libtool-$REQUIRED_LIBTOOL_VERSION.tar.gz" || DIE=1
279     require_m4macro libtool.m4
280 fi
281
282 if $want_gettext; then
283     version_check gettext GETTEXTIZE gettextize $REQUIRED_GETTEXT_VERSION \
284         "http://ftp.gnu.org/pub/gnu/gettext/gettext-$REQUIRED_GETTEXT_VERSION.tar.gz" || DIE=1
285     require_m4macro gettext.m4
286 fi
287
288 if $want_glib_gettext; then
289     version_check glib-gettext GLIB_GETTEXTIZE glib-gettextize $REQUIRED_GLIB_GETTEXT_VERSION \
290         "ftp://ftp.gtk.org/pub/gtk/v2.2/glib-$REQUIRED_GLIB_GETTEXT_VERSION.tar.gz" || DIE=1
291     require_m4macro glib-gettext.m4
292 fi
293
294 if $want_intltool; then
295     version_check intltool INTLTOOLIZE intltoolize $REQUIRED_INTLTOOL_VERSION \
296         "http://ftp.gnome.org/pub/GNOME/sources/intltool/" || DIE=1
297     require_m4macro intltool.m4
298 fi
299
300 if $want_pkg_config; then
301     version_check pkg-config PKG_CONFIG pkg-config $REQUIRED_PKG_CONFIG_VERSION \
302         "'http://www.freedesktop.org/software/pkgconfig/releases/pkgconfig-$REQUIRED_PKG_CONFIG_VERSION.tar.gz" || DIE=1
303     require_m4macro pkg.m4
304 fi
305
306 if $want_gtk_doc; then
307     version_check gtk-doc GTKDOCIZE gtkdocize $REQUIRED_GTK_DOC_VERSION \
308         "http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/" || DIE=1
309     require_m4macro gtk-doc.m4
310 fi
311
312 if $want_gnome_doc_utils; then
313     version_check gnome-doc-utils GNOME_DOC_PREPARE gnome-doc-prepare $REQUIRED_GNOME_DOC_UTILS_VERSION \
314         "http://ftp.gnome.org/pub/GNOME/sources/gnome-doc-utils/" || DIE=1
315 fi
316
317 if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
318     version_check gnome-common DOC_COMMON gnome-doc-common \
319         $REQUIRED_DOC_COMMON_VERSION " " || DIE=1
320 fi
321
322 check_m4macros || DIE=1
323
324 if [ "$DIE" -eq 1 ]; then
325   exit 1
326 fi
327
328 if [ "$#" = 0 ]; then
329   printerr "**Warning**: I am going to run \`configure' with no arguments."
330   printerr "If you wish to pass any to it, please specify them on the"
331   printerr \`$0\'" command line."
332   printerr
333 fi
334
335 topdir=`pwd`
336 for configure_ac in $configure_files; do 
337     dirname=`dirname $configure_ac`
338     basename=`basename $configure_ac`
339     if [ -f $dirname/NO-AUTO-GEN ]; then
340         echo skipping $dirname -- flagged as no auto-gen
341     elif [ ! -w $dirname ]; then
342         echo skipping $dirname -- directory is read only
343     else
344         printbold "Processing $configure_ac"
345         cd $dirname
346
347         # Note that the order these tools are called should match what
348         # autoconf's "autoupdate" package does.  See bug 138584 for
349         # details.
350
351         # programs that might install new macros get run before aclocal
352         if grep "^A[CM]_PROG_LIBTOOL" $basename >/dev/null ||
353            grep "^LT_INIT" $basename >/dev/null; then
354             printbold "Running $LIBTOOLIZE..."
355             $LIBTOOLIZE --force --copy || exit 1
356         fi
357
358         if grep "^AM_GLIB_GNU_GETTEXT" $basename >/dev/null; then
359             printbold "Running $GLIB_GETTEXTIZE... Ignore non-fatal messages."
360             echo "no" | $GLIB_GETTEXTIZE --force --copy || exit 1
361         elif grep "^AM_GNU_GETTEXT" $basename >/dev/null; then
362            if grep "^AM_GNU_GETTEXT_VERSION" $basename > /dev/null; then
363                 printbold "Running autopoint..."
364                 autopoint --force || exit 1
365            else
366                 printbold "Running $GETTEXTIZE... Ignore non-fatal messages."
367                 echo "no" | $GETTEXTIZE --force --copy || exit 1
368            fi
369         fi
370
371         if grep "^AC_PROG_INTLTOOL" $basename >/dev/null ||
372            grep "^IT_PROG_INTLTOOL" $basename >/dev/null; then
373             printbold "Running $INTLTOOLIZE..."
374             $INTLTOOLIZE --force --copy --automake || exit 1
375         fi
376         if grep "^GTK_DOC_CHECK" $basename >/dev/null; then
377             printbold "Running $GTKDOCIZE..."
378             $GTKDOCIZE --copy || exit 1
379         fi
380
381         if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
382             printbold "Running gnome-doc-common..."
383             gnome-doc-common --copy || exit 1
384         fi
385         if grep "^GNOME_DOC_INIT" $basename >/dev/null; then
386             printbold "Running $GNOME_DOC_PREPARE..."
387             $GNOME_DOC_PREPARE --force --copy || exit 1
388         fi
389
390         # Now run aclocal to pull in any additional macros needed
391
392         # if the AC_CONFIG_MACRO_DIR() macro is used, pass that
393         # directory to aclocal.
394         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`
395         if [ -n "$m4dir" ]; then
396             m4dir="-I $m4dir"
397         fi
398         printbold "Running $ACLOCAL..."
399         $ACLOCAL $m4dir $ACLOCAL_FLAGS || exit 1
400
401         if grep "GNOME_AUTOGEN_OBSOLETE" aclocal.m4 >/dev/null; then
402             printerr "*** obsolete gnome macros were used in $configure_ac"
403         fi
404
405         # Now that all the macros are sorted, run autoconf and autoheader ...
406         printbold "Running $AUTOCONF..."
407         $AUTOCONF || exit 1
408         if grep "^A[CM]_CONFIG_HEADER" $basename >/dev/null; then
409             printbold "Running $AUTOHEADER..."
410             $AUTOHEADER || exit 1
411             # this prevents automake from thinking config.h.in is out of
412             # date, since autoheader doesn't touch the file if it doesn't
413             # change.
414             test -f config.h.in && touch config.h.in
415         fi
416
417         # Finally, run automake to create the makefiles ...
418         printbold "Running $AUTOMAKE..."
419         cp -pf COPYING COPYING.autogen_bak
420         cp -pf INSTALL INSTALL.autogen_bak
421         if [ $REQUIRED_AUTOMAKE_VERSION != 1.4 ]; then
422             $AUTOMAKE --gnu --add-missing --force --copy || exit 1
423         else
424             $AUTOMAKE --gnu --add-missing --copy || exit 1
425         fi
426         cmp COPYING COPYING.autogen_bak || cp -pf COPYING.autogen_bak COPYING
427         cmp INSTALL INSTALL.autogen_bak || cp -pf INSTALL.autogen_bak INSTALL
428         rm -f COPYING.autogen_bak INSTALL.autogen_bak
429
430         cd "$topdir"
431     fi
432 done
433
434 conf_flags="--enable-maintainer-mode"
435
436 if test x$NOCONFIGURE = x; then
437     printbold Running $srcdir/configure $conf_flags "$@" ...
438     $srcdir/configure $conf_flags "$@" \
439         && echo Now type \`make\' to compile $PKG_NAME || exit 1
440 else
441     echo Skipping configure process.
442 fi