]> git.saurik.com Git - wxWidgets.git/blob - acinclude.m4
Allow setting default file name in wxMotif wxFileDialog.
[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 FIXME - doesn't work, Solaris linker doesn't accept wildcards
401 dnl in the script.
402 dnl dnl Check for known non-gcc cases:
403 dnl case "${host}" in
404 dnl *-*-solaris2* )
405 dnl if test "x$GCC" != "xyes" ; then
406 dnl LDFLAGS_VERSIONING="-M $1"
407 dnl found_versioning=yes
408 dnl fi
409 dnl ;;
410 dnl esac
411
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,
415 [
416 echo "VER_1 { *; };" >conftest.sym
417 echo "int main() { return 0; }" >conftest.cpp
418
419 if AC_TRY_COMMAND([
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
424 else
425 wx_cv_version_script=yes
426 fi
427 else
428 wx_cv_version_script=no
429 fi
430 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
431 ])
432 if test $wx_cv_version_script = yes ; then
433 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
434 fi
435 fi
436 ])
437
438
439 dnl ===========================================================================
440 dnl "3rd party" macros included here because they are not widely available
441 dnl ===========================================================================
442
443 dnl ---------------------------------------------------------------------------
444 dnl test for availability of iconv()
445 dnl ---------------------------------------------------------------------------
446
447 dnl From Bruno Haible.
448
449 AC_DEFUN([AM_ICONV],
450 [
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).
453
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
459 done
460 ])
461
462 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
463 am_cv_func_iconv="no, consider installing GNU libiconv"
464 am_cv_lib_iconv=no
465 AC_TRY_LINK([#include <stdlib.h>
466 #include <iconv.h>],
467 [iconv_t cd = iconv_open("","");
468 iconv(cd,NULL,NULL,NULL,NULL);
469 iconv_close(cd);],
470 am_cv_func_iconv=yes)
471 if test "$am_cv_func_iconv" != yes; then
472 am_save_LIBS="$LIBS"
473 LIBS="$LIBS -liconv"
474 AC_TRY_LINK([#include <stdlib.h>
475 #include <iconv.h>],
476 [iconv_t cd = iconv_open("","");
477 iconv(cd,NULL,NULL,NULL,NULL);
478 iconv_close(cd);],
479 am_cv_lib_iconv=yes
480 am_cv_func_iconv=yes)
481 LIBS="$am_save_LIBS"
482 fi
483 ])
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,
487 AC_TRY_COMPILE([
488 #include <stdlib.h>
489 #include <iconv.h>
490 extern
491 #ifdef __cplusplus
492 "C"
493 #endif
494 #if defined(__STDC__) || defined(__cplusplus)
495 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
496 #else
497 size_t iconv();
498 #endif
499 ],
500 [],
501 wx_cv_func_iconv_const="no",
502 wx_cv_func_iconv_const="yes"
503 )
504 )
505
506 iconv_const=
507 if test "x$wx_cv_func_iconv_const" = "xyes"; then
508 iconv_const="const"
509 fi
510
511 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
512 [Define as const if the declaration of iconv() needs const.])
513 fi
514 LIBICONV=
515 if test "$am_cv_lib_iconv" = yes; then
516 LIBICONV="-liconv"
517 fi
518 AC_SUBST(LIBICONV)
519 ])
520
521 dnl ---------------------------------------------------------------------------
522 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
523 dnl ---------------------------------------------------------------------------
524
525 dnl WX_SYS_LARGEFILE_TEST
526 dnl
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,
532 [typedef struct {
533 unsigned int field: sizeof(off_t) == 8;
534 } wxlf;
535 ])
536
537
538 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
539 define(WX_SYS_LARGEFILE_MACRO_VALUE,
540 [
541 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
542 [
543 AC_TRY_COMPILE([#define $1 $2
544 #include <sys/types.h>],
545 WX_SYS_LARGEFILE_TEST,
546 [$3=$2],
547 [$3=no])
548 ]
549 )
550
551 if test "$$3" != no; then
552 wx_largefile=yes
553 AC_DEFINE_UNQUOTED([$1], [$$3])
554 fi
555 ])
556
557
558 dnl AC_SYS_LARGEFILE
559 dnl ----------------
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
570 wx_largefile=no
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)
574 fi
575
576 AC_MSG_CHECKING(if large file support is available)
577 if test "x$wx_largefile" = "xyes"; then
578 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
579 fi
580 AC_MSG_RESULT($wx_largefile)
581 fi
582 ])