GNOME Bugzilla – Bug 77565
patch for cross-compiling glib2
Last modified: 2011-02-18 15:55:24 UTC
Here's a pair of patches that fix glib2 so it can be cross-compiled. A little background: We need to cross-compile glib2 to run on an embedded system. When cross-compiling, the standard way to get configure to work is to override any AC_TRY_RUNs by pre-setting their results in the environment. Most of the AC_TRY_RUNs in glib2's configure.in can be overridden from the environment, but a few can't, because they aren't wrapped with AC_CACHE_CHECK, which automatically checks for the appropriate environment variables. One AC_TRY_RUN that can't be fixed this way is the one in GLIB_SYSDEFS in acglib.m4, which naughtily uses AC_TRY_RUN for its side-effects. The first patch adds the missing AC_CACHE_CHECKS, and adds a more or less correct fallback for GLIB_SYSDEFS in the cross-compile case. To make it easier to verify by eye, the first patch doesn't reindent the affected areas. The second patch just reindents. We verified that this works on an sh4 processor cross-compiled from an intel machine. All regression tests pass except for the pattern test, but fixing that can wait for another day; these patches at least get glib2 to the point where you can try to use it on embedded systems.
Created attachment 7539 [details] [review] patch to fix cross-compile issues of glib2
Created attachment 7540 [details] [review] reindentation patch. (apply after 1st)
For e.g. sh4-based machines, I use the following environment variables (along with the above patches) to bypass all configure test compile/runs: export glib_cv_long_long_format=ll export glib_cv_stack_grows=no export glib_cv_has__inline__=yes export glib_cv_has__inline=yes export glib_cv_hasinline=yes export glib_cv_working_bcopy=no export glib_cv_sane_realloc=yes export glib_cv_va_copy=yes export glib_cv___va_copy=yes export glib_cv_va_val_copy=yes export glib_cv_rtldglobal_broken=yes export glib_cv_uscore=no export ac_cv_func_posix_getpwuid_r=yes export glib_cv_sizeof_size_t=4 export glib_cv_sizeof_ptrdiff_t=4 export glib_cv_sizeof_intmax_t=8 export glib_cv_sizeof_system_thread=4 export glib_cv_thread_lib=pthread export glib_cv_g_thread_use_pid_surrogate=no export glib_cv_posix_priority_min_lib="" export glib_cv_sizeof_gmutex=24 export glib_cv_ansi_flags=no
Johannes Stenzenbach created a similar patch. Quoting from his mail on gtk-devel-list: 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
Created attachment 8537 [details] [review] the patch Johannes sent to gtk-devel-list
Created attachment 8538 [details] the config.cache file Johannes sent to gtk-devel-list
In the same light I've created a patch which aims to minimize the number of AC_TRY_RUN's in order to simplify the creation of a config.cache file by reducing the number of options. I'm quite sure a lot more can be determined, for instance by slightly rewrting the local CHECK_SIZE macro to use the general autoconf tricks to determine the size of a typedef at compiletime. So far I'll attach my patch and hope we can get the stuff into CVS ASAP.
Created attachment 9875 [details] [review] The proposed patch to reduce the number of AC_TRY_RUN's
Is this work going anywhere ? Some of this work was to enable cross compilation to embedded targets like the Sharp Zarus.
*** Bug 58786 has been marked as a duplicate of this bug. ***
OK, couldn't dig up the original discussion on -std1, but as I recall it (and as seems to be plausible from some docs I dug up): AC_PROG_CC_STDC (now part of AC_PROG_CC) doesn't add -std1 unless the compiler doesn't support prototypes out of the box. However, the default 'cc' on the systems on questions does _support_ prototypes, but without the std1 flag, the header files don't have prototypes. So, -std1 doesn't get included, but the resulting code is broken because expressions like log(1) don't use the correct types when passing the arguments. As always, it's hard to tell when to remove a check like this; it may not matter for current systems (though I don't have Digital Unix around to check), GLib might not even compile on Digital Unix for other reasons... but since it isn't causing any problems, we can easily just not run it when cross compiling. I doubt the compiler in question supports cross compilation :-)
Checked in partial fix; still need to add in CACHE_CHECK/CACHE_VAL where missing. Thu Dec 5 15:24:14 2002 Owen Taylor <otaylor@redhat.com> Start of fixes for cross-compilation. Based on patches from Dimi Shahbaz, Dan Kegel, Johannes Stenzenbach, Amy Lin. (#58786) * configure.in: Don't run the Digital-Unix 4 -std1 check when cross_compiling. * configure.in: Use AC_TRY_COMPILE() rather than AC_TRY_RUN() for inline checks. (Daniel Egger) * configure.in: use AC_CHECK_SIZEOF rather than GLIB_SIZEOF for size_t. Remove unused checks for size of ptrdiff_t/intmax_t. * acglib.m4: Resync GLIB_SIZEOF of to the current AC_CHECK_SIZEOF, which handles cross-compilation. * acglib.m4: Remove no longer needed GLIB_SYSDEFS(), add GLIB_CHECK_VALUE() as a wrapper around the amazing _AC_COMPUTE_INT() autoconf 2.5x internal. * configure.in: Redo the POLL* value checks in a cross-compilation friendly way.
Should finish making GLib fully cross-compilable; I want to add some docs about doing so and cache variables to the distribution. Wed Dec 11 17:00:20 2002 Owen Taylor <otaylor@redhat.com> * acglib.m4 (ac_compile): Add GLIB_ASSERT_SET() as a helper for adding "must be set when cross-compiling" errors. * configure.in: For all cached variables without defaults, error out if they aren't set. Wed Dec 11 15:52:01 2002 Owen Taylor <otaylor@redhat.com> * configure.in: Also assume AC_LINK_IFELSE() is OK when cross-compiling for the libs checks, and for the sched_get_priority_min() check. * configure.in: Add cached value glib_cv_use_pid_surrogate. Wed Dec 11 15:10:25 2002 Owen Taylor <otaylor@redhat.com> * configure.in: Factor out repeated thread test into a m4_define(); when cross-compiling, assume that AC_LINK_IFELSE() is good enough for thinking that -pthread[s] is OK. (More of #58786) * m4macros/glib-gettext.m4: Fix typo. (Manish Singh)
Fri Dec 20 09:52:15 2002 Owen Taylor <otaylor@redhat.com> * INSTALL.in: Document --enable-trio, --disable-mempools, --enable-debug. Include docs on cross compilation.