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 CONF_CC 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_HOST_ARCH, it is possible to
set the desired target architecture for the compiled crash-utility.
When cross-compiling, pass the value of CONF_HOST_ARCH via
the CONF_CFLAGS makefile variable, e.g. like this:
make CONF_CC=gcc CC=s390x-linux-gnu-gcc CONF_FLAGS="-DCONF_HOST_ARCH=S390X"
Signed-off-by: Alexander Egorenkov <egorenar-dev(a)posteo.net>
---
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 | 3 ++-
README | 4 +++
configure.c | 76 ++++++++++++++++++++++++++++-------------------------
3 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/Makefile b/Makefile
index 7455410..d5985bc 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ PROGRAM=crash
#
TARGET=
GDB_CONF_FLAGS=
+CONF_CC = ${CC}
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e
s/sa110/arm/)
ifeq (${ARCH}, ppc64)
@@ -288,7 +289,7 @@ force:
make_configure: force
@rm -f configure
- @${CC} ${CONF_FLAGS} -o configure configure.c ${WARNING_ERROR} ${WARNING_OPTIONS}
+ @${CONF_CC} ${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..707bc63 100644
--- a/README
+++ b/README
@@ -100,6 +100,10 @@
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 e.g. for a s390x target:
+
+ $ make CONF_CC=gcc CC=s390x-linux-gnu-gcc
CONF_CFLAGS="-DCONF_HOST_ARCH=S390X"
+
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..d736c56 100644
--- a/configure.c
+++ b/configure.c
@@ -120,6 +120,45 @@ void add_extra_lib(char *);
#define MIPS 11
#define SPARC64 12
+#ifndef CONF_HOST_ARCH
+#ifdef __alpha__
+#define CONF_HOST_ARCH ALPHA
+#endif
+#ifdef __i386__
+#define CONF_HOST_ARCH X86
+#endif
+#ifdef __powerpc__
+#define CONF_HOST_ARCH PPC
+#endif
+#ifdef __ia64__
+#define CONF_HOST_ARCH IA64
+#endif
+#ifdef __s390__
+#define CONF_HOST_ARCH S390
+#endif
+#ifdef __s390x__
+#define CONF_HOST_ARCH S390X
+#endif
+#ifdef __powerpc64__
+#define CONF_HOST_ARCH PPC64
+#endif
+#ifdef __x86_64__
+#define CONF_HOST_ARCH X86_64
+#endif
+#ifdef __arm__
+#define CONF_HOST_ARCH ARM
+#endif
+#ifdef __aarch64__
+#define CONF_HOST_ARCH ARM64
+#endif
+#ifdef __mips__
+#define CONF_HOST_ARCH MIPS
+#endif
+#ifdef __sparc_v9__
+#define CONF_HOST_ARCH SPARC64
+#endif
+#endif // #ifndef CONF_HOST_ARCH
+
#define TARGET_X86 "TARGET=X86"
#define TARGET_ALPHA "TARGET=ALPHA"
#define TARGET_PPC "TARGET=PPC"
@@ -349,42 +388,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_HOST_ARCH;
set_initial_target(sp);
--
2.28.0