Discussion:
Best practice for recognizing cross-compilation and adjusting Makefile.am
Simon Sobisch
2017-10-19 20:29:57 UTC
Permalink
I'm working on enabling cross-compilation for GnuCOBOL. As a
prerequisite I'd see a release tarball (as `make dist` on the host for
the people cross-compiling from vcs).

The autoconf parts are fixed now [1], but there's one thing in the
Makefiles where we generate a binary with the compiler we've generated
directly beforehand. This obviously can't work and I'd like to skip
this and telling people to do so on the target machine.

The main question is: what is the best practice for doing so? I'd using
AC_SUBST([CROSS_COMPILATION]) and checking this in the "offending"
Makefile for simply dropping the generation completely.

Is there a better practice? How do other projects handle this?

"offending" Makefile.am:

~~~
extrasdir = @COB_LIBRARY_PATH@
extras_DATA = CBL_OC_DUMP.$(COB_MODULE_EXT)

EXTRA_DIST = CBL_OC_DUMP.cob
CLEANFILES = $(extras_DATA)

SUFFIXES = .cob .$(COB_MODULE_EXT)
.cob.$(COB_MODULE_EXT):
. $(top_builddir)/tests/atconfig && \
. $(top_builddir)/tests/atlocal extras-$@ \
&& $$COBC -m -Wall -O -o $@ $<
~~~

Note: The environment variable COBC contains the full path to the
libtoolized executable.


[1]autoconf parts fixed by:
1. replacing AC_RUN_IFELSE by AC_COMPILE_IFELSE for parts that only
checked in the precprocessor
2. "assume" correct values for cross-compiling for example when checking
library vs. header
Simon Richter
2017-10-19 23:49:08 UTC
Permalink
Hi,
Post by Simon Sobisch
The autoconf parts are fixed now [1], but there's one thing in the
Makefiles where we generate a binary with the compiler we've generated
directly beforehand. This obviously can't work and I'd like to skip
this and telling people to do so on the target machine.
With my Debian package maintainer hat on: if it is possible to properly
support cross compilation, please do so.

The sanest way to do that is to build a toplevel project that calls
something like

./configure --build=@build@ \
--host=@build@ \
--target=@target@

to build a compiler running on the build system,

./configure --build=@build@ \
--host=@host@ \
--target=@target@

to build a compiler to install, and

./configure --build=@build@ \
--host=@target@ \
--with-compiler=path-to-compiler

to build the runtime.

This Makefile is usually not built with automake, and will try to merge
the cases where @host@ = @build@, where the configure invocations for
both compiler builds are the same.
Post by Simon Sobisch
The main question is: what is the best practice for doing so? I'd using
AC_SUBST([CROSS_COMPILATION]) and checking this in the "offending"
Makefile for simply dropping the generation completely.
You can compare the host and build triplets and use AM_CONDITIONAL to
comment out parts of the Makefile when cross-compiling.

Simon

Loading...