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