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 ---------------------------------------------------------------------------
11 dnl ===========================================================================
12 dnl macros to detect specialty compiler options
13 dnl ===========================================================================
15 dnl Figure out if we need to pass -ext o to compiler (MetroWerks)
16 AC_DEFUN([AC_WX_METROWERKS_EXTO],
17 [AC_CACHE_CHECK([if the _AC_LANG compiler requires -ext o], wx_cv_[]_AC_LANG_ABBREV[]_exto,
18 dnl First create an empty conf test
19 [AC_LANG_CONFTEST([AC_LANG_PROGRAM()])
20 dnl Now remove .o and .c.o or .cc.o
21 rm -f conftest.$ac_objext conftest.$ac_ext.o
22 dnl Now compile the test
23 AS_IF([AC_TRY_EVAL(ac_compile)],
24 dnl If the test succeeded look for conftest.c.o or conftest.cc.o
25 [for ac_file in `(ls conftest.* 2>/dev/null)`; do
28 wx_cv_[]_AC_LANG_ABBREV[]_exto="-ext o"
34 [AC_MSG_FAILURE([cannot figure out if compiler needs -ext o: cannot compile])
37 rm -f conftest.$ac_ext.o conftest.$ac_objext conftest.$ac_ext
40 if test "x$wx_cv_[]_AC_LANG_ABBREV[]_exto" '!=' "x"; then
41 if test "[]_AC_LANG_ABBREV[]" = "c"; then
42 CFLAGS="$wx_cv_[]_AC_LANG_ABBREV[]_exto $CFLAGS"
44 if test "[]_AC_LANG_ABBREV[]" = "cxx"; then
45 CXXFLAGS="$wx_cv_[]_AC_LANG_ABBREV[]_exto $CXXFLAGS"
51 dnl Based on autoconf _AC_LANG_COMPILER_GNU
52 AC_DEFUN([_AC_WX_LANG_COMPILER_XLC],
53 [AC_CACHE_CHECK([whether we are using the IBM xlC _AC_LANG compiler],
54 [wx_cv_[]_AC_LANG_ABBREV[]_compiler_xlc],
55 [AC_TRY_COMPILE([],[#ifndef __xlC__
59 [wx_compiler_xlc=yes],
61 wx_cv_[]_AC_LANG_ABBREV[]_compiler_xlc=$wx_compiler_xlc
65 dnl Loosely based on autoconf AC_PROG_CC
66 AC_DEFUN([AC_WX_PROG_XLCC],
68 _AC_WX_LANG_COMPILER_XLC
69 XLCC=`test $wx_compiler_xlc = yes && echo yes`
73 dnl Loosely based on autoconf AC_PROG_CXX
74 AC_DEFUN([AC_WX_PROG_XLCXX],
76 _AC_WX_LANG_COMPILER_XLC
77 XLCXX=`test $wx_compiler_xlc = yes && echo yes`
82 dnl ===========================================================================
83 dnl macros to find the a file in the list of include/lib paths
84 dnl ===========================================================================
86 dnl ---------------------------------------------------------------------------
87 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
88 dnl to the full name of the file that was found or leaves it empty if not found
89 dnl ---------------------------------------------------------------------------
90 AC_DEFUN([WX_PATH_FIND_INCLUDES],
93 for ac_dir in $1 /usr/include;
95 if test -f "$ac_dir/$2"; then
96 ac_find_includes=$ac_dir
102 dnl ---------------------------------------------------------------------------
103 dnl call WX_PATH_FIND_LIBRARIES(search path, header name), sets ac_find_libraries
104 dnl to the full name of the file that was found or leaves it empty if not found
105 dnl ---------------------------------------------------------------------------
106 AC_DEFUN([WX_PATH_FIND_LIBRARIES],
109 for ac_dir in $1 /usr/lib;
111 for ac_extension in a so sl dylib; do
112 if test -f "$ac_dir/lib$2.$ac_extension"; then
113 ac_find_libraries=$ac_dir
120 dnl ---------------------------------------------------------------------------
121 dnl Path to include, already defined
122 dnl ---------------------------------------------------------------------------
123 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
125 dnl never add -I/usr/include to the CPPFLAGS
126 if test "x$1" = "x/usr/include"; then
127 ac_path_to_include=""
129 echo "$2" | grep "\-I$1" > /dev/null
131 if test $result = 0; then
132 ac_path_to_include=""
134 ac_path_to_include=" -I$1"
139 dnl ---------------------------------------------------------------------------
140 dnl Path to link, already defined
141 dnl ---------------------------------------------------------------------------
142 AC_DEFUN([WX_LINK_PATH_EXIST],
144 echo "$2" | grep "\-L$1" > /dev/null
146 if test $result = 0; then
149 ac_path_to_link=" -L$1"
153 dnl ===========================================================================
154 dnl C++ features test
155 dnl ===========================================================================
157 dnl ---------------------------------------------------------------------------
158 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
159 dnl or only the old <iostream.h> one - it may be generally assumed that if
160 dnl <iostream> exists, the other "new" headers (without .h) exist too.
162 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
163 dnl ---------------------------------------------------------------------------
165 AC_DEFUN([WX_CPP_NEW_HEADERS],
170 AC_CHECK_HEADERS(iostream)
172 if test "$ac_cv_header_iostream" = "yes" ; then
173 ifelse([$1], , :, [$1])
175 ifelse([$2], , :, [$2])
181 dnl ---------------------------------------------------------------------------
182 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
184 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
185 dnl ---------------------------------------------------------------------------
187 AC_DEFUN([WX_CPP_BOOL],
189 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
213 if test "$wx_cv_cpp_bool" = "yes"; then
218 dnl ---------------------------------------------------------------------------
219 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
220 dnl keyword and defines HAVE_EXPLICIT if this is the case
221 dnl ---------------------------------------------------------------------------
223 AC_DEFUN([WX_CPP_EXPLICIT],
225 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
231 dnl do the test in 2 steps: first check that the compiler knows about the
232 dnl explicit keyword at all and then verify that it really honours it
235 class Foo { public: explicit Foo(int) {} };
243 class Foo { public: explicit Foo(int) {} };
244 static void TakeFoo(const Foo& foo) { }
260 if test "$wx_cv_explicit" = "yes"; then
261 AC_DEFINE(HAVE_EXPLICIT)
265 dnl ---------------------------------------------------------------------------
266 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
267 dnl ---------------------------------------------------------------------------
269 AC_DEFUN([WX_C_BIGENDIAN],
270 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
271 [ac_cv_c_bigendian=unknown
272 # See if sys/param.h defines the BYTE_ORDER macro.
273 AC_TRY_COMPILE([#include <sys/types.h>
274 #include <sys/param.h>], [
275 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
277 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
278 AC_TRY_COMPILE([#include <sys/types.h>
279 #include <sys/param.h>], [
280 #if BYTE_ORDER != BIG_ENDIAN
282 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
283 if test $ac_cv_c_bigendian = unknown; then
284 AC_TRY_RUN([main () {
285 /* Are we little or big endian? From Harbison&Steele. */
289 char c[sizeof (long)];
292 exit (u.c[sizeof (long) - 1] == 1);
293 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
295 if test $ac_cv_c_bigendian = unknown; then
296 AC_MSG_WARN([Assuming little-endian target machine - this may be overriden by adding the line "ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}" to config.cache file])
298 if test $ac_cv_c_bigendian = yes; then
299 AC_DEFINE(WORDS_BIGENDIAN)
303 dnl ---------------------------------------------------------------------------
304 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
305 dnl ---------------------------------------------------------------------------
307 AC_DEFUN([WX_ARG_CACHE_INIT],
309 wx_arg_cache_file="configarg.cache"
310 echo "loading argument cache $wx_arg_cache_file"
311 rm -f ${wx_arg_cache_file}.tmp
312 touch ${wx_arg_cache_file}.tmp
313 touch ${wx_arg_cache_file}
316 AC_DEFUN([WX_ARG_CACHE_FLUSH],
318 echo "saving argument cache $wx_arg_cache_file"
319 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
322 dnl this macro checks for a three-valued command line --with argument:
323 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
324 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
325 AC_DEFUN([WX_ARG_SYS_WITH],
327 AC_MSG_CHECKING([for --with-$1])
329 AC_ARG_WITH($1, [$2],
331 if test "$withval" = yes; then
332 ac_cv_use_$1='$3=yes'
333 elif test "$withval" = no; then
335 elif test "$withval" = sys; then
336 ac_cv_use_$1='$3=sys'
337 elif test "$withval" = builtin; then
338 ac_cv_use_$1='$3=builtin'
340 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
344 LINE=`grep "$3" ${wx_arg_cache_file}`
345 if test "x$LINE" != x ; then
351 ac_cv_use_$1='$3='$DEFAULT_$3
355 if test "$no_cache" != 1; then
356 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
359 if test "$$3" = yes; then
361 elif test "$$3" = no; then
363 elif test "$$3" = sys; then
364 AC_MSG_RESULT([system version])
365 elif test "$$3" = builtin; then
366 AC_MSG_RESULT([builtin version])
368 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
372 dnl this macro checks for a command line argument and caches the result
373 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name)
374 AC_DEFUN([WX_ARG_WITH],
376 AC_MSG_CHECKING([for --with-$1])
378 AC_ARG_WITH($1, [$2],
380 if test "$withval" = yes; then
381 ac_cv_use_$1='$3=yes'
387 LINE=`grep "$3" ${wx_arg_cache_file}`
388 if test "x$LINE" != x ; then
394 ac_cv_use_$1='$3='$DEFAULT_$3
398 if test "$no_cache" != 1; then
399 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
402 if test "$$3" = yes; then
409 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
410 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name, enablestring)
412 dnl enablestring is a hack and allows to show "checking for --disable-foo"
413 dnl message when running configure instead of the default "checking for
414 dnl --enable-foo" one whih is useful for the options enabled by default
415 AC_DEFUN([WX_ARG_ENABLE],
418 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
420 AC_ARG_ENABLE($1, [$2],
422 if test "$enableval" = yes; then
423 ac_cv_use_$1='$3=yes'
429 LINE=`grep "$3" ${wx_arg_cache_file}`
430 if test "x$LINE" != x ; then
436 ac_cv_use_$1='$3='$DEFAULT_$3
440 if test "$no_cache" != 1; then
441 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
444 if test "$$3" = yes; then
452 dnl ===========================================================================
453 dnl Linker features test
454 dnl ===========================================================================
456 dnl ---------------------------------------------------------------------------
457 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
458 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
459 dnl version script file named versionfile
461 dnl call WX_VERSIONED_SYMBOLS(versionfile)
462 dnl ---------------------------------------------------------------------------
463 AC_DEFUN([WX_VERSIONED_SYMBOLS],
467 dnl FIXME - doesn't work, Solaris linker doesn't accept wildcards
469 dnl dnl Check for known non-gcc cases:
470 dnl case "${host}" in
472 dnl if test "x$GCC" != "xyes" ; then
473 dnl LDFLAGS_VERSIONING="-M $1"
474 dnl found_versioning=yes
479 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
480 if test $found_versioning = no ; then
481 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
483 echo "VER_1 { *; };" >conftest.sym
484 echo "int main() { return 0; }" >conftest.cpp
487 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
488 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
489 if test -s conftest.stderr ; then
490 wx_cv_version_script=no
492 wx_cv_version_script=yes
495 wx_cv_version_script=no
497 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
499 if test $wx_cv_version_script = yes ; then
500 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
506 dnl ===========================================================================
507 dnl "3rd party" macros included here because they are not widely available
508 dnl ===========================================================================
510 dnl ---------------------------------------------------------------------------
511 dnl test for availability of iconv()
512 dnl ---------------------------------------------------------------------------
514 dnl From Bruno Haible.
518 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
519 dnl those with the standalone portable GNU libiconv installed).
521 AC_ARG_WITH([libiconv-prefix],
522 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
523 for dir in `echo "$withval" | tr : ' '`; do
524 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
525 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
529 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
530 am_cv_func_iconv="no, consider installing GNU libiconv"
532 AC_TRY_LINK([#include <stdlib.h>
534 [iconv_t cd = iconv_open("","");
535 iconv(cd,NULL,NULL,NULL,NULL);
537 am_cv_func_iconv=yes)
538 if test "$am_cv_func_iconv" != yes; then
541 AC_TRY_LINK([#include <stdlib.h>
543 [iconv_t cd = iconv_open("","");
544 iconv(cd,NULL,NULL,NULL,NULL);
547 am_cv_func_iconv=yes)
551 if test "$am_cv_func_iconv" = yes; then
552 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
553 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
561 #if defined(__STDC__) || defined(__cplusplus)
562 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
568 wx_cv_func_iconv_const="no",
569 wx_cv_func_iconv_const="yes"
574 if test "x$wx_cv_func_iconv_const" = "xyes"; then
578 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
579 [Define as const if the declaration of iconv() needs const.])
582 if test "$am_cv_lib_iconv" = yes; then
588 dnl ---------------------------------------------------------------------------
589 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
590 dnl ---------------------------------------------------------------------------
592 dnl WX_SYS_LARGEFILE_TEST
594 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
595 dnl arithmetic properly but this failed miserably with gcc under Linux
596 dnl whereas the system still supports 64 bit files, so now simply check
597 dnl that off_t is big enough
598 define(WX_SYS_LARGEFILE_TEST,
600 unsigned int field: sizeof(off_t) == 8;
605 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
606 define(WX_SYS_LARGEFILE_MACRO_VALUE,
608 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
610 AC_TRY_COMPILE([#define $1 $2
611 #include <sys/types.h>],
612 WX_SYS_LARGEFILE_TEST,
618 if test "$$3" != no; then
620 AC_DEFINE_UNQUOTED([$1], [$$3])
627 dnl By default, many hosts won't let programs access large files;
628 dnl one must use special compiler options to get large-file access to work.
629 dnl For more details about this brain damage please see:
630 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
631 AC_DEFUN([AC_SYS_LARGEFILE],
632 [AC_ARG_ENABLE(largefile,
633 [ --disable-largefile omit support for large files])
634 if test "$enable_largefile" != no; then
635 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
636 dnl _LARGE_FILES -- for AIX
638 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
639 if test "x$wx_largefile" != "xyes"; then
640 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
643 AC_MSG_CHECKING(if large file support is available)
644 if test "x$wx_largefile" = "xyes"; then
645 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
647 AC_MSG_RESULT($wx_largefile)
652 dnl Available from the GNU Autoconf Macro Archive at:
653 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
655 AC_DEFUN([AC_CXX_CONST_CAST],
656 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
657 ac_cv_cxx_const_cast,
660 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
661 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
664 if test "$ac_cv_cxx_const_cast" = yes; then
665 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
669 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_reinterpret_cast.html
670 AC_DEFUN([AC_CXX_REINTERPRET_CAST],
671 [AC_CACHE_CHECK(whether the compiler supports reinterpret_cast<>,
672 ac_cv_cxx_reinterpret_cast,
675 AC_TRY_COMPILE([#include <typeinfo>
676 class Base { public : Base () {} virtual void f () = 0;};
677 class Derived : public Base { public : Derived () {} virtual void f () {} };
678 class Unrelated { public : Unrelated () {} };
679 int g (Unrelated&) { return 0; }],[
680 Derived d;Base& b=d;Unrelated& e=reinterpret_cast<Unrelated&>(b);return g(e);],
681 ac_cv_cxx_reinterpret_cast=yes, ac_cv_cxx_reinterpret_cast=no)
684 if test "$ac_cv_cxx_reinterpret_cast" = yes; then
685 AC_DEFINE(HAVE_REINTERPRET_CAST,,
686 [define if the compiler supports reinterpret_cast<>])
690 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
691 AC_DEFUN([AC_CXX_STATIC_CAST],
692 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
693 ac_cv_cxx_static_cast,
696 AC_TRY_COMPILE([#include <typeinfo>
697 class Base { public : Base () {} virtual void f () = 0; };
698 class Derived : public Base { public : Derived () {} virtual void f () {} };
699 int g (Derived&) { return 0; }],[
700 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
701 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
704 if test "$ac_cv_cxx_static_cast" = yes; then
705 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])