]> git.saurik.com Git - wxWidgets.git/blob - acinclude.m4
don't output -DwxUSE_GUI=0 in cflags by default, do output it if 'base' is specified...
[wxWidgets.git] / acinclude.m4
1 dnl ---------------------------------------------------------------------------
2 dnl
3 dnl Macros for configure.in for wxWindows by Robert Roebling, Phil Blecker,
4 dnl Vadim Zeitlin and Ron Lee
5 dnl
6 dnl This script is under the wxWindows licence.
7 dnl
8 dnl Version: $Id$
9 dnl ---------------------------------------------------------------------------
10
11
12 dnl ===========================================================================
13 dnl Objective-C(++) related macros
14 dnl ===========================================================================
15 m4_define([AC_WX_LANG_OBJECTIVEC],
16 [AC_LANG(C)
17 ac_ext=m
18 ])
19
20 m4_define([AC_WX_LANG_OBJECTIVECPLUSPLUS],
21 [AC_LANG(C++)
22 ac_ext=mm
23 ])
24
25 dnl ===========================================================================
26 dnl macros to find the a file in the list of include/lib paths
27 dnl ===========================================================================
28
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],
34 [
35 ac_find_includes=
36 for ac_dir in $1 /usr/include;
37 do
38 if test -f "$ac_dir/$2"; then
39 ac_find_includes=$ac_dir
40 break
41 fi
42 done
43 ])
44
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],
50 [
51 ac_find_libraries=
52 for ac_dir in $1;
53 do
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
57 break 2
58 fi
59 done
60 done
61 ])
62
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
71 dnl
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])
75
76 dnl ---------------------------------------------------------------------------
77 dnl Path to include, already defined
78 dnl ---------------------------------------------------------------------------
79 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
80 [
81 dnl never add -I/usr/include to the CPPFLAGS
82 if test "x$1" = "x/usr/include"; then
83 ac_path_to_include=""
84 else
85 echo "$2" | grep "\-I$1" > /dev/null
86 result=$?
87 if test $result = 0; then
88 ac_path_to_include=""
89 else
90 ac_path_to_include=" -I$1"
91 fi
92 fi
93 ])
94
95 dnl ---------------------------------------------------------------------------
96 dnl Usage: WX_LINK_PATH_EXIST(path, libpath)
97 dnl
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],
103 [
104 dnl never add -L/usr/libXXX explicitely to libpath
105 if test "$1" = "default location"; then
106 ac_path_to_link=""
107 else
108 echo "$2" | grep "\-L$1" > /dev/null
109 result=$?
110 if test $result = 0; then
111 ac_path_to_link=""
112 else
113 ac_path_to_link=" -L$1"
114 fi
115 fi
116 ])
117
118 dnl ===========================================================================
119 dnl C++ features test
120 dnl ===========================================================================
121
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.
126 dnl
127 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
128 dnl ---------------------------------------------------------------------------
129
130 AC_DEFUN([WX_CPP_NEW_HEADERS],
131 [
132 AC_LANG_SAVE
133 AC_LANG_CPLUSPLUS
134
135 AC_CHECK_HEADER(iostream,,, [ ])
136
137 if test "$ac_cv_header_iostream" = "yes" ; then
138 ifelse([$1], , :, [$1])
139 else
140 ifelse([$2], , :, [$2])
141 fi
142
143 AC_LANG_RESTORE
144 ])
145
146 dnl ---------------------------------------------------------------------------
147 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
148 dnl
149 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
150 dnl ---------------------------------------------------------------------------
151
152 AC_DEFUN([WX_CPP_BOOL],
153 [
154 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
155 [
156 AC_LANG_SAVE
157 AC_LANG_CPLUSPLUS
158
159 AC_TRY_COMPILE(
160 [
161 ],
162 [
163 bool b = true;
164
165 return 0;
166 ],
167 [
168 wx_cv_cpp_bool=yes
169 ],
170 [
171 wx_cv_cpp_bool=no
172 ]
173 )
174
175 AC_LANG_RESTORE
176 ])
177
178 if test "$wx_cv_cpp_bool" = "yes"; then
179 AC_DEFINE(HAVE_BOOL)
180 fi
181 ])
182
183 dnl ---------------------------------------------------------------------------
184 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
185 dnl keyword and defines HAVE_EXPLICIT if this is the case
186 dnl ---------------------------------------------------------------------------
187
188 AC_DEFUN([WX_CPP_EXPLICIT],
189 [
190 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
191 wx_cv_explicit,
192 [
193 AC_LANG_SAVE
194 AC_LANG_CPLUSPLUS
195
196 dnl do the test in 2 steps: first check that the compiler knows about the
197 dnl explicit keyword at all and then verify that it really honours it
198 AC_TRY_COMPILE(
199 [
200 class Foo { public: explicit Foo(int) {} };
201 ],
202 [
203 return 0;
204 ],
205 [
206 AC_TRY_COMPILE(
207 [
208 class Foo { public: explicit Foo(int) {} };
209 static void TakeFoo(const Foo& foo) { }
210 ],
211 [
212 TakeFoo(17);
213 return 0;
214 ],
215 wx_cv_explicit=no,
216 wx_cv_explicit=yes
217 )
218 ],
219 wx_cv_explicit=no
220 )
221
222 AC_LANG_RESTORE
223 ])
224
225 if test "$wx_cv_explicit" = "yes"; then
226 AC_DEFINE(HAVE_EXPLICIT)
227 fi
228 ])
229
230 dnl ---------------------------------------------------------------------------
231 dnl WX_CHECK_FUNCS(FUNCTIONS...,
232 dnl [ACTION-IF-FOUND],
233 dnl [ACTION-IF-NOT-FOUND],
234 dnl [EXTRA-DEFINES-AND-INCLUDES],
235 dnl [EXTRA-TEST-CODE])
236 dnl
237 dnl Checks that the functions listed in FUNCTIONS exist in the headers and the
238 dnl libs. For each function, if it is found then defines 'HAVE_FUNCTION' and
239 dnl executes ACTION-IF-FOUND, otherwise executes ACTION-IF-NOT-FOUND.
240 dnl
241 dnl The code from EXTRA-DEFINES-AND-INCLUDES is inserted into the test before
242 dnl the default headers are included, and EXTRA-TEST-CODE is inserted into
243 dnl the main() function after the default test for existence.
244 dnl
245 dnl Examples:
246 dnl # the simple case
247 dnl WX_CHECK_FUNCS(stat)
248 dnl # use break to finish the loop early
249 dnl WX_CHECK_FUNCS(mkstemp mktemp, break)
250 dnl # extra defines
251 dnl WX_CHECK_FUNCS(strtok_r, [], [], [#define _RREENTRANT])
252 dnl # extra includes
253 dnl WX_CHECK_FUNCS(swprintf, [], [], [#include <wchar.h>])
254 dnl # checking the signature with extra test code
255 dnl WX_CHECK_FUNCS(gettimeofday, [], [], [#include <sys/time.h>]
256 dnl [struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz)])
257 dnl ---------------------------------------------------------------------------
258
259 AC_DEFUN([WX_CHECK_FUNCS],
260 [
261 for wx_func in $1
262 do
263 AC_CACHE_CHECK(
264 [for $wx_func],
265 [wx_cv_func_$wx_func],
266 [
267 AC_LINK_IFELSE(
268 [
269 AC_LANG_PROGRAM(
270 [
271 $4
272 AC_INCLUDES_DEFAULT
273 ],
274 [
275 #ifndef $wx_func
276 &$wx_func;
277 #endif
278 $5
279 ])
280 ],
281 [eval wx_cv_func_$wx_func=yes],
282 [eval wx_cv_func_$wx_func=no])
283 ])
284
285 if eval test \$wx_cv_func_$wx_func = yes
286 then
287 AC_DEFINE_UNQUOTED([HAVE_`echo $wx_func | tr 'a-z' 'A-Z'`])
288 $2
289 else
290 :
291 $3
292 fi
293 done
294 ])
295
296 dnl ---------------------------------------------------------------------------
297 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
298 dnl ---------------------------------------------------------------------------
299
300 AC_DEFUN([WX_C_BIGENDIAN],
301 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
302 [ac_cv_c_bigendian=unknown
303 # See if sys/param.h defines the BYTE_ORDER macro.
304 AC_TRY_COMPILE([#include <sys/types.h>
305 #include <sys/param.h>], [
306 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
307 bogus endian macros
308 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
309 AC_TRY_COMPILE([#include <sys/types.h>
310 #include <sys/param.h>], [
311 #if BYTE_ORDER != BIG_ENDIAN
312 not big endian
313 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
314 if test $ac_cv_c_bigendian = unknown; then
315 AC_TRY_RUN([main () {
316 /* Are we little or big endian? From Harbison&Steele. */
317 union
318 {
319 long l;
320 char c[sizeof (long)];
321 } u;
322 u.l = 1;
323 exit (u.c[sizeof (long) - 1] == 1);
324 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
325 fi])
326 if test $ac_cv_c_bigendian = unknown; then
327 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])
328 fi
329 if test $ac_cv_c_bigendian = yes; then
330 AC_DEFINE(WORDS_BIGENDIAN)
331 fi
332 ])
333
334 dnl ---------------------------------------------------------------------------
335 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
336 dnl ---------------------------------------------------------------------------
337
338 AC_DEFUN([WX_ARG_CACHE_INIT],
339 [
340 wx_arg_cache_file="configarg.cache"
341 echo "loading argument cache $wx_arg_cache_file"
342 rm -f ${wx_arg_cache_file}.tmp
343 touch ${wx_arg_cache_file}.tmp
344 touch ${wx_arg_cache_file}
345 ])
346
347 AC_DEFUN([WX_ARG_CACHE_FLUSH],
348 [
349 echo "saving argument cache $wx_arg_cache_file"
350 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
351 ])
352
353 dnl this macro checks for a three-valued command line --with argument:
354 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
355 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
356 dnl
357 dnl the default value (used if the option is not specified at all) is the value
358 dnl of wxUSE_ALL_FEATURES (which is "yes" by default but can be changed by
359 dnl giving configure --disable-all-features option)
360 AC_DEFUN([WX_ARG_SYS_WITH],
361 [
362 AC_MSG_CHECKING([for --with-$1])
363 no_cache=0
364 AC_ARG_WITH($1, [$2],
365 [
366 if test "$withval" = yes; then
367 ac_cv_use_$1='$3=yes'
368 elif test "$withval" = no; then
369 ac_cv_use_$1='$3=no'
370 elif test "$withval" = sys; then
371 ac_cv_use_$1='$3=sys'
372 elif test "$withval" = builtin; then
373 ac_cv_use_$1='$3=builtin'
374 else
375 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
376 fi
377 ],
378 [
379 LINE=`grep "^$3=" ${wx_arg_cache_file}`
380 if test "x$LINE" != x ; then
381 eval "DEFAULT_$LINE"
382 else
383 no_cache=1
384 fi
385
386 ac_cv_use_$1='$3=${'DEFAULT_$3":-$wxUSE_ALL_FEATURES}"
387 ])
388
389 eval "$ac_cv_use_$1"
390 if test "$no_cache" != 1; then
391 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
392 fi
393
394 if test "$$3" = yes; then
395 AC_MSG_RESULT(yes)
396 elif test "$$3" = no; then
397 AC_MSG_RESULT(no)
398 elif test "$$3" = sys; then
399 AC_MSG_RESULT([system version])
400 elif test "$$3" = builtin; then
401 AC_MSG_RESULT([builtin version])
402 else
403 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
404 fi
405 ])
406
407 dnl this macro checks for a command line argument and caches the result
408 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name, [withstring])
409 AC_DEFUN([WX_ARG_WITH],
410 [
411 withstring=$4
412 AC_MSG_CHECKING([for --${withstring:-with}-$1])
413 no_cache=0
414 AC_ARG_WITH($1, [$2],
415 [
416 if test "$withval" = yes; then
417 ac_cv_use_$1='$3=yes'
418 else
419 ac_cv_use_$1='$3=no'
420 fi
421 ],
422 [
423 LINE=`grep "^$3=" ${wx_arg_cache_file}`
424 if test "x$LINE" != x ; then
425 eval "DEFAULT_$LINE"
426 else
427 no_cache=1
428 fi
429
430 ac_cv_use_$1='$3=${'DEFAULT_$3":-$wxUSE_ALL_FEATURES}"
431 ])
432
433 eval "$ac_cv_use_$1"
434 if test "$no_cache" != 1; then
435 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
436 fi
437
438 if test x"$withstring" = xwithout; then
439 if test $$3 = yes; then
440 result=no
441 else
442 result=yes
443 fi
444 else
445 result=$$3
446 fi
447
448 AC_MSG_RESULT($result)
449 ])
450
451 dnl same as WX_ARG_WITH but makes it clear that the option is enabled by default
452 AC_DEFUN([WX_ARG_WITHOUT], [WX_ARG_WITH($1, [$2], $3, without)])
453
454 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
455 dnl usage: WX_ARG_ENABLE(option, helpmessage, var, [enablestring], [default])
456 dnl
457 dnl enablestring can be omitted or a literal string "disable" and allows to
458 dnl show "checking for --disable-foo" message when running configure instead of
459 dnl the default "checking for --enable-foo" one whih is useful for the options
460 dnl enabled by default
461 dnl
462 dnl the "default" argument can be omitted or contain the default value to use
463 dnl for the option if it's unspecified
464 AC_DEFUN([WX_ARG_ENABLE],
465 [
466 enablestring=$4
467 defaultval=$5
468 if test -z "$defaultval"; then
469 if test x"$enablestring" = xdisable; then
470 defaultval=yes
471 else
472 defaultval=no
473 fi
474 fi
475
476 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
477 no_cache=0
478 AC_ARG_ENABLE($1, [$2],
479 [
480 if test "$enableval" = yes; then
481 ac_cv_use_$1='$3=yes'
482 else
483 ac_cv_use_$1='$3=no'
484 fi
485 ],
486 [
487 LINE=`grep "^$3=" ${wx_arg_cache_file}`
488 if test "x$LINE" != x ; then
489 eval "DEFAULT_$LINE"
490 else
491 no_cache=1
492 fi
493
494 ac_cv_use_$1='$3=${'DEFAULT_$3":-$defaultval}"
495 ])
496
497 eval "$ac_cv_use_$1"
498 if test "$no_cache" != 1; then
499 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
500 fi
501
502 if test x"$enablestring" = xdisable; then
503 if test $$3 = yes; then
504 result=no
505 else
506 result=yes
507 fi
508 else
509 result=$$3
510 fi
511
512 AC_MSG_RESULT($result)
513 ])
514
515 dnl the same as WX_ARG_ENABLE but makes it more clear that the option is
516 dnl enabled by default
517 AC_DEFUN([WX_ARG_DISABLE], [WX_ARG_ENABLE($1, [$2], $3, disable)])
518
519 dnl same as WX_ARG_ENABLE but defaults to wxUSE_ALL_FEATURES instead of "yes"
520 AC_DEFUN([WX_ARG_FEATURE], [WX_ARG_ENABLE($1, [$2], $3,, $wxUSE_ALL_FEATURES)])
521
522 dnl Like WX_ARG_ENABLE but accepts a parameter.
523 dnl
524 dnl Usage:
525 dnl WX_ARG_ENABLE_PARAM(option, helpmessage, variable-name, enablestring)
526 dnl
527 dnl Example:
528 dnl WX_ARG_ENABLE_PARAM(foo, [[ --enable-foo[=bar] use foo]], wxUSE_FOO)
529 dnl
530 dnl --enable-foo wxUSE_FOO=yes
531 dnl --disable-foo wxUSE_FOO=no
532 dnl --enable-foo=bar wxUSE_FOO=bar
533 dnl <not given> value from configarg.cache or
534 dnl wxUSE_FOO=$DEFAULT_wxUSE_FOO
535 dnl
536 AC_DEFUN([WX_ARG_ENABLE_PARAM],
537 [
538 enablestring=$4
539 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
540 no_cache=0
541 AC_ARG_ENABLE($1, [$2],
542 [
543 wx_cv_use_$1="$3='$enableval'"
544 ],
545 [
546 LINE=`grep "^$3=" ${wx_arg_cache_file}`
547 if test "x$LINE" != x ; then
548 eval "DEFAULT_$LINE"
549 else
550 no_cache=1
551 fi
552
553 wx_cv_use_$1='$3='$DEFAULT_$3
554 ])
555
556 eval "$wx_cv_use_$1"
557 if test "$no_cache" != 1; then
558 echo $wx_cv_use_$1 >> ${wx_arg_cache_file}.tmp
559 fi
560
561 AC_MSG_RESULT([$$3])
562 ])
563
564 dnl ===========================================================================
565 dnl Linker features test
566 dnl ===========================================================================
567
568 dnl ---------------------------------------------------------------------------
569 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
570 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
571 dnl version script file named versionfile
572 dnl
573 dnl call WX_VERSIONED_SYMBOLS(versionfile)
574 dnl ---------------------------------------------------------------------------
575 AC_DEFUN([WX_VERSIONED_SYMBOLS],
576 [
577 case "${host}" in
578 *-*-cygwin* | *-*-mingw* )
579 dnl although ld does support version script option on these
580 dnl platforms, it doesn't make much sense to use it under Win32
581 dnl and, moreover, this breaks linking because of a bug in handling
582 dnl paths in -Wl,--version-script,path option (if we ever do need
583 dnl to use it for cygwin/mingw32, keep in mind that replacing last
584 dnl comma with the equal sign works) so
585 dnl simply disable it
586 wx_cv_version_script=no
587 ;;
588
589 *)
590 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
591 [
592 echo "VER_1 { *; };" >conftest.sym
593 echo "int main() { return 0; }" >conftest.cpp
594
595 if AC_TRY_COMMAND([
596 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
597 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
598 if test -s conftest.stderr ; then
599 wx_cv_version_script=no
600 else
601 wx_cv_version_script=yes
602 fi
603 else
604 wx_cv_version_script=no
605 fi
606
607 dnl There's a problem in some old linkers with --version-script that
608 dnl can cause linking to fail when you have objects with vtables in
609 dnl libs 3 deep. This is known to happen in netbsd and openbsd with
610 dnl ld 2.11.2.
611 dnl
612 dnl To test for this we need to make some shared libs and
613 dnl unfortunately we can't be sure of the right way to do that. If the
614 dnl first two compiles don't succeed then it looks like the test isn't
615 dnl working and the result is ignored, but if OTOH the first two
616 dnl succeed but the third does not then the bug has been detected and
617 dnl the --version-script flag is dropped.
618 if test $wx_cv_version_script = yes
619 then
620 echo "struct B { virtual ~B() { } }; \
621 struct D : public B { }; \
622 void F() { D d; }" > conftest.cpp
623
624 if AC_TRY_COMMAND([
625 $CXX -shared -fPIC -o conftest1.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
626 -Wl,--version-script,conftest.sym >/dev/null 2>/dev/null]) &&
627 AC_TRY_COMMAND([
628 $CXX -shared -fPIC -o conftest2.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
629 -Wl,--version-script,conftest.sym conftest1.output >/dev/null 2>/dev/null])
630 then
631 if AC_TRY_COMMAND([
632 $CXX -shared -fPIC -o conftest3.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
633 -Wl,--version-script,conftest.sym conftest2.output conftest1.output >/dev/null 2>/dev/null])
634 then
635 wx_cv_version_script=yes
636 else
637 wx_cv_version_script=no
638 fi
639 fi
640 fi
641
642 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
643 rm -f conftest1.output conftest2.output conftest3.output
644 ])
645
646 if test $wx_cv_version_script = yes ; then
647 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
648 fi
649 ;;
650 esac
651 ])
652
653
654 dnl ===========================================================================
655 dnl "3rd party" macros included here because they are not widely available
656 dnl ===========================================================================
657
658 dnl ---------------------------------------------------------------------------
659 dnl test for availability of iconv()
660 dnl ---------------------------------------------------------------------------
661
662 dnl From Bruno Haible.
663
664 AC_DEFUN([AM_ICONV],
665 [
666 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
667 dnl those with the standalone portable GNU libiconv installed).
668
669 AC_ARG_WITH([libiconv-prefix],
670 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
671 for dir in `echo "$withval" | tr : ' '`; do
672 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
673 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
674 done
675 ])
676
677 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
678 am_cv_func_iconv="no, consider installing GNU libiconv"
679 am_cv_lib_iconv=no
680 AC_TRY_LINK([#include <stdlib.h>
681 #include <iconv.h>],
682 [iconv_t cd = iconv_open("","");
683 iconv(cd,NULL,NULL,NULL,NULL);
684 iconv_close(cd);],
685 am_cv_func_iconv=yes)
686 if test "$am_cv_func_iconv" != yes; then
687 am_save_LIBS="$LIBS"
688 LIBS="$LIBS -liconv"
689 AC_TRY_LINK([#include <stdlib.h>
690 #include <iconv.h>],
691 [iconv_t cd = iconv_open("","");
692 iconv(cd,NULL,NULL,NULL,NULL);
693 iconv_close(cd);],
694 am_cv_lib_iconv=yes
695 am_cv_func_iconv=yes)
696 LIBS="$am_save_LIBS"
697 fi
698 ])
699 if test "$am_cv_func_iconv" = yes; then
700 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
701 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
702 AC_TRY_COMPILE([
703 #include <stdlib.h>
704 #include <iconv.h>
705 extern
706 #ifdef __cplusplus
707 "C"
708 #endif
709 #if defined(__STDC__) || defined(__cplusplus)
710 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
711 #else
712 size_t iconv();
713 #endif
714 ],
715 [],
716 wx_cv_func_iconv_const="no",
717 wx_cv_func_iconv_const="yes"
718 )
719 )
720
721 iconv_const=
722 if test "x$wx_cv_func_iconv_const" = "xyes"; then
723 iconv_const="const"
724 fi
725
726 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
727 [Define as const if the declaration of iconv() needs const.])
728 fi
729 LIBICONV=
730 if test "$am_cv_lib_iconv" = yes; then
731 LIBICONV="-liconv"
732 fi
733 AC_SUBST(LIBICONV)
734 ])
735
736 dnl ---------------------------------------------------------------------------
737 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
738 dnl ---------------------------------------------------------------------------
739
740 dnl WX_SYS_LARGEFILE_TEST
741 dnl
742 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
743 dnl arithmetic properly but this failed miserably with gcc under Linux
744 dnl whereas the system still supports 64 bit files, so now simply check
745 dnl that off_t is big enough
746 define(WX_SYS_LARGEFILE_TEST,
747 [typedef struct {
748 unsigned int field: sizeof(off_t) == 8;
749 } wxlf;
750 ])
751
752
753 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
754 define(WX_SYS_LARGEFILE_MACRO_VALUE,
755 [
756 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
757 [
758 AC_TRY_COMPILE([#define $1 $2
759 #include <sys/types.h>],
760 WX_SYS_LARGEFILE_TEST,
761 [$3=$2],
762 [$3=no])
763 ]
764 )
765
766 if test "$$3" != no; then
767 wx_largefile=yes
768 AC_DEFINE_UNQUOTED([$1], [$$3])
769 fi
770 ])
771
772
773 dnl AC_SYS_LARGEFILE
774 dnl ----------------
775 dnl By default, many hosts won't let programs access large files;
776 dnl one must use special compiler options to get large-file access to work.
777 dnl For more details about this brain damage please see:
778 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
779 AC_DEFUN([AC_SYS_LARGEFILE],
780 [AC_ARG_ENABLE(largefile,
781 [ --disable-largefile omit support for large files])
782 if test "$enable_largefile" != no; then
783 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
784 dnl _LARGE_FILES -- for AIX
785 wx_largefile=no
786 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
787 if test "x$wx_largefile" != "xyes"; then
788 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
789 fi
790
791 AC_MSG_CHECKING(if large file support is available)
792 if test "x$wx_largefile" = "xyes"; then
793 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
794 fi
795 AC_MSG_RESULT($wx_largefile)
796 fi
797 ])
798
799
800 dnl Available from the GNU Autoconf Macro Archive at:
801 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
802 dnl
803 AC_DEFUN([AC_CXX_CONST_CAST],
804 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
805 ac_cv_cxx_const_cast,
806 [AC_LANG_SAVE
807 AC_LANG_CPLUSPLUS
808 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
809 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
810 AC_LANG_RESTORE
811 ])
812 if test "$ac_cv_cxx_const_cast" = yes; then
813 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
814 fi
815 ])
816
817 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_reinterpret_cast.html
818 AC_DEFUN([AC_CXX_REINTERPRET_CAST],
819 [AC_CACHE_CHECK(whether the compiler supports reinterpret_cast<>,
820 ac_cv_cxx_reinterpret_cast,
821 [AC_LANG_SAVE
822 AC_LANG_CPLUSPLUS
823 AC_TRY_COMPILE([#include <typeinfo>
824 class Base { public : Base () {} virtual void f () = 0;};
825 class Derived : public Base { public : Derived () {} virtual void f () {} };
826 class Unrelated { public : Unrelated () {} };
827 int g (Unrelated&) { return 0; }],[
828 Derived d;Base& b=d;Unrelated& e=reinterpret_cast<Unrelated&>(b);return g(e);],
829 ac_cv_cxx_reinterpret_cast=yes, ac_cv_cxx_reinterpret_cast=no)
830 AC_LANG_RESTORE
831 ])
832 if test "$ac_cv_cxx_reinterpret_cast" = yes; then
833 AC_DEFINE(HAVE_REINTERPRET_CAST,,
834 [define if the compiler supports reinterpret_cast<>])
835 fi
836 ])
837
838 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
839 AC_DEFUN([AC_CXX_STATIC_CAST],
840 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
841 ac_cv_cxx_static_cast,
842 [AC_LANG_SAVE
843 AC_LANG_CPLUSPLUS
844 AC_TRY_COMPILE([#include <typeinfo>
845 class Base { public : Base () {} virtual void f () = 0; };
846 class Derived : public Base { public : Derived () {} virtual void f () {} };
847 int g (Derived&) { return 0; }],[
848 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
849 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
850 AC_LANG_RESTORE
851 ])
852 if test "$ac_cv_cxx_static_cast" = yes; then
853 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])
854 fi
855 ])
856
857 dnl http://autoconf-archive.cryp.to/ac_cxx_dynamic_cast.html
858 AC_DEFUN([AC_CXX_DYNAMIC_CAST],
859 [AC_CACHE_CHECK(whether the compiler supports dynamic_cast<>,
860 ac_cv_cxx_dynamic_cast,
861 [AC_LANG_SAVE
862 AC_LANG_CPLUSPLUS
863 AC_TRY_COMPILE([#include <typeinfo>
864 class Base { public : Base () {} virtual void f () = 0;};
865 class Derived : public Base { public : Derived () {} virtual void f () {} };],[
866 Derived d; Base& b=d; return dynamic_cast<Derived*>(&b) ? 0 : 1;],
867 ac_cv_cxx_dynamic_cast=yes, ac_cv_cxx_dynamic_cast=no)
868 AC_LANG_RESTORE
869 ])
870 if test "$ac_cv_cxx_dynamic_cast" = yes; then
871 AC_DEFINE(HAVE_DYNAMIC_CAST,,[define if the compiler supports dynamic_cast<>])
872 fi
873 ])
874