]> granicus.if.org Git - libexpat/blob - expat/configure.ac
b429281d3bcb83ac749ac0635bd1a8ea627d4f63
[libexpat] / expat / configure.ac
1 dnl   configuration script for expat
2 dnl   Process this file with autoconf to produce a configure script.
3 dnl
4 dnl   Copyright 2000 Clark Cooper
5 dnl
6 dnl   This file is part of EXPAT.
7 dnl
8 dnl   EXPAT is free software; you can redistribute it and/or modify it
9 dnl   under the terms of the License (based on the MIT/X license) contained
10 dnl   in the file COPYING that comes with this distribution.
11 dnl
12
13 dnl Ensure that Expat is configured with autoconf 2.69 or newer.
14 AC_PREREQ(2.69)
15
16 dnl Get the version number of Expat, using m4's esyscmd() command to run
17 dnl the command at m4-generation time. This allows us to create an m4
18 dnl symbol holding the correct version number. AC_INIT() requires the
19 dnl version number at m4-time, rather than when ./configure is run, so
20 dnl all this must happen as part of m4, not as part of the shell code
21 dnl contained in ./configure.
22 dnl
23 dnl NOTE: esyscmd() is a GNU M4 extension. Thus, we wrap it in an appropriate
24 dnl test. I believe this test will work, but I don't have a place with non-
25 dnl GNU M4 to test it right now.
26 m4_define([expat_version],
27   m4_ifdef([__gnu__],
28            [esyscmd(conftools/get-version.sh lib/expat.h)],
29            [2.2.x]))
30 AC_INIT(expat, expat_version, expat-bugs@libexpat.org)
31 m4_undefine([expat_version])
32
33 AC_CONFIG_SRCDIR([Makefile.in])
34 AC_CONFIG_AUX_DIR([conftools])
35 AC_CONFIG_MACRO_DIR([m4])
36 AC_CANONICAL_HOST
37 AM_INIT_AUTOMAKE
38
39
40 dnl
41 dnl Increment LIBREVISION if source code has changed at all
42 dnl
43 dnl If the API has changed, increment LIBCURRENT and set LIBREVISION to 0
44 dnl
45 dnl If the API changes compatibly (i.e. simply adding a new function
46 dnl without changing or removing earlier interfaces), then increment LIBAGE.
47 dnl
48 dnl If the API changes incompatibly set LIBAGE back to 0
49 dnl
50
51 LIBCURRENT=7   # sync
52 LIBREVISION=9  # with
53 LIBAGE=6       # CMakeLists.txt!
54
55 AX_APPEND_FLAG([-DHAVE_EXPAT_CONFIG_H], [CPPFLAGS])
56 AC_CONFIG_HEADER([expat_config.h])
57
58 AM_PROG_AR
59 AC_PROG_INSTALL
60 AC_PROG_LN_S
61 AC_PROG_MAKE_SET
62
63 LT_PREREQ([2.4])
64 LT_INIT([win32-dll])
65
66 AC_SUBST(LIBCURRENT)
67 AC_SUBST(LIBREVISION)
68 AC_SUBST(LIBAGE)
69
70 AC_LANG([C])
71 AC_PROG_CC_C99
72 AS_IF([test "$GCC" = yes],
73   [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra], [CFLAGS])
74    dnl Be careful about adding the -fexceptions option; some versions of
75    dnl GCC don't support it and it causes extra warnings that are only
76    dnl distracting; avoid.
77    AX_APPEND_COMPILE_FLAGS([-fexceptions], [CFLAGS])
78    AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing -Wmissing-prototypes -Wstrict-prototypes], [CFLAGS])
79    AX_APPEND_COMPILE_FLAGS([-pedantic -Wduplicated-cond -Wduplicated-branches -Wlogical-op], [CFLAGS])
80    AX_APPEND_COMPILE_FLAGS([-Wrestrict -Wnull-dereference -Wjump-misses-init -Wdouble-promotion], [CFLAGS])
81    AX_APPEND_COMPILE_FLAGS([-Wshadow -Wformat=2 -Wmisleading-indentation], [CFLAGS])])
82
83 AC_LANG_PUSH([C++])
84 AC_PROG_CXX
85 AS_IF([test "$GCC" = yes],
86   [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra], [CXXFLAGS])
87    dnl Be careful about adding the -fexceptions option; some versions of
88    dnl GCC don't support it and it causes extra warnings that are only
89    dnl distracting; avoid.
90    AX_APPEND_COMPILE_FLAGS([-fexceptions], [CXXFLAGS])
91    AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [CXXFLAGS])])
92 AC_LANG_POP([C++])
93
94 AS_IF([test "$GCC" = yes],
95   [AX_APPEND_LINK_FLAGS([-fno-strict-aliasing],[LDFLAGS])])
96
97 EXPATCFG_COMPILER_SUPPORTS_VISIBILITY([
98   AX_APPEND_FLAG([-fvisibility=hidden],       [CFLAGS])
99   AX_APPEND_FLAG([-DXML_ENABLE_VISIBILITY=1], [CFLAGS])])
100
101 dnl Checks for header files.
102 AC_HEADER_STDC
103
104 dnl Checks for typedefs, structures, and compiler characteristics.
105
106 dnl We define BYTEORDER to 1234 when the platform is little endian; it
107 dnl defines it to 4321 when the  platform is big endian.  We also define
108 dnl WORDS_BIGENDIAN to 1 when the platform is big endian.
109 dnl
110 dnl A  long time  ago (early 2000  years) AC_C_BIGENDIAN  was considered
111 dnl wrong when cross compiling, now (2018, GNU Autoconf 2.69) we assume
112 dnl it is fine.
113 AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1)
114                 AS_VAR_SET([BYTEORDER], 4321)],
115                [AS_VAR_SET([BYTEORDER], 1234)])
116 AC_DEFINE_UNQUOTED([BYTEORDER], $BYTEORDER, [1234 = LILENDIAN, 4321 = BIGENDIAN])
117
118 AC_C_CONST
119 AC_TYPE_SIZE_T
120
121 AC_ARG_WITH([xmlwf],
122   [AS_HELP_STRING([--without-xmlwf], [do not build xmlwf])],
123   [],
124   [with_xmlwf=yes])
125 AM_CONDITIONAL([WITH_XMLWF], [test x${with_xmlwf} = xyes])
126
127 AC_ARG_WITH([examples],
128   [AS_HELP_STRING([--without-examples], [do not build examples @<:@default=included@:>@])],
129   [],
130   [with_examples=yes])
131 AM_CONDITIONAL([WITH_EXAMPLES], [test x${with_examples} = xyes])
132
133 AC_ARG_WITH([tests],
134   [AS_HELP_STRING([--without-tests], [do not build tests @<:@default=included@:>@])],
135   [],
136   [with_tests=yes])
137 AM_CONDITIONAL([WITH_TESTS], [test x${with_tests} = xyes])
138
139
140 AS_VAR_SET([EXPATCFG_ON_MINGW],[no])
141 AS_CASE("${host_os}",
142   [mingw*],
143   [AS_VAR_SET([EXPATCFG_ON_MINGW],[yes])
144    AC_MSG_NOTICE([detected OS: MinGW])])
145 AM_CONDITIONAL([MINGW], [test x${EXPATCFG_ON_MINGW} = xyes])
146
147 AM_CONDITIONAL([UNICODE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE >/dev/null])
148
149
150 AC_ARG_WITH([libbsd],
151   [AS_HELP_STRING([--with-libbsd], [utilize libbsd (for arc4random_buf)])],
152   [],
153   [with_libbsd=no])
154 AS_IF([test "x${with_libbsd}" != xno],
155   [AC_CHECK_LIB([bsd],
156      [arc4random_buf],
157      [],
158      [AS_IF([test "x${with_libbsd}" = xyes],
159         [AC_MSG_ERROR([Enforced use of libbsd cannot be satisfied.])])])])
160 AC_MSG_CHECKING([for arc4random_buf (BSD or libbsd)])
161 AC_LINK_IFELSE([AC_LANG_SOURCE([
162     #include <stdlib.h>  /* for arc4random_buf on BSD, for NULL */
163     #if defined(HAVE_LIBBSD)
164     # include <bsd/stdlib.h>
165     #endif
166     int main() {
167       arc4random_buf(NULL, 0U);
168       return 0;
169     }
170   ])],
171   [AC_DEFINE([HAVE_ARC4RANDOM_BUF], [1], [Define to 1 if you have the `arc4random_buf' function.])
172    AC_MSG_RESULT([yes])],
173   [AC_MSG_RESULT([no])
174
175    AC_MSG_CHECKING([for arc4random (BSD, macOS or libbsd)])
176    AC_LINK_IFELSE([AC_LANG_SOURCE([
177        #if defined(HAVE_LIBBSD)
178        # include <bsd/stdlib.h>
179        #else
180        # include <stdlib.h>
181        #endif
182        int main() {
183           arc4random();
184           return 0;
185        }
186      ])],
187      [AC_DEFINE([HAVE_ARC4RANDOM], [1], [Define to 1 if you have the `arc4random' function.])
188       AC_MSG_RESULT([yes])],
189      [AC_MSG_RESULT([no])])])
190
191 AC_ARG_WITH([getrandom],
192   [AS_HELP_STRING([--with-getrandom],
193                   [enforce the use of getrandom function in the system @<:@default=check@:>@])
194 AS_HELP_STRING([--without-getrandom],
195                [skip auto detect of getrandom @<:@default=check@:>@])],
196   [],
197   [with_getrandom=check])
198
199 AS_IF([test "x$with_getrandom" != xno],
200   [AC_MSG_CHECKING([for getrandom (Linux 3.17+, glibc 2.25+)])
201    AC_LINK_IFELSE([AC_LANG_SOURCE([
202        #include <stdlib.h>  /* for NULL */
203        #include <sys/random.h>
204        int main() {
205          return getrandom(NULL, 0U, 0U);
206        }
207      ])],
208      [AC_DEFINE([HAVE_GETRANDOM], [1], [Define to 1 if you have the `getrandom' function.])
209       AC_MSG_RESULT([yes])],
210      [AC_MSG_RESULT([no])
211       AS_IF([test "x$with_getrandom" = xyes],
212         [AC_MSG_ERROR([enforced the use of getrandom --with-getrandom, but not detected])])])])
213
214 AC_ARG_WITH([sys_getrandom],
215   [AS_HELP_STRING([--with-sys-getrandom],
216                   [enforce the use of syscall SYS_getrandom function in the system @<:@default=check@:>@])
217 AS_HELP_STRING([--without-sys-getrandom],
218                [skip auto detect of syscall SYS_getrandom @<:@default=check@:>@])],
219   [],
220   [with_sys_getrandom=check])
221
222 AS_IF([test "x$with_sys_getrandom" != xno],
223   [AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)])
224    AC_LINK_IFELSE([AC_LANG_SOURCE([
225        #include <stdlib.h>  /* for NULL */
226        #include <unistd.h>  /* for syscall */
227        #include <sys/syscall.h>  /* for SYS_getrandom */
228        int main() {
229          syscall(SYS_getrandom, NULL, 0, 0);
230          return 0;
231      }
232    ])],
233      [AC_DEFINE([HAVE_SYSCALL_GETRANDOM], [1], [Define to 1 if you have `syscall' and `SYS_getrandom'.])
234       AC_MSG_RESULT([yes])],
235      [AC_MSG_RESULT([no])
236       AS_IF([test "x$with_sys_getrandom" = xyes],
237         [AC_MSG_ERROR([enforced the use of syscall SYS_getrandom --with-sys-getrandom, but not detected])])])])
238
239 dnl Only needed for xmlwf:
240 AC_CHECK_HEADERS(fcntl.h unistd.h)
241 AC_TYPE_OFF_T
242 AC_FUNC_MMAP
243
244 AS_IF([test "$ac_cv_func_mmap_fixed_mapped" = "yes"],
245   [AS_VAR_SET(FILEMAP,unixfilemap)],
246   [AS_VAR_SET(FILEMAP,readfilemap)])
247 AC_SUBST(FILEMAP)
248
249
250 dnl Some basic configuration:
251 AC_DEFINE([XML_NS], 1,
252           [Define to make XML Namespaces functionality available.])
253 AC_DEFINE([XML_DTD], 1,
254           [Define to make parameter entity parsing functionality available.])
255 AC_DEFINE([XML_DEV_URANDOM], 1,
256           [Define to include code reading entropy from `/dev/urandom'.])
257
258 AC_ARG_ENABLE([xml-attr-info],
259   [AS_HELP_STRING([--enable-xml-attr-info],
260      [Enable retrieving the byte offsets for attribute names and values @<:@default=no@:>@])],
261   [],
262   [enable_xml_attr_info=no])
263 AS_IF([test "x${enable_xml_attr_info}" = "xyes"],
264       [AC_DEFINE([XML_ATTR_INFO], 1,
265          [Define to allow retrieving the byte offsets for attribute names and values.])])
266
267 AC_ARG_ENABLE([xml-context],
268   AS_HELP_STRING([--enable-xml-context @<:@COUNT@:>@],
269     [Retain context around the current parse point;
270      default is enabled and a size of 1024 bytes])
271 AS_HELP_STRING([--disable-xml-context],
272     [Do not retain context around the current parse point]),
273     [enable_xml_context=${enableval}])
274 AS_IF([test "x${enable_xml_context}" != "xno"],
275   [AS_IF([test "x${enable_xml_context}" = "xyes" \
276             -o "x${enable_xml_context}" = "x"],
277      [AS_VAR_SET(enable_xml_context,1024)])
278    AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}],
279      [Define to specify how much context to retain around the current parse point.])])
280
281 AC_ARG_WITH([docbook],
282   [AS_HELP_STRING([--with-docbook],
283                   [enforce XML to man page compilation @<:@default=check@:>@])
284 AS_HELP_STRING([--without-docbook],
285                [skip XML to man page compilation @<:@default=check@:>@])],
286   [],
287   [with_docbook=check])
288
289 AC_ARG_VAR([DOCBOOK_TO_MAN], [docbook2x-man command])
290 AS_IF([test "x$with_docbook" != xno],
291   [AC_CHECK_PROGS([DOCBOOK_TO_MAN], [docbook2x-man db2x_docbook2man docbook2man docbook-to-man])])
292 AS_IF([test "x${DOCBOOK_TO_MAN}" = x -a "x$with_docbook" = xyes],
293   [AC_MSG_ERROR([Required program 'docbook2x-man' not found.])])
294 AS_IF([test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno],
295   [AS_IF([${DOCBOOK_TO_MAN} --help | grep -i -q -F sgmlbase],
296     [AC_MSG_ERROR([Your local ${DOCBOOK_TO_MAN} was found to work with SGML rather
297   than XML. Please install docbook2X and use variable DOCBOOK_TO_MAN to point
298   configure to command docbook2x-man of docbook2X.
299   Or use DOCBOOK_TO_MAN="xmlto man --skip-validation" if you have xmlto around.
300   You can also configure using --without-docbook if you can do without a man
301   page for xmlwf.])])])
302
303 AM_CONDITIONAL(WITH_DOCBOOK, [test "x${DOCBOOK_TO_MAN}" != x])
304
305 AC_CONFIG_FILES([Makefile]
306   [expat.pc]
307   [doc/Makefile]
308   [examples/Makefile]
309   [lib/Makefile]
310   [tests/Makefile]
311   [tests/benchmark/Makefile]
312   [xmlwf/Makefile])
313 AC_CONFIG_FILES([run.sh], [chmod +x run.sh])
314 AC_OUTPUT