]> git.saurik.com Git - wxWidgets.git/blob - acinclude.m4
A bit of distribution/makefiles things.
[wxWidgets.git] / acinclude.m4
1 dnl ---------------------------------------------------------------------------
2 dnl
3 dnl Purpose: Cursom macros for autoconf configure script.
4 dnl Author: Vadim Zeitlin
5 dnl Created: 26.05.99
6 dnl Version: $Id$
7 dnl ---------------------------------------------------------------------------
8
9 dnl ===========================================================================
10 dnl GKT+ version test
11 dnl ===========================================================================
12
13 dnl ---------------------------------------------------------------------------
14 dnl AM_PATH_GTK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
15 dnl Test for GTK, and define GTK_CFLAGS and GTK_LIBS. Uses variables
16 dnl gtk_config_prefix and/or gtk_config_exec_prefix if defined.
17 dnl ---------------------------------------------------------------------------
18 dnl
19 AC_DEFUN(AM_PATH_GTK,
20 [
21 if test x$gtk_config_exec_prefix != x ; then
22 gtk_config_args="$gtk_config_args --exec-prefix=$gtk_config_exec_prefix"
23 if test x${GTK_CONFIG+set} != xset ; then
24 GTK_CONFIG=$gtk_config_exec_prefix/bin/gtk-config
25 fi
26 fi
27 if test x$gtk_config_prefix != x ; then
28 gtk_config_args="$gtk_config_args --prefix=$gtk_config_prefix"
29 if test x${GTK_CONFIG+set} != xset ; then
30 GTK_CONFIG=$gtk_config_prefix/bin/gtk-config
31 fi
32 fi
33
34 AC_PATH_PROG(GTK_CONFIG, gtk-config, no)
35 min_gtk_version=ifelse([$1], ,0.99.7,$1)
36 AC_MSG_CHECKING(for GTK - version >= $min_gtk_version)
37 no_gtk=""
38 if test "$GTK_CONFIG" != "no" ; then
39 GTK_CFLAGS=`$GTK_CONFIG --cflags`
40 GTK_LIBS=`$GTK_CONFIG --libs`
41 ac_save_CFLAGS="$CFLAGS"
42 ac_save_LIBS="$LIBS"
43 CFLAGS="$CFLAGS $GTK_CFLAGS"
44 LIBS="$LIBS $GTK_LIBS"
45 dnl
46 dnl Now check if the installed GTK is sufficiently new. (Also sanity
47 dnl checks the results of gtk-config to some extent)
48 dnl
49 AC_TRY_RUN([
50 #include <gtk/gtk.h>
51 #include <stdio.h>
52
53 int
54 main ()
55 {
56 int major, minor, micro;
57
58 if (sscanf("$min_gtk_version", "%d.%d.%d", &major, &minor, &micro) != 3) {
59 printf("%s, bad version string\n", "$min_gtk_version");
60 exit(1);
61 }
62
63 if (gtk_minor_version == 1) return FALSE;
64
65 return !((gtk_major_version > major) ||
66 ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
67 ((gtk_major_version == major) && (gtk_minor_version == minor) && (gtk_micro_version >= micro)));
68 }
69 ],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
70 CFLAGS="$ac_save_CFLAGS"
71 LIBS="$ac_save_LIBS"
72 else
73 no_gtk=yes
74 fi
75 if test "x$no_gtk" = x ; then
76 AC_MSG_RESULT(yes)
77 ifelse([$2], , :, [$2])
78 else
79 AC_MSG_RESULT(no)
80 GTK_CFLAGS=""
81 GTK_LIBS=""
82 ifelse([$3], , :, [$3])
83 fi
84 AC_SUBST(GTK_CFLAGS)
85 AC_SUBST(GTK_LIBS)
86 ])
87
88 dnl ===========================================================================
89 dnl macros to find the a file in the list of include/lib paths
90 dnl ===========================================================================
91
92 dnl ---------------------------------------------------------------------------
93 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
94 dnl to the full name of the file that was found or leaves it empty if not found
95 dnl ---------------------------------------------------------------------------
96 AC_DEFUN(WX_PATH_FIND_INCLUDES,
97 [
98 ac_find_includes=
99 for ac_dir in $1;
100 do
101 if test -f "$ac_dir/$2"; then
102 ac_find_includes=$ac_dir
103 break
104 fi
105 done
106 ])
107
108 dnl ---------------------------------------------------------------------------
109 dnl call WX_PATH_FIND_LIBRARIES(search path, header name), sets ac_find_includes
110 dnl to the full name of the file that was found or leaves it empty if not found
111 dnl ---------------------------------------------------------------------------
112 AC_DEFUN(WX_PATH_FIND_LIBRARIES,
113 [
114 ac_find_libraries=
115 for ac_dir in $1;
116 do
117 for ac_extension in a so sl; do
118 if test -f "$ac_dir/lib$2.$ac_extension"; then
119 ac_find_libraries=$ac_dir
120 break 2
121 fi
122 done
123 done
124 ])
125
126 dnl ---------------------------------------------------------------------------
127 dnl Path to include, already defined
128 dnl ---------------------------------------------------------------------------
129 AC_DEFUN(WX_INCLUDE_PATH_EXIST,
130 [
131 ac_path_to_include=$1
132 echo "$2" | grep "\-I$1" > /dev/null
133 result=$?
134 if test $result = 0; then
135 ac_path_to_include=""
136 else
137 ac_path_to_include="-I$1"
138 fi
139 ])
140
141 dnl ---------------------------------------------------------------------------
142 dnl Path to link, already defined
143 dnl ---------------------------------------------------------------------------
144 AC_DEFUN(WX_LINK_PATH_EXIST,
145 [
146 echo "$2" | grep "\-L$1" > /dev/null
147 result=$?
148 if test $result = 0; then
149 ac_path_to_link=""
150 else
151 ac_path_to_link="-L$1"
152 fi
153 ])
154
155 dnl ===========================================================================
156 dnl C++ features test
157 dnl ===========================================================================
158
159 dnl ---------------------------------------------------------------------------
160 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
161 dnl or only the old <iostream.h> one - it may be generally assumed that if
162 dnl <iostream> exists, the other "new" headers (without .h) exist too.
163 dnl
164 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false-or-cross-compiling)
165 dnl ---------------------------------------------------------------------------
166
167 AC_DEFUN(WX_CPP_NEW_HEADERS,
168 [
169 if test "$cross_compiling" = "yes"; then
170 ifelse([$2], , :, [$2])
171 else
172 AC_LANG_SAVE
173 AC_LANG_CPLUSPLUS
174
175 AC_CHECK_HEADERS(iostream)
176
177 if test "x$HAVE_IOSTREAM" = x ; then
178 ifelse([$2], , :, [$2])
179 else
180 ifelse([$1], , :, [$1])
181 fi
182
183 AC_LANG_RESTORE
184 fi
185 ])
186
187 dnl ---------------------------------------------------------------------------
188 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
189 dnl
190 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
191 dnl ---------------------------------------------------------------------------
192
193 AC_DEFUN(WX_CPP_BOOL,
194 [
195 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
196 [
197 AC_LANG_SAVE
198 AC_LANG_CPLUSPLUS
199
200 AC_TRY_RUN([
201 int main()
202 {
203 bool b = true;
204
205 return 0;
206 }
207 ],
208 [
209 AC_DEFINE(HAVE_BOOL)
210 wx_cv_cpp_bool=yes
211 ],
212 wx_cv_cpp_bool=no,
213 wx_cv_cpp_bool=no
214 )
215
216 AC_LANG_RESTORE
217 ])
218
219 if test "$wx_cv_cpp_bool" = "yes"; then
220 AC_DEFINE(HAVE_BOOL)
221 fi
222 ])
223
224 dnl ---------------------------------------------------------------------------
225 dnl WX_CPP_SIZE_T_IS_NOT_INT checks whether size_t and int are different types,
226 dnl i.e. whether we may overload operator[] on its argument type
227 dnl ---------------------------------------------------------------------------
228
229 AC_DEFUN(WX_CPP_SIZE_T_IS_NOT_INT,
230 [
231 AC_CACHE_CHECK([if size_t and int are different types], wx_cv_cpp_sizet_not_int,
232 [
233 AC_LANG_SAVE
234 AC_LANG_CPLUSPLUS
235
236 AC_TRY_RUN([
237 #include <stdlib.h>
238
239 class S
240 {
241 public:
242 S(char *s) { m_s = s; }
243
244 char operator[](size_t n) const { return m_s[n]; }
245 char operator[](int n) const { return m_s[n]; }
246
247 private:
248 char *m_s;
249 };
250
251 int main()
252 {
253 S s("dummy");
254 size_t n1 = 2;
255 int n2 = 3;
256
257 return s[n1] == s[n2];
258 }
259 ],
260 AC_DEFINE(wxUSE_SIZE_T_STRING_OPERATOR) wx_cv_cpp_sizet_not_int=yes,
261 wx_cv_cpp_sizet_not_int=no,
262 wx_cv_cpp_sizet_not_int=no
263 )
264
265 AC_LANG_RESTORE
266 ])
267 ])
268
269 dnl ---------------------------------------------------------------------------
270 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
271 dnl ---------------------------------------------------------------------------
272
273 AC_DEFUN(WX_C_BIGENDIAN,
274 [AC_CACHE_CHECK(whether byte ordering is bigendian, ac_cv_c_bigendian,
275 [ac_cv_c_bigendian=unknown
276 # See if sys/param.h defines the BYTE_ORDER macro.
277 AC_TRY_COMPILE([#include <sys/types.h>
278 #include <sys/param.h>], [
279 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
280 bogus endian macros
281 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
282 AC_TRY_COMPILE([#include <sys/types.h>
283 #include <sys/param.h>], [
284 #if BYTE_ORDER != BIG_ENDIAN
285 not big endian
286 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
287 if test $ac_cv_c_bigendian = unknown; then
288 AC_TRY_RUN([main () {
289 /* Are we little or big endian? From Harbison&Steele. */
290 union
291 {
292 long l;
293 char c[sizeof (long)];
294 } u;
295 u.l = 1;
296 exit (u.c[sizeof (long) - 1] == 1);
297 }], ac_cv_c_bigendian=no, ac_cv_c_bigendian=yes, ac_cv_c_bigendian=unknown)
298 fi])
299 if test $ac_cv_c_bigendian = unknown; then
300 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])
301 fi
302 if test $ac_cv_c_bigendian = yes; then
303 AC_DEFINE(WORDS_BIGENDIAN)
304 fi
305 ])
306
307 dnl ---------------------------------------------------------------------------
308 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
309 dnl ---------------------------------------------------------------------------
310
311 AC_DEFUN(WX_ARG_CACHE_INIT,
312 [
313 wx_arg_cache_file="configarg.cache"
314 echo "loading argument cache $wx_arg_cache_file"
315 rm -f ${wx_arg_cache_file}.tmp
316 touch ${wx_arg_cache_file}.tmp
317 touch ${wx_arg_cache_file}
318 ])
319
320 AC_DEFUN(WX_ARG_CACHE_FLUSH,
321 [
322 echo "saving argument cache $wx_arg_cache_file"
323 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
324 ])
325
326 dnl this macro checks for a command line argument and caches the result
327 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name)
328 AC_DEFUN(WX_ARG_WITH,
329 [
330 AC_MSG_CHECKING("for --with-$1")
331 no_cache=0
332 AC_ARG_WITH($1, $2,
333 [
334 if test "$withval" = yes; then
335 ac_cv_use_$1='$3=yes'
336 else
337 ac_cv_use_$1='$3=no'
338 fi
339 ],
340 [
341 LINE=`grep "$3" ${wx_arg_cache_file}`
342 if test "x$LINE" != x ; then
343 eval "DEFAULT_$LINE"
344 else
345 no_cache=1
346 fi
347
348 ac_cv_use_$1='$3='$DEFAULT_$3
349 ])
350
351 eval "$ac_cv_use_$1"
352 if test "$no_cache" != 1; then
353 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
354 fi
355
356 if test "$$3" = yes; then
357 AC_MSG_RESULT(yes)
358 else
359 AC_MSG_RESULT(no)
360 fi
361 ])
362
363 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
364 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name)
365 AC_DEFUN(WX_ARG_ENABLE,
366 [
367 AC_MSG_CHECKING("for --enable-$1")
368 no_cache=0
369 AC_ARG_ENABLE($1, $2,
370 [
371 if test "$enableval" = yes; then
372 ac_cv_use_$1='$3=yes'
373 else
374 ac_cv_use_$1='$3=no'
375 fi
376 ],
377 [
378 LINE=`grep "$3" ${wx_arg_cache_file}`
379 if test "x$LINE" != x ; then
380 eval "DEFAULT_$LINE"
381 else
382 no_cache=1
383 fi
384
385 ac_cv_use_$1='$3='$DEFAULT_$3
386 ])
387
388 eval "$ac_cv_use_$1"
389 if test "$no_cache" != 1; then
390 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
391 fi
392
393 if test "$$3" = yes; then
394 AC_MSG_RESULT(yes)
395 else
396 AC_MSG_RESULT(no)
397 fi
398 ])
399