Skip to contentSkip to conversation

RFC/Patch: Build changes for cross-compilation

PATCH Michal Ostrowski 1 participant 1 message Mar 21, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

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]>

# 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
diff -Nru a/Config.mk b/Config.mk
@@ -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
diff -Nru a/Makefile b/Makefile
@@ -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
diff -Nru a/tools/Rules.mk b/tools/Rules.mk
@@ -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
diff -Nru a/tools/libxc/Makefile b/tools/libxc/Makefile
@@ -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
diff -Nru a/tools/libxutil/Makefile b/tools/libxutil/Makefile
@@ -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
diff -Nru a/tools/misc/Makefile b/tools/misc/Makefile
@@ -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
diff -Nru a/tools/xentrace/Makefile b/tools/xentrace/Makefile
@@ -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
diff -Nru a/xen/Rules.mk b/xen/Rules.mk
@@ -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
diff -Nru a/xen/arch/x86/Rules.mk b/xen/arch/x86/Rules.mk
@@ -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
diff -Nru a/xen/tools/figlet/Makefile b/xen/tools/figlet/Makefile
@@ -1,8 +1,8 @@
 
-CC := gcc
+include ../../Config.mk
 
 figlet: figlet.c
-	$(CC) -o $@ $<
+	$(HOSTCC) -o $@ $<
 
 clean:
 	rm -f *.o figlet