d54bc04ed723f0c9c760a68ede5caaf9728ac016
[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_AUTORECONF_VERSION" || REQUIRED_AUTORECONF_VERSION=2.53
10 test "$REQUIRED_GLIB_GETTEXT_VERSION" || REQUIRED_GLIB_GETTEXT_VERSION=2.2.0
11 test "$REQUIRED_INTLTOOL_VERSION" || REQUIRED_INTLTOOL_VERSION=0.25
12 test "$REQUIRED_PKG_CONFIG_VERSION" || REQUIRED_PKG_CONFIG_VERSION=0.14.0
13 test "$REQUIRED_GTK_DOC_VERSION" || REQUIRED_GTK_DOC_VERSION=1.0
14 test "$REQUIRED_DOC_COMMON_VERSION" || REQUIRED_DOC_COMMON_VERSION=2.3.0
15 test "$REQUIRED_GNOME_DOC_UTILS_VERSION" || REQUIRED_GNOME_DOC_UTILS_VERSION=0.4.2
16
17 # a list of required m4 macros.  Package can set an initial value
18 test "$REQUIRED_M4MACROS" || REQUIRED_M4MACROS=
19 test "$FORBIDDEN_M4MACROS" || FORBIDDEN_M4MACROS=
20
21 # Not all echo versions allow -n, so we check what is possible. This test is
22 # based on the one in autoconf.
23 ECHO_C=
24 ECHO_N=
25 case `echo -n x` in
26 -n*)
27   case `echo 'x\c'` in
28   *c*) ;;
29   *)   ECHO_C='\c';;
30   esac;;
31 *)
32   ECHO_N='-n';;
33 esac
34
35 # some terminal codes ...
36 if tty < /dev/null 1>/dev/null 2>&1; then
37     boldface="`tput bold 2>/dev/null`"
38     normal="`tput sgr0 2>/dev/null`"
39 else
40     boldface=
41     normal=
42 fi
43 printbold() {
44     echo $ECHO_N "$boldface" $ECHO_C
45     echo "$@"
46     echo $ECHO_N "$normal" $ECHO_C
47 }    
48 printerr() {
49     echo "$@" >&2
50 }
51
52 # Usage:
53 #     compare_versions MIN_VERSION ACTUAL_VERSION
54 # returns true if ACTUAL_VERSION >= MIN_VERSION
55 compare_versions() {
56     ch_min_version=$1
57     ch_actual_version=$2
58     ch_status=0
59     IFS="${IFS=         }"; ch_save_IFS="$IFS"; IFS="."
60     set $ch_actual_version
61     for ch_min in $ch_min_version; do
62         ch_cur=`echo $1 | sed 's/[^0-9].*$//'`; shift # remove letter suffixes
63         if [ -z "$ch_min" ]; then break; fi
64         if [ -z "$ch_cur" ]; then ch_status=1; break; fi
65         if [ $ch_cur -gt $ch_min ]; then break; fi
66         if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
67     done
68     IFS="$ch_save_IFS"
69     return $ch_status
70 }
71
72 # Usage:
73 #     version_check PACKAGE VARIABLE CHECKPROGS MIN_VERSION SOURCE
74 # checks to see if the package is available
75 version_check() {
76     vc_package=$1
77     vc_variable=$2
78     vc_checkprogs=$3
79     vc_min_version=$4
80     vc_source=$5
81     vc_status=1
82
83     vc_checkprog=`eval echo "\\$$vc_variable"`
84     if [ -n "$vc_checkprog" ]; then
85         printbold "using $vc_checkprog for $vc_package"
86         return 0
87     fi
88
89     printbold "checking for $vc_package >= $vc_min_version..."
90     for vc_checkprog in $vc_checkprogs; do
91         echo $ECHO_N "  testing $vc_checkprog... " $ECHO_C
92         if $vc_checkprog --version < /dev/null > /dev/null 2>&1; then
93             vc_actual_version=`$vc_checkprog --version | head -n 1 | \
94                                sed 's/^.*[      ]\([0-9.]*[a-z]*\).*$/\1/'`
95             if compare_versions $vc_min_version $vc_actual_version; then
96                 echo "found $vc_actual_version"
97                 # set variables
98                 eval "$vc_variable=$vc_checkprog; \
99                         ${vc_variable}_VERSION=$vc_actual_version"
100                 vc_status=0
101                 break
102             else
103                 echo "too old (found version $vc_actual_version)"
104             fi
105         else
106             echo "not found."
107         fi
108     done
109     if [ "$vc_status" != 0 ]; then
110         printerr "***Error***: You must have $vc_package >= $vc_min_version installed"
111         printerr "  to build $PKG_NAME.  Download the appropriate package for"
112         printerr "  from your distribution or get the source tarball at"
113         printerr "    $vc_source"
114         printerr
115         exit $vc_status
116     fi
117     return $vc_status
118 }
119
120 # Usage:
121 #     require_m4macro filename.m4
122 # adds filename.m4 to the list of required macros
123 require_m4macro() {
124     case "$REQUIRED_M4MACROS" in
125         $1\ * | *\ $1\ * | *\ $1) ;;
126         *) REQUIRED_M4MACROS="$REQUIRED_M4MACROS $1" ;;
127     esac
128 }
129
130 forbid_m4macro() {
131     case "$FORBIDDEN_M4MACROS" in
132         $1\ * | *\ $1\ * | *\ $1) ;;
133         *) FORBIDDEN_M4MACROS="$FORBIDDEN_M4MACROS $1" ;;
134     esac
135 }
136
137 # Usage:
138 #     add_to_cm_macrodirs dirname
139 # Adds the dir to $cm_macrodirs, if it's not there yet.
140 add_to_cm_macrodirs() {
141     case $cm_macrodirs in
142     "$1 "* | *" $1 "* | *" $1") ;;
143     *) cm_macrodirs="$cm_macrodirs $1";;
144     esac
145 }
146
147 # Usage:
148 #     print_m4macros_error
149 # Prints an error message saying that autoconf macros were misused
150 print_m4macros_error() {
151     printerr "***Error***: some autoconf macros required to build $PKG_NAME"
152     printerr "  were not found in your aclocal path, or some forbidden"
153     printerr "  macros were found.  Perhaps you need to adjust your"
154     printerr "  ACLOCAL_FLAGS?"
155     printerr
156 }
157
158 # Usage:
159 #     check_m4macros
160 # Checks that all the requested macro files are in the aclocal macro path
161 # Uses REQUIRED_M4MACROS and ACLOCAL variables.
162 check_m4macros() {
163     # construct list of macro directories
164     cm_macrodirs=`aclocal --print-ac-dir`
165     # aclocal also searches a version specific dir, eg. /usr/share/aclocal-1.9
166     # but it contains only Automake's own macros, so we can ignore it.
167
168     # Read the dirlist file, supported by Automake >= 1.7.
169     # If AUTOMAKE was defined, no version was detected.
170     if [ -z "$AUTOMAKE_VERSION" ] || compare_versions 1.7 $AUTOMAKE_VERSION && [ -s $cm_macrodirs/dirlist ]; then
171         cm_dirlist=`sed 's/[    ]*#.*//;/^$/d' $cm_macrodirs/dirlist`
172         if [ -n "$cm_dirlist" ] ; then
173             for cm_dir in $cm_dirlist; do
174                 if [ -d $cm_dir ]; then
175                     add_to_cm_macrodirs $cm_dir
176                 fi
177             done
178         fi
179     fi
180
181     # Parse $ACLOCAL_FLAGS
182     set - $ACLOCAL_FLAGS
183     while [ $# -gt 0 ]; do
184         if [ "$1" = "-I" ]; then
185             add_to_cm_macrodirs "$2"
186             shift
187         fi
188         shift
189     done
190
191     cm_status=0
192     if [ -n "$REQUIRED_M4MACROS" ]; then
193         printbold "Checking for required M4 macros..."
194         # check that each macro file is in one of the macro dirs
195         for cm_macro in $REQUIRED_M4MACROS; do
196             cm_macrofound=false
197             for cm_dir in $cm_macrodirs; do
198                 if [ -f "$cm_dir/$cm_macro" ]; then
199                     cm_macrofound=true
200                     break
201                 fi
202                 # The macro dir in Cygwin environments may contain a file
203                 # called dirlist containing other directories to look in.
204                 if [ -f "$cm_dir/dirlist" ]; then
205                     for cm_otherdir in `cat $cm_dir/dirlist`; do
206                         if [ -f "$cm_otherdir/$cm_macro" ]; then
207                             cm_macrofound=true
208                             break
209                         fi
210                     done
211                 fi
212             done
213             if $cm_macrofound; then
214                 :
215             else
216                 printerr "  $cm_macro not found"
217                 cm_status=1
218             fi
219         done
220     fi
221     if [ "$cm_status" != 0 ]; then
222         print_m4macros_error
223         exit $cm_status
224     fi
225     if [ -n "$FORBIDDEN_M4MACROS" ]; then
226         printbold "Checking for forbidden M4 macros..."
227         # check that each macro file is in one of the macro dirs
228         for cm_macro in $FORBIDDEN_M4MACROS; do
229             cm_macrofound=false
230             for cm_dir in $cm_macrodirs; do
231                 if [ -f "$cm_dir/$cm_macro" ]; then
232                     cm_macrofound=true
233                     break
234                 fi
235             done
236             if $cm_macrofound; then
237                 printerr "  $cm_macro found (should be cleared from macros dir)"
238                 cm_status=1
239             fi
240         done
241     fi
242     if [ "$cm_status" != 0 ]; then
243         print_m4macros_error
244         exit $cm_status
245     fi
246 }
247
248 # try to catch the case where the macros2/ directory hasn't been cleared out.
249 forbid_m4macro gnome-cxx-check.m4
250
251 want_glib_gettext=false
252 want_intltool=false
253 want_pkg_config=false
254 want_gtk_doc=false
255 want_gnome_doc_utils=false
256 want_maintainer_mode=false
257
258 version_check autoreconf AUTORECONF autoreconf $REQUIRED_AUTORECONF_VERSION \
259     "http://ftp.gnu.org/pub/gnu/autoconf/autoconf-$REQUIRED_AUTORECONF_VERSION.tar.xz"
260
261 find_configure_files() {
262     configure_ac=
263     if test -f "$1/configure.ac"; then
264         configure_ac="$1/configure.ac"
265     elif test -f "$1/configure.in"; then
266         configure_ac="$1/configure.in"
267     fi
268     if test "x$configure_ac" != x; then
269         echo "$configure_ac"
270         autoconf -t 'AC_CONFIG_SUBDIRS:$1' "$configure_ac" | while read dir; do
271             find_configure_files "$1/$dir"
272         done
273     fi
274 }
275
276 configure_files="`find_configure_files $srcdir`"
277
278 for configure_ac in $configure_files; do
279     dirname=`dirname $configure_ac`
280     if [ -f $dirname/NO-AUTO-GEN ]; then
281         echo skipping $dirname -- flagged as no auto-gen
282         continue
283     fi
284     if grep "^AM_GLIB_GNU_GETTEXT" $configure_ac >/dev/null; then
285         want_glib_gettext=true
286     fi
287     if grep "^AC_PROG_INTLTOOL" $configure_ac >/dev/null ||
288        grep "^IT_PROG_INTLTOOL" $configure_ac >/dev/null; then
289         want_intltool=true
290     fi
291     if grep "^PKG_CHECK_MODULES" $configure_ac >/dev/null; then
292         want_pkg_config=true
293     fi
294     if grep "^GTK_DOC_CHECK" $configure_ac >/dev/null; then
295         want_gtk_doc=true
296     fi
297     if grep "^GNOME_DOC_INIT" $configure_ac >/dev/null; then
298         want_gnome_doc_utils=true
299     fi
300
301     # check that AM_MAINTAINER_MODE is used
302     if grep "^AM_MAINTAINER_MODE" $configure_ac >/dev/null; then
303         want_maintainer_mode=true
304     fi
305
306     if grep "^YELP_HELP_INIT" $configure_ac >/dev/null; then
307         require_m4macro yelp.m4
308     fi
309
310     # check to make sure gnome-common macros can be found ...
311     if grep "^GNOME_COMMON_INIT" $configure_ac >/dev/null ||
312        grep "^GNOME_DEBUG_CHECK" $configure_ac >/dev/null ||
313        grep "^GNOME_MAINTAINER_MODE_DEFINES" $configure_ac >/dev/null; then
314         require_m4macro gnome-common.m4
315     fi
316     if grep "^GNOME_COMPILE_WARNINGS" $configure_ac >/dev/null ||
317        grep "^GNOME_CXX_WARNINGS" $configure_ac >/dev/null; then
318         require_m4macro gnome-compiler-flags.m4
319     fi
320     if grep "^GNOME_CODE_COVERAGE" $configure_ac >/dev/null; then
321         require_m4macro gnome-code-coverage.m4
322     fi
323 done
324
325 if $want_glib_gettext; then
326     version_check glib-gettext GLIB_GETTEXTIZE glib-gettextize $REQUIRED_GLIB_GETTEXT_VERSION \
327         "ftp://ftp.gtk.org/pub/gtk/v2.2/glib-$REQUIRED_GLIB_GETTEXT_VERSION.tar.gz"
328     require_m4macro glib-gettext.m4
329 fi
330
331 if $want_intltool; then
332     version_check intltool INTLTOOLIZE intltoolize $REQUIRED_INTLTOOL_VERSION \
333         "http://ftp.gnome.org/pub/GNOME/sources/intltool/"
334     require_m4macro intltool.m4
335 fi
336
337 if $want_pkg_config; then
338     version_check pkg-config PKG_CONFIG pkg-config $REQUIRED_PKG_CONFIG_VERSION \
339         "'http://www.freedesktop.org/software/pkgconfig/releases/pkgconfig-$REQUIRED_PKG_CONFIG_VERSION.tar.gz"
340     require_m4macro pkg.m4
341 fi
342
343 if $want_gtk_doc; then
344     version_check gtk-doc GTKDOCIZE gtkdocize $REQUIRED_GTK_DOC_VERSION \
345         "http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/"
346     require_m4macro gtk-doc.m4
347 fi
348
349 if $want_gnome_doc_utils; then
350     version_check gnome-doc-utils GNOME_DOC_PREPARE gnome-doc-prepare $REQUIRED_GNOME_DOC_UTILS_VERSION \
351         "http://ftp.gnome.org/pub/GNOME/sources/gnome-doc-utils/"
352 fi
353
354 if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
355     version_check gnome-common DOC_COMMON gnome-doc-common \
356         $REQUIRED_DOC_COMMON_VERSION " "
357 fi
358
359 check_m4macros
360
361 if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
362   printerr "**Warning**: I am going to run \`configure' with no arguments."
363   printerr "If you wish to pass any to it, please specify them on the"
364   printerr \`$0\'" command line."
365   printerr
366 fi
367
368 topdir=`pwd`
369 for configure_ac in $configure_files; do 
370     dirname=`dirname $configure_ac`
371     basename=`basename $configure_ac`
372     if [ -f $dirname/NO-AUTO-GEN ]; then
373         echo skipping $dirname -- flagged as no auto-gen
374     elif [ ! -w $dirname ]; then
375         echo skipping $dirname -- directory is read only
376     else
377         printbold "Processing $configure_ac"
378         cd $dirname
379
380         # if the AC_CONFIG_MACRO_DIR() macro is used, create that directory
381         # This is a automake bug fixed in automake 1.13.2
382         # See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13514
383         m4dir=`autoconf --trace 'AC_CONFIG_MACRO_DIR:$1'`
384         if [ -n "$m4dir" ]; then
385             mkdir -p $m4dir
386         fi
387
388         if grep "^GTK_DOC_CHECK" $basename >/dev/null; then
389             printbold "Running $GTKDOCIZE..."
390             $GTKDOCIZE --copy || exit 1
391         fi
392
393         if [ "x$USE_COMMON_DOC_BUILD" = "xyes" ]; then
394             printbold "Running gnome-doc-common..."
395             gnome-doc-common --copy || exit 1
396         fi
397         if grep "^GNOME_DOC_INIT" $basename >/dev/null; then
398             printbold "Running $GNOME_DOC_PREPARE..."
399             $GNOME_DOC_PREPARE --force --copy || exit 1
400         fi
401
402         # Now that all the macros are sorted, run autoreconf ...
403         printbold "Running autoreconf..."
404         autoreconf --verbose --force --install -Wno-portability || exit 1
405
406         if grep "^AC_PROG_INTLTOOL" $basename >/dev/null ||
407            grep "^IT_PROG_INTLTOOL" $basename >/dev/null; then
408             printbold "Running $INTLTOOLIZE..."
409             $INTLTOOLIZE --force --copy --automake || exit 1
410         fi
411
412         cd "$topdir"
413     fi
414 done
415
416 conf_flags=""
417
418 if $want_maintainer_mode; then
419     conf_flags="--enable-maintainer-mode"
420 fi
421
422 if test x$NOCONFIGURE = x; then
423     printbold Running $srcdir/configure $conf_flags "$@" ...
424     $srcdir/configure $conf_flags "$@" \
425         && echo Now type \`make\' to compile $PKG_NAME || exit 1
426 else
427     echo Skipping configure process.
428 fi