1 dnl ---------------------------------------------------------------------------
3 dnl Macros for configure.in for wxWindows by Robert Roebling, Phil Blecker,
4 dnl Vadim Zeitlin and Ron Lee
6 dnl This script is under the wxWindows licence.
9 dnl ---------------------------------------------------------------------------
12 dnl ===========================================================================
13 dnl Objective-C(++) related macros
14 dnl ===========================================================================
15 m4_define([AC_WX_LANG_OBJECTIVEC],
20 m4_define([AC_WX_LANG_OBJECTIVECPLUSPLUS],
25 dnl ===========================================================================
26 dnl macros to find a file in the list of include/lib paths
27 dnl ===========================================================================
29 dnl ---------------------------------------------------------------------------
30 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
31 dnl to the full name of the file that was found or leaves it empty if not found
32 dnl ---------------------------------------------------------------------------
33 AC_DEFUN([WX_PATH_FIND_INCLUDES],
36 for ac_dir in $1 /usr/include
38 if test -f "$ac_dir/$2"; then
39 ac_find_includes=$ac_dir
45 dnl ---------------------------------------------------------------------------
46 dnl call WX_PATH_FIND_LIBRARIES(search path, lib name), sets ac_find_libraries
47 dnl to the full name of the file that was found or leaves it empty if not found
48 dnl ---------------------------------------------------------------------------
49 AC_DEFUN([WX_PATH_FIND_LIBRARIES],
54 for ac_extension in a so sl dylib dll.a; do
55 if test -f "$ac_dir/lib$2.$ac_extension"; then
56 ac_find_libraries=$ac_dir
63 dnl ---------------------------------------------------------------------------
64 dnl return list of standard library paths
65 dnl ---------------------------------------------------------------------------
66 dnl return all default locations:
67 dnl - /usr/lib: standard
68 dnl - /usr/lib32: n32 ABI on IRIX
69 dnl - /usr/lib64: n64 ABI on IRIX
70 dnl - /usr/lib/64: 64 bit ABI on Solaris and Linux x86-64
72 dnl NB: if any of directories in the list is not a subdir of /usr, code setting
73 dnl wx_cv_std_libpath needs to be updated
74 AC_DEFUN([WX_STD_LIBPATH], [/usr/lib /usr/lib32 /usr/lib/64 /usr/lib64])
76 dnl ---------------------------------------------------------------------------
77 dnl Path to include, already defined
78 dnl ---------------------------------------------------------------------------
79 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
81 dnl never add -I/usr/include to the CPPFLAGS
82 if test "x$1" = "x/usr/include"; then
85 echo "$2" | grep "\-I$1" > /dev/null
87 if test $result = 0; then
90 ac_path_to_include=" -I$1"
95 dnl ---------------------------------------------------------------------------
96 dnl Usage: WX_LINK_PATH_EXIST(path, libpath)
98 dnl Set ac_path_to_link to nothing if path is already in libpath of to -Lpath
99 dnl if it is not, so that libpath can be set to "$libpath$ac_path_to_link"
100 dnl after calling this function
101 dnl ---------------------------------------------------------------------------
102 AC_DEFUN([WX_LINK_PATH_EXIST],
104 dnl never add -L/usr/libXXX explicitly to libpath
105 if test "$1" = "default location"; then
108 echo "$2" | grep "\-L$1" > /dev/null
110 if test $result = 0; then
113 ac_path_to_link=" -L$1"
118 dnl ===========================================================================
119 dnl C++ features test
120 dnl ===========================================================================
122 dnl ---------------------------------------------------------------------------
123 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
124 dnl or only the old <iostream.h> one - it may be generally assumed that if
125 dnl <iostream> exists, the other "new" headers (without .h) exist too.
127 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
128 dnl ---------------------------------------------------------------------------
130 AC_DEFUN([WX_CPP_NEW_HEADERS],
135 AC_CHECK_HEADERS([iostream],,, [ ])
137 if test "$ac_cv_header_iostream" = "yes" ; then
138 ifelse([$1], , :, [$1])
140 ifelse([$2], , :, [$2])
146 dnl ---------------------------------------------------------------------------
147 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
148 dnl keyword and defines HAVE_EXPLICIT if this is the case
149 dnl ---------------------------------------------------------------------------
151 AC_DEFUN([WX_CPP_EXPLICIT],
153 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
159 dnl do the test in 2 steps: first check that the compiler knows about the
160 dnl explicit keyword at all and then verify that it really honours it
163 class Foo { public: explicit Foo(int) {} };
171 class Foo { public: explicit Foo(int) {} };
172 static void TakeFoo(const Foo& foo) { }
188 if test "$wx_cv_explicit" = "yes"; then
189 AC_DEFINE(HAVE_EXPLICIT)
193 dnl ---------------------------------------------------------------------------
194 dnl WX_CHECK_FUNCS(FUNCTIONS...,
195 dnl [ACTION-IF-FOUND],
196 dnl [ACTION-IF-NOT-FOUND],
197 dnl [EXTRA-DEFINES-AND-INCLUDES],
198 dnl [EXTRA-TEST-CODE])
200 dnl Checks that the functions listed in FUNCTIONS exist in the headers and the
201 dnl libs. For each function, if it is found then defines 'HAVE_FUNCTION' and
202 dnl executes ACTION-IF-FOUND, otherwise executes ACTION-IF-NOT-FOUND.
204 dnl The code from EXTRA-DEFINES-AND-INCLUDES is inserted into the test before
205 dnl the default headers are included, and EXTRA-TEST-CODE is inserted into
206 dnl the main() function after the default test for existence.
209 dnl # the simple case
210 dnl WX_CHECK_FUNCS(stat)
211 dnl # use break to finish the loop early
212 dnl WX_CHECK_FUNCS(mkstemp mktemp, break)
214 dnl WX_CHECK_FUNCS(strtok_r, [], [], [#define _RREENTRANT])
216 dnl WX_CHECK_FUNCS(swprintf, [], [], [#include <wchar.h>])
217 dnl # checking the signature with extra test code
218 dnl WX_CHECK_FUNCS(gettimeofday, [], [], [#include <sys/time.h>]
219 dnl [struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz)])
220 dnl ---------------------------------------------------------------------------
222 AC_DEFUN([WX_CHECK_FUNCS],
228 [wx_cv_func_$wx_func],
244 [eval wx_cv_func_$wx_func=yes],
245 [eval wx_cv_func_$wx_func=no])
248 if eval test \$wx_cv_func_$wx_func = yes
250 AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$wx_func]))
259 dnl ---------------------------------------------------------------------------
260 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
261 dnl ---------------------------------------------------------------------------
263 AC_DEFUN([WX_C_BIGENDIAN],
264 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
265 [ac_cv_c_bigendian=unknown
266 # See if sys/param.h defines the BYTE_ORDER macro.
267 AC_TRY_COMPILE([#include <sys/types.h>
268 #include <sys/param.h>], [
269 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
271 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
272 AC_TRY_COMPILE([#include <sys/types.h>
273 #include <sys/param.h>], [
274 #if BYTE_ORDER != BIG_ENDIAN
276 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
277 if test $ac_cv_c_bigendian = unknown; then
278 AC_TRY_RUN([main () {
279 /* Are we little or big endian? From Harbison&Steele. */
283 char c[sizeof (long)];
286 exit (u.c[sizeof (long) - 1] == 1);
287 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
289 if test $ac_cv_c_bigendian = unknown; then
290 AC_MSG_WARN([Assuming little-endian target machine - this may be overridden by adding the line "ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}" to config.cache file])
292 if test $ac_cv_c_bigendian = yes; then
293 AC_DEFINE(WORDS_BIGENDIAN)
297 dnl ---------------------------------------------------------------------------
298 dnl override AC_ARG_ENABLE/WITH to handle options defaults
299 dnl ---------------------------------------------------------------------------
301 dnl this macro checks for a three-valued command line --with argument:
302 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
303 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
305 dnl the default value (used if the option is not specified at all) is the value
306 dnl of wxUSE_ALL_FEATURES (which is "yes" by default but can be changed by
307 dnl giving configure --disable-all-features option)
308 AC_DEFUN([WX_ARG_SYS_WITH],
310 AC_MSG_CHECKING([for --with-$1])
311 AC_ARG_WITH($1, [$2],
313 if test "$withval" = yes; then
314 AS_TR_SH(wx_cv_use_$1)='$3=yes'
315 elif test "$withval" = no; then
316 AS_TR_SH(wx_cv_use_$1)='$3=no'
317 elif test "$withval" = sys; then
318 AS_TR_SH(wx_cv_use_$1)='$3=sys'
319 elif test "$withval" = builtin; then
320 AS_TR_SH(wx_cv_use_$1)='$3=builtin'
322 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
326 AS_TR_SH(wx_cv_use_$1)='$3=${'DEFAULT_$3":-$wxUSE_ALL_FEATURES}"
329 eval "$AS_TR_SH(wx_cv_use_$1)"
331 if test "$$3" = yes; then
333 elif test "$$3" = no; then
335 elif test "$$3" = sys; then
336 AC_MSG_RESULT([system version])
337 elif test "$$3" = builtin; then
338 AC_MSG_RESULT([builtin version])
340 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
344 dnl this macro simply checks for a command line argument
345 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name, [withstring])
346 AC_DEFUN([WX_ARG_WITH],
349 defaultval=$wxUSE_ALL_FEATURES
350 if test -z "$defaultval"; then
351 if test x"$withstring" = xwithout; then
357 AC_MSG_CHECKING([for --${withstring:-with}-$1])
358 AC_ARG_WITH($1, [$2],
360 if test "$withval" = yes; then
361 AS_TR_SH(wx_cv_use_$1)='$3=yes'
363 AS_TR_SH(wx_cv_use_$1)='$3=no'
367 AS_TR_SH(wx_cv_use_$1)='$3=${'DEFAULT_$3":-$defaultval}"
370 eval "$AS_TR_SH(wx_cv_use_$1)"
372 if test x"$withstring" = xwithout; then
373 if test $$3 = yes; then
382 AC_MSG_RESULT($result)
385 dnl same as WX_ARG_WITH but makes it clear that the option is enabled by default
386 AC_DEFUN([WX_ARG_WITHOUT], [WX_ARG_WITH($1, [$2], $3, without)])
388 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
389 dnl usage: WX_ARG_ENABLE(option, helpmessage, var, [enablestring], [default])
391 dnl enablestring can be omitted or a literal string "disable" and allows to
392 dnl show "checking for --disable-foo" message when running configure instead of
393 dnl the default "checking for --enable-foo" one whih is useful for the options
394 dnl enabled by default
396 dnl the "default" argument can be omitted or contain the default value to use
397 dnl for the option if it's unspecified
398 AC_DEFUN([WX_ARG_ENABLE],
402 if test -z "$defaultval"; then
403 if test x"$enablestring" = xdisable; then
410 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
411 AC_ARG_ENABLE($1, [$2],
413 if test "$enableval" = yes; then
414 AS_TR_SH(wx_cv_use_$1)='$3=yes'
416 AS_TR_SH(wx_cv_use_$1)='$3=no'
420 AS_TR_SH(wx_cv_use_$1)='$3=${'DEFAULT_$3":-$defaultval}"
423 eval "$AS_TR_SH(wx_cv_use_$1)"
425 if test x"$enablestring" = xdisable; then
426 if test $$3 = no; then
435 AC_MSG_RESULT($result)
438 dnl the same as WX_ARG_ENABLE but makes it more clear that the option is
439 dnl enabled by default
440 AC_DEFUN([WX_ARG_DISABLE], [WX_ARG_ENABLE($1, [$2], $3, disable)])
442 dnl same as WX_ARG_ENABLE but defaults to wxUSE_ALL_FEATURES instead of "yes"
443 AC_DEFUN([WX_ARG_FEATURE], [WX_ARG_ENABLE($1, [$2], $3,, $wxUSE_ALL_FEATURES)])
445 dnl Like WX_ARG_ENABLE but accepts a parameter.
448 dnl WX_ARG_ENABLE_PARAM(option, helpmessage, variable-name, enablestring)
451 dnl WX_ARG_ENABLE_PARAM(foo, [[ --enable-foo[=bar] use foo]], wxUSE_FOO)
453 dnl --enable-foo wxUSE_FOO=yes
454 dnl --disable-foo wxUSE_FOO=no
455 dnl --enable-foo=bar wxUSE_FOO=bar
456 dnl <not given> wxUSE_FOO=$DEFAULT_wxUSE_FOO
458 AC_DEFUN([WX_ARG_ENABLE_PARAM],
461 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
462 AC_ARG_ENABLE($1, [$2],
464 wx_cv_use_$1="$3='$enableval'"
467 wx_cv_use_$1='$3='$DEFAULT_$3
475 dnl ===========================================================================
476 dnl Linker features test
477 dnl ===========================================================================
479 dnl ---------------------------------------------------------------------------
480 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
481 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
482 dnl version script file named versionfile
484 dnl call WX_VERSIONED_SYMBOLS(versionfile)
485 dnl ---------------------------------------------------------------------------
486 AC_DEFUN([WX_VERSIONED_SYMBOLS],
489 *-*-cygwin* | *-*-mingw* )
490 dnl although ld does support version script option on these
491 dnl platforms, it doesn't make much sense to use it under Win32
492 dnl and, moreover, this breaks linking because of a bug in handling
493 dnl paths in -Wl,--version-script,path option (if we ever do need
494 dnl to use it for cygwin/mingw32, keep in mind that replacing last
495 dnl comma with the equal sign works) so
496 dnl simply disable it
497 wx_cv_version_script=no
501 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
503 echo "VER_1 { *; };" >conftest.sym
504 echo "int main() { return 0; }" >conftest.cpp
507 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
508 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
509 if test -s conftest.stderr ; then
510 wx_cv_version_script=no
512 wx_cv_version_script=yes
515 wx_cv_version_script=no
518 dnl There's a problem in some old linkers with --version-script that
519 dnl can cause linking to fail when you have objects with vtables in
520 dnl libs 3 deep. This is known to happen in netbsd and openbsd with
523 dnl To test for this we need to make some shared libs and
524 dnl unfortunately we can't be sure of the right way to do that. If the
525 dnl first two compiles don't succeed then it looks like the test isn't
526 dnl working and the result is ignored, but if OTOH the first two
527 dnl succeed but the third does not then the bug has been detected and
528 dnl the --version-script flag is dropped.
529 if test $wx_cv_version_script = yes
531 echo "struct B { virtual ~B() { } }; \
532 struct D : public B { }; \
533 void F() { D d; }" > conftest.cpp
536 $CXX -shared -fPIC -o conftest1.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
537 -Wl,--version-script,conftest.sym >/dev/null 2>/dev/null]) &&
539 $CXX -shared -fPIC -o conftest2.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
540 -Wl,--version-script,conftest.sym conftest1.output >/dev/null 2>/dev/null])
543 $CXX -shared -fPIC -o conftest3.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
544 -Wl,--version-script,conftest.sym conftest2.output conftest1.output >/dev/null 2>/dev/null])
546 wx_cv_version_script=yes
548 wx_cv_version_script=no
553 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
554 rm -f conftest1.output conftest2.output conftest3.output
557 if test $wx_cv_version_script = yes ; then
558 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
565 dnl ===========================================================================
566 dnl "3rd party" macros included here because they are not widely available
567 dnl ===========================================================================
569 dnl ---------------------------------------------------------------------------
570 dnl test for availability of iconv()
571 dnl ---------------------------------------------------------------------------
573 dnl From Bruno Haible.
577 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
578 dnl those with the standalone portable GNU libiconv installed).
580 AC_ARG_WITH([libiconv-prefix],
581 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
582 for dir in `echo "$withval" | tr : ' '`; do
583 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
584 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
588 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
589 am_cv_func_iconv="no, consider installing GNU libiconv"
591 AC_TRY_LINK([#include <stdlib.h>
593 [iconv_t cd = iconv_open("","");
594 iconv(cd,NULL,NULL,NULL,NULL);
596 am_cv_func_iconv=yes)
597 if test "$am_cv_func_iconv" != yes; then
600 AC_TRY_LINK([#include <stdlib.h>
602 [iconv_t cd = iconv_open("","");
603 iconv(cd,NULL,NULL,NULL,NULL);
606 am_cv_func_iconv=yes)
610 if test "$am_cv_func_iconv" = yes; then
611 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
612 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
620 #if defined(__STDC__) || defined(__cplusplus)
621 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
627 wx_cv_func_iconv_const="no",
628 wx_cv_func_iconv_const="yes"
633 if test "x$wx_cv_func_iconv_const" = "xyes"; then
637 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
638 [Define as const if the declaration of iconv() needs const.])
641 if test "$am_cv_lib_iconv" = yes; then
647 dnl ---------------------------------------------------------------------------
648 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
649 dnl ---------------------------------------------------------------------------
651 dnl WX_SYS_LARGEFILE_TEST
653 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
654 dnl arithmetic properly but this failed miserably with gcc under Linux
655 dnl whereas the system still supports 64 bit files, so now simply check
656 dnl that off_t is big enough
657 define(WX_SYS_LARGEFILE_TEST,
659 unsigned int field: sizeof(off_t) == 8;
664 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
665 define(WX_SYS_LARGEFILE_MACRO_VALUE,
667 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
669 AC_TRY_COMPILE([#define $1 $2
670 #include <sys/types.h>],
671 WX_SYS_LARGEFILE_TEST,
677 if test "$$3" != no; then
679 AC_DEFINE_UNQUOTED([$1], [$$3])
686 dnl By default, many hosts won't let programs access large files;
687 dnl one must use special compiler options to get large-file access to work.
688 dnl For more details about this brain damage please see:
689 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
690 AC_DEFUN([AC_SYS_LARGEFILE],
691 [AC_ARG_ENABLE(largefile,
692 [ --disable-largefile omit support for large files])
693 if test "$enable_largefile" != no; then
694 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
695 dnl _LARGE_FILES -- for AIX
697 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
698 if test "x$wx_largefile" != "xyes"; then
699 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
702 AC_MSG_CHECKING(if large file support is available)
703 if test "x$wx_largefile" = "xyes"; then
704 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
706 AC_MSG_RESULT($wx_largefile)