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