Revert the whole custom memory allocation work (#540)
[geos.git] / macros / geos.m4
blobf0691020ec2244d22be163a2783bceafbe60eec3
1 dnl 
2 dnl GEOS_INIT (MINIMUM_VERSION)
3 dnl
4 dnl Test for GEOS: define HAVE_GEOS, GEOS_LIBS, GEOS_C_LIBS, GEOS_CFLAGS, GEOS_VERSION
5 dnl 
6 dnl Call as GEOS_INIT or GEOS_INIT(minimum version) in configure.in. Test
7 dnl HAVE_GEOS (yes|no) afterwards. If yes, all other vars above can be 
8 dnl used in program.
9 dnl
10 dnl UPDATE 2006/07/06
11 dnl Now, --with-geos takes values: yes or no, or full path to the geos-config
12 dnl utility. Note that the utility can have different name,
13 dnl e.g. geos-config-cvs.
14 dnl Example: --with-geos=/home/foo/usr/bin/geos-config-cvs
15 dnl
16 AC_DEFUN([GEOS_INIT],[
17         AC_SUBST(GEOS_LIBS)
18         AC_SUBST(GEOS_CFLAGS)
19         AC_SUBST(GEOS_C_LIBS)
20         AC_SUBST(GEOS_C_CFLAGS)
21         AC_SUBST(HAVE_GEOS) 
22         AC_SUBST(GEOS_VERSION)
24     if test x"$with_geos" = x"no" ; then
25         AC_MSG_RESULT([GEOS support disabled])
26         GEOS_CONFIG="no"
27         HAVE_GEOS="no"  
28     elif test x"$with_geos" = x"yes" -o x"$with_geos" = x"" ; then
29         AC_PATH_PROG([GEOS_CONFIG], [geos-config], [no])
30     else
31         ac_geos_config=`basename $with_geos`
32         ac_geos_config_dir=`dirname $with_geos`
34         AC_CHECK_PROG(
35             GEOS_CONFIG,
36             $ac_geos_config,
37             $with_geos,
38             [no],
39             [$ac_geos_config_dir],
40             []
41         )
42     fi
44         min_geos_version=ifelse([$1], ,0.0.1,$1)
46     if test "$GEOS_CONFIG" = "no"; then
47       no_geos_config="yes"
48     else
49        AC_MSG_CHECKING(for GEOS version >= $min_geos_version)
51        geos_major_version=`$GEOS_CONFIG --version | \
52           sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
53        geos_minor_version=`$GEOS_CONFIG --version | \
54           sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
55        geos_micro_version=`$GEOS_CONFIG --version | \
56           sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
58     req_major=`echo $min_geos_version | \
59        sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
60     req_minor=`echo $min_geos_version | \
61        sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
62     req_micro=`echo $min_geos_version | \
63        sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/\3/'`
64     
65     version_ok="no"
66     ac_req_version=`expr $req_major \* 100000 \+  $req_minor \* 100 \+ $req_micro`
67     ac_geos_version=`expr $geos_major_version \* 100000 \+  $geos_minor_version \* 100 \+ $geos_micro_version`
69     if test $ac_req_version -le $ac_geos_version; then
70         version_ok="yes"
71     fi
73       if test $version_ok = "no"; then
74          HAVE_GEOS="no" 
75       else
76         if $GEOS_CONFIG --libs >/dev/null 2>&1; then
77           AC_MSG_RESULT(yes)
78           HAVE_GEOS="yes"
79           GEOS_LIBS="`$GEOS_CONFIG --libs`"
80           GEOS_C_LIBS="`$GEOS_CONFIG --ldflags` -lgeos_c"
81           GEOS_CFLAGS="`$GEOS_CONFIG --cflags`"
82           GEOS_VERSION="`$GEOS_CONFIG --version`"
83         else
84           AC_MSG_RESULT(no)
85           HAVE_GEOS="no"
86           no_geos_config="yes"
87         fi
88     fi