public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Chao Zeng <chao.zeng@siemens.com>, Le Jin <le.jin@siemens.com>
Subject: [PATCH 3/6] sdk: Add script to relocate SDK
Date: Sun, 22 Mar 2020 09:37:18 +0100	[thread overview]
Message-ID: <cc933d1a80907e7b50b28e2b72a50460017dcb43.1584866240.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1584866240.git.jan.kiszka@siemens.com>
In-Reply-To: <cover.1584866240.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

When run inside the unpacked SDK, this script tunes interp and rpath
entry in relevant binaries so that the cross conpilation tool can be
called outside of the chroot, irrespective of the host distribution.
Then only "--sysroot /path/to/sdkroot" needs to be passed to the
compiler.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 .../sdkchroot/files/relocate-sdk.sh                | 29 ++++++++++++++++++++++
 meta/recipes-devtools/sdkchroot/sdkchroot.bb       |  2 ++
 2 files changed, 31 insertions(+)
 create mode 100755 meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh

diff --git a/meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh b/meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh
new file mode 100755
index 00000000..98827139
--- /dev/null
+++ b/meta/recipes-devtools/sdkchroot/files/relocate-sdk.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2020
+#
+# SPDX-License-Identifier: MIT
+
+sdkroot=$(realpath $(dirname $0))
+arch=$(uname -m)
+
+if [ -z $(which patchelf 2>/dev/null) ]; then
+	echo "Please install 'patchelf' package first."
+	exit 1
+fi
+
+echo -n "Adjusting path of SDK to '${sdkroot}'... "
+
+for binary in $(find ${sdkroot}/usr/bin ${sdkroot}/usr/sbin ${sdkroot}/usr/lib/gcc* -executable -type f); do
+	interpreter=$(patchelf --print-interpreter ${binary} 2>/dev/null)
+	oldpath=${interpreter%/lib*/ld-linux*}
+	interpreter=${interpreter#${oldpath}}
+	if [ -n "${interpreter}" ]; then
+		patchelf --set-interpreter ${sdkroot}${interpreter} \
+			--set-rpath ${sdkroot}/usr/lib:${sdkroot}/usr/lib/${arch}-linux-gnu \
+			$binary 2>/dev/null
+	fi
+done
+
+echo "done"
diff --git a/meta/recipes-devtools/sdkchroot/sdkchroot.bb b/meta/recipes-devtools/sdkchroot/sdkchroot.bb
index ab0a66dc..2bc9d291 100644
--- a/meta/recipes-devtools/sdkchroot/sdkchroot.bb
+++ b/meta/recipes-devtools/sdkchroot/sdkchroot.bb
@@ -10,6 +10,7 @@ LIC_FILES_CHKSUM = "file://${LAYERDIR_core}/licenses/COPYING.GPLv2;md5=751419260
 
 SRC_URI = " \
     file://configscript.sh \
+    file://relocate-sdk.sh \
     file://README.sdk"
 PV = "0.1"
 
@@ -58,6 +59,7 @@ ROOTFS_POSTPROCESS_COMMAND =+ "sdkchroot_install_files"
 sdkchroot_install_files() {
     # Configure root filesystem
     sudo install -m 644 ${WORKDIR}/README.sdk ${S}
+    sudo install -m 755 ${WORKDIR}/relocate-sdk.sh ${S}
     sudo install -m 755 ${WORKDIR}/configscript.sh ${S}
     sudo chroot ${S} /configscript.sh  ${DISTRO_ARCH}
 }
-- 
2.16.4


  parent reply	other threads:[~2020-03-22  8:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22  8:37 [PATCH 0/6] Evolve SDK to chroot-free usage Jan Kiszka
2020-03-22  8:37 ` [PATCH 1/6] sdk: Add support for adding self-defined sdk packages Jan Kiszka
2020-03-22  8:37 ` [PATCH 2/6] sdk: Make all links in the SDK chroot relative Jan Kiszka
2020-03-22  8:37 ` Jan Kiszka [this message]
2020-03-22  8:37 ` [PATCH 4/6] sdk: Do not ship the isar-apt repo Jan Kiszka
2020-03-22  8:37 ` [PATCH 5/6] sdk: Inject sysroot path when calling relocated toolchain Jan Kiszka
2020-03-22  8:55   ` [PATCH v2 " Jan Kiszka
2020-03-22  8:37 ` [PATCH 6/6] sdk: Update README.sdk Jan Kiszka
2020-03-27 23:48 ` [PATCH 0/6] Evolve SDK to chroot-free usage Christopher Larson
2020-03-28  7:33   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cc933d1a80907e7b50b28e2b72a50460017dcb43.1584866240.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=chao.zeng@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=le.jin@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox