]> git.saurik.com Git - wxWidgets.git/blob - acinclude.m4
fixed VC++ warning
[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 dnl ===========================================================================
12 dnl macros to find the a file in the list of include/lib paths
13 dnl ===========================================================================
14
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],
20 [
21 ac_find_includes=
22 for ac_dir in $1 /usr/include;
23 do
24 if test -f "$ac_dir/$2"; then
25 ac_find_includes=$ac_dir
26 break
27 fi
28 done
29 ])
30
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],
36 [
37 ac_find_libraries=
38 for ac_dir in $1 /usr/lib;
39 do
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
43 break 2
44 fi
45 done
46 done
47 ])
48
49 dnl ---------------------------------------------------------------------------
50 dnl Path to include, already defined
51 dnl ---------------------------------------------------------------------------
52 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
53 [
54 dnl never add -I/usr/include to the CPPFLAGS
55 if test "x$1" = "x/usr/include"; then
56 ac_path_to_include=""
57 else
58 echo "$2" | grep "\-I$1" > /dev/null
59 result=$?
60 if test $result = 0; then
61 ac_path_to_include=""
62 else
63 ac_path_to_include=" -I$1"
64 fi
65 fi
66 ])
67
68 dnl ---------------------------------------------------------------------------
69 dnl Path to link, already defined
70 dnl ---------------------------------------------------------------------------
71 AC_DEFUN([WX_LINK_PATH_EXIST],
72 [
73 echo "$2" | grep "\-L$1" > /dev/null
74 result=$?
75 if test $result = 0; then
76 ac_path_to_link=""
77 else
78 ac_path_to_link=" -L$1"
79 fi
80 ])
81
82 dnl ===========================================================================
83 dnl C++ features test
84 dnl ===========================================================================
85
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.
90 dnl
91 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false-or-cross-compiling)
92 dnl ---------------------------------------------------------------------------
93
94 AC_DEFUN([WX_CPP_NEW_HEADERS],
95 [
96 if test "$cross_compiling" = "yes"; then
97 ifelse([$2], , :, [$2])
98 else
99 AC_LANG_SAVE
100 AC_LANG_CPLUSPLUS
101
102 AC_CHECK_HEADERS(iostream)
103
104 if test "$ac_cv_header_iostream" = "yes" ; then
105 ifelse([$1], , :, [$1])
106 else
107 ifelse([$2], , :, [$2])
108 fi
109
110 AC_LANG_RESTORE
111 fi
112 ])
113
114 dnl ---------------------------------------------------------------------------
115 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
116 dnl
117 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
118 dnl ---------------------------------------------------------------------------
119
120 AC_DEFUN([WX_CPP_BOOL],
121 [
122 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
123 [
124 AC_LANG_SAVE
125 AC_LANG_CPLUSPLUS
126
127 AC_TRY_COMPILE(
128 [
129 ],
130 [
131 bool b = true;
132
133 return 0;
134 ],
135 [
136 wx_cv_cpp_bool=yes
137 ],
138 [
139 wx_cv_cpp_bool=no
140 ]
141 )
142
143 AC_LANG_RESTORE
144 ])
145
146 if test "$wx_cv_cpp_bool" = "yes"; then
147 AC_DEFINE(HAVE_BOOL)
148 fi
149 ])
150
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 ---------------------------------------------------------------------------
155
156 AC_DEFUN([WX_CPP_EXPLICIT],
157 [
158 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
159 wx_cv_explicit,
160 [
161 AC_LANG_SAVE
162 AC_LANG_CPLUSPLUS
163
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
166 AC_TRY_COMPILE(
167 [
168 class Foo { public: explicit Foo(int) {} };
169 ],
170 [
171 return 0;
172 ],
173 [
174 AC_TRY_COMPILE(
175 [
176 class Foo { public: explicit Foo(int) {} };
177 static void TakeFoo(const Foo& foo) { }
178 ],
179 [
180 TakeFoo(17);
181 return 0;
182 ],
183 wx_cv_explicit=no,
184 wx_cv_explicit=yes
185 )
186 ],
187 wx_cv_explicit=no
188 )
189
190 AC_LANG_RESTORE
191 ])
192
193 if test "$wx_cv_explicit" = "yes"; then
194 AC_DEFINE(HAVE_EXPLICIT)
195 fi
196 ])
197
198 dnl ---------------------------------------------------------------------------
199 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
200 dnl ---------------------------------------------------------------------------
201
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
209 bogus endian macros
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
214 not 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. */
219 union
220 {
221 long l;
222 char c[sizeof (long)];
223 } u;
224 u.l = 1;
225 exit (u.c[sizeof (long) - 1] == 1);
226 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
227 fi])
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])
230 fi
231 if test $ac_cv_c_bigendian = yes; then
232 AC_DEFINE(WORDS_BIGENDIAN)
233 fi
234 ])
235
236 dnl ---------------------------------------------------------------------------
237 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
238 dnl ---------------------------------------------------------------------------
239
240 AC_DEFUN([WX_ARG_CACHE_INIT],
241 [
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}
247 ])
248
249 AC_DEFUN([WX_ARG_CACHE_FLUSH],
250 [
251 echo "saving argument cache $wx_arg_cache_file"
252 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
253 ])
254
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],
259 [
260 AC_MSG_CHECKING([for --with-$1])
261 no_cache=0
262 AC_ARG_WITH($1, [$2],
263 [
264 if test "$withval" = yes; then
265 ac_cv_use_$1='$3=yes'
266 elif test "$withval" = no; then
267 ac_cv_use_$1='$3=no'
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'
272 else
273 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
274 fi
275 ],
276 [
277 LINE=`grep "$3" ${wx_arg_cache_file}`
278 if test "x$LINE" != x ; then
279 eval "DEFAULT_$LINE"
280 else
281 no_cache=1
282 fi
283
284 ac_cv_use_$1='$3='$DEFAULT_$3
285 ])
286
287 eval "$ac_cv_use_$1"
288 if test "$no_cache" != 1; then
289 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
290 fi
291
292 if test "$$3" = yes; then
293 AC_MSG_RESULT(yes)
294 elif test "$$3" = no; then
295 AC_MSG_RESULT(no)
296 elif test "$$3" = sys; then
297 AC_MSG_RESULT([system version])
298 elif test "$$3" = builtin; then
299 AC_MSG_RESULT([builtin version])
300 else
301 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
302 fi
303 ])
304
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],
308 [
309 AC_MSG_CHECKING([for --with-$1])
310 no_cache=0
311 AC_ARG_WITH($1, [$2],
312 [
313 if test "$withval" = yes; then
314 ac_cv_use_$1='$3=yes'
315 else
316 ac_cv_use_$1='$3=no'
317 fi
318 ],
319 [
320 LINE=`grep "$3" ${wx_arg_cache_file}`
321 if test "x$LINE" != x ; then
322 eval "DEFAULT_$LINE"
323 else
324 no_cache=1
325 fi
326
327 ac_cv_use_$1='$3='$DEFAULT_$3
328 ])
329
330 eval "$ac_cv_use_$1"
331 if test "$no_cache" != 1; then
332 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
333 fi
334
335 if test "$$3" = yes; then
336 AC_MSG_RESULT(yes)
337 else
338 AC_MSG_RESULT(no)
339 fi
340 ])
341
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)
344 dnl
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],
349 [
350 enablestring=$4
351 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
352 no_cache=0
353 AC_ARG_ENABLE($1, [$2],
354 [
355 if test "$enableval" = yes; then
356 ac_cv_use_$1='$3=yes'
357 else
358 ac_cv_use_$1='$3=no'
359 fi
360 ],
361 [
362 LINE=`grep "$3" ${wx_arg_cache_file}`
363 if test "x$LINE" != x ; then
364 eval "DEFAULT_$LINE"
365 else
366 no_cache=1
367 fi
368
369 ac_cv_use_$1='$3='$DEFAULT_$3
370 ])
371
372 eval "$ac_cv_use_$1"
373 if test "$no_cache" != 1; then
374 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
375 fi
376
377 if test "$$3" = yes; then
378 AC_MSG_RESULT(yes)
379 else
380 AC_MSG_RESULT(no)
381 fi
382 ])
383
384
385 dnl ===========================================================================
386 dnl Linker features test
387 dnl ===========================================================================
388
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
393 dnl
394 dnl call WX_VERSIONED_SYMBOLS(versionfile)
395 dnl ---------------------------------------------------------------------------
396 AC_DEFUN([WX_VERSIONED_SYMBOLS],
397 [
398 found_versioning=no
399
400 dnl Check for known non-gcc cases:
401 case "${host}" in
402 *-*-solaris2* )
403 if test "x$GCC" != "xyes" ; then
404 LDFLAGS_VERSIONING="-M $1"
405 found_versioning=yes
406 fi
407 ;;
408 esac
409
410 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
411 if test $found_versioning = no ; then
412 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
413 [
414 echo "VER_1 { *; };" >conftest.sym
415 echo "int main() { return 0; }" >conftest.cpp
416
417 if AC_TRY_COMMAND([
418 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
419 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
420 if test -s conftest.stderr ; then
421 wx_cv_version_script=no
422 else
423 wx_cv_version_script=yes
424 fi
425 else
426 wx_cv_version_script=no
427 fi
428 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
429 ])
430 if test $wx_cv_version_script = yes ; then
431 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
432 fi
433 fi
434 ])
435
436
437 dnl ===========================================================================
438 dnl "3rd party" macros included here because they are not widely available
439 dnl ===========================================================================
440
441 dnl ---------------------------------------------------------------------------
442 dnl test for availability of iconv()
443 dnl ---------------------------------------------------------------------------
444
445 dnl From Bruno Haible.
446
447 AC_DEFUN([AM_ICONV],
448 [
449 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
450 dnl those with the standalone portable GNU libiconv installed).
451
452 AC_ARG_WITH([libiconv-prefix],
453 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
454 for dir in `echo "$withval" | tr : ' '`; do
455 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
456 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
457 done
458 ])
459
460 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
461 am_cv_func_iconv="no, consider installing GNU libiconv"
462 am_cv_lib_iconv=no
463 AC_TRY_LINK([#include <stdlib.h>
464 #include <iconv.h>],
465 [iconv_t cd = iconv_open("","");
466 iconv(cd,NULL,NULL,NULL,NULL);
467 iconv_close(cd);],
468 am_cv_func_iconv=yes)
469 if test "$am_cv_func_iconv" != yes; then
470 am_save_LIBS="$LIBS"
471 LIBS="$LIBS -liconv"
472 AC_TRY_LINK([#include <stdlib.h>
473 #include <iconv.h>],
474 [iconv_t cd = iconv_open("","");
475 iconv(cd,NULL,NULL,NULL,NULL);
476 iconv_close(cd);],
477 am_cv_lib_iconv=yes
478 am_cv_func_iconv=yes)
479 LIBS="$am_save_LIBS"
480 fi
481 ])
482 if test "$am_cv_func_iconv" = yes; then
483 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
484 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
485 AC_TRY_COMPILE([
486 #include <stdlib.h>
487 #include <iconv.h>
488 extern
489 #ifdef __cplusplus
490 "C"
491 #endif
492 #if defined(__STDC__) || defined(__cplusplus)
493 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
494 #else
495 size_t iconv();
496 #endif
497 ],
498 [],
499 wx_cv_func_iconv_const="no",
500 wx_cv_func_iconv_const="yes"
501 )
502 )
503
504 iconv_const=
505 if test "x$wx_cv_func_iconv_const" = "xyes"; then
506 iconv_const="const"
507 fi
508
509 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
510 [Define as const if the declaration of iconv() needs const.])
511 fi
512 LIBICONV=
513 if test "$am_cv_lib_iconv" = yes; then
514 LIBICONV="-liconv"
515 fi
516 AC_SUBST(LIBICONV)
517 ])
518
519 dnl ---------------------------------------------------------------------------
520 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
521 dnl ---------------------------------------------------------------------------
522
523 dnl WX_SYS_LARGEFILE_TEST
524 dnl
525 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
526 dnl arithmetic properly but this failed miserably with gcc under Linux
527 dnl whereas the system still supports 64 bit files, so now simply check
528 dnl that off_t is big enough
529 define(WX_SYS_LARGEFILE_TEST,
530 [typedef struct {
531 unsigned int field: sizeof(off_t) == 8;
532 } wxlf;
533 ])
534
535
536 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
537 define(WX_SYS_LARGEFILE_MACRO_VALUE,
538 [
539 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
540 [
541 AC_TRY_COMPILE([#define $1 $2
542 #include <sys/types.h>],
543 WX_SYS_LARGEFILE_TEST,
544 [$3=$2],
545 [$3=no])
546 ]
547 )
548
549 if test "$$3" != no; then
550 wx_largefile=yes
551 AC_DEFINE_UNQUOTED([$1], [$$3])
552 fi
553 ])
554
555
556 dnl AC_SYS_LARGEFILE
557 dnl ----------------
558 dnl By default, many hosts won't let programs access large files;
559 dnl one must use special compiler options to get large-file access to work.
560 dnl For more details about this brain damage please see:
561 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
562 AC_DEFUN([AC_SYS_LARGEFILE],
563 [AC_ARG_ENABLE(largefile,
564 [ --disable-largefile omit support for large files])
565 if test "$enable_largefile" != no; then
566 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
567 dnl _LARGE_FILES -- for AIX
568 wx_largefile=no
569 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
570 if test "x$wx_largefile" != "xyes"; then
571 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
572 fi
573
574 AC_MSG_CHECKING(if large file support is available)
575 if test "x$wx_largefile" = "xyes"; then
576 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
577 fi
578 AC_MSG_RESULT($wx_largefile)
579 fi
580 ])