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