Add m4 files that look for expat and OpenSSL libraries.
[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         ]
82     )
83
84     AC_ARG_WITH([expat-inc],
85         AC_HELP_STRING([--with-expat-inc=@<:@DIR@:>@],
86             [path to Expat XML Parser headers]
87         ),
88         [expat_include_dir="$withval"],
89         [expat_include_dir=""]
90     )
91     AC_ARG_WITH([expat-lib],
92         AC_HELP_STRING([--with-expat-lib=@<:@ARG@:>@],
93             [link options for Expat XML Parser libraries]
94         ),
95         [expat_lib_flags="$withval"],
96         [expat_lib_flags=""]
97     )
98
99     EXPAT_CFLAGS=""
100     EXPAT_LDFLAGS=""
101     EXPAT_VERSION=""
102
103     dnl
104     dnl Collect include/lib paths and flags
105     dnl
106     run_expat_test="no"
107
108     if test -n "$expat_prefix"; then
109         expat_include_dir="$expat_prefix/include"
110         expat_lib_flags="-L$expat_prefix/lib -lexpat"
111         run_expat_test="yes"
112     elif test "$expat_requested" = "yes"; then
113         if test -n "$expat_include_dir" -a -n "$expat_lib_flags"; then
114             run_expat_test="yes"
115         fi
116     else
117         run_expat_test="no"
118     fi
119
120     dnl
121     dnl Check Expat XML Parser files
122     dnl
123     if test "$run_expat_test" = "yes"; then
124
125         saved_CPPFLAGS="$CPPFLAGS"
126         CPPFLAGS="$CPPFLAGS -I$expat_include_dir"
127
128         saved_LDFLAGS="$LDFLAGS"
129         LDFLAGS="$LDFLAGS $expat_lib_flags"
130
131         dnl
132         dnl Check Expat headers
133         dnl
134         AC_MSG_CHECKING([for Expat XML Parser headers in $expat_include_dir])
135
136         AC_LANG_PUSH([C++])
137         AC_COMPILE_IFELSE([
138             AC_LANG_PROGRAM(
139                 [[
140 @%:@include <expat.h>
141                 ]],
142                 [[]]
143             )],
144             [
145             EXPAT_CFLAGS="-I$expat_include_dir"
146             expat_header_found="yes"
147             AC_MSG_RESULT([found])
148             ],
149             [
150             expat_header_found="no"
151             AC_MSG_RESULT([not found])
152             ]
153         )
154         AC_LANG_POP([C++])
155
156         dnl
157         dnl Check Expat libraries
158         dnl
159         if test "$expat_header_found" = "yes"; then
160
161             AC_MSG_CHECKING([for Expat XML Parser libraries])
162
163             AC_LANG_PUSH([C++])
164             AC_LINK_IFELSE([
165                 AC_LANG_PROGRAM(
166                     [[
167 @%:@include <expat.h>
168                     ]],
169                     [[
170 XML_Parser p = XML_ParserCreate(NULL);
171 XML_ParserFree(p);
172 p = NULL;
173                     ]]
174                 )],
175                 [
176                 EXPAT_LDFLAGS="$expat_lib_flags"
177                 expat_lib_found="yes"
178                 AC_MSG_RESULT([found])
179                 ],
180                 [
181                 expat_lib_found="no"
182                 AC_MSG_RESULT([not found])
183                 ]
184             )
185             AC_LANG_POP([C++])
186         fi
187
188         CPPFLAGS="$saved_CPPFLAGS"
189         LDFLAGS="$saved_LDFLAGS"
190     fi
191
192     AC_MSG_CHECKING([for Expat XML Parser])
193
194     if test "$run_expat_test" = "yes"; then
195         if test "$expat_header_found" = "yes" -a "$expat_lib_found" = "yes"; then
196
197             AC_SUBST([EXPAT_CFLAGS])
198             AC_SUBST([EXPAT_LDFLAGS])
199
200             HAVE_EXPAT="yes"
201         else
202             HAVE_EXPAT="no"
203         fi
204
205         AC_MSG_RESULT([$HAVE_EXPAT])
206
207         dnl
208         dnl Check Expat version
209         dnl
210         if test "$HAVE_EXPAT" = "yes"; then
211
212             expat_version_req=ifelse([$1], [], [], [$1])
213
214             if test  -n "$expat_version_req"; then
215
216                 AC_MSG_CHECKING([if Expat XML Parser version is >= $expat_version_req])
217
218                 if test -f "$expat_include_dir/expat.h"; then
219
220                     expat_major=`cat $expat_include_dir/expat.h | \
221                                     grep '^#define.*XML_MAJOR_VERSION.*[0-9]$' | \
222                                     sed -e 's/#define XML_MAJOR_VERSION.//'`
223
224                     expat_minor=`cat $expat_include_dir/expat.h | \
225                                     grep '^#define.*XML_MINOR_VERSION.*[0-9]$' | \
226                                     sed -e 's/#define XML_MINOR_VERSION.//'`
227
228                     expat_revision=`cat $expat_include_dir/expat.h | \
229                                     grep '^#define.*XML_MICRO_VERSION.*[0-9]$' | \
230                                     sed -e 's/#define XML_MICRO_VERSION.//'`
231
232                     EXPAT_VERSION="$expat_major.$expat_minor.$expat_revision"
233                     AC_SUBST([EXPAT_VERSION])
234
235                     dnl Decompose required version string and calculate numerical representation
236                     expat_version_req_major=`expr $expat_version_req : '\([[0-9]]*\)'`
237                     expat_version_req_minor=`expr $expat_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
238                     expat_version_req_revision=`expr $expat_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
239                     if test "x$expat_version_req_revision" = "x"; then
240                         expat_version_req_revision="0"
241                     fi
242
243                     expat_version_req_number=`expr $expat_version_req_major \* 10000 \
244                                                \+ $expat_version_req_minor \* 100 \
245                                                \+ $expat_version_req_revision`
246
247                     dnl Calculate numerical representation of detected version
248                     expat_version_number=`expr $expat_major \* 10000 \
249                                           \+ $expat_minor \* 100 \
250                                            \+ $expat_revision`
251
252                     expat_version_check=`expr $expat_version_number \>\= $expat_version_req_number`
253                     if test "$expat_version_check" = "1"; then
254                         AC_MSG_RESULT([yes])
255                     else
256                         AC_MSG_RESULT([no])
257                         AC_MSG_WARN([Found Expat XML Parser $EXPAT_VERSION, which is older than required. Possible compilation failure.])
258                     fi
259                 else
260                     AC_MSG_RESULT([no])
261                     AC_MSG_WARN([Missing expat.h header. Unable to determine Expat version.])
262                 fi
263             fi
264         fi
265
266     else
267         HAVE_EXPAT="no"
268         AC_MSG_RESULT([$HAVE_EXPAT])
269
270         if test "$expat_requested" = "yes"; then
271             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])
272         fi
273     fi
274 ])