Include a printf implementation supporting C99 snprintf and SUS
[platform/upstream/glib.git] / configure.in
index 0e79180..65a6fc9 100644 (file)
@@ -32,10 +32,10 @@ GLIB_AC_DIVERT_BEFORE_HELP([
 # set GLIB_BINARY_AGE _and_ GLIB_INTERFACE_AGE to 0.
 #
 GLIB_MAJOR_VERSION=2
-GLIB_MINOR_VERSION=0
+GLIB_MINOR_VERSION=1
 GLIB_MICRO_VERSION=3
-GLIB_INTERFACE_AGE=3
-GLIB_BINARY_AGE=3
+GLIB_INTERFACE_AGE=0
+GLIB_BINARY_AGE=`expr 100 '*' $GLIB_MINOR_VERSION + $GLIB_MICRO_VERSION`
 GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION
 ])dnl
 
@@ -48,7 +48,7 @@ AC_SUBST(GLIB_BINARY_AGE)
 
 # libtool versioning
 LT_RELEASE=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION
-LT_CURRENT=`expr $GLIB_MICRO_VERSION - $GLIB_INTERFACE_AGE`
+LT_CURRENT=`expr 100 '*' $GLIB_MINOR_VERSION + $GLIB_MICRO_VERSION - $GLIB_INTERFACE_AGE`
 LT_REVISION=$GLIB_INTERFACE_AGE
 LT_AGE=`expr $GLIB_BINARY_AGE - $GLIB_INTERFACE_AGE`
 LT_CURRENT_MINUS_AGE=`expr $LT_CURRENT - $LT_AGE`
@@ -206,10 +206,10 @@ if test x$PKG_CONFIG = xno ; then
   AC_MSG_ERROR([*** pkg-config not found. See http://www.freedesktop.org/software/pkgconfig/])
 fi
 
-if $PKG_CONFIG --atleast-pkgconfig-version 0.5 ; then
+if $PKG_CONFIG --atleast-pkgconfig-version 0.14 ; then
   :
 else
-  AC_MSG_ERROR([*** pkg-config too old; version 0.5 or better required.])
+  AC_MSG_ERROR([*** pkg-config too old; version 0.14 or better required.])
 fi
 
 if test "x$enable_debug" = "xyes"; then
@@ -222,18 +222,45 @@ if test "x$enable_debug" = "xyes"; then
        
   GLIB_DEBUG_FLAGS="-DG_ENABLE_DEBUG"
 else
+  GLIB_DEBUG_FLAGS="-DG_DISABLE_CAST_CHECKS"
+
   if test "x$enable_debug" = "xno"; then
-    GLIB_DEBUG_FLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
+    GLIB_DEBUG_FLAGS="$GLIB_DEBUG_FLAGS -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
   fi
 fi
 
-# Ensure -fnative-struct is used when compiling for Win32
-if test "x$glib_native_win32" = "xyes"; then
-  if test "x$GCC" = "xyes"; then
-    case " $CFLAGS " in
-    *[[\ \     ]]-fnative-struct[[\ \  ]]*) ;;
-    *) CFLAGS="$CFLAGS -fnative-struct" ;;
+# Ensure MSVC-compatible struct packing convention is used when
+# compiling for Win32 with gcc.
+# What flag to depends on gcc version: gcc3 uses "-mms-bitfields", while
+# gcc2 uses "-fnative-struct".
+if test x"$glib_native_win32" = xyes; then
+  if test x"$GCC" = xyes; then
+    msnative_struct=''
+    AC_MSG_CHECKING([how to get MSVC-compatible struct packing])
+    if test -z "$ac_cv_prog_CC"; then
+      our_gcc="$CC"
+    else
+      our_gcc="$ac_cv_prog_CC"
+    fi
+    case `$our_gcc --version | sed -e 's,\..*,.,' -e q` in
+      2.)
+       if $our_gcc -v --help 2>/dev/null | grep fnative-struct >/dev/null; then
+         msnative_struct='-fnative-struct'
+       fi
+       ;;
+      *)
+       if $our_gcc -v --help 2>/dev/null | grep ms-bitfields >/dev/null; then
+         msnative_struct='-mms-bitfields'
+       fi
+       ;;
     esac
+    if test x"$msnative_struct" = x ; then
+      AC_MSG_RESULT([no way])
+      AC_MSG_WARN([produced libraries might be incompatible with MSVC-compiled code])
+    else
+      CFLAGS="$CFLAGS $msnative_struct"
+      AC_MSG_RESULT([${msnative_struct}])
+    fi
   fi
 fi
 
@@ -305,7 +332,7 @@ dnl
 dnl gettext support
 dnl
 
-ALL_LINGUAS="az ca cs de el es eu fr gl hi ja ko ms nl nn no pl pt ro ru sk sl sv ta tr uk vi zh_CN zh_TW"
+ALL_LINGUAS="az be bg ca cs de el es eu fr gl hi ja ko ms nl nn no pl pt pt_BR ro ru sk sl sq sv ta tr uk vi zh_CN zh_TW"
 AM_GLIB_GNU_GETTEXT
 
 if test "$gt_cv_func_dgettext_libc" = "yes" || test "$gt_cv_func_dgettext_libintl" = "yes"; then
@@ -685,6 +712,32 @@ AC_MSG_RESULT(unsigned $glib_size_type)
 AC_CHECK_FUNCS(lstat strerror strsignal memmove mkstemp vsnprintf stpcpy strcasecmp strncasecmp poll getcwd nanosleep vasprintf unsetenv getc_unlocked)
 
 AC_FUNC_VSNPRINTF_C99
+AC_FUNC_PRINTF_UNIX98
+
+#
+# Check whether to use trio printf
+#
+
+AC_ARG_ENABLE(included-printf, [  --enable-included-printf    use included printf [default=auto]], enable_trio="$enableval")
+
+if test "$enable_trio" != "no" ; then
+  if test "$ac_cv_func_vsnprintf_c99" != "yes" ; then
+    enable_trio = yes
+  fi
+  if test "$ac_cv_func_printf_unix98" != "yes" ; then
+    enable_trio = yes
+  fi
+fi
+
+AM_CONDITIONAL(HAVE_GOOD_PRINTF, test "$enable_trio" != "yes")
+if test "$enable_trio" != "yes" ; then 
+  AC_DEFINE(HAVE_GOOD_PRINTF,1,[define to use system printf])
+  AC_DEFINE(HAVE_VASPRINTF,1)
+  AC_DEFINE(HAVE_C99_VSNPRINTF,1)
+  AC_DEFINE(HAVE_UNIX98_PRINTF,1)
+else
+  AC_DEFINE(HAVE_GOOD_PRINTF,0)
+fi
 
 # Check if bcopy can be used for overlapping copies, if memmove isn't found.
 # The check is borrowed from the PERL Configure script.
@@ -890,7 +943,12 @@ dnl ***********************
 G_MODULE_LIBS=
 G_MODULE_LIBS_EXTRA=
 G_MODULE_PLUGIN_LIBS=
-G_MODULE_LDFLAGS=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
+if test x"$glib_native_win32" = xyes; then
+  dnl No use for this on Win32
+  G_MODULE_LDFLAGS=
+else
+  G_MODULE_LDFLAGS=`(./libtool --config; echo eval echo \\$export_dynamic_flag_spec) | sh`
+fi
 dnl G_MODULE_IMPL= don't reset, so cmd-line can override
 G_MODULE_NEED_USCORE=0
 G_MODULE_BROKEN_RTLD_GLOBAL=0
@@ -1163,6 +1221,12 @@ POSIX_NO_PRIORITIES="I can not find the minimal and maximal priorities for
                priority. If you happen to know these main/max
                priorities, please inform the GLib developers."
 
+AIX_COMPILE_INFO="AIX's C compiler needs to be called by a different name, when
+               linking threaded applications. As GLib cannot do that 
+               automatically, you will get an linkg error everytime you are 
+               not using the right compiler. In that case you have to relink 
+               with the right compiler. Ususally just '_r' is appended 
+               to the compiler name."
 
 dnl determination of thread implementation
 dnl ***************************************
@@ -1187,12 +1251,13 @@ if test "x$want_threads" = xyes || test "x$want_threads" = xposix \
        CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
         if test "x$have_threads" = xno; then
                 AC_TRY_COMPILE([#include <pthread.h>],
-                       [pthread_attr_t attr; pthread_attr_init(&attr);],
+                       [pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;],
                        have_threads=posix)
         fi
         if test "x$have_threads" = xno; then
                 AC_TRY_COMPILE([#include <pthread.h>],
-                       [pthread_attr_t attr; pthread_attr_create(&attr);],
+                       [pthread_mutex_t m; 
+                         pthread_mutex_init (&m, pthread_mutexattr_default);],
                        have_threads=dce)
         fi
        CPPFLAGS="$glib_save_CPPFLAGS"
@@ -1227,37 +1292,83 @@ G_THREAD_CFLAGS=
 
 if test x"$have_threads" != xno; then
 
-    G_THREAD_CFLAGS="-D_REENTRANT" # good default guess
+  if test x"$have_threads" = xposix; then
+    # First we test for posix, whether -pthread or -pthreads do the trick as 
+    # both CPPFLAG and LIBS. 
+    # One of them does for most gcc versions and some other platforms/compilers
+    # too and could be considered as the canonical way to go. 
+    for flag in pthread pthreads; do
+      glib_save_CFLAGS="$CFLAGS"
+      CFLAGS="$CFLAGS -$flag"
+      AC_TRY_RUN([#include <pthread.h> 
+                 int check_me = 0;
+                 void* func(void* data) {return check_me = 42;}
+                 main()
+                 { pthread_t t; 
+                   void *ret;
+                   pthread_create (&t, 0, func, 0);
+                   pthread_join (t, &ret);
+                   exit (check_me != 42 || ret != 42);
+                  }],
+                  [G_THREAD_CFLAGS=-$flag
+                   G_THREAD_LIBS=-$flag])
+      CFLAGS="$glib_save_CFLAGS"
+    done
+  fi
+
+  if test x"$G_THREAD_CFLAGS" = x; then
+
+    # The canonical -pthread[s] does not work. Try something different.
 
     case $host in
        *-aix*)
-               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -D_THREAD_SAFE"
                if test x"$GCC" = xyes; then
-                       # GCC 3.0 and above needs -pthread
+                       # GCC 3.0 and above needs -pthread. 
+                       # Should be coverd by the case above.
                        # GCC 2.x and below needs -mthreads
-                       AC_TRY_COMPILE(,[#if __GNUC__ <= 2
-                                       bail out here
-                                       #endif],
-                               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -pthread", 
-                               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -mthreads")
+                       G_THREAD_CFLAGS="-mthreads"             
+                       G_THREAD_LIBS=$G_THREAD_CFLAGS
+               else 
+                       # We are probably using the aix compiler. Normaly a 
+                       # program would have to be compiled with the _r variant
+                       # of the corresponding compiler, but we as GLib cannot 
+                       # do that: but the good news is that for compiling the
+                       # only difference is the added -D_THREAD_SAFE compile 
+                       # option. This is according to the "C for AIX User's 
+                       # Guide".
+                       G_THREAD_CFLAGS="-D_THREAD_SAFE"
                fi
                ;;
-       *-freebsd2.2*)
-               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -D_THREAD_SAFE"
-
-               # FreeBSD 2.2.x shiped with gcc 2.7.2.x, which doesn't support
-               # -mthreads flag.
-               ;;      
-       *-sysv5uw7*)  # UnixWare 7 
-               if test "$GCC" != "yes"; then
-                               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -Kthread"
-               else    
-                       G_THREAD_CFLAGS="$G_THREAD_CFLAGS -pthread"
-               fi      
-               ;;
        *-dg-dgux*)  # DG/UX
-               G_THREAD_CFLAGS="$G_THREAD_CFLAGS -D_POSIX4A_DRAFT10_SOURCE"
+               G_THREAD_CFLAGS="-D_REENTRANT -D_POSIX4A_DRAFT10_SOURCE"
+               ;;
+       *-osf*)
+               # So we are using dce threads. posix threads are already 
+               # catched above.
+               G_THREAD_CFLAGS="-threads"
+               G_THREAD_LIBS=$G_THREAD_CFLAGS
+               ;;
+       *-solaris*)
+               if test x"$GCC" = xyes; then
+                  # We are using solaris threads. posix threads are 
+                  # already catched above.
+                       G_THREAD_CFLAGS="-threads"
+               else
+                       G_THREAD_CFLAGS="-mt"
+               fi
+               G_THREAD_LIBS=$G_THREAD_CFLAGS
+               ;;
+       *-sysv5uw7*) # UnixWare 7 
+               # We are not using gcc with -pthread. Catched above.
+               G_THREAD_CFLAGS="-Kthread"
+               G_THREAD_LIBS=$G_THREAD_CFLAGS
+               ;;
+       *)
+               G_THREAD_CFLAGS="-D_REENTRANT" # good default guess otherwise
+               ;;
     esac
+  fi
 
     # if we are not finding the localtime_r function, then we probably are
     # not using the proper multithread flag
@@ -1289,25 +1400,19 @@ dnl ******************************
 mutex_has_default=no
 case $have_threads in
         posix|dce)
-          glib_save_CPPFLAGS="$CPPFLAGS"
-          CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
-           G_THREAD_LIBS=error
-          glib_save_LIBS="$LIBS"
-          case $host in
-            *-sysv5uw7*) # UnixWare 7 
-               if test "$GCC" != "yes"; then
-                               G_THREAD_LIBS="-Kthread"
-               else    
-                       G_THREAD_LIBS="-pthread"
-               fi      
-               ;;
-            *-*-openbsd* | *-*-freebsd*) 
-               # FreeBSD and OpenBSD want us to use the -pthread flag 
-                # instead of linking to -lc_r and libtool enforces that.
-               G_THREAD_LIBS="-pthread"
-               ;;
-             *)
-               for thread_lib in "" pthread pthread32 pthreads thread dce; do
+          if test x"$G_THREAD_LIBS" = x; then
+            case $host in
+              *-aix*)
+                # We are not using gcc (would have set G_THREAD_LIBS) and thus 
+                # probably using the aix compiler.
+               AC_MSG_WARN($AIX_COMPILE_INFO)
+                ;;
+              *)
+               glib_save_CPPFLAGS="$CPPFLAGS"
+               CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
+                G_THREAD_LIBS=error
+               glib_save_LIBS="$LIBS"
+               for thread_lib in "" pthread pthread32 pthreads thread dce; do
                        if test x"$thread_lib" = x; then
                                add_thread_lib=""
                                IN=""
@@ -1339,52 +1444,54 @@ case $have_threads in
                                break],
                                [AC_MSG_RESULT(no)])
                done
+               if test "x$G_THREAD_LIBS" = xerror; then
+                 AC_MSG_ERROR($LIBS_NOT_FOUND_1$have_threads$LIBS_NOT_FOUND_2)
+               fi 
+               LIBS="$glib_save_LIBS"
                 ;;
-          esac         
-          if test "x$G_THREAD_LIBS" = xerror; then
-             AC_MSG_ERROR($LIBS_NOT_FOUND_1$have_threads$LIBS_NOT_FOUND_2)
-          fi
-          for thread_lib in "" rt rte; do
-            if test x"$thread_lib" = x; then
-              add_thread_lib=""
-              IN=""
-            else
-              add_thread_lib="-l$thread_lib"
-              IN=" in -l$thread_lib"
-            fi
-            LIBS="$glib_save_LIBS $add_thread_lib"
-                       
-            AC_MSG_CHECKING(for sched_get_priority_min$IN)
-            AC_TRY_RUN([#include <sched.h>
-                        #include <errno.h>
-                        int main() {
-                        errno = 0;
-                         return sched_get_priority_min(SCHED_OTHER)==-1
-                               && errno != 0;}],
-                       [AC_MSG_RESULT(yes)
-                        G_THREAD_LIBS="$G_THREAD_LIBS $add_thread_lib"
+            esac
+          fi
+
+          glib_save_LIBS="$LIBS"
+         for thread_lib in "" rt rte; do
+           if test x"$thread_lib" = x; then
+             add_thread_lib=""
+             IN=""
+           else
+             add_thread_lib="-l$thread_lib"
+             IN=" in -l$thread_lib"
+           fi
+           LIBS="$glib_save_LIBS $add_thread_lib"
+       
+            AC_MSG_CHECKING(for sched_get_priority_min$IN)
+           AC_TRY_RUN([#include <sched.h>
+                       #include <errno.h>
+                       int main() {
+                         errno = 0;
+                          return sched_get_priority_min(SCHED_OTHER)==-1
+                               && errno != 0;}],
+                       [AC_MSG_RESULT(yes)
+                        G_THREAD_LIBS="$G_THREAD_LIBS $add_thread_lib"
                         posix_priority_min="sched_get_priority_min(SCHED_OTHER)"
                         posix_priority_max="sched_get_priority_max(SCHED_OTHER)"
                         break],
                        [AC_MSG_RESULT(no)])
-          done
-          LIBS="$glib_save_LIBS"
-           mutex_has_default=yes
-           mutex_default_type='pthread_mutex_t'
-           mutex_default_init='PTHREAD_MUTEX_INITIALIZER'
-           mutex_header_file='pthread.h'
-          if test "x$have_threads" = "xposix"; then
-            g_threads_impl="POSIX"
-          else
-            g_threads_impl="DCE"
-            have_threads="posix"
-          fi
-          AC_SUBST(GTHREAD_COMPILE_IMPL_DEFINES)
-           CPPFLAGS="$glib_save_CPPFLAGS"
-           ;;
+         done
+         LIBS="$glib_save_LIBS"
+          mutex_has_default=yes
+          mutex_default_type='pthread_mutex_t'
+          mutex_default_init='PTHREAD_MUTEX_INITIALIZER'
+          mutex_header_file='pthread.h'
+         if test "x$have_threads" = "xposix"; then
+           g_threads_impl="POSIX"
+         else
+           g_threads_impl="DCE"
+           have_threads="posix"
+         fi
+         AC_SUBST(GTHREAD_COMPILE_IMPL_DEFINES)
+          CPPFLAGS="$glib_save_CPPFLAGS"
+          ;;
         solaris)
-          G_THREAD_LIBS=error
-           AC_CHECK_LIB(thread, cond_init, G_THREAD_LIBS="-lthread")
            mutex_has_default=yes
            mutex_default_type='mutex_t'
           mutex_default_init="DEFAULTMUTEX"
@@ -1393,7 +1500,6 @@ case $have_threads in
            ;;
        win32)
           g_threads_impl="WIN32"
-          G_THREAD_LIBS=""
           ;;
         none|no)
           g_threads_impl="NONE"
@@ -1479,13 +1585,20 @@ if test x"$have_threads" != xno; then
                                  [Have function pthread_attr_setstacksize])],
                        [AC_MSG_RESULT(no)])
                AC_MSG_CHECKING(for minimal/maximal thread priority)
-               if test x"$posix_priority_min" = xnone; then
+               if test x"$posix_priority_min" = x; then
                        AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
                                PX_PRIO_MIN],,[
                                posix_priority_min=PX_PRIO_MIN
                                posix_priority_max=PX_PRIO_MAX])
                fi
-               if test x"$posix_priority_min" = xnone; then
+               if test x"$posix_priority_min" = x; then
+                       # AIX
+                       AC_EGREP_CPP(PTHREAD_PRIO_MIN,[#include <pthread.h>
+                               PTHREAD_PRIO_MIN],,[
+                               posix_priority_min=PTHREAD_PRIO_MIN
+                               posix_priority_max=PTHREAD_PRIO_MIN])
+               fi
+               if test x"$posix_priority_min" = x; then
                        AC_EGREP_CPP(PRI_OTHER_MIN,[#include <pthread.h>
                                PRI_OTHER_MIN],,[
                                posix_priority_min=PRI_OTHER_MIN        
@@ -1615,7 +1728,7 @@ dnl **********************
 
 case $host in
   *-*-cygwin*)
-       G_LIBS_EXTRA="-luser32 -lwsock32 -lkernel32"
+       G_LIBS_EXTRA="-luser32 -lkernel32"
     ;;
   *-*-mingw*)
        G_LIBS_EXTRA="-lwsock32"
@@ -2268,6 +2381,7 @@ build/win32/Makefile
 build/win32/dirent/Makefile
 glib/Makefile
 glib/libcharset/Makefile
+glib/trio/Makefile
 gmodule/gmoduleconf.h
 gmodule/Makefile
 gobject/Makefile