Added library names
[asdcplib.git] / m4 / ax_lib_expat.m4
1 ##### http://autoconf-archive.cryp.to/ax_lib_expat.html
2 #
3 # SYNOPSIS
4 #
5 #   AX_LIB_EXPAT([MINIMUM-VERSION])
6 #
7 # DESCRIPTION
8 #
9 #   This macro provides tests of availability of Expat XML Parser of
10 #   particular version or newer. This macro checks for Expat XML Parser
11 #   headers and libraries and defines compilation flags
12 #
13 #   Macro supports following options and their values:
14 #
15 #   1) Single-option usage:
16 #
17 #     --with-expat      -- yes, no, or path to Expat XML Parser
18 #                          installation prefix
19 #
20 #   2) Three-options usage (all options are required):
21 #
22 #     --with-expat=yes
23 #     --with-expat-inc  -- path to base directory with Expat headers
24 #     --with-expat-lib  -- linker flags for Expat
25 #
26 #   This macro calls:
27 #
28 #     AC_SUBST(EXPAT_CFLAGS)
29 #     AC_SUBST(EXPAT_LDFLAGS)
30 #     AC_SUBST(EXPAT_VERSION)  -- only if version requirement is used
31 #
32 #   And sets:
33 #
34 #     HAVE_EXPAT
35 #
36 # LAST MODIFICATION
37 #
38 #   2007-12-05
39 #
40 # COPYLEFT
41 #
42 #   Copyright (c) 2007 Mateusz Loskot <mateusz@loskot.net>
43 #
44 #   Copying and distribution of this file, with or without
45 #   modification, are permitted in any medium without royalty provided
46 #   the copyright notice and this notice are preserved.
47
48 AC_DEFUN([AX_LIB_EXPAT],
49 [
50     AC_ARG_WITH([expat],
51         AC_HELP_STRING([--with-expat=@<:@ARG@:>@],
52             [use Expat XML Parser from given prefix (ARG=path); check standard prefixes (ARG=yes); disable (ARG=no)]
53         ),
54         [
55         if test "$withval" = "yes"; then
56             if test -f /usr/local/include/expat.h ; then
57                 expat_prefix=/usr/local
58             elif test -f /usr/include/expat.h ; then
59                 expat_prefix=/usr
60             else
61                 expat_prefix=""
62             fi
63             expat_requested="yes"
64         elif test -d "$withval"; then
65             expat_prefix="$withval"
66             expat_requested="yes"
67         else
68             expat_prefix=""
69             expat_requested="no"
70         fi
71         ],
72         [
73 #        dnl Default behavior is implicit yes
74 #        if test -f /usr/local/include/expat.h ; then
75 #            expat_prefix=/usr/local
76 #        elif test -f /usr/include/expat.h ; then
77 #            expat_prefix=/usr
78 #        else
79 #            expat_prefix=""
80 #        fi
81         dnl Default behavior is implicit no
82         expat_prefix=""
83         expat_requested="no"
84         ]
85     )
86
87     AC_ARG_WITH([expat-inc],
88         AC_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
89             [path to Expat XML Parser headers]
90         ),
91         [expat_include_dir="$withval"],
92         [expat_include_dir=""]
93     )
94     AC_ARG_WITH([expat-lib],
95         AC_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
96             [link options for Expat XML Parser libraries]
97         ),
98         [expat_lib_flags="$withval"],
99         [expat_lib_flags=""]
100     )
101
102     EXPAT_CFLAGS=""
103     EXPAT_LDFLAGS=""
104     EXPAT_VERSION=""
105
106     dnl
107     dnl Collect include/lib paths and flags
108     dnl
109     run_expat_test="no"
110
111     if test -n "$expat_prefix"; then
112         expat_include_dir="$expat_prefix/include"
113         expat_lib_flags="-L$expat_prefix/lib64 -L$expat_prefix/lib -lexpat"
114         run_expat_test="yes"
115     elif test "$expat_requested" = "yes"; then
116         if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
117             run_expat_test="yes"
118         fi
119     else
120         run_expat_test="no"
121     fi
122
123     dnl
124     dnl Check Expat XML Parser files
125     dnl
126     if test "$run_expat_test" = "yes"; then
127
128         saved_CPPFLAGS="$CPPFLAGS"
129         CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
130
131         saved_LDFLAGS="$LDFLAGS"
132         LDFLAGS="$LDFLAGS $expat_lib_flags"
133
134         dnl
135         dnl Check Expat headers
136         dnl
137         AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
138
139         AC_LANG_PUSH([C++])
140         AC_COMPILE_IFELSE([
141             AC_LANG_PROGRAM(
142                 [[
143 @%:@include <expat.h>
144                 ]],
145                 [[]]
146             )],
147             [
148             EXPAT_CFLAGS="-I$expat_include_dir"
149             expat_header_found="yes"
150             AC_MSG_RESULT([found])
151             ],
152             [
153             expat_header_found="no"
154             AC_MSG_RESULT([not found])
155             ]
156         )
157         AC_LANG_POP([C++])
158
159         dnl
160         dnl Check Expat libraries
161         dnl
162         if test "$expat_header_found" = "yes"; then
163
164             AC_MSG_CHECKING([for Expat XML Parser libraries])
165
166             AC_LANG_PUSH([C++])
167             AC_LINK_IFELSE([
168                 AC_LANG_PROGRAM(
169                     [[
170 @%:@include <expat.h>
171                     ]],
172                     [[
173 XML_Parser p = XML_ParserCreate(NULL);
174 XML_ParserFree(p);
175 p = NULL;
176                     ]]
177                 )],
178                 [
179                 EXPAT_LDFLAGS="$expat_lib_flags"
180                 expat_lib_found="yes"
181                 AC_MSG_RESULT([found])
182                 ],
183                 [
184                 expat_lib_found="no"
185                 AC_MSG_RESULT([not found])
186                 ]
187             )
188             AC_LANG_POP([C++])
189         fi
190
191         CPPFLAGS="$saved_CPPFLAGS"
192         LDFLAGS="$saved_LDFLAGS"
193     fi
194
195     AC_MSG_CHECKING([for Expat XML Parser])
196
197     if test "$run_expat_test" = "yes"; then
198         if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
199
200             AC_SUBST([EXPAT_CFLAGS])
201             AC_SUBST([EXPAT_LDFLAGS])
202
203             HAVE_EXPAT="yes"
204         else
205             HAVE_EXPAT="no"
206         fi
207
208         AC_MSG_RESULT([$HAVE_EXPAT])
209
210         dnl
211         dnl Check Expat version
212         dnl
213         if test "$HAVE_EXPAT" = "yes"; then
214
215             expat_version_req=ifelse([$1], [], [], [$1])
216
217             if test  -n "$expat_version_req"; then
218
219                 AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
220
221                 if test -f "$expat_include_dir/expat.h"; then
222
223                     expat_major=`cat $expat_include_dir/expat.h | \
224                                     grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
225                                     sed -e 's/#define XML_MAJOR_VERSION.//'`
226
227                     expat_minor=`cat $expat_include_dir/expat.h | \
228                                     grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
229                                     sed -e 's/#define XML_MINOR_VERSION.//'`
230
231                     expat_revision=`cat $expat_include_dir/expat.h | \
232                                     grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
233                                     sed -e 's/#define XML_MICRO_VERSION.//'`
234
235                     EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
236                     AC_SUBST([EXPAT_VERSION])
237
238                     dnl Decompose required version string and calculate numerical representation
239                     expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
240                     expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
241                     expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
242                     if test "x$expat_version_req_revision" = "x"; then
243                         expat_version_req_revision="0"
244                     fi
245
246                     expat_version_req_number=`expr $expat_version_req_major \* 10000 \
247                                                \+ $expat_version_req_minor \* 100 \
248                                                \+ $expat_version_req_revision`
249
250                     dnl Calculate numerical representation of detected version
251                     expat_version_number=`expr $expat_major \* 10000 \
252                                           \+ $expat_minor \* 100 \
253                                            \+ $expat_revision`
254
255                     expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
256                     if test "$expat_version_check" = "1"; then
257                         AC_MSG_RESULT([yes])
258                     else
259                         AC_MSG_RESULT([no])
260                         AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
261                     fi
262                 else
263                     AC_MSG_RESULT([no])
264                     AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
265                 fi
266             fi
267         fi
268
269     else
270         HAVE_EXPAT="no"
271         AC_MSG_RESULT([$HAVE_EXPAT])
272
273         if test "$expat_requested" = "yes"; then
274             AC_MSG_WARN([Expat XML Parser support requested but headers or library not found. Specify valid prefix of Expat using --with-expat=@<:@DIR@:>@ or provide include directory and linker flags using --with-expat-inc and --with-expat-lib])
275         fi
276     fi
277     if test "$HAVE_EXPAT" = "yes"; then
278         CPPFLAGS="$CPPFLAGS $EXPAT_CFLAGS -DHAVE_EXPAT=1"
279         LDFLAGS="$LDFLAGS $EXPAT_LDFLAGS"
280     fi
281 ])