pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc cwrappers: Add cross-compilation support.
details: https://anonhg.NetBSD.org/pkgsrc/rev/3b8309209242
branches: trunk
changeset: 376280:3b8309209242
user: riastradh <riastradh%pkgsrc.org@localhost>
date: Mon Apr 04 11:22:50 2022 +0000
description:
cwrappers: Add cross-compilation support.
- New option `sysroot=<dir>':
. Wrapper will add `--sysroot=<dir>' as first argument.
. For every rpath argument, e.g. -Wl,-R<path> to cc, wrapper will
pass `-rpath-link <dir><path>' to the linker.
This matches the old mk/wrapper/cmd-sink-cross-* logic.
- Create wrappers for the ${MACHINE_GNU_PLATFORM}-cc style of command,
as in ${CC}, ${CXX}, ${LD} for cross-builds.
- Bump version.
- Use TOOL_DEPENDS, not BUILD_DEPENDS, for cwrappers.
diffstat:
doc/HOWTO-use-crosscompile | 5 +---
mk/cwrappers.mk | 13 ++++++++-
pkgtools/cwrappers/Makefile | 4 +-
pkgtools/cwrappers/files/bin/base-wrapper.c | 21 +++++++++++++++-
pkgtools/cwrappers/files/bin/common.c | 8 +++++-
pkgtools/cwrappers/files/bin/common.h | 3 +-
pkgtools/cwrappers/files/bin/normalise-cc.c | 38 ++++++++++++++++++++++------
pkgtools/cwrappers/files/bin/normalise-ld.c | 33 ++++++++++++++++++++++++-
8 files changed, 105 insertions(+), 20 deletions(-)
diffs (truncated from 325 to 300 lines):
diff -r 09a33a062092 -r 3b8309209242 doc/HOWTO-use-crosscompile
--- a/doc/HOWTO-use-crosscompile Mon Apr 04 09:59:28 2022 +0000
+++ b/doc/HOWTO-use-crosscompile Mon Apr 04 11:22:50 2022 +0000
@@ -1,7 +1,7 @@
Cross-compilation in pkgsrc (user's guide) -*- outline -*-
Taylor R. Campbell <riastradh%NetBSD.org@localhost>
-$NetBSD: HOWTO-use-crosscompile,v 1.7 2019/07/09 15:45:35 riastradh Exp $
+$NetBSD: HOWTO-use-crosscompile,v 1.8 2022/04/04 11:22:50 riastradh Exp $
The following steps enable you to build binary packages for a machine
architecture other than the one you are building on. For example, you
@@ -66,9 +66,6 @@
# XXX Should not need this.
PACKAGES= ${PKGSRCDIR}/packages.${MACHINE_ARCH}
WRKDIR_BASENAME= work.${MACHINE_ARCH}
-
- # XXX cwrappers needs to be taught to pass --sysroot.
- USE_CWRAPPERS= no
.endif
You can bootstrap pkgsrc or not; it shouldn't make a difference for
diff -r 09a33a062092 -r 3b8309209242 mk/cwrappers.mk
--- a/mk/cwrappers.mk Mon Apr 04 09:59:28 2022 +0000
+++ b/mk/cwrappers.mk Mon Apr 04 11:22:50 2022 +0000
@@ -1,11 +1,11 @@
-# $NetBSD: cwrappers.mk,v 1.33 2022/03/13 06:26:57 nia Exp $
+# $NetBSD: cwrappers.mk,v 1.34 2022/04/04 11:22:50 riastradh Exp $
#
# This Makefile fragment implements integration of pkgtools/cwrappers.
.include "../../mk/wrapper/wrapper-defs.mk"
.include "../../mk/buildlink3/bsd.buildlink3.mk"
-BUILD_DEPENDS+= cwrappers>=20150314:../../pkgtools/cwrappers
+TOOL_DEPENDS+= cwrappers>=20220403:../../pkgtools/cwrappers
# XXX This should be PREFIX, but USE_CROSSBASE overrides it.
CWRAPPERS_SRC_DIR= ${LOCALBASE}/libexec/cwrappers
@@ -37,6 +37,12 @@
CWRAPPERS_ALIASES.libtool= libtool
CWRAPPERS_ALIASES.shlibtool= shlibtool
+.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+CWRAPPERS_ALIASES.cc+= ${CC:T}
+CWRAPPERS_ALIASES.cxx+= ${CXX:T}
+CWRAPPERS_ALIASES.ld+= ${LD:T}
+.endif
+
CWRAPPERS_WRAPPEE.as= ${AS:Ufalse}
CWRAPPERS_WRAPPEE.cxx= ${PKG_CXX:Ufalse}
CWRAPPERS_WRAPPEE.cc= ${PKG_CC:Ufalse}
@@ -95,6 +101,9 @@
. endfor
. endif
. endif
+. if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
+ ${RUN}echo sysroot=${_CROSS_DESTDIR:Q} >> ${CWRAPPERS_CONFIG_DIR}/${CWRAPPERS_CONFIG.${wrappee}}
+. endif
.endfor
PREPEND_PATH+= ${WRAPPER_BINDIR}
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/Makefile
--- a/pkgtools/cwrappers/Makefile Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/Makefile Mon Apr 04 11:22:50 2022 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.26 2020/06/02 19:46:00 rillig Exp $
+# $NetBSD: Makefile,v 1.27 2022/04/04 11:22:51 riastradh Exp $
-PKGNAME= cwrappers-20180325
+PKGNAME= cwrappers-20220403
CATEGORIES= pkgtools sysutils
MAINTAINER= joerg%NetBSD.org@localhost
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/files/bin/base-wrapper.c
--- a/pkgtools/cwrappers/files/bin/base-wrapper.c Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/files/bin/base-wrapper.c Mon Apr 04 11:22:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: base-wrapper.c,v 1.6 2017/10/27 20:59:59 khorben Exp $ */
+/* $NetBSD: base-wrapper.c,v 1.7 2022/04/04 11:22:51 riastradh Exp $ */
/*-
* Copyright (c) 2007, 2017 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -99,6 +99,18 @@
}
#endif
+static void
+apply_sysroot(struct arglist *args)
+{
+ struct argument *arg;
+
+ if (sysroot == NULL)
+ return;
+
+ arg = argument_new(concat("--sysroot=", sysroot));
+ TAILQ_INSERT_HEAD(args, arg, link);
+}
+
int
main(int argc, char **argv)
{
@@ -136,6 +148,13 @@
operation_mode_cc(&args);
#endif
arglist_apply_config(&args);
+#if !defined(WRAPPER_LIBTOOL) && !defined(WRAPPER_SHLIBTOOL)
+ /*
+ * The --sysroot argument will be applied only to the compiler
+ * or linker that libtool invokes, not to libtool itself.
+ */
+ apply_sysroot(&args);
+#endif
#if defined(WRAPPER_LD)
normalise_ld(&args);
#else
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/files/bin/common.c
--- a/pkgtools/cwrappers/files/bin/common.c Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/files/bin/common.c Mon Apr 04 11:22:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.10 2018/03/25 20:45:25 joerg Exp $ */
+/* $NetBSD: common.c,v 1.11 2022/04/04 11:22:51 riastradh Exp $ */
/*-
* Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -48,6 +48,7 @@
char *exec_path;
char *exec_name;
char *wrksrc;
+char *sysroot;
int debug;
enum operation_mode current_operation_mode = mode_unknown;
@@ -294,6 +295,11 @@
wrksrc = xstrdup(line + 7);
continue;
}
+ if (strncmp(line, "sysroot=", 8) == 0) {
+ free(sysroot);
+ sysroot = xstrdup(line + 8);
+ continue;
+ }
if (strncmp(line, "unwrap=", 7) == 0) {
register_unwrap(line + 7);
continue;
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/files/bin/common.h
--- a/pkgtools/cwrappers/files/bin/common.h Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/files/bin/common.h Mon Apr 04 11:22:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: common.h,v 1.9 2021/11/07 12:38:12 christos Exp $ */
+/* $NetBSD: common.h,v 1.10 2022/04/04 11:22:51 riastradh Exp $ */
/*-
* Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -42,6 +42,7 @@
extern char *exec_path;
extern char *exec_name;
extern char *wrksrc;
+extern char *sysroot;
extern int debug;
enum operation_mode {
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/files/bin/normalise-cc.c
--- a/pkgtools/cwrappers/files/bin/normalise-cc.c Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/files/bin/normalise-cc.c Mon Apr 04 11:22:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: normalise-cc.c,v 1.6 2021/11/07 12:38:12 christos Exp $ */
+/* $NetBSD: normalise-cc.c,v 1.7 2022/04/04 11:22:51 riastradh Exp $ */
/*-
* Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -38,7 +38,8 @@
static void
normalise_path_list(struct arglist *args, struct argument *arg,
- const char *prefix, const char *val, int strip_relative)
+ const char *prefix, const char *sysroot_prefix, const char *val,
+ int strip_relative)
{
const char *sep;
struct argument *arg2;
@@ -51,6 +52,14 @@
arg2 = argument_new(concat2(prefix, val, sep - val));
TAILQ_INSERT_AFTER(args, arg, arg2, link);
arg = arg2;
+ if (sysroot_prefix && sysroot) {
+ char *sysroot_val = concat2(sysroot, val, sep - val);
+ arg2 = argument_new(concat(sysroot_prefix,
+ sysroot_val));
+ free(sysroot_val);
+ TAILQ_INSERT_AFTER(args, arg, arg2, link);
+ arg = arg2;
+ }
val = sep + 1;
}
if (val[0] == '\0' || (strip_relative && !isabs(val[0])))
@@ -58,6 +67,13 @@
arg2 = argument_new(concat(prefix, val));
TAILQ_INSERT_AFTER(args, arg, arg2, link);
arg = arg2;
+ if (sysroot_prefix && sysroot) {
+ char *sysroot_val = concat(sysroot, val);
+ arg2 = argument_new(concat(sysroot_prefix, sysroot_val));
+ free(sysroot_val);
+ TAILQ_INSERT_AFTER(args, arg, arg2, link);
+ arg = arg2;
+ }
}
void
@@ -201,7 +217,8 @@
if (strcmp(arg->val, "-Wl,-rpath-link") == 0) {
if (arg2 == NULL || strncmp(arg2->val, "-Wl,", 4))
errx(255, "Missing argument for %s", arg->val);
- normalise_path_list(args, arg, "-Wl,-rpath-link,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath-link,", NULL,
arg2->val + 4, 0);
argument_unlink(args, &arg);
argument_unlink(args, &arg2);
@@ -210,7 +227,8 @@
if (strcmp(arg->val, "-R") == 0) {
if (arg2 == NULL || arg2->val[0] == '-')
errx(255, "Missing argument for %s", arg->val);
- normalise_path_list(args, arg, "-Wl,-rpath,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath,", "-Wl,-rpath-link,"/*sysroot*/,
arg2->val, 1);
argument_unlink(args, &arg);
argument_unlink(args, &arg2);
@@ -221,26 +239,30 @@
strcmp(arg->val, "-Wl,--rpath") == 0) {
if (arg2 == NULL || strncmp(arg2->val, "-Wl,", 4))
errx(255, "Missing argument for %s", arg->val);
- normalise_path_list(args, arg, "-Wl,-rpath,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath,", "-Wl,-rpath-link,"/*sysroot*/,
arg2->val + 4, 1);
argument_unlink(args, &arg);
argument_unlink(args, &arg2);
continue;
}
if (strncmp(arg->val, "-Wl,-R", 6) == 0) {
- normalise_path_list(args, arg, "-Wl,-rpath,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath,", "-Wl,-rpath-link,"/*sysroot*/,
arg->val + 6, 1);
argument_unlink(args, &arg);
continue;
}
if (strncmp(arg->val, "-R", 2) == 0) {
- normalise_path_list(args, arg, "-Wl,-rpath,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath,", "-Wl,-rpath-link,"/*sysroot*/,
arg->val + 2, 1);
argument_unlink(args, &arg);
continue;
}
if (strncmp(arg->val, "-Wl,-rpath,", 10) == 0) {
- normalise_path_list(args, arg, "-Wl,-rpath,",
+ normalise_path_list(args, arg,
+ "-Wl,-rpath,", "-Wl,-rpath-link,"/*sysroot*/,
arg->val + 10, 1);
argument_unlink(args, &arg);
continue;
diff -r 09a33a062092 -r 3b8309209242 pkgtools/cwrappers/files/bin/normalise-ld.c
--- a/pkgtools/cwrappers/files/bin/normalise-ld.c Mon Apr 04 09:59:28 2022 +0000
+++ b/pkgtools/cwrappers/files/bin/normalise-ld.c Mon Apr 04 11:22:50 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: normalise-ld.c,v 1.4 2017/11/07 16:49:22 khorben Exp $ */
+/* $NetBSD: normalise-ld.c,v 1.5 2022/04/04 11:22:51 riastradh Exp $ */
/*-
* Copyright (c) 2009, 2017 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -62,6 +62,29 @@
}
}
+/*
+ * append_rpath_link(args, path, &lastarg)
+ *
+ * If sysroot is enabled, append `-rpath-link ${sysroot}${path}'
+ * to the argument list after lastarg, and update lastarg to be
+ * the last argument appended.
+ */
+static void
+append_rpath_link(struct arglist *args, const char *path,
+ struct argument **lastargp)
+{
+ struct argument *arg_opt, *arg_val;
+
+ if (sysroot == NULL)
+ return;
+
+ arg_opt = argument_new(xstrdup("-rpath-link"));
+ arg_val = argument_new(concat(sysroot, path));
+ TAILQ_INSERT_AFTER(args, *lastargp, arg_opt, link);
+ TAILQ_INSERT_AFTER(args, arg_opt, arg_val, link);
+ *lastargp = arg_val;
+}
Home |
Main Index |
Thread Index |
Old Index