Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.287
diff -u -r1.287 configure.in
--- configure.in	13 May 2002 15:57:25 -0000	1.287
+++ configure.in	15 May 2002 17:22:00 -0000
@@ -14,9 +14,6 @@
 # Save this value here, since automake will set cflags later
 cflags_set=${CFLAGS+set}
 
-# we rewrite this file
-rm -f glibconfig-sysdefs.h
-
 GLIB_AC_DIVERT_BEFORE_HELP([
 #
 # The following version number definitions apply to GLib, GModule, GObject 
@@ -318,24 +315,30 @@
 fi
 
 dnl DU4 native cc currently needs -std1 for ANSI mode (instead of K&R)
-AC_MSG_CHECKING([for extra flags to get ANSI library prototypes])
-glib_save_LIBS=$LIBS
-LIBS="$LIBS -lm"
-AC_TRY_RUN([#include <math.h>
-             int main (void) { return (log(1) != log(1.)); }],
-     AC_MSG_RESULT(none needed),
-     glib_save_CFLAGS=$CFLAGS
-     CFLAGS="$CFLAGS -std1"
-     AC_TRY_RUN([#include <math.h>
-                 int main (void) { return (log(1) != log(1.)); }],
-         AC_MSG_RESULT(-std1),
-         AC_MSG_RESULT()
-         CFLAGS=$glib_save_CFLAGS
-         AC_MSG_WARN(
-                [No ANSI prototypes found in library. (-std1 didn't work.)])
-     )
-)
-LIBS=$glib_save_LIBS
+dnl ??? why not use AC_PROG_CC_STDC ???
+AC_CACHE_CHECK([for extra flags to get ANSI library prototypes],
+  glib_cv_ansi_extra_flags,[
+  glib_save_LIBS=$LIBS
+  LIBS="$LIBS -lm"
+  AC_TRY_RUN([#include <math.h>
+	       int main (void) { return (log(1) != log(1.)); }],
+       glib_cv_ansi_extra_flags="",
+       glib_save_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS -std1"
+       AC_TRY_RUN([#include <math.h>
+		   int main (void) { return (log(1) != log(1.)); }],
+	   glib_cv_ansi_extra_flags="-std1",
+	   glib_cv_ansi_extra_flags=""
+	   AC_MSG_WARN(
+		  [No ANSI prototypes found in library. (-std1 didn't work.)])
+       )
+       CFLAGS=$glib_save_CFLAGS
+  )
+  LIBS=$glib_save_LIBS
+])
+if test -n "$glib_cv_ansi_extra_flags"; then
+  CFLAGS="$CFLAGS $glib_cv_ansi_extra_flags"
+fi
 
 dnl NeXTStep cc seems to need this
 AC_MSG_CHECKING([for extra flags for POSIX compliance])
@@ -1249,24 +1252,25 @@
 		G_THREAD_LIBS="-pthread"
 		;;
              *)
-		for thread_lib in "" pthread pthread32 pthreads thread dce; 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
-			if test x"$have_threads" = xposix; then
-				defattr=0
-			else
-				defattr=pthread_attr_default
-			fi
+	        AC_CACHE_CHECK([for pthread library], glib_cv_thread_lib,[
+		  for thread_lib in "" pthread pthread32 pthreads thread dce; 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
+		    if test x"$have_threads" = xposix; then
+		      defattr=0
+		    else
+		      defattr=pthread_attr_default
+		    fi
 			
-			LIBS="$glib_save_LIBS $add_thread_lib"
+		    LIBS="$glib_save_LIBS $add_thread_lib"
 			
-			AC_MSG_CHECKING(for pthread_create/pthread_join$IN)
-			AC_TRY_RUN([#include <pthread.h> 
+		    AC_MSG_CHECKING(for pthread_create/pthread_join$IN)
+		    AC_TRY_RUN([#include <pthread.h> 
 				int check_me = 0;
 				void* func(void* data) {check_me = 42;}
                                 main()
@@ -1280,36 +1284,48 @@
 				G_THREAD_LIBS="$add_thread_lib"
 				break],
 				[AC_MSG_RESULT(no)])
-		done
+		  done
+		  glib_cv_thread_lib="$G_THREAD_LIBS"
+		])
+		G_THREAD_LIBS="$glib_cv_thread_lib"
                 ;;
 	   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_CACHE_CHECK([for sched_get_priority_min],
+			       glib_cv_sched_get_priority_min_lib,[
+              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
+		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
+	      glib_cv_sched_get_priority_min_lib="$G_THREAD_LIBS"
+	   ])
+	   if test -n "$glib_cv_sched_get_priority_min_lib"; then
+	     G_THREAD_LIBS="$glib_cv_sched_get_priority_min_lib"
+	     posix_priority_min="sched_get_priority_min(SCHED_OTHER)"
+	     posix_priority_max="sched_get_priority_max(SCHED_OTHER)"
+	   fi
 	   LIBS="$glib_save_LIBS"
            mutex_has_default=yes
            mutex_default_type='pthread_mutex_t'
@@ -1463,8 +1479,9 @@
 		AC_DEFINE_UNQUOTED(POSIX_YIELD_FUNC,$posix_yield_func,[The POSIX RT yield function])
 		CPPFLAGS="$glib_save_CPPFLAGS"
 
-		AC_MSG_CHECKING(whether to use the PID niceness surrogate for thread priorities)
-		AC_TRY_RUN([#include <pthread.h> 
+		AC_CACHE_CHECK([whether to use the PID niceness surrogate for thread priorities],
+		  glib_cv_g_thread_use_pid_surrogate,[
+		  AC_TRY_RUN([#include <pthread.h> 
 			#include <sys/types.h>
 			#include <unistd.h>
 			pid_t other_pid = 0;
@@ -1479,9 +1496,14 @@
 				$posix_priority_min != $posix_priority_max);
 			}],
 			[AC_MSG_RESULT(yes)
-			  AC_DEFINE(G_THREAD_USE_PID_SURROGATE, 1, [whether to use the PID niceness surrogate for thread priorities])
+			glib_cv_g_thread_use_pid_surrogate=yes
                         ],
-			[AC_MSG_RESULT(no)])
+			[AC_MSG_RESULT(no)
+			glib_cv_g_thread_use_pid_surrogate=no])
+		  ])
+		if test "$glib_cv_g_thread_use_pid_surrogate" = "yes"; then
+		  AC_DEFINE(G_THREAD_USE_PID_SURROGATE, 1, [whether to use the PID niceness surrogate for thread priorities])
+		fi
 	elif test x"$have_threads" = xwin32; then
 		# It's a pointer to a private struct
 		GLIB_SIZEOF(,struct _GThreadData *, system_thread)
@@ -1544,12 +1566,34 @@
 dnl ****************************************
 dnl *** GLib POLL* compatibility defines ***
 dnl ****************************************
-GLIB_SYSDEFS(
-[#include <sys/types.h>
+dnl when cross compiling, you must provide a suitable glibconfig-sysdefs.h,
+dnl unless you are using gcc
+if test $cross_compiling = yes; then
+  AC_MSG_NOTICE([checking system definitions for POLLIN POLLOUT POLLPRI POLLERR POLLHUP POLLNVAL:])
+  if test -r glibconfig-sysdefs.h; then
+    AC_MSG_NOTICE([cross compiling: using exisiting glibconfig-sysdefs.h])
+  else
+    if test x$GCC = xyes; then
+      AC_MSG_NOTICE([cross compiling: using gcc hack for building glibconfig-sysdefs.h])
+      $CC -E -dM - <<__GLIBPOLLEOF | egrep 'POLL(IN|OUT|PRI|ERR|HUP|NVAL)' \
+         | sed 's/POLL\([[A-Z]]\+\) \+/GLIB_SYSDEF_POLL\1 = /' > glibconfig-sysdefs.h
+#include <sys/poll.h>
+__GLIBPOLLEOF
+    else
+      AC_MSG_ERROR([cross compiling: you must supply a suitable glibconfig-sysdefs.h])
+    fi
+  fi
+else
+  # we rewrite this file
+  rm -f glibconfig-sysdefs.h
+
+  GLIB_SYSDEFS(
+  [#include <sys/types.h>
 #include <sys/poll.h>],
 	POLLIN:1 POLLOUT:4 POLLPRI:2 POLLERR:8 POLLHUP:16 POLLNVAL:32,
 	glibconfig-sysdefs.h,
 	=)
+fi
 
 dnl **********************
 dnl *** Win32 API libs ***
