build icon indicating copy to clipboard operation
build copied to clipboard

Support cross-building

Open fabled opened this issue 7 years ago • 8 comments

Is there some way to use CROSS_COMPILE or specify the cross-building toolchain to use?

fabled avatar Jun 18 '17 07:06 fabled

My primary use case for a c/c++ build system would be in a cross compiling environment as well. I'm playing around with places to add hooks to build.

One that pops to mind is allowing the user to override the config folder directory, or perhaps instead the initial specific config file that gets included. kamathba/build@7147959

kamathba avatar Jun 18 '17 17:06 kamathba

Actually, one of the first projects to use build was using it mostly for cross-compilation.

Typically, you would simply create a config.gcc-cross-arm.mk and set your BUILDENV to match. It may be as simple as:

CC=cross-gcc
CXX=cross-g++
LD=cross-ld
include $(BUILD)config.gnu.mk

Please re-open the issue if you feel this is not good enough.

c3d avatar Jun 19 '17 08:06 c3d

I would prefer that CROSS_COMPILE is considered automatically, or that there is a built in profile to account for it. I would not like to create config for each target I need to build, but pick the configuration from environment variable compatible with autotools. CROSS_COMPILE is used widely for this purpose, and most distro build systems set it appropriately.

fabled avatar Jun 19 '17 08:06 fabled

Makes sense.

c3d avatar Jun 19 '17 08:06 c3d

Would something like https://github.com/c3d/build/commit/a7e9b464d9c822c8650fb44c2748b68ba82df0b8 be the right direction?

What I'm not too sure about is: how to deal with the -I path. I'm surprised that at least on Fedora 26, the cross-compilers don't seem to set the right paths for include and libraries. Any suggestion?

c3d avatar Jun 19 '17 11:06 c3d

Looks like right direction. Normally cross compilers are configured for sysroot, and often CFLAGS or similar will contain --sysroot=$target_root or similar. The affect of this is that all -I paths are searched under the given sysroot.

fabled avatar Jun 19 '17 11:06 fabled

The CFLAGS and others are usually (at least in case of yocto) setup using environment-setup-* file which is sourced into the shell running cross-compilation. See https://www.yoctoproject.org/docs/2.3/sdk-manual/sdk-manual.html for example.

ghost avatar Jun 27 '17 10:06 ghost