From e12dfb2914a40eb989dc4a12ba4c181f754e1a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Mon, 15 Jul 2024 21:15:04 +0200 Subject: [PATCH] Add cross-compile argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When cross-compiling on SUSE distributions vng fails to find gcc, since it's named '-suse-linux-gcc', instead of the hardcoded '-linux-gnu-gcc'. This commit provides a '--cross-compile' argument that will override the hardcoded prefix if used, otherwise it should do nothing. Signed-off-by: Fredrik Lönnegren --- virtme/commands/configkernel.py | 17 ++++++++++++++--- virtme/commands/run.py | 6 ++++++ virtme_ng/run.py | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/virtme/commands/configkernel.py b/virtme/commands/configkernel.py index 02ce47d..bbd163c 100644 --- a/virtme/commands/configkernel.py +++ b/virtme/commands/configkernel.py @@ -31,6 +31,13 @@ def make_parser(): help="Target architecture", ) + parser.add_argument( + "--cross-compile", + action="store", + metavar="CROSS_COMPILE_PREFIX", + help="Cross-compile compiler prefix", + ) + parser.add_argument( "--custom", action="append", @@ -313,9 +320,13 @@ def do_it(): linuxname = shlex.quote(arch.linuxname) archargs = [f"ARCH={linuxname}"] - if shutil.which(f"{arch.gccname}-linux-gnu-gcc") and arch.gccname != uname.machine: - gccname = shlex.quote(f"{arch.gccname}-linux-gnu-") - archargs.append(f"CROSS_COMPILE={gccname}") + cross_compile_prefix = f"{arch.gccname}-linux-gnu-" + if args.cross_compile != "": + cross_compile_prefix = args.cross_compile + + if shutil.which(f"{cross_compile_prefix}-gcc") and arch.gccname != uname.machine: + gccname = shlex.quote(cross_compile_prefix) + archargs.append(f"CROSS_COMPILE={cross_compile_prefix}") maketarget: Optional[str] diff --git a/virtme/commands/run.py b/virtme/commands/run.py index abbaab2..de66574 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -204,6 +204,12 @@ def make_parser() -> argparse.ArgumentParser: default=uname.machine, help="Guest architecture", ) + g.add_argument( + "--cross-compile", + action="store", + metavar="CROSS_COMPILE_PREFIX", + help="Cross-compile compiler prefix", + ) g.add_argument( "--busybox", action="store", diff --git a/virtme_ng/run.py b/virtme_ng/run.py index f4f9813..fb54e8a 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -442,6 +442,12 @@ def make_parser(): "(default is host architecture)", ) + parser.add_argument( + "--cross-compile", + action="store", + help="Set cross-compile prefix" + ) + parser.add_argument( "--force", action="store_true", @@ -733,6 +739,9 @@ def make(self, args): arg_fail(f"unsupported architecture: {arch}") target = ARCH_MAPPING[arch]["kernel_target"] cross_compile = ARCH_MAPPING[arch]["cross_compile"] + if args.cross_compile != "": + cross_compile=args.cross_compile + cross_arch = ARCH_MAPPING[arch]["linux_name"] else: target = "bzImage"