xref: /freebsd/contrib/expat/configure.ac (revision 058ac3e8063366dafa634d9107642e12b038bf09)
1dnl   configuration script for expat
2dnl   Process this file with autoconf to produce a configure script.
3dnl                            __  __            _
4dnl                         ___\ \/ /_ __   __ _| |_
5dnl                        / _ \\  /| '_ \ / _` | __|
6dnl                       |  __//  \| |_) | (_| | |_
7dnl                        \___/_/\_\ .__/ \__,_|\__|
8dnl                                 |_| XML parser
9dnl
10dnl   Copyright (c) 2000      Clark Cooper <coopercc@users.sourceforge.net>
11dnl   Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
12dnl   Copyright (c) 2001-2003 Greg Stein <gstein@users.sourceforge.net>
13dnl   Copyright (c) 2006-2012 Karl Waclawek <karl@waclawek.net>
14dnl   Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
15dnl   Copyright (c) 2017      S. P. Zeidler <spz@netbsd.org>
16dnl   Copyright (c) 2017      Stephen Groat <stephen@groat.us>
17dnl   Copyright (c) 2017-2020 Joe Orton <jorton@redhat.com>
18dnl   Copyright (c) 2018      Yury Gribov <tetra2005@gmail.com>
19dnl   Copyright (c) 2018      Benjamin Peterson <benjamin@python.org>
20dnl   Copyright (c) 2018      Marco Maggi <marco.maggi-ipsu@poste.it>
21dnl   Copyright (c) 2018      KangLin <kl222@126.com>
22dnl   Copyright (c) 2019      Mohammed Khajapasha <mohammed.khajapasha@intel.com>
23dnl   Copyright (c) 2019      Kishore Kunche <kishore.kunche@intel.com>
24dnl   Copyright (c) 2020      Jeffrey Walton <noloader@gmail.com>
25dnl   Licensed under the MIT license:
26dnl
27dnl   Permission is  hereby granted,  free of charge,  to any  person obtaining
28dnl   a  copy  of  this  software   and  associated  documentation  files  (the
29dnl   "Software"),  to  deal in  the  Software  without restriction,  including
30dnl   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
31dnl   distribute, sublicense, and/or sell copies of the Software, and to permit
32dnl   persons  to whom  the Software  is  furnished to  do so,  subject to  the
33dnl   following conditions:
34dnl
35dnl   The above copyright  notice and this permission notice  shall be included
36dnl   in all copies or substantial portions of the Software.
37dnl
38dnl   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
39dnl   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
40dnl   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
41dnl   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
42dnl   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
43dnl   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
44dnl   USE OR OTHER DEALINGS IN THE SOFTWARE.
45
46dnl Ensure that Expat is configured with autoconf 2.69 or newer.
47AC_PREREQ([2.69])
48
49dnl Get the version number of Expat, using m4's esyscmd() command to run
50dnl the command at m4-generation time. This allows us to create an m4
51dnl symbol holding the correct version number. AC_INIT requires the
52dnl version number at m4-time, rather than when ./configure is run, so
53dnl all this must happen as part of m4, not as part of the shell code
54dnl contained in ./configure.
55dnl
56dnl NOTE: esyscmd() is a GNU M4 extension. Thus, we wrap it in an appropriate
57dnl test. I believe this test will work, but I don't have a place with non-
58dnl GNU M4 to test it right now.
59m4_define([expat_version],
60  m4_ifdef([__gnu__],
61           [esyscmd(conftools/get-version.sh lib/expat.h)],
62           [2.2.x]))
63AC_INIT([expat], expat_version, [expat-bugs@libexpat.org])
64m4_undefine([expat_version])
65
66AC_CONFIG_SRCDIR([Makefile.in])
67AC_CONFIG_AUX_DIR([conftools])
68AC_CONFIG_MACRO_DIR([m4])
69AC_CANONICAL_HOST
70AM_INIT_AUTOMAKE
71
72
73dnl
74dnl Increment LIBREVISION if source code has changed at all
75dnl
76dnl If the API has changed, increment LIBCURRENT and set LIBREVISION to 0
77dnl
78dnl If the API changes compatibly (i.e. simply adding a new function
79dnl without changing or removing earlier interfaces), then increment LIBAGE.
80dnl
81dnl If the API changes incompatibly set LIBAGE back to 0
82dnl
83
84LIBCURRENT=9    # sync
85LIBREVISION=10  # with
86LIBAGE=8        # CMakeLists.txt!
87
88AC_CONFIG_HEADERS([expat_config.h])
89AH_TOP([#ifndef EXPAT_CONFIG_H
90#define EXPAT_CONFIG_H 1])
91AH_BOTTOM([#endif // ndef EXPAT_CONFIG_H])
92
93AM_PROG_AR
94AC_PROG_INSTALL
95AC_PROG_LN_S
96AC_PROG_MAKE_SET
97
98LT_PREREQ([2.4])
99LT_INIT([win32-dll])
100
101AC_SUBST(LIBCURRENT)
102AC_SUBST(LIBREVISION)
103AC_SUBST(LIBAGE)
104
105AC_LANG([C])
106AC_PROG_CC_C99
107
108AS_IF([test "$GCC" = yes],
109  [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra], [AM_CFLAGS])
110   dnl Be careful about adding the -fexceptions option; some versions of
111   dnl GCC don't support it and it causes extra warnings that are only
112   dnl distracting; avoid.
113   AX_APPEND_COMPILE_FLAGS([-fexceptions], [AM_CFLAGS])
114   AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing -Wmissing-prototypes -Wstrict-prototypes], [AM_CFLAGS])
115   AX_APPEND_COMPILE_FLAGS([-pedantic -Wduplicated-cond -Wduplicated-branches -Wlogical-op], [AM_CFLAGS])
116   AX_APPEND_COMPILE_FLAGS([-Wrestrict -Wnull-dereference -Wjump-misses-init -Wdouble-promotion], [AM_CFLAGS])
117   AX_APPEND_COMPILE_FLAGS([-Wshadow -Wformat=2 -Wno-pedantic-ms-format -Wmisleading-indentation], [AM_CFLAGS])])
118
119AC_LANG_PUSH([C++])
120AC_PROG_CXX
121
122AS_IF([test "$GCC" = yes],
123  [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra], [AM_CXXFLAGS])
124   dnl Be careful about adding the -fexceptions option; some versions of
125   dnl GCC don't support it and it causes extra warnings that are only
126   dnl distracting; avoid.
127   AX_APPEND_COMPILE_FLAGS([-fexceptions], [AM_CXXFLAGS])
128   AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [AM_CXXFLAGS])])
129AC_LANG_POP([C++])
130
131AS_IF([test "$GCC" = yes],
132  [AX_APPEND_LINK_FLAGS([-fno-strict-aliasing],[AM_LDFLAGS])])
133
134dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang (issue #312)
135AS_CASE(["$LD"],[*clang*],
136  [AS_CASE(["${host_os}"],
137     [*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])])
138
139EXPATCFG_COMPILER_SUPPORTS_VISIBILITY([
140  AX_APPEND_FLAG([-fvisibility=hidden],              [AM_CFLAGS])
141  AS_IF([test "${enable_shared}" = yes],
142        [AX_APPEND_FLAG([-DXML_ENABLE_VISIBILITY=1], [AM_CPPFLAGS])])])
143
144dnl Checks for typedefs, structures, and compiler characteristics.
145
146dnl We define BYTEORDER to 1234 when the platform is little endian; it
147dnl defines it to 4321 when the  platform is big endian.  We also define
148dnl WORDS_BIGENDIAN to 1 when the platform is big endian.
149dnl
150dnl A  long time  ago (early 2000  years) AC_C_BIGENDIAN  was considered
151dnl wrong when cross compiling, now (2018, GNU Autoconf 2.69) we assume
152dnl it is fine.
153AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1)
154                AS_VAR_SET([BYTEORDER], 4321)],
155               [AS_VAR_SET([BYTEORDER], 1234)])
156AC_DEFINE_UNQUOTED([BYTEORDER], $BYTEORDER, [1234 = LILENDIAN, 4321 = BIGENDIAN])
157
158AC_C_CONST
159AC_TYPE_SIZE_T
160
161AC_ARG_WITH([xmlwf],
162  [AS_HELP_STRING([--without-xmlwf], [do not build xmlwf])],
163  [],
164  [with_xmlwf=yes])
165AM_CONDITIONAL([WITH_XMLWF], [test x${with_xmlwf} = xyes])
166
167AC_ARG_WITH([examples],
168  [AS_HELP_STRING([--without-examples], [do not build examples @<:@default=included@:>@])],
169  [],
170  [with_examples=yes])
171AM_CONDITIONAL([WITH_EXAMPLES], [test x${with_examples} = xyes])
172
173AC_ARG_WITH([tests],
174  [AS_HELP_STRING([--without-tests], [do not build tests @<:@default=included@:>@])],
175  [],
176  [with_tests=yes])
177AM_CONDITIONAL([WITH_TESTS], [test x${with_tests} = xyes])
178
179
180AS_VAR_SET([EXPATCFG_ON_MINGW],[no])
181AS_CASE("${host_os}",
182  [mingw*],
183  [AS_VAR_SET([EXPATCFG_ON_MINGW],[yes])
184   AC_MSG_NOTICE([detected OS: MinGW])])
185AM_CONDITIONAL([MINGW], [test x${EXPATCFG_ON_MINGW} = xyes])
186
187dnl Note: Prefix "_INTERNAL_" here means exclusive use inside of file configure.ac
188AM_CONDITIONAL([UNICODE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE >/dev/null])
189AM_CONDITIONAL([_INTERNAL_UNICODE_WCHAR_T], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE_WCHAR_T >/dev/null])
190AM_CONDITIONAL([_INTERNAL_MIN_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_MIN_SIZE >/dev/null])
191AM_CONDITIONAL([_INTERNAL_LARGE_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_LARGE_SIZE >/dev/null])
192
193LT_LIB_M
194
195AC_ARG_WITH([libbsd],
196  [AS_HELP_STRING([--with-libbsd], [utilize libbsd (for arc4random_buf)])],
197  [],
198  [with_libbsd=no])
199AS_IF([test "x${with_libbsd}" != xno],
200  [AC_CHECK_LIB([bsd],
201     [arc4random_buf],
202     [],
203     [AS_IF([test "x${with_libbsd}" = xyes],
204        [AC_MSG_ERROR([Enforced use of libbsd cannot be satisfied.])])])])
205AC_MSG_CHECKING([for arc4random_buf (BSD or libbsd)])
206AC_LINK_IFELSE([AC_LANG_SOURCE([
207    #include <stdlib.h>  /* for arc4random_buf on BSD, for NULL */
208    #if defined(HAVE_LIBBSD)
209    # include <bsd/stdlib.h>
210    #endif
211    int main() {
212      arc4random_buf(NULL, 0U);
213      return 0;
214    }
215  ])],
216  [AC_DEFINE([HAVE_ARC4RANDOM_BUF], [1], [Define to 1 if you have the `arc4random_buf' function.])
217   AC_MSG_RESULT([yes])],
218  [AC_MSG_RESULT([no])
219
220   AC_MSG_CHECKING([for arc4random (BSD, macOS or libbsd)])
221   AC_LINK_IFELSE([AC_LANG_SOURCE([
222       #if defined(HAVE_LIBBSD)
223       # include <bsd/stdlib.h>
224       #else
225       # include <stdlib.h>
226       #endif
227       int main() {
228          arc4random();
229          return 0;
230       }
231     ])],
232     [AC_DEFINE([HAVE_ARC4RANDOM], [1], [Define to 1 if you have the `arc4random' function.])
233      AC_MSG_RESULT([yes])],
234     [AC_MSG_RESULT([no])])])
235
236AC_ARG_WITH([getrandom],
237  [AS_HELP_STRING([--with-getrandom],
238                  [enforce the use of getrandom function in the system @<:@default=check@:>@])
239AS_HELP_STRING([--without-getrandom],
240               [skip auto detect of getrandom @<:@default=check@:>@])],
241  [],
242  [with_getrandom=check])
243
244AS_IF([test "x$with_getrandom" != xno],
245  [AC_MSG_CHECKING([for getrandom (Linux 3.17+, glibc 2.25+)])
246   AC_LINK_IFELSE([AC_LANG_SOURCE([
247       #include <stdlib.h>  /* for NULL */
248       #include <sys/random.h>
249       int main() {
250         return getrandom(NULL, 0U, 0U);
251       }
252     ])],
253     [AC_DEFINE([HAVE_GETRANDOM], [1], [Define to 1 if you have the `getrandom' function.])
254      AC_MSG_RESULT([yes])],
255     [AC_MSG_RESULT([no])
256      AS_IF([test "x$with_getrandom" = xyes],
257        [AC_MSG_ERROR([enforced the use of getrandom --with-getrandom, but not detected])])])])
258
259AC_ARG_WITH([sys_getrandom],
260  [AS_HELP_STRING([--with-sys-getrandom],
261                  [enforce the use of syscall SYS_getrandom function in the system @<:@default=check@:>@])
262AS_HELP_STRING([--without-sys-getrandom],
263               [skip auto detect of syscall SYS_getrandom @<:@default=check@:>@])],
264  [],
265  [with_sys_getrandom=check])
266
267AS_IF([test "x$with_sys_getrandom" != xno],
268  [AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)])
269   AC_LINK_IFELSE([AC_LANG_SOURCE([
270       #include <stdlib.h>  /* for NULL */
271       #include <unistd.h>  /* for syscall */
272       #include <sys/syscall.h>  /* for SYS_getrandom */
273       int main() {
274         syscall(SYS_getrandom, NULL, 0, 0);
275         return 0;
276     }
277   ])],
278     [AC_DEFINE([HAVE_SYSCALL_GETRANDOM], [1], [Define to 1 if you have `syscall' and `SYS_getrandom'.])
279      AC_MSG_RESULT([yes])],
280     [AC_MSG_RESULT([no])
281      AS_IF([test "x$with_sys_getrandom" = xyes],
282        [AC_MSG_ERROR([enforced the use of syscall SYS_getrandom --with-sys-getrandom, but not detected])])])])
283
284dnl Only needed for xmlwf:
285AC_CHECK_HEADERS(fcntl.h unistd.h)
286AC_TYPE_OFF_T
287AC_FUNC_MMAP
288
289AS_IF([test "$ac_cv_func_mmap_fixed_mapped" = "yes"],
290  [AS_VAR_SET(FILEMAP,unixfilemap)],
291  [AS_VAR_SET(FILEMAP,readfilemap)])
292AC_SUBST(FILEMAP)
293
294
295dnl Some basic configuration:
296AC_DEFINE([XML_NS], 1,
297          [Define to make XML Namespaces functionality available.])
298AC_DEFINE([XML_DTD], 1,
299          [Define to make parameter entity parsing functionality available.])
300AC_DEFINE([XML_DEV_URANDOM], 1,
301          [Define to include code reading entropy from `/dev/urandom'.])
302
303AC_ARG_ENABLE([xml-attr-info],
304  [AS_HELP_STRING([--enable-xml-attr-info],
305     [Enable retrieving the byte offsets for attribute names and values @<:@default=no@:>@])],
306  [],
307  [enable_xml_attr_info=no])
308AS_IF([test "x${enable_xml_attr_info}" = "xyes"],
309      [AC_DEFINE([XML_ATTR_INFO], 1,
310         [Define to allow retrieving the byte offsets for attribute names and values.])])
311
312AC_ARG_ENABLE([xml-context],
313  AS_HELP_STRING([--enable-xml-context @<:@COUNT@:>@],
314    [Retain context around the current parse point;
315     default is enabled and a size of 1024 bytes])
316AS_HELP_STRING([--disable-xml-context],
317    [Do not retain context around the current parse point]),
318    [enable_xml_context=${enableval}])
319AS_IF([test "x${enable_xml_context}" != "xno"],
320  [AS_IF([test "x${enable_xml_context}" = "xyes" \
321            -o "x${enable_xml_context}" = "x"],
322     [AS_VAR_SET(enable_xml_context,1024)])
323   AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}],
324     [Define to specify how much context to retain around the current parse point.])])
325
326AC_ARG_WITH([docbook],
327  [AS_HELP_STRING([--with-docbook],
328                  [enforce XML to man page compilation @<:@default=check@:>@])
329AS_HELP_STRING([--without-docbook],
330               [skip XML to man page compilation @<:@default=check@:>@])],
331  [],
332  [with_docbook=check])
333
334AC_ARG_VAR([DOCBOOK_TO_MAN], [docbook2x-man command])
335AS_IF([test "x$with_docbook" != xno],
336  [AC_CHECK_PROGS([DOCBOOK_TO_MAN], [docbook2x-man db2x_docbook2man docbook2man docbook-to-man])])
337AS_IF([test "x${DOCBOOK_TO_MAN}" = x -a "x$with_docbook" = xyes],
338  [AC_MSG_ERROR([Required program 'docbook2x-man' not found.])])
339AS_IF([test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno],
340  [AS_IF([${DOCBOOK_TO_MAN} --help | grep -i -q -F sgmlbase],
341    [AC_MSG_ERROR([Your local ${DOCBOOK_TO_MAN} was found to work with SGML rather
342  than XML. Please install docbook2X and use variable DOCBOOK_TO_MAN to point
343  configure to command docbook2x-man of docbook2X.
344  Or use DOCBOOK_TO_MAN="xmlto man --skip-validation" if you have xmlto around.
345  You can also configure using --without-docbook if you can do without a man
346  page for xmlwf.])])])
347
348AM_CONDITIONAL(WITH_DOCBOOK, [test "x${DOCBOOK_TO_MAN}" != x])
349
350
351dnl Configure CMake file templates
352dnl NOTE: The *_TRUE variables read here are Automake conditionals
353dnl       that are either set to "" when enabled or to "#" when disabled
354dnl       (because they are used to dynamically comment out certain things)
355AS_IF([test "x${enable_xml_attr_info}" = xyes],
356  [EXPAT_ATTR_INFO=ON],
357  [EXPAT_ATTR_INFO=OFF])
358EXPAT_DTD=ON
359AS_IF([test "x${_INTERNAL_LARGE_SIZE_TRUE}" = x],
360  [EXPAT_LARGE_SIZE=ON],
361  [EXPAT_LARGE_SIZE=OFF])
362AS_IF([test "x${_INTERNAL_MIN_SIZE_TRUE}" = x],
363  [EXPAT_MIN_SIZE=ON],
364  [EXPAT_MIN_SIZE=OFF])
365EXPAT_NS=ON
366AS_IF([test "x${enable_xml_context}" != xno],
367  [EXPAT_CONTEXT_BYTES=${enable_xml_context}],
368  [EXPAT_CONTEXT_BYTES=OFF])
369AS_IF([test "x${UNICODE_TRUE}" = x],
370  [AS_IF(
371     [test "x${_INTERNAL_UNICODE_WCHAR_T_TRUE}" = x],
372        [EXPAT_CHAR_TYPE=wchar_t],
373        [EXPAT_CHAR_TYPE=ushort])],
374  [EXPAT_CHAR_TYPE=char])
375PACKAGE_INIT="${srcdir}"/cmake/autotools/expat-package-init.cmake
376LIBDIR_BASENAME="$(basename "${libdir}")"
377SO_MAJOR="$(expr "${LIBCURRENT}" - "${LIBAGE}")"
378SO_MINOR="${LIBAGE}"
379SO_PATCH="${LIBREVISION}"
380AC_CHECK_SIZEOF([void *])  # sets ac_cv_sizeof_void_p
381AC_SUBST([EXPAT_ATTR_INFO])
382AC_SUBST([EXPAT_DTD])
383AC_SUBST([EXPAT_LARGE_SIZE])
384AC_SUBST([EXPAT_MIN_SIZE])
385AC_SUBST([EXPAT_NS])
386AC_SUBST([EXPAT_CONTEXT_BYTES])
387AC_SUBST([EXPAT_CHAR_TYPE])
388AC_SUBST_FILE([PACKAGE_INIT])
389AC_SUBST([LIBDIR_BASENAME])
390AC_SUBST([SO_MAJOR])
391AC_SUBST([SO_MINOR])
392AC_SUBST([SO_PATCH])
393AC_SUBST([ac_cv_sizeof_void_p])
394
395
396dnl write the Automake flags we set
397AC_SUBST([AM_CPPFLAGS])
398AC_SUBST([AM_CFLAGS])
399AC_SUBST([AM_CXXFLAGS])
400AC_SUBST([AM_LDFLAGS])
401
402dnl Emulate the use of CMAKE_SHARED_LIBRARY_PREFIX under CMake
403AC_MSG_CHECKING([for shared library name prefix])
404AS_CASE("${host_os}",
405  [cygwin*], [CMAKE_SHARED_LIBRARY_PREFIX=cyg],
406  [CMAKE_SHARED_LIBRARY_PREFIX=lib])
407AC_MSG_RESULT([${CMAKE_SHARED_LIBRARY_PREFIX}])
408AC_SUBST([CMAKE_SHARED_LIBRARY_PREFIX])
409
410AS_CASE("${host_os}",
411  [darwin*], [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__macos.cmake.in],
412  [mingw*|cygwin*], [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__windows.cmake.in],
413  [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__linux.cmake.in])
414AC_CONFIG_FILES([Makefile]
415  [expat.pc]
416  [cmake/expat-config.cmake]
417  [cmake/autotools/expat-config-version.cmake]
418  [cmake/autotools/expat-noconfig.cmake:${CMAKE_NOCONFIG_SOURCE}]
419  [doc/Makefile]
420  [examples/Makefile]
421  [lib/Makefile]
422  [tests/Makefile]
423  [tests/benchmark/Makefile]
424  [xmlwf/Makefile])
425AC_CONFIG_FILES([run.sh], [chmod +x run.sh])
426AC_OUTPUT
427
428
429AC_MSG_NOTICE([
430
431Automake flags (can be overridden by user flags):
432  [AM_CPPFLAGS]: ${AM_CPPFLAGS}
433    [AM_CFLAGS]: ${AM_CFLAGS}
434  [AM_CXXFLAGS]: ${AM_CXXFLAGS}
435   [AM_LDFLAGS]: ${AM_LDFLAGS}
436
437User flags (override Automake flags on conflict):
438     CPPFLAGS: ${CPPFLAGS}
439       CFLAGS: ${CFLAGS}
440     CXXFLAGS: ${CXXFLAGS}
441      LDFLAGS: ${LDFLAGS}])
442