Skip to contentSkip to conversation

package/environment-setup: new package

PATCH New Angelo Compagnucci 4 participants 11 messages Apr 28, 2020 – Nov 3, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/4 package/environment-setup: new package

From: Angelo Compagnucci <[email protected]>

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.

---
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
docs/manual/using-buildroot-toolchain.txt +8 -0
index 0c0c35f..98dae6c 100644
@@ -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
package/Config.in.host +1 -0
index f1246c7..ba1dcb7 100644
@@ -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"
package/environment-setup/Config.in.host new file +6 -0
new file mode 100644
index 0000000..87f460d
@@ -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
package/environment-setup/environment-setup new file +16 -0
new file mode 100644
index 0000000..b48f197
@@ -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]}"))
package/environment-setup/environment-setup.mk new file +34 -0
new file mode 100644
index 0000000..6d2396f
@@ -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))
Signature · 1 line
2.7.4
#1 lore raw

PATCH v6 2/4 package/environment-setup: add configure alias

From: Angelo Compagnucci <[email protected]>

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a "configure" alias is provided to call ./configure with the correct flags.

---
 docs/manual/using-buildroot-toolchain.txt      | 4 ++--
 package/environment-setup/environment-setup    | 1 +
 package/environment-setup/environment-setup.mk | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
docs/manual/using-buildroot-toolchain.txt +2 -2
index 98dae6c..fbe25a9 100644
@@ -32,8 +32,8 @@ 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+.
+set up with the correct PATH, the complete list of +target configure
+options+ and some useful commands.
 
 Alternatively, if you just want to prepare the SDK without generating
 the tarball (e.g. because you will just be moving the +host+ directory,
package/environment-setup/environment-setup +1 -0
index b48f197..db652fe 100644
@@ -11,6 +11,7 @@ Some tips:
 * PATH is now pointing to the HOST_DIR path
 * Target configure options are already exported
 * To configure do "./configure $CONFIGURE_FLAGS"
+* Alternatively use the alias "configure"
 
 EOF
 SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}"))
package/environment-setup/environment-setup.mk +2 -0
index 6d2396f..138710c 100644
@@ -22,6 +22,8 @@ define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS
 		--sysconfdir=/etc \
 		--localstatedir=/var \
 		--program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE)
+	printf "alias configure=\"./configure \$${CONFIGURE_FLAGS}\"\n" \
+		>> $(ENVIRONMENT_SETUP_FILE)
 	$(SED) $(ENVIRONMENT_SETUP_HOST_BIN_DIR_SED_EXP) \
 		-e $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) \
 		-e '/^export "PATH=/c\' \
Signature · 1 line
2.7.4
#2 lore raw

PATCH v6 2/4 package/environment-setup: add configure alias

Quoted 6 lines · On Tue, 28 Apr 2020 16:45:59 +0200 Angelo Compagnucci…

From: Angelo Compagnucci <[email protected]>

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a "configure" alias is provided to call ./configure with the correct flags.

Quoted 6 lines
---
 docs/manual/using-buildroot-toolchain.txt      | 4 ++--
 package/environment-setup/environment-setup    | 1 +
 package/environment-setup/environment-setup.mk | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)

I have applied, with a few tweaks here and there. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH v6 3/4 package/environment-setup: add cmake alias

In reply to Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a "cmake" alias is provided to call cmake with the correct toolchain file and options.

---
 package/environment-setup/environment-setup    | 1 +
 package/environment-setup/environment-setup.mk | 3 +++
 2 files changed, 4 insertions(+)
package/environment-setup/environment-setup +1 -0
index db652fe..7c3ddda 100644
@@ -12,6 +12,7 @@ Some tips:
 * Target configure options are already exported
 * To configure do "./configure $CONFIGURE_FLAGS"
 * Alternatively use the alias "configure"
+* A "cmake" alias is available
 
 EOF
 SDK_PATH=$(dirname $(realpath "${BASH_SOURCE[0]}"))
package/environment-setup/environment-setup.mk +3 -0
index 138710c..ba85691 100644
@@ -24,6 +24,9 @@ define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS
 		--program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE)
 	printf "alias configure=\"./configure \$${CONFIGURE_FLAGS}\"\n" \
 		>> $(ENVIRONMENT_SETUP_FILE)
+	printf "alias cmake=\"cmake \
+		-DCMAKE_TOOLCHAIN_FILE=$(HOST_DIR)/share/buildroot/toolchainfile.cmake \
+		-DCMAKE_INSTALL_PREFIX=/usr\"\n" >> $(ENVIRONMENT_SETUP_FILE)
 	$(SED) $(ENVIRONMENT_SETUP_HOST_BIN_DIR_SED_EXP) \
 		-e $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) \
 		-e '/^export "PATH=/c\' \
Signature · 1 line
2.7.4
#4 lore raw

PATCH v6 3/4 package/environment-setup: add cmake alias

Quoted 11 lines · On Tue, 28 Apr 2020 16:46:00 +0200 Angelo Compagnucci…

From: Angelo Compagnucci <[email protected]>

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a "cmake" alias is provided to call cmake with the correct toolchain file and options.

---
 package/environment-setup/environment-setup    | 1 +
 package/environment-setup/environment-setup.mk | 3 +++
 2 files changed, 4 insertions(+)

I have applied, with a few tweaks here and there. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH v6 4/4 package/environment-setup: adding custom PS1

In reply to Angelo Compagnucci

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a custom PS1 is optionally available. This PS1 will show the sdk version actually loaded, this can be useful to not confuse this shell with a normal one.

---
 package/environment-setup/Config.in.host       | 10 ++++++++++
 package/environment-setup/environment-setup.mk |  3 +++
 2 files changed, 13 insertions(+)
package/environment-setup/Config.in.host +10 -0
index 87f460d..1af826e 100644
@@ -4,3 +4,13 @@ config BR2_PACKAGE_HOST_ENVIRONMENT_SETUP
 	  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
+
+if BR2_PACKAGE_HOST_ENVIRONMENT_SETUP
+
+config BR2_PACKAGE_HOST_ENVIRONMENT_SETUP_PS1
+	bool "export custom PS1"
+	help
+	  Whan sourced, the script will replace the PS1 with a
+	  custom one reporting SDK version in use.
+
+endif
package/environment-setup/environment-setup.mk +3 -0
index ba85691..b024983 100644
@@ -34,6 +34,9 @@ define HOST_ENVIRONMENT_SETUP_INSTALL_CMDS
 	printf "export \"PATH=\$$SDK_PATH/bin:\$$SDK_PATH/sbin:\$$PATH\"\n" \
 		>> $(ENVIRONMENT_SETUP_FILE)
 
+	$(if $(BR2_PACKAGE_HOST_ENVIRONMENT_SETUP_PS1),\
+		printf "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"\n" \
+		>> $(ENVIRONMENT_SETUP_FILE),)
 endef
 
 $(eval $(host-generic-package))
Signature · 1 line
2.7.4
#6 lore raw

PATCH v6 4/4 package/environment-setup: adding custom PS1

Quoted 10 lines · On Tue, 28 Apr 2020 16:46:01 +0200 Angelo Compagnucci…

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a custom PS1 is optionally available. This PS1 will show the sdk version actually loaded, this can be useful to not confuse this shell with a normal one.

---
 package/environment-setup/Config.in.host       | 10 ++++++++++
 package/environment-setup/environment-setup.mk |  3 +++
 2 files changed, 13 insertions(+)

I've marked this one as Rejected: since the beginning Yann has expressed that changing the PS1 of the user was not acceptable, and we believe indeed it shouldn't be changed. Also, it's probably not the most important aspect of environment-setup.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

PATCH v6 4/4 package/environment-setup: adding custom PS1

Hi Thomas,

Quoted 15 lines · Thomas Petazzoni
Quoted 10 lines · On Tue, 28 Apr 2020 16:46:01 +0200 Angelo Compagnucci…

In order to simplify the usage of a buildroot toolchain within the buildroot shell, a custom PS1 is optionally available. This PS1 will show the sdk version actually loaded, this can be useful to not confuse this shell with a normal one.

---
 package/environment-setup/Config.in.host       | 10 ++++++++++
 package/environment-setup/environment-setup.mk |  3 +++
 2 files changed, 13 insertions(+)
Quoted 4 lines

I've marked this one as Rejected: since the beginning Yann has expressed that changing the PS1 of the user was not acceptable, and we believe indeed it shouldn't be changed. Also, it's probably not the most important aspect of environment-setup.

I honestly totally disagree. I consider having a custom PS1 quite important, I had several funny moments understand why I was having a python version on a shell and a totally different python version on the next one.
Restoring your old PS1 is quite easy and people like Yann will not use the buildroot shell anyway ;)
The feature was of course taught for the average daily programmer who needs to know boldly where he is running what.

Anyway, I'm happy this series was finally accepted, I would post some more things in the feature.

Thanks

Quoted 8 lines

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Signature · 13 lines
Angelo Compagnucci

Amarula Solutions SRL

Embedded Linux Developer

Via Le Canevare 30 31100 Treviso IT

T. +390422435310

M. +393479922139

[`as] https://www.amarulasolutions.com|
#8 lore raw

PATCH v6 1/4 package/environment-setup: new package

In reply to Angelo Compagnucci

Hi all

Quoted 8 lines · Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

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.

I have merged today in some customers project and I think that is really nice to have feature

Michael

Quoted 159 lines

---
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
docs/manual/using-buildroot-toolchain.txt +8 -0
index 0c0c35f..98dae6c 100644
@@ -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
package/Config.in.host +1 -0
index f1246c7..ba1dcb7 100644
@@ -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"
package/environment-setup/Config.in.host new file +6 -0
new file mode 100644
index 0000000..87f460d
@@ -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
package/environment-setup/environment-setup new file +16 -0
new file mode 100644
index 0000000..b48f197
@@ -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]}"))
package/environment-setup/environment-setup.mk new file +34 -1
new file mode 100644
index 0000000..6d2396f
@@ -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))
--

2.7.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 4 lines
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |
#9 lore raw

PATCH v6 1/4 package/environment-setup: new package

All;

Quoted 12 lines · Michael Nazzareno Trimarchi

Hi all

Quoted 7 lines · Angelo Compagnucci

From: Angelo Compagnucci <[email protected]>

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.

Quoted 9 lines
Quoted 1 line

I have merged today in some customers project and I think that is really nice to have feature

Michael

I too think this is a great idea and my boss will be really happy with this script!

Quoted 171 lines
Quoted 155 lines

---
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
docs/manual/using-buildroot-toolchain.txt +8 -0
index 0c0c35f..98dae6c 100644
@@ -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
package/Config.in.host +1 -0
index f1246c7..ba1dcb7 100644
@@ -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"
package/environment-setup/Config.in.host new file +6 -0
new file mode 100644
index 0000000..87f460d
@@ -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
package/environment-setup/environment-setup new file +16 -0
new file mode 100644
index 0000000..b48f197
@@ -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]}"))
package/environment-setup/environment-setup.mk new file +34 -1
new file mode 100644
index 0000000..6d2396f
@@ -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))
--

2.7.4

Quoted 4 lines

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

--

| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

#10 lore raw

PATCH v6 1/4 package/environment-setup: new package

In reply to Angelo Compagnucci
Quoted 17 lines · On Tue, 28 Apr 2020 16:45:58 +0200 Angelo Compagnucci…

From: Angelo Compagnucci <[email protected]>

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.

---
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)

Quoted 8 lines

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

This one was superseded by Matt's patch, which I have applied.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com