]> git.openstreetmap.org Git - nominatim.git/blob - m4/ax_lib_xml2.m4
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / m4 / ax_lib_xml2.m4
1 # SYNOPSIS
2 #
3 #   AX_LIB_XML2([MINIMUM-VERSION])
4 #
5 # DESCRIPTION
6 #
7 #   This macro provides tests of availability of xml2 'libxml2' library
8 #   of particular version or newer.
9 #
10 #   AX_LIB_LIBXML2 macro takes only one argument which is optional. If
11 #   there is no required version passed, then macro does not run version
12 #   test.
13 #
14 #   The --with-libxml2 option takes one of three possible values:
15 #
16 #   no - do not check for xml2 library
17 #
18 #   yes - do check for xml2 library in standard locations (xml2-config
19 #   should be in the PATH)
20 #
21 #   path - complete path to xml2-config utility, use this option if xml2-config
22 #   can't be found in the PATH
23 #
24 #   This macro calls:
25 #
26 #     AC_SUBST(XML2_CFLAGS)
27 #     AC_SUBST(XML2_LDFLAGS)
28 #     AC_SUBST(XML2_VERSION)
29 #
30 #   And sets:
31 #
32 #     HAVE_XML2
33 #
34 # LICENSE
35 #
36 #   Copyright (c) 2009 Hartmut Holzgraefe <hartmut@php.net>
37 #
38 #   Copying and distribution of this file, with or without modification, are
39 #   permitted in any medium without royalty provided the copyright notice
40 #   and this notice are preserved.
41
42 AC_DEFUN([AX_LIB_XML2],
43 [
44     AC_ARG_WITH([libxml2],
45         AC_HELP_STRING([--with-libxml2=@<:@ARG@:>@],
46             [use libxml2 library @<:@default=yes@:>@, optionally specify path to xml2-config]
47         ),
48         [
49         if test "$withval" = "no"; then
50             want_libxml2="no"
51         elif test "$withval" = "yes"; then
52             want_libxml2="yes"
53         else
54             want_libxml2="yes"
55             XML2_CONFIG="$withval"
56         fi
57         ],
58         [want_libxml2="yes"]
59     )
60
61     XML2_CFLAGS=""
62     XML2_LDFLAGS=""
63     XML2_VERSION=""
64
65     dnl
66     dnl Check xml2 libraries (libxml2)
67     dnl
68
69     if test "$want_libxml2" = "yes"; then
70
71         if test -z "$XML2_CONFIG" -o test; then
72             AC_PATH_PROG([XML2_CONFIG], [xml2-config], [])
73         fi
74
75         if test ! -x "$XML2_CONFIG"; then
76             AC_MSG_ERROR([$XML2_CONFIG does not exist or it is not an exectuable file])
77             XML2_CONFIG="no"
78             found_libxml2="no"
79         fi
80
81         if test "$XML2_CONFIG" != "no"; then
82             AC_MSG_CHECKING([for xml2 libraries])
83
84             XML2_CFLAGS="`$XML2_CONFIG --cflags`"
85             XML2_LDFLAGS="`$XML2_CONFIG --libs`"
86
87             XML2_VERSION=`$XML2_CONFIG --version`
88
89             AC_DEFINE([HAVE_XML2], [1],
90                 [Define to 1 if xml2 libraries are available])
91
92             found_libxml2="yes"
93             AC_MSG_RESULT([yes])
94         else
95             found_libxml2="no"
96             AC_MSG_RESULT([no])
97         fi
98     fi
99
100     dnl
101     dnl Check if required version of xml2 is available
102     dnl
103
104
105     libxml2_version_req=ifelse([$1], [], [], [$1])
106
107
108     if test "$found_libxml2" = "yes" -a -n "$libxml2_version_req"; then
109
110         AC_MSG_CHECKING([if libxml2 version is >= $libxml2_version_req])
111
112         dnl Decompose required version string of libxml2
113         dnl and calculate its number representation
114         libxml2_version_req_major=`expr $libxml2_version_req : '\([[0-9]]*\)'`
115         libxml2_version_req_minor=`expr $libxml2_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
116         libxml2_version_req_micro=`expr $libxml2_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
117         if test "x$libxml2_version_req_micro" = "x"; then
118             libxml2_version_req_micro="0"
119         fi
120
121         libxml2_version_req_number=`expr $libxml2_version_req_major \* 1000000 \
122                                    \+ $libxml2_version_req_minor \* 1000 \
123                                    \+ $libxml2_version_req_micro`
124
125         dnl Decompose version string of installed PostgreSQL
126         dnl and calculate its number representation
127         libxml2_version_major=`expr $XML2_VERSION : '\([[0-9]]*\)'`
128         libxml2_version_minor=`expr $XML2_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
129         libxml2_version_micro=`expr $XML2_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
130         if test "x$libxml2_version_micro" = "x"; then
131             libxml2_version_micro="0"
132         fi
133
134         libxml2_version_number=`expr $libxml2_version_major \* 1000000 \
135                                    \+ $libxml2_version_minor \* 1000 \
136                                    \+ $libxml2_version_micro`
137
138         libxml2_version_check=`expr $libxml2_version_number \>\= $libxml2_version_req_number`
139         if test "$libxml2_version_check" = "1"; then
140             AC_MSG_RESULT([yes])
141         else
142             AC_MSG_RESULT([no])
143         fi
144     fi
145
146     AC_SUBST([XML2_VERSION])
147     AC_SUBST([XML2_CFLAGS])
148     AC_SUBST([XML2_LDFLAGS])
149 ])
150