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