Skip to contentSkip to conversation

package/environment-setup: new package

PATCH New Angelo Compagnucci 3 participants 4 messages Apr 18, 2020

lore
Share & tools
lore
#0 lore raw

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

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.

---
 docs/manual/using-buildroot-toolchain.txt     |  7 +++++
 package/Config.in                             |  1 +
 package/environment-setup/Config.in           |  6 ++++
 .../environment-setup/environment-setup.mk    | 28 +++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 package/environment-setup/Config.in
 create mode 100644 package/environment-setup/environment-setup.mk
docs/manual/using-buildroot-toolchain.txt +7 -0
index 0c0c35fced..15096cfec8 100644
@@ -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 +. environment-setup.sh+ 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
package/Config.in +1 -0
index ccf54f2417..eff51d7451 100644
@@ -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"
package/environment-setup/Config.in new file +6 -0
new file mode 100644
index 0000000000..f0fcc7d0f8
@@ -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
package/environment-setup/environment-setup.mk new file +28 -0
new file mode 100644
index 0000000000..840ee2a1a0
@@ -0,0 +1,28 @@
+################################################################################
+#
+# environment-setup
+#
+################################################################################
+
+ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup.sh
+ENVIRONMENT_SETUP_SED_EXP = --expression='s+$(HOST_DIR)+\$$SDK_PATH+g'
+
+define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS
+	cp package/environment-setup/environment-setup.sh $(ENVIRONMENT_SETUP_FILE)
+	for var in $(TARGET_CONFIGURE_OPTS); do \
+		echo export \"$$var\" | sed $(ENVIRONMENT_SETUP_SED_EXP) >> $(ENVIRONMENT_SETUP_FILE); \
+	done
+	echo export \"CROSS_COMPILE=$(TARGET_CROSS)\" | sed $(ENVIRONMENT_SETUP_SED_EXP) >> $(ENVIRONMENT_SETUP_FILE)
+	echo 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=\" >> $(ENVIRONMENT_SETUP_FILE)
+	echo "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"" >> $(ENVIRONMENT_SETUP_FILE)
+	echo alias "configure=\"./configure \$${CONFIGURE_FLAGS}\"" >> $(ENVIRONMENT_SETUP_FILE)
+endef
+
+$(eval $(generic-package))
Signature · 1 line
2.17.1
#1 lore raw

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

Angelo, All,

On 2020-04-18 12:31 +0200, Angelo Compagnucci spake thusly:

Quoted 19 lines

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.

---
 docs/manual/using-buildroot-toolchain.txt     |  7 +++++
 package/Config.in                             |  1 +
 package/environment-setup/Config.in           |  6 ++++
 .../environment-setup/environment-setup.mk    | 28 +++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 package/environment-setup/Config.in
 create mode 100644 package/environment-setup/environment-setup.mk
docs/manual/using-buildroot-toolchain.txt +0 -0
index 0c0c35fced..15096cfec8 100644

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run the script · line 35

Quoted 9 lines
docs/manual/using-buildroot-toolchain.txt +6 -0
@@ -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 +. environment-setup.sh+ 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.

I don't think this should warrant a blurb in the manual. Otherwise, you would have to add the same for the meson cross-compilation file that we provide. And the ones for cmake as well...

Also. I don't like it being a package. There is no reason for that. Instead, install it like we do the similar other cross-compilaiton helpers, with the package that actually provides the tools:

- the mexon's cross-compilation file is installed by host-meson

- the cmake's toolchainfile.cmake and Buildroot.cmake files are installed by the cmake infra (yeah, that's not so nice...)

So, since this script is geared towards autotools, I guess host-autoconf should bear the burden of installing that file.

Quoted 18 lines
package/environment-setup/Config.in new file +6 -0
new file mode 100644
index 0000000000..f0fcc7d0f8
@@ -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
package/environment-setup/environment-setup.mk new file +0 -0
new file mode 100644
index 0000000000..840ee2a1a0

package/environment-setup/environment-setup.mk line 7

Quoted 7 lines
package/environment-setup/environment-setup.mk new file +7 -0
@@ -0,0 +1,28 @@
+################################################################################
+#
+# environment-setup
+#
+################################################################################
+
+ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup.sh

Don't install that at the root of the host dir, that's ugly.

package/environment-setup/environment-setup.mk line 11

Quoted 4 lines
package/environment-setup/environment-setup.mk new file +4 -0
+ENVIRONMENT_SETUP_SED_EXP = --expression='s+$(HOST_DIR)+\$$SDK_PATH+g'
+
+define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS
+	cp package/environment-setup/environment-setup.sh $(ENVIRONMENT_SETUP_FILE)

package/environment-setup/environment-setup.sh is missing in your patch.

Also, I don't think it should spawn a shell. Instead, it should be a file that has to be sourced:

. /path/to/sdk-dir/usr/share/buildroot/autoconf-env

package/environment-setup/environment-setup.mk line 12

Quoted 1 line
package/environment-setup/environment-setup.mk new file +1 -0
+	for var in $(TARGET_CONFIGURE_OPTS); do \

No-no: there are variables which values have spaces in them; that's not going to work very well for those...

package/environment-setup/environment-setup.mk line 13

Quoted 1 line
package/environment-setup/environment-setup.mk new file +1 -0
+		echo export \"$$var\" | sed $(ENVIRONMENT_SETUP_SED_EXP) >> $(ENVIRONMENT_SETUP_FILE); \

Why don't you just do (export can export multiple variables_:

    printf 'export %s\n' '$(TARGET_CONFIGURE_OPTS)' >>$(ENVIRONMENT_SETUP_FILE)

(use printf, not echo).

package/environment-setup/environment-setup.mk line 15

Quoted 2 lines
package/environment-setup/environment-setup.mk new file +2 -0
+	done
+	echo export \"CROSS_COMPILE=$(TARGET_CROSS)\" | sed $(ENVIRONMENT_SETUP_SED_EXP) >> $(ENVIRONMENT_SETUP_FILE)

Is CROSS_COMPILE really a variable used by autotools?

Yeah, kernel... But this file should be only autotools, like the ones we have for meson and cmake.

package/environment-setup/environment-setup.mk line 24

Quoted 9 lines
package/environment-setup/environment-setup.mk new file +9 -0
+	echo 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=\" >> $(ENVIRONMENT_SETUP_FILE)
+	echo "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"" >> $(ENVIRONMENT_SETUP_FILE)

Do not ever play with the PS1 of users: they all have their prompt very well crafted over the years! ;-] And this is absolutely not usefull for the purpose of that script.

Regards,
Yann E. MORIN.

Quoted 11 lines
package/environment-setup/environment-setup.mk new file +4 -0
+	echo alias "configure=\"./configure \$${CONFIGURE_FLAGS}\"" >> $(ENVIRONMENT_SETUP_FILE)
+endef
+
+$(eval $(generic-package))
Signature · 6 lines
2.17.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

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

Quoted 10 lines · On Sat, 18 Apr 2020 14:45:25 +0200 "Yann E. MORIN" <[email protected]>…

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run the script · line 35

Quoted 6 lines
docs/manual/using-buildroot-toolchain.txt +6 -0
+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 +. environment-setup.sh+ 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.  

I don't think this should warrant a blurb in the manual. Otherwise, you would have to add the same for the meson cross-compilation file that we provide. And the ones for cmake as well...

I actually think the meson cross-compilation, the cmake toolchain file and al. should be documented in the manual. I'm not sure where exactly. In fact we should probably a section "Application development" in Buildroot, where we cover how to manually build stuff against the Buildroot toolchain, how to use the SDK, how to use the local site method or <pkg>_OVERRIDE_SRCDIR, etc.

Besides that aspect, I agree with Yann's review.

Best regards,

Thomas

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

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

In reply to Yann E. MORIN

Il giorno sab 18 apr 2020 alle ore 14:45 Yann E. MORIN < [email protected]> ha scritto:

Quoted 45 lines

Angelo, All,

On 2020-04-18 12:31 +0200, Angelo Compagnucci spake thusly:

Quoted 14 lines

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.

---
 docs/manual/using-buildroot-toolchain.txt     |  7 +++++
 package/Config.in                             |  1 +
 package/environment-setup/Config.in           |  6 ++++
 .../environment-setup/environment-setup.mk    | 28 +++++++++++++++++++
 4 files changed, 42 insertions(+)
 create mode 100644 package/environment-setup/Config.in
 create mode 100644 package/environment-setup/environment-setup.mk

Review

Quoted 1 line
(quoted diff) +0 -0

b/docs/manual/using-buildroot-toolchain.txt

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run

Quoted 4 lines

index 0c0c35fced..15096cfec8 100644

docs/manual/using-buildroot-toolchain.txt +0 -0
@@ -27,6 +27,13 @@ Upon extracting the SDK tarball, the user must run

the script

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run the script

Quoted 4 lines
docs/manual/using-buildroot-toolchain.txt +1 -0
 +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,

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run · line 31

Quoted 1 line
docs/manual/using-buildroot-toolchain.txt +1 -0
+you can have a +setup-environment.sh+ script installed in

+output/host/+.

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run · line 33

Quoted 2 lines
docs/manual/using-buildroot-toolchain.txt +2 -0
+This script can be sourced with +. environment-setup.sh+ to launch
+the buildroot shell. Inside this shell, you will find an environment

already

docs/manual/using-buildroot-toolchain.txt Upon extracting the SDK tarball, the user must run the script · line 35

Quoted 2 lines
docs/manual/using-buildroot-toolchain.txt +2 -0
+set up with the correct PATH, the complete list of +target configure+
+variables and some useful commands like the +configure+ alias.

I don't think this should warrant a blurb in the manual. Otherwise, you would have to add the same for the meson cross-compilation file that we provide. And the ones for cmake as well...

Also. I don't like it being a package. There is no reason for that. Instead, install it like we do the similar other cross-compilaiton helpers, with the package that actually provides the tools:

Quoted 8 lines

- the mexon's cross-compilation file is installed by host-meson

- the cmake's toolchainfile.cmake and Buildroot.cmake files are installed by the cmake infra (yeah, that's not so nice...)

So, since this script is geared towards autotools, I guess host-autoconf should bear the burden of installing that file.

Why do you think it's geared toward autotools? By having path properly configured, it's pretty universal, for example I can do a qmake well sure the qmake from buildroot is used, or cmake.

Quoted 27 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/package/environment-setup/Config.in

Review

Quoted 12 lines

new file mode 100644
index 0000000000..f0fcc7d0f8

package/environment-setup/Config.in new file +6 -0
@@ -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
(quoted diff) +0 -0

b/package/environment-setup/environment-setup.mk

package/environment-setup/environment-setup.mk

Quoted 6 lines

new file mode 100644
index 0000000000..840ee2a1a0

package/environment-setup/environment-setup.mk new file +0 -0
@@ -0,0 +1,28 @@

+################################################################################

package/environment-setup/environment-setup.mk line 4

Quoted 4 lines
package/environment-setup/environment-setup.mk new file +3 -0
+#
+# environment-setup
+#

+################################################################################

Quoted 5 lines

package/environment-setup/environment-setup.mk line 7

Quoted 2 lines
package/environment-setup/environment-setup.mk new file +2 -0
+
+ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup.sh

Don't install that at the root of the host dir, that's ugly.

Why? This is common for other build systems like Yocto. This script is intended to mimic that.

Quoted 8 lines

package/environment-setup/environment-setup.mk

Quoted 4 lines
package/environment-setup/environment-setup.mk new file +4 -0
+ENVIRONMENT_SETUP_SED_EXP = --expression='s+$(HOST_DIR)+\$$SDK_PATH+g'
+
+define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS
+     cp package/environment-setup/environment-setup.sh

$(ENVIRONMENT_SETUP_FILE)

package/environment-setup/environment-setup.sh is missing in your patch.

Ops.

Quoted 5 lines

Also, I don't think it should spawn a shell. Instead, it should be a file that has to be sourced:

. /path/to/sdk-dir/usr/share/buildroot/autoconf-env

Well, if you intend to remove the .sh extension, no problem

Quoted 7 lines

package/environment-setup/environment-setup.mk line 12

Quoted 2 lines
package/environment-setup/environment-setup.mk new file +1 -0
+     for var in $(TARGET_CONFIGURE_OPTS); do \

No-no: there are variables which values have spaces in them; that's not going to work very well for those...

Quoted 1 line
package/environment-setup/environment-setup.mk new file +1 -0
+             echo export \"$$var\" | sed $(ENVIRONMENT_SETUP_SED_EXP)
Quoted 9 lines
Quoted 1 line
Quoted 1 line

$(ENVIRONMENT_SETUP_FILE); \

Why don't you just do (export can export multiple variables_:

    printf 'export %s\n' '$(TARGET_CONFIGURE_OPTS)'
Quoted 1 line
Quoted 1 line

$(ENVIRONMENT_SETUP_FILE)

(use printf, not echo).

I will try

Quoted 6 lines

package/environment-setup/environment-setup.mk

Quoted 2 lines
package/environment-setup/environment-setup.mk new file +2 -0
+     done
+     echo export \"CROSS_COMPILE=$(TARGET_CROSS)\" | sed

$(ENVIRONMENT_SETUP_SED_EXP) >> $(ENVIRONMENT_SETUP_FILE)

Is CROSS_COMPILE really a variable used by autotools?

No, but it is very useful in the contest of compiling other software.

Quoted 50 lines

Yeah, kernel... But this file should be only autotools, like the ones we have for meson and cmake.

package/environment-setup/environment-setup.mk

Quoted 9 lines
package/environment-setup/environment-setup.mk new file +9 -0
+     echo 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=\" >> $(ENVIRONMENT_SETUP_FILE)
+     echo

"PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ \"" >> $(ENVIRONMENT_SETUP_FILE)

Do not ever play with the PS1 of users: they all have their prompt very well crafted over the years! ;-] And this is absolutely not usefull for the purpose of that script.

Regards,
Yann E. MORIN.

Quoted 1 line

+ echo alias "configure=\"./configure \$${CONFIGURE_FLAGS}\"" >>

$(ENVIRONMENT_SETUP_FILE)

Quoted 10 lines
package/environment-setup/environment-setup.mk new file +3 -1
+endef
+
+$(eval $(generic-package))
--

2.17.1

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

--

.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics'
conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___
     |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is
no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v
 conspiracy.  |

'------------------------------^-------^------------------^--------------------'

Signature · 4 lines
Profile: http://it.linkedin.com/in/compagnucciangelo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20200418/dbda1f42/attachment.html>