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 find the a file in the list of include/lib paths
13 dnl ===========================================================================
15 dnl ---------------------------------------------------------------------------
16 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
17 dnl to the full name of the file that was found or leaves it empty if not found
18 dnl ---------------------------------------------------------------------------
19 AC_DEFUN([WX_PATH_FIND_INCLUDES],
22 for ac_dir in $1 /usr/include;
24 if test -f "$ac_dir/$2"; then
25 ac_find_includes=$ac_dir
31 dnl ---------------------------------------------------------------------------
32 dnl call WX_PATH_FIND_LIBRARIES(search path, header name), sets ac_find_libraries
33 dnl to the full name of the file that was found or leaves it empty if not found
34 dnl ---------------------------------------------------------------------------
35 AC_DEFUN([WX_PATH_FIND_LIBRARIES],
38 for ac_dir in $1 /usr/lib;
40 for ac_extension in a so sl dylib; do
41 if test -f "$ac_dir/lib$2.$ac_extension"; then
42 ac_find_libraries=$ac_dir
49 dnl ---------------------------------------------------------------------------
50 dnl Path to include, already defined
51 dnl ---------------------------------------------------------------------------
52 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
54 dnl never add -I/usr/include to the CPPFLAGS
55 if test "x$1" = "x/usr/include"; then
58 echo "$2" | grep "\-I$1" > /dev/null
60 if test $result = 0; then
63 ac_path_to_include=" -I$1"
68 dnl ---------------------------------------------------------------------------
69 dnl Path to link, already defined
70 dnl ---------------------------------------------------------------------------
71 AC_DEFUN([WX_LINK_PATH_EXIST],
73 echo "$2" | grep "\-L$1" > /dev/null
75 if test $result = 0; then
78 ac_path_to_link=" -L$1"
82 dnl ===========================================================================
84 dnl ===========================================================================
86 dnl ---------------------------------------------------------------------------
87 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
88 dnl or only the old <iostream.h> one - it may be generally assumed that if
89 dnl <iostream> exists, the other "new" headers (without .h) exist too.
91 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false-or-cross-compiling)
92 dnl ---------------------------------------------------------------------------
94 AC_DEFUN([WX_CPP_NEW_HEADERS],
96 if test "$cross_compiling" = "yes"; then
97 ifelse([$2], , :, [$2])
102 AC_CHECK_HEADERS(iostream)
104 if test "$ac_cv_header_iostream" = "yes" ; then
105 ifelse([$1], , :, [$1])
107 ifelse([$2], , :, [$2])
114 dnl ---------------------------------------------------------------------------
115 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
117 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
118 dnl ---------------------------------------------------------------------------
120 AC_DEFUN([WX_CPP_BOOL],
122 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
146 if test "$wx_cv_cpp_bool" = "yes"; then
151 dnl ---------------------------------------------------------------------------
152 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
153 dnl keyword and defines HAVE_EXPLICIT if this is the case
154 dnl ---------------------------------------------------------------------------
156 AC_DEFUN([WX_CPP_EXPLICIT],
158 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
164 dnl do the test in 2 steps: first check that the compiler knows about the
165 dnl explicit keyword at all and then verify that it really honours it
168 class Foo { public: explicit Foo(int) {} };
176 class Foo { public: explicit Foo(int) {} };
177 static void TakeFoo(const Foo& foo) { }
193 if test "$wx_cv_explicit" = "yes"; then
194 AC_DEFINE(HAVE_EXPLICIT)
198 dnl ---------------------------------------------------------------------------
199 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
200 dnl ---------------------------------------------------------------------------
202 AC_DEFUN([WX_C_BIGENDIAN],
203 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
204 [ac_cv_c_bigendian=unknown
205 # See if sys/param.h defines the BYTE_ORDER macro.
206 AC_TRY_COMPILE([#include <sys/types.h>
207 #include <sys/param.h>], [
208 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
210 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
211 AC_TRY_COMPILE([#include <sys/types.h>
212 #include <sys/param.h>], [
213 #if BYTE_ORDER != BIG_ENDIAN
215 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
216 if test $ac_cv_c_bigendian = unknown; then
217 AC_TRY_RUN([main () {
218 /* Are we little or big endian? From Harbison&Steele. */
222 char c[sizeof (long)];
225 exit (u.c[sizeof (long) - 1] == 1);
226 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
228 if test $ac_cv_c_bigendian = unknown; then
229 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])
231 if test $ac_cv_c_bigendian = yes; then
232 AC_DEFINE(WORDS_BIGENDIAN)
236 dnl ---------------------------------------------------------------------------
237 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
238 dnl ---------------------------------------------------------------------------
240 AC_DEFUN([WX_ARG_CACHE_INIT],
242 wx_arg_cache_file="configarg.cache"
243 echo "loading argument cache $wx_arg_cache_file"
244 rm -f ${wx_arg_cache_file}.tmp
245 touch ${wx_arg_cache_file}.tmp
246 touch ${wx_arg_cache_file}
249 AC_DEFUN([WX_ARG_CACHE_FLUSH],
251 echo "saving argument cache $wx_arg_cache_file"
252 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
255 dnl this macro checks for a three-valued command line --with argument:
256 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
257 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
258 AC_DEFUN([WX_ARG_SYS_WITH],
260 AC_MSG_CHECKING([for --with-$1])
262 AC_ARG_WITH($1, [$2],
264 if test "$withval" = yes; then
265 ac_cv_use_$1='$3=yes'
266 elif test "$withval" = no; then
268 elif test "$withval" = sys; then
269 ac_cv_use_$1='$3=sys'
270 elif test "$withval" = builtin; then
271 ac_cv_use_$1='$3=builtin'
273 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
277 LINE=`grep "$3" ${wx_arg_cache_file}`
278 if test "x$LINE" != x ; then
284 ac_cv_use_$1='$3='$DEFAULT_$3
288 if test "$no_cache" != 1; then
289 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
292 if test "$$3" = yes; then
294 elif test "$$3" = no; then
296 elif test "$$3" = sys; then
297 AC_MSG_RESULT([system version])
298 elif test "$$3" = builtin; then
299 AC_MSG_RESULT([builtin version])
301 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
305 dnl this macro checks for a command line argument and caches the result
306 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name)
307 AC_DEFUN([WX_ARG_WITH],
309 AC_MSG_CHECKING([for --with-$1])
311 AC_ARG_WITH($1, [$2],
313 if test "$withval" = yes; then
314 ac_cv_use_$1='$3=yes'
320 LINE=`grep "$3" ${wx_arg_cache_file}`
321 if test "x$LINE" != x ; then
327 ac_cv_use_$1='$3='$DEFAULT_$3
331 if test "$no_cache" != 1; then
332 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
335 if test "$$3" = yes; then
342 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
343 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name, enablestring)
345 dnl enablestring is a hack and allows to show "checking for --disable-foo"
346 dnl message when running configure instead of the default "checking for
347 dnl --enable-foo" one whih is useful for the options enabled by default
348 AC_DEFUN([WX_ARG_ENABLE],
351 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
353 AC_ARG_ENABLE($1, [$2],
355 if test "$enableval" = yes; then
356 ac_cv_use_$1='$3=yes'
362 LINE=`grep "$3" ${wx_arg_cache_file}`
363 if test "x$LINE" != x ; then
369 ac_cv_use_$1='$3='$DEFAULT_$3
373 if test "$no_cache" != 1; then
374 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
377 if test "$$3" = yes; then
385 dnl ===========================================================================
386 dnl Linker features test
387 dnl ===========================================================================
389 dnl ---------------------------------------------------------------------------
390 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
391 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
392 dnl version script file named versionfile
394 dnl call WX_VERSIONED_SYMBOLS(versionfile)
395 dnl ---------------------------------------------------------------------------
396 AC_DEFUN([WX_VERSIONED_SYMBOLS],
400 dnl FIXME - doesn't work, Solaris linker doesn't accept wildcards
402 dnl dnl Check for known non-gcc cases:
403 dnl case "${host}" in
405 dnl if test "x$GCC" != "xyes" ; then
406 dnl LDFLAGS_VERSIONING="-M $1"
407 dnl found_versioning=yes
412 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
413 if test $found_versioning = no ; then
414 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
416 echo "VER_1 { *; };" >conftest.sym
417 echo "int main() { return 0; }" >conftest.cpp
420 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
421 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
422 if test -s conftest.stderr ; then
423 wx_cv_version_script=no
425 wx_cv_version_script=yes
428 wx_cv_version_script=no
430 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
432 if test $wx_cv_version_script = yes ; then
433 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
439 dnl ===========================================================================
440 dnl "3rd party" macros included here because they are not widely available
441 dnl ===========================================================================
443 dnl ---------------------------------------------------------------------------
444 dnl test for availability of iconv()
445 dnl ---------------------------------------------------------------------------
447 dnl From Bruno Haible.
451 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
452 dnl those with the standalone portable GNU libiconv installed).
454 AC_ARG_WITH([libiconv-prefix],
455 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
456 for dir in `echo "$withval" | tr : ' '`; do
457 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
458 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
462 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
463 am_cv_func_iconv="no, consider installing GNU libiconv"
465 AC_TRY_LINK([#include <stdlib.h>
467 [iconv_t cd = iconv_open("","");
468 iconv(cd,NULL,NULL,NULL,NULL);
470 am_cv_func_iconv=yes)
471 if test "$am_cv_func_iconv" != yes; then
474 AC_TRY_LINK([#include <stdlib.h>
476 [iconv_t cd = iconv_open("","");
477 iconv(cd,NULL,NULL,NULL,NULL);
480 am_cv_func_iconv=yes)
484 if test "$am_cv_func_iconv" = yes; then
485 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
486 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
494 #if defined(__STDC__) || defined(__cplusplus)
495 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
501 wx_cv_func_iconv_const="no",
502 wx_cv_func_iconv_const="yes"
507 if test "x$wx_cv_func_iconv_const" = "xyes"; then
511 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
512 [Define as const if the declaration of iconv() needs const.])
515 if test "$am_cv_lib_iconv" = yes; then
521 dnl ---------------------------------------------------------------------------
522 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
523 dnl ---------------------------------------------------------------------------
525 dnl WX_SYS_LARGEFILE_TEST
527 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
528 dnl arithmetic properly but this failed miserably with gcc under Linux
529 dnl whereas the system still supports 64 bit files, so now simply check
530 dnl that off_t is big enough
531 define(WX_SYS_LARGEFILE_TEST,
533 unsigned int field: sizeof(off_t) == 8;
538 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
539 define(WX_SYS_LARGEFILE_MACRO_VALUE,
541 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
543 AC_TRY_COMPILE([#define $1 $2
544 #include <sys/types.h>],
545 WX_SYS_LARGEFILE_TEST,
551 if test "$$3" != no; then
553 AC_DEFINE_UNQUOTED([$1], [$$3])
560 dnl By default, many hosts won't let programs access large files;
561 dnl one must use special compiler options to get large-file access to work.
562 dnl For more details about this brain damage please see:
563 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
564 AC_DEFUN([AC_SYS_LARGEFILE],
565 [AC_ARG_ENABLE(largefile,
566 [ --disable-largefile omit support for large files])
567 if test "$enable_largefile" != no; then
568 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
569 dnl _LARGE_FILES -- for AIX
571 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
572 if test "x$wx_largefile" != "xyes"; then
573 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
576 AC_MSG_CHECKING(if large file support is available)
577 if test "x$wx_largefile" = "xyes"; then
578 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
580 AC_MSG_RESULT($wx_largefile)
585 dnl Available from the GNU Autoconf Macro Archive at:
586 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
588 AC_DEFUN([AC_CXX_CONST_CAST],
589 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
590 ac_cv_cxx_const_cast,
593 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
594 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
597 if test "$ac_cv_cxx_const_cast" = yes; then
598 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
602 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
603 AC_DEFUN([AC_CXX_STATIC_CAST],
604 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
605 ac_cv_cxx_static_cast,
608 AC_TRY_COMPILE([#include <typeinfo>
609 class Base { public : Base () {} virtual void f () = 0; };
610 class Derived : public Base { public : Derived () {} virtual void f () {} };
611 int g (Derived&) { return 0; }],[
612 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
613 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
616 if test "$ac_cv_cxx_static_cast" = yes; then
617 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])