From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v5 1/3] package/environment-setup: new package
Date: Mon, 27 Apr 2020 22:36:55 +0200 [thread overview]
Message-ID: <20200427203657.77392-1-angelo@amarulasolutions.com> (raw)
From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
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.
Due to the nature of the intrusiveness of this script, a new PS1 is
installed to let the user understand that the current running shell is
not a normal shell.
Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
---
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)
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 | 16 +++++++++
.../environment-setup/environment-setup.mk | 34 +++++++++++++++++++
5 files changed, 64 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..7b2de4bdfa 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+ 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 b/package/Config.in
index bf02870ea2..b698d6f184 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1955,6 +1955,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..b48f1979d6
--- /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 0000000000..7c6e352bde
--- /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'
+ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP = 's+$(TARGET_CROSS)+\$${CROSS_COMPILE}+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 \"$$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 $(ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP) \
+ $(ENVIRONMENT_SETUP_FILE)
+ printf "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"\n" \
+ >> $(ENVIRONMENT_SETUP_FILE)
+endef
+
+$(eval $(generic-package))
--
2.25.1
next reply other threads:[~2020-04-27 20:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 20:36 Angelo Compagnucci [this message]
2020-04-27 20:36 ` [Buildroot] [PATCH v5 2/3] package/environment-setup: add configure alias Angelo Compagnucci
2020-04-27 20:36 ` [Buildroot] [PATCH v5 3/3] package/environment-setup: add cmake alias Angelo Compagnucci
2020-04-28 7:42 ` [Buildroot] [PATCH v5 1/3] package/environment-setup: new package Mircea GLIGA
2020-04-28 8:42 ` Angelo Compagnucci
2020-04-28 11:04 ` Mircea GLIGA
2020-05-05 20:43 ` Angelo Compagnucci
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=20200427203657.77392-1-angelo@amarulasolutions.com \
--to=angelo.compagnucci@gmail.com \
--cc=buildroot@busybox.net \
/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