alloca and vasprintf go away
[platform/upstream/glib.git] / configure.in
1 dnl ***********************************
2 dnl *** include special GLib macros ***
3 dnl ***********************************
4 builtin(include, acglib.m4)dnl
5
6 # Process this file with autoconf to produce a configure script.
7 AC_INIT(glist.c)
8
9 # Save this value here, since automake will set cflags later
10 cflags_set=${CFLAGS+set}
11
12 # we rewrite this file
13 rm -f glibconfig-sysdefs.h
14
15 # The following version number definitions apply to GLib and GModule
16 # as a whole, so if changes occoured in either of them, they are both
17 # treated with the same interface and binary age.
18 #
19 # Making releases:
20 #   GLIB_MICRO_VERSION += 1;
21 #   GLIB_INTERFACE_AGE += 1;
22 #   GLIB_BINARY_AGE += 1;
23 # if any functions have been added, set GLIB_INTERFACE_AGE to 0.
24 # if backwards compatibility has been broken,
25 # set GLIB_BINARY_AGE and GLIB_INTERFACE_AGE to 0.
26 #
27 GLIB_MAJOR_VERSION=1
28 GLIB_MINOR_VERSION=1
29 GLIB_MICRO_VERSION=12
30 GLIB_INTERFACE_AGE=0
31 GLIB_BINARY_AGE=0
32 GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION
33 AC_SUBST(GLIB_VERSION)
34
35 # libtool versioning
36 LT_RELEASE=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION
37 LT_CURRENT=`expr $GLIB_MICRO_VERSION - $GLIB_INTERFACE_AGE`
38 LT_REVISION=$GLIB_INTERFACE_AGE
39 LT_AGE=`expr $GLIB_BINARY_AGE - $GLIB_INTERFACE_AGE`
40 AC_SUBST(LT_RELEASE)
41 AC_SUBST(LT_CURRENT)
42 AC_SUBST(LT_REVISION)
43 AC_SUBST(LT_AGE)
44
45 VERSION=$GLIB_VERSION
46 PACKAGE=glib
47
48 AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
49
50 # Specify a configuration file
51 AM_CONFIG_HEADER(config.h)
52
53 AC_DEFINE_UNQUOTED(GLIB_MAJOR_VERSION, $GLIB_MAJOR_VERSION)
54 AC_DEFINE_UNQUOTED(GLIB_MINOR_VERSION, $GLIB_MINOR_VERSION)
55 AC_DEFINE_UNQUOTED(GLIB_MICRO_VERSION, $GLIB_MICRO_VERSION)
56 AC_DEFINE_UNQUOTED(GLIB_INTERFACE_AGE, $GLIB_INTERFACE_AGE)
57 AC_DEFINE_UNQUOTED(GLIB_BINARY_AGE, $GLIB_BINARY_AGE)
58
59 dnl Initialize libtool
60 AM_PROG_LIBTOOL
61
62 dnl Initialize maintainer mode
63 AM_MAINTAINER_MODE
64
65 AC_CANONICAL_HOST
66
67 AC_ARG_ENABLE(debug, [  --enable-debug=[no/minimum/yes] turn on debugging [default=minimum]],,enable_debug=minimum)
68 AC_ARG_ENABLE(mem_check, [  --enable-mem-check      turn on malloc/free sanity checking [default=no]],,enable_mem_check=no)
69 AC_ARG_ENABLE(mem_profile, [  --enable-mem-profile    turn on malloc profiling atexit [default=no]],,enable_mem_profile=no)
70 AC_ARG_ENABLE(ansi, [  --enable-ansi           turn on strict ansi [default=no]],
71                     , enable_ansi=no)
72 AC_ARG_ENABLE(threads, [  --enable-threads        turn on basic thread support [default=yes]
73                           ([=no] will override --with-threads)],,enable_threads=yes)
74
75 if test "x$enable_threads" != "xyes"; then
76   enable_threads=no
77 fi
78
79 AC_MSG_CHECKING(whether to enable memory checking)
80 if test "x$enable_mem_check" = "xyes"; then
81   AC_DEFINE(ENABLE_MEM_CHECK, 1)
82   AC_SUBST(ENABLE_MEM_CHECK)
83   AC_MSG_RESULT(yes)
84 else
85   AC_MSG_RESULT(no)
86 fi
87
88 AC_MSG_CHECKING(whether to enable memory profiling)
89 if test "x$enable_mem_profile" = "xyes"; then
90   AC_DEFINE(ENABLE_MEM_PROFILE, 1)
91   AC_SUBST(ENABLE_MEM_PROFILE)
92   AC_MSG_RESULT(yes)
93 else
94   AC_MSG_RESULT(no)
95 fi
96
97 if test "x$enable_debug" = "xyes"; then
98   test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
99   GLIB_DEBUG_FLAGS="-DG_ENABLE_DEBUG"
100 else
101   if test "x$enable_debug" = "xno"; then
102     GLIB_DEBUG_FLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
103   fi
104 fi
105
106 AC_DEFINE_UNQUOTED(G_COMPILED_WITH_DEBUGGING, "${enable_debug}")
107
108 # Checks for programs.
109 AC_PROG_CC
110 AM_PROG_CC_STDC
111 AC_PROG_INSTALL
112
113 changequote(,)dnl
114 if test "x$GCC" = "xyes"; then
115   case " $CFLAGS " in
116   *[\ \ ]-Wall[\ \      ]*) ;;
117   *) CFLAGS="$CFLAGS -Wall" ;;
118   esac
119
120   if test "x$enable_ansi" = "xyes"; then
121     case " $CFLAGS " in
122     *[\ \       ]-ansi[\ \      ]*) ;;
123     *) CFLAGS="$CFLAGS -ansi" ;;
124     esac
125
126     case " $CFLAGS " in
127     *[\ \       ]-pedantic[\ \  ]*) ;;
128     *) CFLAGS="$CFLAGS -pedantic" ;;
129     esac
130   fi
131 fi
132 changequote([,])dnl
133
134 dnl DU4 native cc currently needs -std1 for ANSI mode (instead of K&R)
135 AC_MSG_CHECKING([for extra flags to get ANSI library prototypes])
136 glib_save_LIBS=$LIBS
137 LIBS="$LIBS -lm"
138 AC_TRY_RUN([#include <math.h>
139              int main (void) { return (log(1) != log(1.)); }],
140      AC_MSG_RESULT(none needed),
141      glib_save_CFLAGS=$CFLAGS
142      CFLAGS="$CFLAGS -std1"
143      AC_TRY_RUN([#include <math.h>
144                  int main (void) { return (log(1) != log(1.)); }],
145          AC_MSG_RESULT(-std1),
146          AC_MSG_RESULT()
147          CFLAGS=$glib_save_CFLAGS
148          AC_MSG_WARN(
149                 [No ANSI prototypes found in library. (-std1 didn't work.)])
150      )
151 )
152 LIBS=$glib_save_LIBS
153
154 dnl NeXTStep cc seems to need this
155 AC_MSG_CHECKING([for extra flags for POSIX compliance])
156 AC_TRY_COMPILE([#include <dirent.h>], [DIR *dir;],
157   AC_MSG_RESULT(none needed),
158   glib_save_CFLAGS=$CFLAGS
159   CFLAGS="$CFLAGS -posix"
160   AC_TRY_COMPILE([#include <dirent.h>], [DIR *dir;],
161     AC_MSG_RESULT(-posix),
162     AC_MSG_RESULT()
163     CFLAGS=$glib_save_CFLAGS
164     AC_MSG_WARN([Could not determine POSIX flag. (-posix didn't work.)])))
165
166 # Checks for header files.
167 AC_HEADER_STDC
168
169 # Checks for library functions.
170 AC_FUNC_VPRINTF
171
172 AC_CHECK_FUNCS(atexit on_exit)
173
174 AC_CHECK_SIZEOF(char)
175 AC_CHECK_SIZEOF(short)
176 AC_CHECK_SIZEOF(long)
177 AC_CHECK_SIZEOF(int)
178 AC_CHECK_SIZEOF(void *)
179 AC_CHECK_SIZEOF(long long)
180
181 dnl long doubles were not used, and a portability problem 
182 dnl AC_C_LONG_DOUBLE
183 AC_C_CONST
184
185 dnl AC_C_INLINE is useless to us since it bails out too early, we need to
186 dnl truely know which ones of `inline', `__inline' and `__inline__' are
187 dnl actually supported.
188 AC_MSG_CHECKING(for __inline)
189 AC_CACHE_VAL(glib_cv_has__inline,[
190         AC_TRY_RUN([
191         __inline int foo () { return 0; }
192         int main () { return foo (); }
193         ],
194         glib_cv_has__inline=yes
195         ,
196         glib_cv_has__inline=no
197         ,)
198 ])
199 AC_MSG_RESULT($glib_cv_has__inline)
200 case x$glib_cv_has__inline in
201 xyes) AC_DEFINE(G_HAVE___INLINE)
202 esac
203 AC_MSG_CHECKING(for __inline__)
204 AC_CACHE_VAL(glib_cv_has__inline__,[
205         AC_TRY_RUN([
206         __inline__ int foo () { return 0; }
207         int main () { return foo (); }
208         ],
209         glib_cv_has__inline__=yes
210         ,
211         glib_cv_has__inline__=no
212         ,)
213 ])
214 AC_MSG_RESULT($glib_cv_has__inline__)
215 case x$glib_cv_has__inline__ in
216 xyes) AC_DEFINE(G_HAVE___INLINE__)
217 esac
218 AC_MSG_CHECKING(for inline)
219 AC_CACHE_VAL(glib_cv_hasinline,[
220         AC_TRY_RUN([
221         inline int foo () { return 0; }
222         int main () { return foo (); }
223         ],
224         glib_cv_hasinline=yes
225         ,
226         glib_cv_hasinline=no
227         ,)
228 ])
229 AC_MSG_RESULT($glib_cv_hasinline)
230 case x$glib_cv_hasinline in
231 xyes) AC_DEFINE(G_HAVE_INLINE)
232 esac
233
234 dnl for bytesex stuff
235 AC_C_BIGENDIAN
236
237 dnl header file checks
238 AC_CHECK_HEADERS(float.h, AC_DEFINE(HAVE_FLOAT_H))
239 AC_CHECK_HEADERS(limits.h, AC_DEFINE(HAVE_LIMITS_H))
240 AC_CHECK_HEADERS(pwd.h, AC_DEFINE(HAVE_PWD_H))
241 AC_CHECK_HEADERS(sys/param.h, AC_DEFINE(HAVE_SYS_PARAM_H))
242 AC_CHECK_HEADERS(sys/poll.h, AC_DEFINE(HAVE_SYS_POLL_H))
243 AC_CHECK_HEADERS(sys/select.h, AC_DEFINE(HAVE_SYS_SELECT_H))
244 AC_CHECK_HEADERS(sys/time.h, AC_DEFINE(HAVE_SYS_TIME_H))
245 AC_CHECK_HEADERS(sys/times.h, AC_DEFINE(HAVE_SYS_TIMES_H))
246 AC_CHECK_HEADERS(unistd.h, AC_DEFINE(HAVE_UNISTD_H))
247 AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
248
249 # Check for some functions
250 AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp poll)
251
252 # Check for sys_errlist
253 AC_MSG_CHECKING(for sys_errlist)
254 AC_TRY_LINK(, [
255 extern char *sys_errlist[];
256 extern int sys_nerr;
257 sys_errlist[sys_nerr-1][0] = 0;
258 ], glib_ok=yes, glib_ok=no)
259 AC_MSG_RESULT($glib_ok)
260 if test $glib_ok = no; then
261     AC_DEFINE(NO_SYS_ERRLIST)
262 fi
263
264 # Check for sys_siglist
265 AC_MSG_CHECKING(for sys_siglist)
266 AC_TRY_LINK(, [
267 extern char *sys_siglist[];
268 sys_siglist[1][0] = 0;
269 ], glib_ok=yes, glib_ok=no)
270 AC_MSG_RESULT($glib_ok)
271 if test $glib_ok = no; then
272     AC_DEFINE(NO_SYS_SIGLIST)
273 fi
274
275 # Check if <sys/select.h> needs to be included for fd_set
276 AC_MSG_CHECKING([for fd_set])
277 AC_TRY_COMPILE([#include <sys/types.h>],
278         [fd_set readMask, writeMask;], gtk_ok=yes, gtk_ok=no)
279 if test $gtk_ok = yes; then
280     AC_MSG_RESULT([yes, found in sys/types.h])
281 else
282     AC_HEADER_EGREP(fd_mask, sys/select.h, gtk_ok=yes)
283     if test $gtk_ok = yes; then
284         AC_DEFINE(HAVE_SYS_SELECT_H)
285         AC_MSG_RESULT([yes, found in sys/select.h])
286     else
287         AC_DEFINE(NO_FD_SET)
288         AC_MSG_RESULT(no)
289     fi
290 fi
291
292 # These are used only in GDK (gdki18n.h)
293 # This stuff is here only so that we can define these
294 # things in glibconfig.h. If gtk+ started using an installed
295 # gdkconfig.h file, then the definitions would belong there. 
296
297 # Check for wchar.h
298
299 AC_MSG_CHECKING(for wchar.h)
300 AC_TRY_CPP([#include <wchar.h>], glib_wchar_h=yes, glib_wchar_h=no)
301 if test $glib_wchar_h = yes; then
302    AC_DEFINE(HAVE_WCHAR_H)
303 fi
304 AC_MSG_RESULT($glib_wchar_h)
305
306 # Check for wctype.h (for iswalnum)
307
308 AC_MSG_CHECKING(for wctype.h)
309 AC_TRY_CPP([#include <wctype.h>], glib_wctype_h=yes, glib_wctype_h=no)
310 if test $glib_wctype_h = yes; then
311    AC_DEFINE(HAVE_WCTYPE_H)
312 fi
313 AC_MSG_RESULT($glib_wctype_h)
314
315 oLIBS="$LIBS"
316 # in Solaris 2.5, `iswalnum' is in -lw
317 AC_CHECK_FUNC(iswalnum,,[AC_CHECK_LIB(w,iswalnum)])
318
319 # The following is necessary for Linux libc-5.4.38
320 AC_MSG_CHECKING(if iswalnum() and friends are properly defined)
321 AC_TRY_LINK([#include <stdlib.h>],[
322 #if (defined(HAVE_WCTYPE_H) || defined(HAVE_WCHAR_H))
323 #  ifdef HAVE_WCTYPE_H
324 #    include <wctype.h>
325 #  else
326 #    ifdef HAVE_WCHAR_H
327 #      include <wchar.h>
328 #    endif
329 #  endif
330 #else
331 #  define iswalnum(c) ((wchar_t)(c) <= 0xFF && isalnum(c))
332 #endif
333 iswalnum((wchar_t) 0);
334 ], glib_working_wctype=yes, glib_working_wctype=no)
335 LIBS="$oLIBS"
336
337 if test $glib_working_wctype = no; then
338    AC_DEFINE(HAVE_BROKEN_WCTYPE)
339 fi
340 AC_MSG_RESULT($glib_working_wctype)
341
342
343 dnl **********************
344 dnl *** va_copy checks ***
345 dnl **********************
346 dnl we currently check for all three va_copy possibilities, so we get
347 dnl all results in config.log for bug reports.
348 AC_MSG_CHECKING(for an implementation of va_copy())
349 AC_CACHE_VAL(glib_cv_va_copy,[
350         AC_TRY_RUN([
351         #include <stdarg.h>
352         void f (int i, ...) {
353         va_list args1, args2;
354         va_start (args1, i);
355         va_copy (args2, args1);
356         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
357           exit (1);
358         va_end (args1); va_end (args2);
359         }
360         int main() {
361           f (0, 42);
362           return 0;
363         }],
364         glib_cv_va_copy=yes
365         ,
366         glib_cv_va_copy=no
367         ,)
368 ])
369 AC_MSG_RESULT($glib_cv_va_copy)
370 AC_MSG_CHECKING(for an implementation of __va_copy())
371 AC_CACHE_VAL(glib_cv___va_copy,[
372         AC_TRY_RUN([
373         #include <stdarg.h>
374         void f (int i, ...) {
375         va_list args1, args2;
376         va_start (args1, i);
377         __va_copy (args2, args1);
378         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
379           exit (1);
380         va_end (args1); va_end (args2);
381         }
382         int main() {
383           f (0, 42);
384           return 0;
385         }],
386         glib_cv___va_copy=yes
387         ,
388         glib_cv___va_copy=no
389         ,)
390 ])
391 AC_MSG_RESULT($glib_cv___va_copy)
392 AC_MSG_CHECKING(whether va_lists can be copied by value)
393 AC_CACHE_VAL(glib_cv_va_val_copy,[
394         AC_TRY_RUN([
395         #include <stdarg.h>
396         void f (int i, ...) {
397         va_list args1, args2;
398         va_start (args1, i);
399         args2 = args1;
400         if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
401           exit (1);
402         va_end (args1); va_end (args2);
403         }
404         int main() {
405           f (0, 42);
406           return 0;
407         }],
408         glib_cv_va_val_copy=yes
409         ,
410         glib_cv_va_val_copy=no
411         ,)
412 ])
413 if test "x$glib_cv_va_copy" = "xyes"; then
414   AC_DEFINE(G_VA_COPY, va_copy)
415 else if test "x$glib_cv___va_copy" = "xyes"; then
416   AC_DEFINE(G_VA_COPY, __va_copy)
417 fi
418 fi
419 if test "x$glib_cv_va_val_copy" = "xno"; then
420   AC_DEFINE(G_VA_COPY_AS_ARRAY)
421 fi
422 AC_MSG_RESULT($glib_cv_va_val_copy)
423
424
425 dnl ***********************
426 dnl *** g_module checks ***
427 dnl ***********************
428 G_MODULE_LIBS=
429 G_MODULE_LDFLAGS=
430 G_MODULE_IMPL=
431 G_MODULE_NEED_USCORE=0
432 G_MODULE_HAVE_DLERROR=0
433 dnl *** dlopen() in system libraries
434 if test -z "$G_MODULE_IMPL"; then
435         AC_CHECK_FUNC(dlopen,
436                 G_MODULE_IMPL=G_MODULE_IMPL_DL
437         ,)
438 fi
439 dnl *** dlopen() in libdl
440 if test -z "$G_MODULE_IMPL"; then
441         AC_CHECK_LIB(dl, dlopen,
442                 G_MODULE_LIBS=-ldl
443                 G_MODULE_IMPL=G_MODULE_IMPL_DL
444         ,)
445 fi
446 dnl *** shl_load() in libdld (HP-UX)
447 if test -z "$G_MODULE_IMPL"; then
448         AC_MSG_CHECKING(how to export all symbols)
449         SAVED_LDFLAGS=$LDFLAGS
450         LDFLAGS="$LDFLAGS -Wl,-E"
451         AC_TRY_LINK(,[ return 0; ],
452                 [ G_MODULE_LDFLAGS="-Wl,-E" ],[
453                 LDFLAGS="$SAVED_LDFLAGS -bexpall"
454                 AC_TRY_LINK(,[ return 0; ],
455                         G_MODULE_LDFLAGS="-bexpall",
456                         G_MODULE_LDFLAGS="none"
457                 )
458         ])
459         LDFLAGS=$SAVED_LDFLAGS
460         AC_MSG_RESULT($G_MODULE_LDFLAGS)
461         if test "x$G_MODULE_LDFLAGS" = "xnone"; then
462                 G_MODULE_LDFLAGS=
463         fi
464         AC_CHECK_LIB(dld, shl_load,
465                 G_MODULE_LIBS=-ldld
466                 G_MODULE_IMPL=G_MODULE_IMPL_DLD
467         ,)
468 fi
469 dnl *** additional checks for G_MODULE_IMPL_DL
470 if test "$G_MODULE_IMPL" = "G_MODULE_IMPL_DL"; then
471         case "$host_os" in
472           linux*)
473             G_MODULE_LDFLAGS='-rdynamic'
474             ;;
475         esac
476         LIBS_orig="$LIBS"
477         LDFLAGS_orig="$LDFLAGS"
478         LIBS="$LIBS $G_MODULE_LIBS"
479         LDFLAGS="$LDFLAGS $G_MODULE_LDFLAGS"
480 dnl *** check whether we need preceeding underscores
481         AC_MSG_CHECKING(for preceeding underscore in symbols)
482         AC_CACHE_VAL(glib_cv_uscore,[
483                 AC_TRY_RUN([
484                 #include <dlfcn.h>
485                 int glib_underscore_test (void) { return 42; }
486                 int main() {
487                   void *f1 = (void*)0, *f2 = (void*)0, *handle;
488                   handle = dlopen ((void*)0, 0);
489                   if (handle) {
490                     f1 = dlsym (handle, "glib_underscore_test");
491                     f2 = dlsym (handle, "_glib_underscore_test");
492                   } return (!f2 || f1);
493                 }],     
494                         glib_cv_uscore=yes,     
495                         glib_cv_uscore=no,
496                 )
497                 rm -f plugin.c plugin.o plugin.lo
498         ])
499         AC_MSG_RESULT($glib_cv_uscore)  
500         if test "x$glib_cv_uscore" = "xyes"; then
501                 G_MODULE_NEED_USCORE=1
502         else
503                 G_MODULE_NEED_USCORE=0
504         fi      
505         
506         LDFLAGS="$LDFLAGS_orig"
507 dnl *** check for having dlerror()
508         AC_CHECK_FUNC(dlerror,
509                 G_MODULE_HAVE_DLERROR=1,
510                 G_MODULE_HAVE_DLERROR=0)
511         LIBS="$LIBS_orig"
512 fi
513 dnl *** done, have e got an implementation?
514 if test -z "$G_MODULE_IMPL"; then
515         G_MODULE_IMPL=0
516 fi
517 AC_SUBST(G_MODULE_IMPL)
518 AC_SUBST(G_MODULE_LIBS)
519 AC_SUBST(G_MODULE_LDFLAGS)
520 AC_SUBST(G_MODULE_HAVE_DLERROR)
521 AC_SUBST(G_MODULE_NEED_USCORE)
522 AC_SUBST(GLIB_DEBUG_FLAGS)
523
524
525 dnl ***********************
526 dnl *** g_thread checks ***
527 dnl ***********************
528
529 AC_ARG_WITH(threads, [  --with-threads=[none/posix/solaris/nspr] specify a thread implementation to use],
530         if test "x$with_threads" = x; then
531                 want_threads=yes
532         else
533                 want_threads=$with_threads
534         fi,
535         want_threads=yes)
536 if test "x$enable_threads" = "xno"; then
537         want_threads=no
538 fi
539 if test "x$want_threads" = "xnone"; then
540         want_threads=no
541 fi
542
543 dnl error and warning message
544 dnl *************************
545
546 THREAD_NO_IMPLEMENTATION="You do not have any known thread system on your
547                 computer. glib will not be thread safe on your computer."
548
549 FLAG_DOES_NOT_WORK="I can't find the MACRO, that enables thread safety on your
550                 platform (normaly it's "_REENTRANT"). I'll not use any flag on
551                 compilation now, but then your programs might not work. 
552                 Please provide information on how it is done on your system."
553
554 LIBS_NOT_FOUND_1="I can't find the libraries for the thread implementation
555                 "
556
557 LIBS_NOT_FOUND_2=". Please choose another thread implementation or 
558                 provide informationon your thread implementation."
559
560 dnl determination of thread implementation
561 dnl ***************************************
562
563 have_threads=none
564 if test "x$want_threads" = xyes || test "x$want_threads" = xsolaris; then
565         case $host in
566                 *-*-solaris*)
567                 AC_CHECK_LIB(thread, cond_init, have_threads=solaris)
568                 ;;
569         esac
570 fi
571 if test "x$want_threads" = xyes || test "x$want_threads" = xposix; then
572         if test "x$have_threads" = xnone; then
573                 AC_CHECK_LIB(pthread, pthread_attr_init, have_threads=posix)
574         fi
575         if test "x$have_threads" = xnone; then
576                 AC_CHECK_LIB(pthreads, pthread_attr_init, have_threads=posix)
577         fi
578         if test "x$have_threads" = xnone; then
579                 AC_CHECK_LIB(c_r, pthread_attr_init, have_threads=posix)
580         fi
581         if test "x$have_threads" = xnone; then
582                 AC_CHECK_FUNC(pthread_attr_init, have_threads=posix)
583         fi
584         dnl ********** DG/UX ************
585         if test "x$have_threads" = xnone; then
586                 AC_CHECK_LIB(thread, __d10_pthread_attr_init, 
587                         have_threads=posix)
588         fi
589 fi
590 if test "x$want_threads" = xyes || test "x$want_threads" = xnspr; then
591         if test "x$have_threads" = xnone; then
592                 AC_CHECK_LIB(nspr21, PRP_NewNakedCondVar, have_threads=nspr)
593         fi
594 fi
595
596 AC_MSG_CHECKING(for thread implementation)
597
598 if test "x$have_threads" = xnone && test "x$want_threads" != xno; then
599         AC_MSG_RESULT(none available)
600         AC_MSG_WARN($THREAD_NO_IMPLEMENTATION)
601 else
602         AC_MSG_RESULT($have_threads)
603 fi
604
605
606 dnl determination of G_THREAD_LIBS
607 dnl ******************************
608
609 G_THREAD_LIBS=
610 G_THREAD_CFLAGS=
611
612 mutex_has_default=no
613 case $have_threads in
614         posix)
615                 G_THREAD_LIBS=error
616                 AC_CHECK_LIB(pthread, pthread_attr_init,
617                              G_THREAD_LIBS="-lpthread") 
618                 if test "x$G_THREAD_LIBS" = xerror; then
619                         AC_CHECK_LIB(pthreads, pthread_attr_init,
620                                 G_THREAD_LIBS="-lpthreads")
621                 fi
622                 if test "x$G_THREAD_LIBS" = xerror; then
623                         AC_CHECK_LIB(c_r, pthread_attr_init,
624                                 G_THREAD_LIBS="-lc_r")
625                 fi
626                 if test "x$G_THREAD_LIBS" = xerror; then
627                         AC_CHECK_FUNC(pthread_attr_init, G_THREAD_LIBS="")
628                 fi
629                 dnl ********** DG/UX ************
630                 if test "x$G_THREAD_LIBS" = xerror; then
631                         AC_CHECK_LIB(thread, __d10_pthread_attr_init, 
632                                 G_THREAD_LIBS="-lthread"
633                                 G_THREAD_CFLAGS="-D_POSIX4A_DRAFT10_SOURCE")
634                 fi
635                 mutex_has_default=yes
636                 mutex_default_type='pthread_mutex_t'
637                 mutex_default_init='PTHREAD_MUTEX_INITIALIZER'
638                 mutex_header_file='pthread.h'
639                 g_threads_impl="POSIX"
640                 ;;
641         solaris)
642                 G_THREAD_LIBS=error
643                 AC_CHECK_LIB(thread, cond_init, G_THREAD_LIBS="-lthread")
644                 mutex_has_default=yes
645                 mutex_default_type='mutex_t'
646                 mutex_default_init="DEFAULTMUTEX"
647                 mutex_header_file='thread.h'
648                 g_threads_impl="SOLARIS"
649                 ;;
650         nspr)
651                 AC_CHECK_LIB(nspr21, PRP_NewNakedCondVar,
652                              G_THREAD_LIBS="-lnspr21")
653                 g_threads_impl="NSPR"
654                 ;;
655         none)
656                 g_threads_impl="NONE"
657                 ;;
658         *)
659                 g_threads_impl="NONE"
660                 G_THREAD_LIBS=error
661                 ;;
662 esac
663
664 if test "x$G_THREAD_LIBS" = xerror; then
665         AC_MSG_ERROR($LIBS_NOT_FOUND_1$have_threads$LIBS_NOT_FOUND_2)
666 fi
667
668 AC_MSG_CHECKING(necessary linker options)
669 AC_MSG_RESULT($G_THREAD_LIBS)
670
671
672 dnl determination of G_THREAD_CFLAGS
673 dnl ********************************
674
675 if test x"$have_threads" != xnone; then
676         G_THREAD_CFLAGS="$G_THREAD_CFLAGS -D_REENTRANT" # good default
677
678         case $host in
679                *-aix*)
680                         G_THREAD_CFLAGS="$G_THREAD_CFLAGS -D_THREAD_SAFE"
681                         if test x"$GCC" = xyes; then 
682                                 G_THREAD_CFLAGS="$G_THREAD_CFLAGS -mthreads"
683                         fi
684                         ;;
685         esac
686
687         # if we are not finding the ctime_r function, then we probably are 
688         # not using the proper multithread flag
689         old_CPPFLAGS=$CPPFLAGS
690         CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
691         AC_EGREP_HEADER([[^a-zA-Z_]ctime_r[^a-zA-Z_]], time.h, , 
692                 G_THREAD_CFLAGS=
693                 AC_MSG_WARN($FLAG_DOES_NOT_WORK))
694         CPPFLAGS=$old_CPPFLAGS
695
696         AC_MSG_CHECKING(necessary compiler options)
697
698         AC_MSG_RESULT($G_THREAD_CFLAGS)
699 else
700         G_THREAD_CFLAGS=
701 fi
702
703 AC_DEFINE_UNQUOTED(G_THREAD_SOURCE,"gthread-$have_threads.c")
704 AC_SUBST(G_THREAD_CFLAGS)
705 AC_SUBST(G_THREAD_LIBS)
706
707 CFLAGS="$CFLAGS $G_THREAD_CFLAGS"
708
709 AC_CHECK_FUNCS(localtime_r rand_r)
710
711 dnl **********************************************
712 dnl *** GDefaultMutex setup and initialization ***
713 dnl **********************************************
714 dnl
715 dnl if mutex_has_default = yes, we also got
716 dnl mutex_default_type, mutex_default_init and mutex_header_file
717 GLIB_IF_VAR_EQ(mutex_has_default, yes,
718         GLIB_SIZEOF([#include <$mutex_header_file>],
719                     $mutex_default_type,
720                     gmutex,
721                     )
722         GLIB_BYTE_CONTENTS([#include <$mutex_header_file>],
723                            $mutex_default_type,
724                            gmutex,
725                            $glib_cv_sizeof_gmutex,
726                            $mutex_default_init)
727         ,
728 )
729
730
731 dnl ****************************************
732 dnl *** GLib POLL* compatibility defines ***
733 dnl ****************************************
734 GLIB_SYSDEFS(
735 [#include <sys/types.h>
736 #include <sys/poll.h>],
737         POLLIN:1 POLLOUT:4 POLLPRI:2 POLLERR:8 POLLHUP:16 POLLNVAL:32,
738         glibconfig-sysdefs.h,
739         =)
740
741
742 dnl ******************************
743 dnl *** output the whole stuff ***
744 dnl ******************************
745
746 AC_OUTPUT_COMMANDS([
747
748 ## Generate `glibconfig.h' in two cases
749 ## 1. `config.status' is run either explicitly, or via configure.
750 ##     Esp. not when it is run in `Makefile' to generate makefiles and
751 ##     config.h
752 ## 2. CONFIG_OTHER is set explicitly
753 ##
754 ## Case 1 is difficult.  We know that `automake' sets one of
755 ## CONFIG_FILES or CONFIG_HEADERS to empty.  This heuristic works
756 ## only when AM_CONFIG_HEADER is set, however.  
757
758 if test -n "${CONFIG_FILES}" && test -n "${CONFIG_HEADERS}"; then
759   # Both CONFIG_FILES and CONFIG_HEADERS are non-empty ==> Case 1
760   CONFIG_OTHER=${CONFIG_OTHER:-glibconfig.h}
761 fi
762 case "$CONFIG_OTHER" in
763 *glibconfig.h*)
764         echo creating glibconfig.h
765         outfile=glibconfig.h-tmp
766         cat > $outfile <<\_______EOF
767 /* glibconfig.h
768  *
769  * This is a generated file.  Please modify `configure.in'
770  */
771
772 #ifndef GLIBCONFIG_H
773 #define GLIBCONFIG_H
774
775 #ifdef __cplusplus
776 extern "C" {
777 #endif /* __cplusplus */
778
779 _______EOF
780
781         if test x$glib_limits_h = xyes; then
782           echo '#include <limits.h>' >> $outfile
783         fi 
784         if test x$glib_float_h = xyes; then
785           echo '#include <float.h>' >> $outfile
786         fi 
787         if test x$glib_values_h = xyes; then
788           echo '#include <values.h>' >> $outfile
789         fi
790         if test x$g_mutex_header_file != x; then
791           echo '#include <'"$g_mutex_header_file"'>' >> $outfile
792         fi
793         if test x$glib_sys_poll_h = xyes; then
794           echo '#define GLIB_HAVE_SYS_POLL_H' >> $outfile
795         fi
796
797         cat >> $outfile <<_______EOF
798
799 #define G_MINFLOAT      $glib_mf
800 #define G_MAXFLOAT      $glib_Mf
801 #define G_MINDOUBLE     $glib_md
802 #define G_MAXDOUBLE     $glib_Md
803 #define G_MINSHORT      $glib_ms
804 #define G_MAXSHORT      $glib_Ms
805 #define G_MININT        $glib_mi
806 #define G_MAXINT        $glib_Mi
807 #define G_MINLONG       $glib_ml
808 #define G_MAXLONG       $glib_Ml
809
810 _______EOF
811
812
813         ### this should always be true in a modern C/C++ compiler
814         cat >>$outfile <<_______EOF
815 typedef signed char gint8;
816 typedef unsigned char guint8;
817 _______EOF
818
819
820         if test -n "$gint16"; then
821           cat >>$outfile <<_______EOF
822 typedef signed $gint16 gint16;
823 typedef unsigned $gint16 guint16;
824 _______EOF
825         fi
826
827
828         if test -n "$gint32"; then
829           cat >>$outfile <<_______EOF
830 typedef signed $gint32 gint32;
831 typedef unsigned $gint32 guint32;
832 _______EOF
833         fi 
834
835
836         if test -n "$gint64"; then
837           cat >>$outfile <<_______EOF
838 ${glib_warning_guard}#define G_HAVE_GINT64 1
839
840 ${glib_extension}typedef signed $gint64 gint64;
841 ${glib_extension}typedef unsigned $gint64 guint64;
842
843 #define G_GINT64_CONSTANT(val)  $gint64_constant
844 _______EOF
845         fi 
846
847         
848         if test -z "$glib_unknown_void_p"; then
849           cat >>$outfile <<_______EOF
850
851 #define GPOINTER_TO_INT(p)      ((gint)  ${glib_gpi_cast} (p))
852 #define GPOINTER_TO_UINT(p)     ((guint) ${glib_gpui_cast} (p))
853
854 #define GINT_TO_POINTER(i)      ((gpointer) ${glib_gpi_cast} (i))
855 #define GUINT_TO_POINTER(u)     ((gpointer) ${glib_gpui_cast} (u))
856 _______EOF
857         else
858           echo '#error SIZEOF_VOID_P unknown - This should never happen' >>$outfile
859         fi
860
861
862
863         cat >>$outfile <<_______EOF
864 $glib_atexit
865 $glib_memmove
866 $glib_defines
867
868 $glib_vacopy
869
870 #ifdef  __cplusplus
871 #define G_HAVE_INLINE   1
872 #else   /* !__cplusplus */
873 $glib_inline
874 #endif  /* !__cplusplus */
875 _______EOF
876
877         echo >>$outfile
878         if test x$g_mutex_has_default = xyes; then
879                 cat >>$outfile <<_______EOF
880 $g_enable_threads_def G_THREADS_ENABLED
881 #define G_THREADS_IMPL_$g_threads_impl_def
882 typedef struct _GStaticMutex GStaticMutex;
883 struct _GStaticMutex
884 {
885   struct _GMutex *runtime_mutex;
886   union {
887     char   pad[$g_mutex_sizeof];
888     double dummy_double;
889     void  *dummy_pointer;
890     long   dummy_long;
891   } aligned_pad_u;
892 };
893 #define G_STATIC_MUTEX_INIT     { NULL, { { $g_mutex_contents} } }
894 #define g_static_mutex_get_mutex(mutex) \
895   (g_thread_use_default_impl ? ((GMutex*) &(mutex).aligned_pad_u) : \
896    g_static_mutex_get_mutex_impl (&(mutex).runtime_mutex))
897 _______EOF
898         else
899                 cat >>$outfile <<_______EOF
900 $g_enable_threads_def G_THREADS_ENABLED
901 #define $g_threads_impl_def
902 typedef struct _GMutex* GStaticMutex;
903 #define G_STATIC_MUTEX_INIT NULL
904 #define g_static_mutex_get_mutex(mutex) (g_static_mutex_get_mutex_impl (&(mutex)))
905 _______EOF
906         fi
907         
908         echo >>$outfile
909         g_bit_sizes="16 32"
910         if test -n "$gint64"; then
911           g_bit_sizes="$g_bit_sizes 64"
912         fi
913         for bits in $g_bit_sizes; do
914           cat >>$outfile <<_______EOF
915 #define GINT${bits}_TO_${g_bs_native}(val)      ((gint${bits}) (val))
916 #define GUINT${bits}_TO_${g_bs_native}(val)     ((guint${bits}) (val))
917 #define GINT${bits}_TO_${g_bs_alien}(val)       ((gint${bits}) GUINT${bits}_SWAP_LE_BE (val))
918 #define GUINT${bits}_TO_${g_bs_alien}(val)      (GUINT${bits}_SWAP_LE_BE (val))
919 _______EOF
920         done
921
922         cat >>$outfile <<_______EOF
923 #define GLONG_TO_LE(val)        ((glong) GINT${glongbits}_TO_LE (val))
924 #define GULONG_TO_LE(val)       ((gulong) GUINT${glongbits}_TO_LE (val))
925 #define GLONG_TO_BE(val)        ((glong) GINT${glongbits}_TO_BE (val))
926 #define GULONG_TO_BE(val)       ((gulong) GUINT${glongbits}_TO_BE (val))
927 #define GINT_TO_LE(val)         ((gint) GINT${gintbits}_TO_LE (val))
928 #define GUINT_TO_LE(val)        ((guint) GUINT${gintbits}_TO_LE (val))
929 #define GINT_TO_BE(val)         ((gint) GINT${gintbits}_TO_BE (val))
930 #define GUINT_TO_BE(val)        ((guint) GUINT${gintbits}_TO_BE (val))
931 #define G_BYTE_ORDER $g_byte_order
932
933 _______EOF
934
935         if test -r glibconfig-sysdefs.h; then
936           cat glibconfig-sysdefs.h >>$outfile
937         fi
938         
939         
940         cat >>$outfile <<_______EOF
941
942 $glib_wc
943
944
945 #ifdef __cplusplus
946 }
947 #endif /* __cplusplus */
948
949 #endif /* GLIBCONFIG_H */
950 _______EOF
951
952
953         if cmp -s $outfile glibconfig.h; then
954           echo glibconfig.h is unchanged
955           rm -f $outfile
956         else
957           mv $outfile glibconfig.h
958         fi ;;
959 esac
960 ],[
961
962 # Note that if two cases are the same, case goes with the first one.
963 # Note also that this is inside an AC_OUTPUT_COMMAND.  We do not depend
964 # on variable expansion in case labels.  Look at the generated config.status
965 # for a hint.
966
967 case xyes in
968 x$ac_cv_header_float_h)
969   glib_float_h=yes
970   glib_mf=FLT_MIN glib_Mf=FLT_MAX
971   glib_md=DBL_MIN glib_Md=DBL_MAX
972   ;;
973 x$ac_cv_header_values_h)
974   glib_values_h=yes
975   glib_mf=MINFLOAT  glib_Mf=MAXFLOAT
976   glib_md=MINDOUBLE glib_Md=MAXDOUBLE
977   ;;
978 esac
979
980 case xyes in
981 x$ac_cv_header_limits_h)
982   glib_limits_h=yes
983   glib_ms=SHRT_MIN glib_Ms=SHRT_MAX
984   glib_mi=INT_MIN  glib_Mi=INT_MAX
985   glib_ml=LONG_MIN glib_Ml=LONG_MAX
986   ;;
987 x$ac_cv_header_values_h)
988   glib_values_h=yes
989   glib_ms=MINSHORT glib_Ms=MAXSHORT
990   glib_mi=MININT   glib_Mi=MAXINT
991   glib_ml=MINLONG  glib_Ml=MAXLONG
992   ;;
993 esac
994
995 if test x$ac_cv_header_sys_poll_h = xyes ; then
996   glib_sys_poll_h=yes
997 fi
998
999 case 2 in
1000 $ac_cv_sizeof_short)            gint16=short;;
1001 $ac_cv_sizeof_int)              gint16=int;;
1002 esac
1003 case 4 in
1004 $ac_cv_sizeof_short)            gint32=short;;
1005 $ac_cv_sizeof_int)              gint32=int;;
1006 $ac_cv_sizeof_long)             gint32=long;;
1007 esac
1008 case 8 in
1009 $ac_cv_sizeof_int)
1010   gint64=int
1011   glib_extension=
1012   glib_warning_guard=
1013   gint64_constant='(val)'
1014   ;;
1015 $ac_cv_sizeof_long)
1016   gint64=long
1017   glib_extension=
1018   glib_warning_guard=
1019   gint64_constant='(val##L)'
1020   ;;
1021 $ac_cv_sizeof_long_long)
1022   gint64='long long'
1023   glib_extension='G_GNUC_EXTENSION '
1024   glib_warning_guard="
1025 #if defined (__GNUC__) && __GNUC__ >= 2 && __GNUC_MINOR__ >= 8
1026 #  define G_GNUC_EXTENSION __extension__
1027 #else
1028 #  define G_GNUC_EXTENSION
1029 #endif
1030
1031 "
1032   gint64_constant='(G_GNUC_EXTENSION (val##LL))'
1033   ;;
1034 esac
1035
1036 gintbits=`expr $ac_cv_sizeof_int \* 8`
1037 glongbits=`expr $ac_cv_sizeof_long \* 8`
1038
1039
1040 case $ac_cv_sizeof_void_p in
1041 $ac_cv_sizeof_int)      glib_gpi_cast=''        glib_gpui_cast=''         ;;
1042 $ac_cv_sizeof_long)     glib_gpi_cast='(glong)' glib_gpui_cast='(gulong)' ;;
1043 *)                      glib_unknown_void_p=yes ;;
1044 esac
1045
1046
1047 case xyes in
1048 x$ac_cv_func_atexit)
1049   glib_atexit="
1050 #ifdef NeXT /* @#%@! NeXTStep */
1051 # define g_ATEXIT(proc) (!atexit (proc))
1052 #else
1053 # define g_ATEXIT(proc) (atexit (proc))
1054 #endif"
1055   ;;
1056 x$ac_cv_func_on_exit)
1057   glib_atexit="
1058 #define g_ATEXIT(proc)  (on_exit ((void (*)(int, void*))(proc), NULL))"
1059   ;;
1060 esac
1061
1062 case xyes in
1063 x$ac_cv_func_memmove)
1064   glib_memmove='
1065 #define g_memmove(d,s,n) G_STMT_START { memmove ((d), (s), (n)); } G_STMT_END'
1066   ;;
1067 *)
1068   glib_memmove="
1069 /* We make the assumption that if memmove isn't available, then
1070  * bcopy will do the job. This isn't safe everywhere. (bcopy can't
1071  * necessarily handle overlapping copies) */
1072 #define g_memmove(d,s,n) G_STMT_START { bcopy ((s), (d), (n)); } G_STMT_END"
1073   ;;
1074 esac
1075
1076 glib_defines="
1077 #define GLIB_MAJOR_VERSION $GLIB_MAJOR_VERSION
1078 #define GLIB_MINOR_VERSION $GLIB_MINOR_VERSION
1079 #define GLIB_MICRO_VERSION $GLIB_MICRO_VERSION
1080 "
1081
1082 case xyes in
1083 x$glib_cv_va_copy)      glib_vacopy='#define G_VA_COPY  va_copy' ;;
1084 x$glib_cv___va_copy)    glib_vacopy='#define G_VA_COPY  __va_copy' ;;
1085 *)                      glib_vacopy=''
1086 esac
1087
1088 if test x$glib_cv_va_val_copy = xno; then
1089   glib_vacopy="\$glib_vacopy
1090 #define G_VA_COPY_AS_ARRAY 1"
1091 fi
1092
1093 if test x$glib_cv_hasinline = xyes; then
1094     glib_inline='#define G_HAVE_INLINE 1'
1095 fi
1096 if test x$glib_cv_has__inline = xyes; then
1097     glib_inline="\$glib_inline
1098 #define G_HAVE___INLINE 1"
1099 fi
1100 if test x$glib_cv_has__inline__ = xyes; then
1101     glib_inline="\$glib_inline
1102 #define G_HAVE___INLINE__ 1"
1103 fi
1104
1105 case xyes in
1106 x$ac_cv_c_bigendian)
1107   g_byte_order=G_BIG_ENDIAN
1108   g_bs_native=BE
1109   g_bs_alien=LE
1110   ;;
1111 *)
1112   g_byte_order=G_LITTLE_ENDIAN
1113   g_bs_native=LE
1114   g_bs_alien=BE
1115   ;;
1116 esac
1117
1118 if test x$glib_wchar_h = xyes; then
1119   glib_wc='
1120 #define G_HAVE_WCHAR_H 1'
1121 fi
1122 if test x$glib_wctype_h = xyes; then
1123   glib_wc="\$glib_wc
1124 #define G_HAVE_WCTYPE_H 1"
1125 fi
1126 if test x$glib_working_wctype = xno; then
1127   glib_wc="\$glib_wc
1128 #define G_HAVE_BROKEN_WCTYPE 1"
1129 fi
1130
1131 case x$enable_threads in
1132 xyes)   g_enable_threads_def="#define";;
1133 *)      g_enable_threads_def="#undef ";;
1134 esac
1135
1136 g_threads_impl_def=$g_threads_impl
1137
1138 g_mutex_has_default="$mutex_has_default"
1139 g_mutex_sizeof="$glib_cv_sizeof_gmutex"
1140 g_mutex_contents="$glib_cv_byte_contents_gmutex"
1141 ])
1142
1143 AC_OUTPUT([
1144 Makefile
1145 glib-config
1146 gmodule/gmoduleconf.h
1147 gmodule/Makefile
1148 gthread/Makefile
1149 docs/Makefile
1150 tests/Makefile
1151 ],[case "$CONFIG_FILES" in
1152 *glib-config*)chmod +x glib-config;;
1153 esac])