After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 77565 - patch for cross-compiling glib2
patch for cross-compiling glib2
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.0.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 58786 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2002-04-04 02:46 UTC by Dimi Shahbaz
Modified: 2011-02-18 15:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to fix cross-compile issues of glib2 (4.73 KB, patch)
2002-04-04 02:48 UTC, Dimi Shahbaz
none Details | Review
reindentation patch. (apply after 1st) (8.76 KB, patch)
2002-04-04 02:49 UTC, Dimi Shahbaz
none Details | Review
the patch Johannes sent to gtk-devel-list (8.15 KB, patch)
2002-05-17 12:43 UTC, Sven Neumann
none Details | Review
the config.cache file Johannes sent to gtk-devel-list (1.40 KB, text/plain)
2002-05-17 12:44 UTC, Sven Neumann
  Details
The proposed patch to reduce the number of AC_TRY_RUN's (2.26 KB, patch)
2002-07-15 13:33 UTC, Daniel Egger
none Details | Review

Description Dimi Shahbaz 2002-04-04 02:46:52 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.
Comment 1 Dimi Shahbaz 2002-04-04 02:48:22 UTC
Created attachment 7539 [details] [review]
patch to fix cross-compile issues of glib2
Comment 2 Dimi Shahbaz 2002-04-04 02:49:07 UTC
Created attachment 7540 [details] [review]
reindentation patch. (apply after 1st)
Comment 3 Dimi Shahbaz 2002-04-25 21:14:33 UTC
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
Comment 4 Sven Neumann 2002-05-17 12:42:29 UTC
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
Comment 5 Sven Neumann 2002-05-17 12:43:47 UTC
Created attachment 8537 [details] [review]
the patch Johannes sent to gtk-devel-list
Comment 6 Sven Neumann 2002-05-17 12:44:51 UTC
Created attachment 8538 [details]
the config.cache file Johannes sent to gtk-devel-list
Comment 7 Daniel Egger 2002-07-15 13:32:09 UTC
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.
Comment 8 Daniel Egger 2002-07-15 13:33:11 UTC
Created attachment 9875 [details] [review]
The proposed patch to reduce the number of AC_TRY_RUN's
Comment 9 Michael Meeks 2002-10-03 11:06:08 UTC
Is this work going anywhere ? Some of this work was to enable cross
compilation to embedded targets like the Sharp Zarus.
Comment 10 Owen Taylor 2002-12-04 02:29:48 UTC
*** Bug 58786 has been marked as a duplicate of this bug. ***
Comment 11 Owen Taylor 2002-12-04 02:59:19 UTC
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 :-)
Comment 12 Owen Taylor 2002-12-05 20:36:38 UTC
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.
Comment 13 Owen Taylor 2002-12-11 22:24:23 UTC
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)
Comment 14 Owen Taylor 2002-12-20 15:22:46 UTC
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.