RFC/Patch: Build changes for cross-compilation
Attached is a number of changes to the build system that I've been using to enable cross-compilation. The biggest change is the introduction of a "Config.mk" file that is included by all Rules.mk files.
Config.mk is intended to define things common to all aspects of the build. This can reduce duplication of definitions across various makefiles throughout the tree and provides a convenient, single location to define the toolchains to be used.
This is by no means a complete answer to cross-compilation issues (e.g. python still assumes "gcc" is the compiler to be used).
Comments/suggestions appreciated.
Signature · 1 line
Michal Ostrowski <[email protected]>
Quoted 4 lines · Michal Ostrowski
Attached is a number of changes to the build system that I've been using to enable cross-compilation. The biggest change is the introduction of a "Config.mk" file that is included by all Rules.mk files.
The attachment was missing. In any case, it's not clear to me that any big changes are needed to the build system to support cross compilation -- could we just prepend a $(CROSS_COMPILE) variable to the name of each toolchain binary used to build images to be run on the target architecture? This is all that Linux provides.
-- Keir
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
Patch attached. (I mean it this time.)
Prepending CROSS_COMPILE is most of the solution. However, there are some Makefile that need to be more careful about using CC vs HOSTCC. I also think it is a bad idea for so many Makefiles to be setting
"CC:=gcc". Something like this should IMO be set in one place only,
and hence my Config.mk suggestion.
Quoted 27 lines · Keir Fraser
Quoted 5 lines · Michal Ostrowski
Attached is a number of changes to the build system that I've been using
to enable cross-compilation. The biggest change is the introduction of a "Config.mk" file that is included by all Rules.mk files.The attachment was missing. In any case, it's not clear to me that any big changes are needed to the build system to support cross compilation -- could we just prepend a $(CROSS_COMPILE) variable to the name of each toolchain binary used to build images to be run on the target architecture? This is all that Linux provides.
-- Keir
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xen-devel
Signature · 1 line
Michal Ostrowski <[email protected]>
# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2005/03/20 15:50:57-05:00 [email protected] # Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk. # Config.mk can eventually be provided by a configuration tool (e.g. autoconf).
#
# BitKeeper/etc/logging_ok
# 2005/03/20 15:50:57-05:00 [email protected] +1 -0
# Logging to [email protected] accepted
#
# Config.mk
# 2005/03/20 15:50:31-05:00 [email protected] +41 -0
#
# xen/tools/figlet/Makefile
# 2005/03/20 15:50:31-05:00 [email protected] +2 -2 # Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk. # Use HOSTCC to build executables to be run during build.
#
# xen/arch/x86/Rules.mk
# 2005/03/20 15:50:31-05:00 [email protected] +3 -6
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# xen/Rules.mk
# 2005/03/20 15:50:31-05:00 [email protected] +2 -6
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# tools/xentrace/Makefile
# 2005/03/20 15:50:31-05:00 [email protected] +0 -1
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# Config.mk
# 2005/03/20 15:50:31-05:00 [email protected] +0 -0
# BitKeeper file /home/mostrows/xen/xeno-unstable.bk/Config.mk
#
# tools/misc/Makefile
# 2005/03/20 15:50:30-05:00 [email protected] +0 -1
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# tools/libxutil/Makefile
# 2005/03/20 15:50:30-05:00 [email protected] +0 -2
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# tools/libxc/Makefile
# 2005/03/20 15:50:30-05:00 [email protected] +1 -1
# Add LDFLAGS to link commands.
#
# tools/Rules.mk
# 2005/03/20 15:50:30-05:00 [email protected] +2 -3
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
# Makefile
# 2005/03/20 15:50:30-05:00 [email protected] +1 -0
# Definitions common to all build steps (e.g. toolchain specification) placed in Config.mk.
#
Config.mk new file +33 -0
@@ -0,0 +1,33 @@ +# -*- mode: Makefile; -*- +# Currently supported architectures: x86_32, x86_64 +XEN_COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) +XEN_TARGET_ARCH ?= $(XEN_COMPILE_ARCH) + +# +# Tool configuration Makefile fragment +# +HOSTCC = gcc +HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer + +AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld +CC = $(CROSS_COMPILE)gcc +CPP = $(CROSS_COMPILE)$(CC) -E +AR = $(CROSS_COMPILE)ar +NM = $(CROSS_COMPILE)nm +STRIP = $(CROSS_COMPILE)strip +OBJCOPY = $(CROSS_COMPILE)objcopy +OBJDUMP = $(CROSS_COMPILE)objdump + + +ifneq ($(EXTRA_PREFIX),) +EXTRA_INCLUDES += $(EXTRA_PREFIX)/include +EXTRA_LIB += $(EXTRA_PREFIX)/lib +endif + +LDFLAGS += $(foreach i, $(EXTRA_LIB), -L$(i)) +CFLAGS += $(foreach i, $(EXTRA_INCLUDES), -I$(i)) + +CFLAGS += -g + +
Makefile +1 -0
@@ -27,6 +27,7 @@ export XEN_TARGET_ARCH SUBARCH endif +include Config.mk include buildconfigs/Rules.mk .PHONY: all dist install xen tools kernels docs world clean mkpatches mrproper
tools/Rules.mk +2 -3
@@ -1,11 +1,10 @@ # -*- mode: Makefile; -*- +include $(XEN_ROOT)/Config.mk + XEN_XC = $(XEN_ROOT)/tools/python/xen/lowlevel/xc XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_LIBXUTIL = $(XEN_ROOT)/tools/libxutil - -XEN_COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) -XEN_TARGET_ARCH ?= $(XEN_COMPILE_ARCH) ifeq ($(XEN_TARGET_ARCH),x86_32) CFLAGS += -m32 -march=i686
tools/libxc/Makefile +1 -1
@@ -105,6 +105,6 @@ ln -sf $< $@ libxc.so.$(MAJOR).$(MINOR): $(PIC_OBJS) - $(CC) $(CFLAGS) -Wl,-soname -Wl,libxc.so.$(MAJOR) -shared -o $@ $^ -L../libxutil -lxutil -lz + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxc.so.$(MAJOR) -shared -o $@ $^ -L../libxutil -lxutil -lz -include $(DEPS)
tools/libxutil/Makefile +0 -2
@@ -7,8 +7,6 @@ include $(XEN_ROOT)/tools/Rules.mk -CC = gcc - LIB_SRCS := LIB_SRCS += allocate.c LIB_SRCS += enum.c
tools/misc/Makefile +0 -1
@@ -5,7 +5,6 @@ XEN_ROOT=../.. include $(XEN_ROOT)/tools/Rules.mk -CC = gcc CFLAGS += -Wall -Werror -O3 INCLUDES += -I $(XEN_XC)
tools/xentrace/Makefile +0 -1
@@ -6,7 +6,6 @@ XEN_ROOT=../.. include $(XEN_ROOT)/tools/Rules.mk -CC = gcc CFLAGS += -Wall -Werror -O3 CFLAGS += -I $(XEN_XC)
xen/Rules.mk +2 -6
@@ -7,9 +7,7 @@ domu_debug ?= n crash_debug ?= n -# Currently supported architectures: x86_32, x86_64 -XEN_COMPILE_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/) -XEN_TARGET_ARCH ?= $(XEN_COMPILE_ARCH) +include $(BASEDIR)/../Config.mk # Set ARCH/SUBARCH appropriately. override COMPILE_SUBARCH := $(XEN_COMPILE_ARCH)
@@ -39,10 +37,8 @@ ALL_OBJS += $(BASEDIR)/drivers/pci/driver.o ALL_OBJS += $(BASEDIR)/arch/$(TARGET_ARCH)/arch.o -HOSTCC = gcc -HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -test-gcc-flag = $(shell gcc -v --help 2>&1 | grep -q " $(1) " && echo $(1)) +test-gcc-flag = $(shell $(CC) -v --help 2>&1 | grep -q " $(1) " && echo $(1)) include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk
xen/arch/x86/Rules.mk +3 -6
@@ -1,10 +1,7 @@ ######################################## # x86-specific definitions -CC := gcc -LD := ld - -CFLAGS := -nostdinc -fno-builtin -fno-common -fno-strict-aliasing +CFLAGS += -nostdinc -fno-builtin -fno-common -fno-strict-aliasing CFLAGS += -iwithprefix include -Wall -Werror -Wno-format -pipe CFLAGS += -I$(BASEDIR)/include -Wno-pointer-arith -Wredundant-decls
@@ -24,13 +21,13 @@ ifeq ($(TARGET_SUBARCH),x86_32) CFLAGS += -m32 -march=i686 -LDFLAGS := -m elf_i386 +LDFLAGS += -m elf_i386 endif ifeq ($(TARGET_SUBARCH),x86_64) CFLAGS += -m64 -mno-red-zone -fpic -fno-reorder-blocks CFLAGS += -fno-asynchronous-unwind-tables -LDFLAGS := -m elf_x86_64 +LDFLAGS += -m elf_x86_64 endif # Test for at least GCC v3.2.x.
xen/tools/figlet/Makefile +2 -2
@@ -1,8 +1,8 @@ -CC := gcc +include ../../Config.mk figlet: figlet.c - $(CC) -o $@ $< + $(HOSTCC) -o $@ $< clean: rm -f *.o figlet
Quoted 5 lines · Michal Ostrowski
Prepending
CROSS_COMPILEis most of the solution. However, there are someMakefilethat need to be more careful about using CC vs HOSTCC. I also think it is a bad idea for so many Makefiles to be setting
"CC:=gcc". Something like this should IMO be set in one place only,
and hence my Config.mk suggestion.
Yes, it does look neater. I've checked it into the unstable tree. It's not so important in this case since the patch is fairly trivial, but in future please add a 'signed-off-by' line to your email when submitting a patch.
Cheers,
Keir
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click