cross compiling glib-2.0
- From: Johannes Stezenbach <js convergence de>
- To: gtk-devel-list gnome org
- Cc: Owen Taylor <otaylor redhat com>
- Subject: cross compiling glib-2.0
- Date: Wed, 15 May 2002 19:49:36 +0200
Hi,
the attached patch fixes exisiting problems with cross compilation
of glib-2.0. It is similar to what Dan Kegel posted here
about a month ago, but not the same because I started working on it
before I stumbled over Dan's patch:
http://mail.gnome.org/archives/gtk-devel-list/2002-April/msg00025.html
Notes:
- there's a check for "DU4 native cc currently needs -std1 for ANSI mode"
which maybe could be replaced by AC_PROG_CC_STDC
(BTW: gtk+ has the same problem)
- the checks for the pthread libraries and options use AC_MSG_CHECKING
with in a for loop which is now wrapped in AC_CACHE_CHECK; this
causes some pretty ugly configure output. Any ideas how to improve
this?
- I added a hack for creating glibconfig-sysdefs.h (POLL* #defines)
which is cross-compiler friedly but only works with gcc
(it uses the -dM option of the GNU preprocessor to dump macro
definitions.) It is possible to override this by supplying a manually
written glibconfig-sysdefs.h. Dan Kegel had a different version of
this hack in his patch.
- indentation of configure.in is already a mess, and I just added
some more to it ;-(
- I hope I haven't broken anything for native builds
To actually cross compile you need to supply a suitable config.cache
with correct values for the host platform (example attached), and
call configure like this:
CC=mips-linux-gcc ./autogen.sh --host=mips-linux \
--cache-file=config.cache --prefix=/mips/usr
If there are any remaining issues with this patch I would like to
resolve them so that it could be comitted to CVS.
Regards,
Johannes
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 ***
ac_cv_sizeof_char=${ac_cv_sizeof_char=1}
ac_cv_sizeof_short=${ac_cv_sizeof_short=2}
ac_cv_sizeof_long=${ac_cv_sizeof_long=4}
ac_cv_sizeof_int=${ac_cv_sizeof_int=4}
ac_cv_sizeof_long_long=${ac_cv_sizeof_long_long=8}
ac_cv_sizeof___int64=${ac_cv_sizeof___int64=0}
ac_cv_sizeof_void_p=${ac_cv_sizeof_void_p=4}
glib_cv_sizeof_size_t=${glib_cv_sizeof_size_t=4}
glib_cv_sizeof_ptrdiff_t=${glib_cv_sizeof_ptrdiff_t=4}
glib_cv_sizeof_intmax_t=${glib_cv_sizeof_intmax_t=8}
glib_cv_sizeof_system_thread=${glib_cv_sizeof_system_thread=4}
glib_cv_sizeof_gmutex=${glib_cv_sizeof_gmutex=24}
glib_cv_long_long_format=${glib_cv_long_long_format=ll}
glib_cv_has__inline=${glib_cv_has__inline=yes}
glib_cv_has__inline__=${glib_cv_has__inline__=yes}
glib_cv_hasinline=${glib_cv_long_hasinline=yes}
glib_cv_sane_realloc=${glib_cv_sane_realloc=yes}
glib_cv_va_copy=${glib_cv_long_va_copy=no}
glib_cv___va_copy=${glib_cv___va_copy=yes}
glib_cv_va_val_copy=${glib_cv_va_val_copy=yes}
glib_cv_rtldglobal_broken=${glib_cv_rtldglobal_broken=no}
glib_cv_uscore=${glib_cv_uscore=no}
glib_cv_stack_grows=${glib_cv_stack_grows=no}
ac_cv_func_posix_getpwuid_r=${ac_cv_func_posix_getpwuid_r=yes}
glib_cv_ansi_extra_flags=${glib_cv_ansi_extra_flags=}
glib_cv_thread_lib=${glib_cv_thread_lib=-lpthread}
glib_cv_sched_get_priority_min_lib=${glib_cv_sched_get_priority_min_lib=-lpthread}
glib_cv_g_thread_use_pid_surrogate=${glib_cv_g_thread_use_pid_surrogate=yes}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]