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