From patchwork Tue Apr 28 14:45:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 1278545 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=KND7Xi9Q; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49BPbY5dx6z9sRY for ; Wed, 29 Apr 2020 00:46:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 89DEC84D16; Tue, 28 Apr 2020 14:46:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Aa1SJ-XlKZv7; Tue, 28 Apr 2020 14:46:12 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id B0074861F4; Tue, 28 Apr 2020 14:46:12 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 810C61BF3FF for ; Tue, 28 Apr 2020 14:46:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 7DB7F869D8 for ; Tue, 28 Apr 2020 14:46:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dLKgKIvxCmIc for ; Tue, 28 Apr 2020 14:46:10 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by hemlock.osuosl.org (Postfix) with ESMTPS id C071D880CA for ; Tue, 28 Apr 2020 14:46:09 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id j14so17116838lfg.9 for ; Tue, 28 Apr 2020 07:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id; bh=sCt4LkndhuW4bAN9T9NCG0qSXf5Fez8AX8dV7lJNPaE=; b=KND7Xi9Q+vQCOCJzHcZbhy3e2SdGjssehxcXEmWIberIYF0RHpHNxg4kaB03GfqYvZ E6ZunCj6do8YF8LIjWqWa+qPhztRtLIe1tpVwpEF1IHrnSsZVIqq1kmL/AFnOHsT+SW7 3k7altK3u9YH+PdbAGYisFAdCdiSGXE9fv5CI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sCt4LkndhuW4bAN9T9NCG0qSXf5Fez8AX8dV7lJNPaE=; b=IXVYK+xnQO04zE9LlVWxUNEwe7Jc0VL3ytD5Ox1KXuwvxk3rHCAMU3kGxS3wr2aAxB Fk3OBnA6uXw/Xcv/X22b5gG9JOPPcvBqTll4zTsmZ4FtY8Xj+zwEGXj5e3mHtYbsoS76 C8ORDMMxk0bsWyaBzJZKM6DufmyvJ8EsSiwHRpsvyoUMJY8kIO+NYA3G2Zj/Ov/FiiQz VZ3RKsJFfCWhA6ufzZNZHBc/E5eLhFVtufO+5z2kM7ljE2bCoH4RyOtBSk40aM63RjlH G0FpktLLAenEOZzi1wed5PYSknO7ieJPKbimyu1q49Jt0XhSQBtUf9XAI45wJaTbholX iq7Q== X-Gm-Message-State: AGi0PuYU5qkDVT/v0MUBVlvcCopsnAPFIjedWxJ3Y0FW+lQrM/p4ld06 yhmkSQFVJrh2aTEI2dOGYhYN4gyT/DI= X-Google-Smtp-Source: APiQypIja3kjS1ow36wS72pavnjVB7SdiyRiq35It9BPBx2jBIrQnia7FK5lAlcdOE15wPUDcGxrdg== X-Received: by 2002:ac2:4892:: with SMTP id x18mr1560757lfc.142.1588085166837; Tue, 28 Apr 2020 07:46:06 -0700 (PDT) Received: from angelo-ThinkPad-T470p.powersoft.it (host185036129193.static.fidoka.tech. [185.36.129.193]) by smtp.gmail.com with ESMTPSA id t13sm12797609ljd.38.2020.04.28.07.46.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Apr 2020 07:46:05 -0700 (PDT) From: Angelo Compagnucci To: buildroot@buildroot.org Date: Tue, 28 Apr 2020 16:45:58 +0200 Message-Id: <1588085161-28104-1-git-send-email-angelo@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 Subject: [Buildroot] [PATCH v6 1/4] package/environment-setup: new package X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Angelo Compagnucci , Angelo Compagnucci MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Angelo Compagnucci Install an helper script to setup a build environment based on buildroot. It's useful when a developer wants to use a buildroot generated sdk to build an external project. Signed-off-by: Angelo Compagnucci Tested-by: Michael Trimarchi Tested-by: Adam Duskett --- Changelog: v1->v2: * Moved from echo to printf (Yann) * removed sh extension (Yann) * Adding missing script v2->v3: * Split the patch v3->v4: * Better handling of SDK_PATH dir (Mircea Gliga) v4->v5: * Cleaning the script using SDK_PATH where possible (Mircea Gliga) v5->v6: * Removed unused sed expressione (Mircea Gliga) * Moved to be an host package * fix PATH leaking: before path from the current user can leak into the script * Removed PS1 Some of the reason I kept several things the way I originally planned: * I kept it being a package because it doesn't fit in any other tool: indeed this script changes your current PATH and exports some variables that can be used for anything. Think of qmake or cmake or a package that doesn't have any build system at all. It has some features geared also towards autotools software but I keep planning others. * I kept looping in TARGET_CONFIGURE_OPTS, indeed it produces a more clean environment script at the end. For the problem raised by Yann: variables in TARGET_CONFIGURE_OPTS _are_ properly escaped, indeed if not, they were a big source of problems on each ./configure invocation due to the fact they are injected on the ./configure commandline invocation. * I kept the manual entry: I think that the most documentation the better. docs/manual/using-buildroot-toolchain.txt | 8 ++++++ package/Config.in.host | 1 + package/environment-setup/Config.in.host | 6 +++++ package/environment-setup/environment-setup | 16 ++++++++++++ package/environment-setup/environment-setup.mk | 34 ++++++++++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 package/environment-setup/Config.in.host create mode 100644 package/environment-setup/environment-setup create mode 100644 package/environment-setup/environment-setup.mk diff --git a/docs/manual/using-buildroot-toolchain.txt b/docs/manual/using-buildroot-toolchain.txt index 0c0c35f..98dae6c 100644 --- a/docs/manual/using-buildroot-toolchain.txt +++ b/docs/manual/using-buildroot-toolchain.txt @@ -27,6 +27,14 @@ Upon extracting the SDK tarball, the user must run the script +relocate-sdk.sh+ (located at the top directory of the SDK), to make sure all paths are updated with the new location. +For your convenience, by selecting the host package +BR2_PACKAGE_HOST_ENVIRONMENT_SETUP, you can have a +setup-environment+ script +installed in +output/host/+. +This script can be sourced with +. your/sdk/path/environment-setup+ to launch +the buildroot shell. Inside this shell, you will find an environment already +set up with the correct PATH and the complete list of +target configure +options+. + Alternatively, if you just want to prepare the SDK without generating the tarball (e.g. because you will just be moving the +host+ directory, or will be generating the tarball on your own), Buildroot also allows diff --git a/package/Config.in.host b/package/Config.in.host index f1246c7..ba1dcb7 100644 --- a/package/Config.in.host +++ b/package/Config.in.host @@ -18,6 +18,7 @@ menu "Host utilities" source "package/dtc/Config.in.host" source "package/e2fsprogs/Config.in.host" source "package/e2tools/Config.in.host" + source "package/environment-setup/Config.in.host" source "package/erofs-utils/Config.in.host" source "package/eudev/Config.in.host" source "package/exfatprogs/Config.in.host" diff --git a/package/environment-setup/Config.in.host b/package/environment-setup/Config.in.host new file mode 100644 index 0000000..87f460d --- /dev/null +++ b/package/environment-setup/Config.in.host @@ -0,0 +1,6 @@ +config BR2_PACKAGE_HOST_ENVIRONMENT_SETUP + bool "Environment setup" + help + Install an helper script to setup a build environment + based on buildroot. It's useful when you export an sdk + and want to use buildroot to build an external project diff --git a/package/environment-setup/environment-setup b/package/environment-setup/environment-setup new file mode 100644 index 0000000..b48f197 --- /dev/null +++ b/package/environment-setup/environment-setup @@ -0,0 +1,16 @@ +cat <<'EOF' + _ _ _ _ _ +| |__ _ _(_) | __| |_ __ ___ ___ | |_ +| '_ \| | | | | |/ _` | '__/ _ \ / _ \| __| +| |_) | |_| | | | (_| | | | (_) | (_) | |_ +|_.__/ \__,_|_|_|\__,_|_| \___/ \___/ \__| shell + + Making embedded Linux easy! + +Some tips: +* PATH is now pointing to the HOST_DIR path +* Target configure options are already exported +* To configure do "./configure $CONFIGURE_FLAGS" + +EOF +SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}")) diff --git a/package/environment-setup/environment-setup.mk b/package/environment-setup/environment-setup.mk new file mode 100644 index 0000000..6d2396f --- /dev/null +++ b/package/environment-setup/environment-setup.mk @@ -0,0 +1,34 @@ +################################################################################ +# +# environment-setup +# +################################################################################ + +ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup +ENVIRONMENT_SETUP_HOST_DIR_SED_EXP = 's+$(HOST_DIR)+\$$SDK_PATH+g' +ENVIRONMENT_SETUP_HOST_BIN_DIR_SED_EXP = 's+$(HOST_DIR)/bin/++g' + +define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS + cp package/environment-setup/environment-setup $(ENVIRONMENT_SETUP_FILE) + for var in $(TARGET_CONFIGURE_OPTS); do \ + printf "export \"$$var\"\n" >> $(ENVIRONMENT_SETUP_FILE); \ + done + printf "export \"CROSS_COMPILE=$(TARGET_CROSS)\"\n" >> $(ENVIRONMENT_SETUP_FILE) + printf "export \"CONFIGURE_FLAGS=--target=$(GNU_TARGET_NAME) \ + --host=$(GNU_TARGET_NAME) \ + --build=$(GNU_HOST_NAME) \ + --prefix=/usr \ + --exec-prefix=/usr \ + --sysconfdir=/etc \ + --localstatedir=/var \ + --program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE) + $(SED) $(ENVIRONMENT_SETUP_HOST_BIN_DIR_SED_EXP) \ + -e $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) \ + -e '/^export "PATH=/c\' \ + $(ENVIRONMENT_SETUP_FILE) + printf "export \"PATH=\$$SDK_PATH/bin:\$$SDK_PATH/sbin:\$$PATH\"\n" \ + >> $(ENVIRONMENT_SETUP_FILE) + +endef + +$(eval $(host-generic-package))