In order to support cross-compilation of crash-utilty,
the configure tool compiled from configure.c must be built
for the host architecture where the cross-compilation will run
instead of the target architecture where the crash-utility shall run.
Therefore, we need to support two C compilers in Maklefile,
one for the host and one for the target. The old CC makefile variable
shall represent the compiler for the target architecture and
the new HOSTCC makefile variable shall represent the host compiler.
Both variables differ only when a cross-compilation is performed.
Furthermore, there must be a way to override the target architecture
which is deduced from the preprocessor macros defined by the compiler
used for the compilation of configure.c, because otherwise the configure
tool will deduce host's architecture instead of the desired target.
With the new preprocessor define CONF_DEFAULT_TARGET, it is possible to
set the desired target architecture for the compiled crash-utility.
When cross-compiling, set the makefile variable CROSS_COMPILE
to the prefix of the cross-compiler and the default target
architecture will be deduced from it, e.g. like this:
make CROSS_COMPILE=s390x-linux-
and the default target architecture shall be S390X.
Signed-off-by: Alexander Egorenkov <egorenar-dev(a)posteo.net>
---
v2 -> v3:
* Use CROSS_COMPILE makefile variable to pass cross-compiler prefix
v1 -> v2:
* Improved commit message
* Added a note how to cross-compile crash-utilty to README
* Moved CONF_CC makefile variable to correct place location
Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
README | 5 +++++
configure.c | 39 +++------------------------------------
3 files changed, 57 insertions(+), 40 deletions(-)
diff --git a/Makefile b/Makefile
index d185719..7185dcd 100644
--- a/Makefile
+++ b/Makefile
@@ -20,15 +20,60 @@
PROGRAM=crash
#
-# Supported targets: X86 ALPHA PPC IA64 PPC64 SPARC64
+# Supported targets: X86 X86_64 IA64 ALPHA PPC PPC64 ARM ARM64 SPARC64 MIPS S390 S390X
# TARGET and GDB_CONF_FLAGS will be configured automatically by configure
#
TARGET=
GDB_CONF_FLAGS=
-ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e
s/sa110/arm/)
+ifneq ($(CROSS_COMPILE),)
+ARCH := $(shell echo $(CROSS_COMPILE) | sed 's:^.*/::g' | cut -d- -f1)
+else
+ARCH := $(shell uname -m)
+endif
+ARCH := $(shell echo $(ARCH) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e
s/sa110/arm/)
+
+CC = $(CROSS_COMPILE)gcc
+HOSTCC = gcc
+
ifeq (${ARCH}, ppc64)
-CONF_FLAGS = -m64
+CONF_FLAGS += -m64
+endif
+
+ifeq (${ARCH}, i386)
+CONF_DEFAULT_TARGET := X86
+else ifeq (${ARCH}, x86_64)
+CONF_DEFAULT_TARGET := X86_64
+else ifeq (${ARCH}, ia64)
+CONF_DEFAULT_TARGET := IA64
+else ifeq (${ARCH}, alpha)
+CONF_DEFAULT_TARGET := ALPHA
+else ifeq (${ARCH}, ppc)
+CONF_DEFAULT_TARGET := PPC
+else ifeq (${ARCH}, ppc64)
+CONF_DEFAULT_TARGET := PPC64
+else ifeq (${ARCH}, ppc64le)
+CONF_DEFAULT_TARGET := PPC64
+else ifeq (${ARCH}, arm)
+CONF_DEFAULT_TARGET := ARM
+else ifeq (${ARCH}, aarch64)
+CONF_DEFAULT_TARGET := ARM64
+else ifeq (${ARCH}, mips)
+CONF_DEFAULT_TARGET := MIPS
+else ifeq (${ARCH}, sparc64)
+CONF_DEFAULT_TARGET := SPARC64
+else ifeq (${ARCH}, s390)
+CONF_DEFAULT_TARGET := S390
+else ifeq (${ARCH}, s390x)
+CONF_DEFAULT_TARGET := S390X
+else
+$(error unsupported architecture ${ARCH})
+endif
+
+CONF_FLAGS += -DCONF_DEFAULT_TARGET=${CONF_DEFAULT_TARGET}
+
+ifneq ($(CROSS_COMPILE),)
+CONF_FLAGS += -DGDB_TARGET_DEFAULT="\"GDB_CONF_FLAGS=--host=$(shell echo
$(CROSS_COMPILE) | sed -e 's:^.*/::g' -e 's/-$$//')\""
endif
#
@@ -288,7 +333,7 @@ force:
make_configure: force
@rm -f configure
- @${CC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS}
+ @${HOSTCC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS}
clean: make_configure
@./configure ${CONF_TARGET_FLAG} -q -b
diff --git a/README b/README
index bfbaef6..f5bd476 100644
--- a/README
+++ b/README
@@ -100,6 +100,11 @@
o On an x86_64 host, an x86_64 binary that can be used to analyze
ppc64le dumpfiles may be built by typing "make target=PPC64".
+ To cross-compile the crash utility, set the makefile variable CROSS_COMPILE to
+ the prefix of the cross-compiler, e.g. like this:
+
+ $ make CROSS_COMPILE=s390x-linux-
+
Traditionally when vmcores are compressed via the makedumpfile(8) facility
the libz compression library is used, and by default the crash utility
only supports libz. Recently makedumpfile has been enhanced to optionally
diff --git a/configure.c b/configure.c
index 7f6d19e..970a547 100644
--- a/configure.c
+++ b/configure.c
@@ -154,7 +154,9 @@ void add_extra_lib(char *);
#define TARGET_CFLAGS_MIPS_ON_X86_64 "TARGET_CFLAGS=-m32
-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_SPARC64 "TARGET_CFLAGS="
+#ifndef GDB_TARGET_DEFAULT
#define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS="
+#endif
#define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux"
#define GDB_TARGET_ARM_ON_X86_64 "GDB_CONF_FLAGS=--target=arm-elf-linux
CFLAGS=-m32"
#define GDB_TARGET_X86_ON_X86_64 "GDB_CONF_FLAGS=--target=i686-pc-linux-gnu
CFLAGS=-m32"
@@ -349,42 +351,7 @@ get_current_configuration(struct supported_gdb_version *sp)
static char buf[512];
char *p;
-#ifdef __alpha__
- target_data.target = ALPHA;
-#endif
-#ifdef __i386__
- target_data.target = X86;
-#endif
-#ifdef __powerpc__
- target_data.target = PPC;
-#endif
-#ifdef __ia64__
- target_data.target = IA64;
-#endif
-#ifdef __s390__
- target_data.target = S390;
-#endif
-#ifdef __s390x__
- target_data.target = S390X;
-#endif
-#ifdef __powerpc64__
- target_data.target = PPC64;
-#endif
-#ifdef __x86_64__
- target_data.target = X86_64;
-#endif
-#ifdef __arm__
- target_data.target = ARM;
-#endif
-#ifdef __aarch64__
- target_data.target = ARM64;
-#endif
-#ifdef __mips__
- target_data.target = MIPS;
-#endif
-#ifdef __sparc_v9__
- target_data.target = SPARC64;
-#endif
+ target_data.target = CONF_DEFAULT_TARGET;
set_initial_target(sp);
--
2.29.2