From patchwork Sat Apr 18 14:29:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 1272609 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.137; helo=fraxinus.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=dxIs7LkJ; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 494Fjb15xJz9sSd for ; Sun, 19 Apr 2020 00:30:04 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 377178650A; Sat, 18 Apr 2020 14:30:01 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iB3xqM2esJ6K; Sat, 18 Apr 2020 14:29:58 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id C197485BE4; Sat, 18 Apr 2020 14:29:58 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id C666A1BF853 for ; Sat, 18 Apr 2020 14:29:57 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id C104086E2A for ; Sat, 18 Apr 2020 14:29:57 +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 CiwXlE7C0n-S for ; Sat, 18 Apr 2020 14:29:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by whitealder.osuosl.org (Postfix) with ESMTPS id 775AF86193 for ; Sat, 18 Apr 2020 14:29:56 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id v4so896241wme.1 for ; Sat, 18 Apr 2020 07:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=RhTlPtOC8UuggctRVFgZaDfI8QuYCYzjW5nBBxKap3s=; b=dxIs7LkJevMLwlSKYKSS0CMdtX2ydHe0DLa6LLgdk6SONroX2pokxOk/bZ+c+TAA5Q RwUpgmsDUFGn34ym9J8NaYzC3cVYs7Sewv5/vQgOnheVuK/7JlbyPWn59TwHL+s65V3a hcQKF7scIpwBYoEC69Vy6J66R3LLlj7rUk+4hXC8VR0knMRk9Fd8c6X6oQ+b7wdfYdW9 xqivakBMuFGEMUN/QqjG6FI6n7ax9+1E1KWqzzVg2NaTxX+mDWRlIkajrMEdPNRlyvjQ jmR95y/xOftQ1cCngrvcWgz7VHjOAMsPCsxlv8LSkjxhtUThlLB/WIWBhTcT2xgLiWpo xY6A== 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=RhTlPtOC8UuggctRVFgZaDfI8QuYCYzjW5nBBxKap3s=; b=KhRldSA1fndBCgxVwx+f/19ImI1Zb2dcQoM6uKjlg+5ADycY4hGLdceuFFp9kvV/CH C6hta5dYvaFTi3qfLD0wgwxQEwvkqwuoqcEzFfRErQlRgchv4sPpfaEGheMxrpfNIhoz v1h2a8pS7ZJDh+M6l2cOBxbTctwlEM86+xo3BOH5EBOLhgC+3OC5SZRLsOo0XUdPCSBO XJ0YRPoi2p4L/PQvlM1vxv7aH+bHhSKOqVEEa5tP7wKGY5nAw6j8pSQZcHq1scL+FzJn m2kU3ifljO3kDp+rNIcUTCqiqPmlJcc7XBR0+t064lqIPLUCWvydMvr7YkOulME+rCHw h4ZA== X-Gm-Message-State: AGi0PuYKqiyG9Y0uUXP3PxeO/jTYCjFUs1uEOQNZUA52/gb2ig3oPJL2 Tz2TnZJCyiogn4V+sCYJyvrWIaR/X+o= X-Google-Smtp-Source: APiQypJCs9vVy7hHp0j1AXe13dRSMbHsyzPmf492pJnV6qi8Mu1R8tYL231C2hxiKH2NZMZCC+R0ng== X-Received: by 2002:a05:600c:2157:: with SMTP id v23mr7026957wml.149.1587220194353; Sat, 18 Apr 2020 07:29:54 -0700 (PDT) Received: from localhost.localdomain (host185100179096.static.fidoka.tech. [185.100.179.96]) by smtp.gmail.com with ESMTPSA id 68sm38675825wrm.65.2020.04.18.07.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 07:29:53 -0700 (PDT) From: Angelo Compagnucci X-Google-Original-From: Angelo Compagnucci To: buildroot@buildroot.org Date: Sat, 18 Apr 2020 16:29:51 +0200 Message-Id: <20200418142951.15630-1-angelo@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 Subject: [Buildroot] [PATCH v2] 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 MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" 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. Signed-off-by: Angelo Compagnucci --- Changelog: v1->v2: * Moved from echo to printf (Yann) * removed sh extension (Yann) * Adding missing script 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 curent 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 the script being installed in host root: other build system does that and I want this script to mimic other build systems. * I kept looping in TARGET_CONFIGURE_OPTS, indeed it produces a more clean environment script at the end. For the problem arised 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 PS1: this script heavily mess with the path, it is expected by the user running it, but it can be very confusing being on a shell that doesn't behaves like your normal shell. So having a different PS1 helps remembering you are running into the buildroot shell and not into an ordinary one (other build systems does the same). * I kept the manual entry: I think that the most documentation the better. docs/manual/using-buildroot-toolchain.txt | 7 ++++ package/Config.in | 1 + package/environment-setup/Config.in | 6 ++++ package/environment-setup/environment-setup | 17 ++++++++++ .../environment-setup/environment-setup.mk | 32 +++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 package/environment-setup/Config.in 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 0c0c35fced..e2697d19ac 100644 --- a/docs/manual/using-buildroot-toolchain.txt +++ b/docs/manual/using-buildroot-toolchain.txt @@ -27,6 +27,13 @@ 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 package BR2_PACKAGE_ENVIRONMENT_SETUP, +you can have a +setup-environment.sh+ 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, the complete list of +target configure+ +variables and some useful commands like the +configure+ alias. + 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 b/package/Config.in index ccf54f2417..eff51d7451 100644 --- a/package/Config.in +++ b/package/Config.in @@ -1949,6 +1949,7 @@ menu "Miscellaneous" source "package/collectl/Config.in" source "package/domoticz/Config.in" source "package/empty/Config.in" + source "package/environment-setup/Config.in" source "package/gnuradio/Config.in" source "package/googlefontdirectory/Config.in" source "package/gqrx/Config.in" diff --git a/package/environment-setup/Config.in b/package/environment-setup/Config.in new file mode 100644 index 0000000000..f0fcc7d0f8 --- /dev/null +++ b/package/environment-setup/Config.in @@ -0,0 +1,6 @@ +config BR2_PACKAGE_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 0000000000..c8ee7aaa0b --- /dev/null +++ b/package/environment-setup/environment-setup @@ -0,0 +1,17 @@ +cat <<'EOF' + _ _ _ _ _ +| |__ _ _(_) | __| |_ __ ___ ___ | |_ +| '_ \| | | | | |/ _` | '__/ _ \ / _ \| __| +| |_) | |_| | | | (_| | | | (_) | (_) | |_ +|_.__/ \__,_|_|_|\__,_|_| \___/ \___/ \__| shell + + Making embedded Linux easy! + +Some tips: +* PATH is now pointing to the HOST_DIR path +* Target configure options are already exported +* You can do "./configure $CONFIGURE_FLAGS" +* Alternatively, you can use the "configure" alias + +EOF +SDK_PATH=$(dirname "${BASH_SOURCE[0]}") diff --git a/package/environment-setup/environment-setup.mk b/package/environment-setup/environment-setup.mk new file mode 100644 index 0000000000..b5438b389a --- /dev/null +++ b/package/environment-setup/environment-setup.mk @@ -0,0 +1,32 @@ +################################################################################ +# +# environment-setup +# +################################################################################ + +ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup +ENVIRONMENT_SETUP_SED_EXP = --expression='s+$(HOST_DIR)+\$$SDK_PATH+g' + +define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS + cp package/environment-setup/environment-setup $(ENVIRONMENT_SETUP_FILE) + for var in $(TARGET_CONFIGURE_OPTS); do \ + printf "export \"%s\"\n" \ + "$$(sed $(ENVIRONMENT_SETUP_SED_EXP) <<< $$var)" \ + >> $(ENVIRONMENT_SETUP_FILE); \ + done + printf "export \"CROSS_COMPILE=$(TARGET_CROSS)\"\n" \ + "$$(sed $(ENVIRONMENT_SETUP_SED_EXP) <<< $$var)" \ + >> $(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) + printf "alias configure=\"./configure \$${CONFIGURE_FLAGS}\"\n" >> $(ENVIRONMENT_SETUP_FILE) + printf "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"" >> $(ENVIRONMENT_SETUP_FILE) +endef + +$(eval $(generic-package))