Message ID | 20200425124836.122729-1-angelo@amarulasolutions.com |
---|---|
State | Superseded |
Headers | show |
Series | [v4,1/3] package/environment-setup: new package | expand |
Angelo, All
I have some ideas to improve the environment script.
In order to keep project/team specific customization outside of
Buildroot, we can add a new configuration variable e.g.
`BR2_ENVIRONMENT_SETUP_FILE_SNIPPET`.
We can use this to specify an external, additional file, which adds
further customizations, e.g. PS1, could be others too
And right at the end of `ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS`, add
the contents of that file:
`cat BR2_ENVIRONMENT_SETUP_FILE_SNIPPET >> $(ENVIRONMENT_SETUP_FILE)`
If this new config value is empty, we only have the original version of
the environment-setup file.
Also, I've added cleanup code(see below) to the variables inside the
`environment-setup` script:
* take advantage of the fact that we've updated the PATH, so don't use
absolute paths
* long absolute paths makes verbose builds difficult to read/follow
* use the CROSS_COMPILE variable in the definition of AR, CC, etc
This results in a more compact/readable code.
All the best,
Mircea
diff --git a/package/environment-setup/environment-setup.mk
b/package/environment-setup/environment-setup.mk
index fc74594459..b057c4fa34 100644
--- a/package/environment-setup/environment-setup.mk
+++ b/package/environment-setup/environment-setup.mk
@@ -5,14 +5,16 @@
################################################################################
ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup
+ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP =
's+$(TARGET_CROSS)+\$${CROSS_COMPILE}+g'
+ENVIRONMENT_SETUP_PATH_SED_EXP = 's+$(HOST_DIR)/bin/++g'
ENVIRONMENT_SETUP_HOST_DIR_SED_EXP = 's+$(HOST_DIR)+\$$SDK_PATH+g'
define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS
cp package/environment-setup/environment-setup $(ENVIRONMENT_SETUP_FILE)
+ printf "export \"CROSS_COMPILE=$(GNU_TARGET_NAME)-\"\n" >>
$(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) \
@@ -21,7 +23,7 @@ define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS
--sysconfdir=/etc \
--localstatedir=/var \
--program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE)
- $(SED) $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) $(ENVIRONMENT_SETUP_FILE)
+ $(SED) $(ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP) -e
$(ENVIRONMENT_SETUP_PATH_SED_EXP) -e
$(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) $(ENVIRONMENT_SETUP_FILE)
printf
"PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$
\"\n" \
>> $(ENVIRONMENT_SETUP_FILE)
endef
Hi Mircea, Il giorno lun 27 apr 2020 alle ore 18:22 Mircea GLIGA <mgliga@bitdefender.com> ha scritto: > > Angelo, All > > I have some ideas to improve the environment script. > In order to keep project/team specific customization outside of > Buildroot, we can add a new configuration variable e.g. > `BR2_ENVIRONMENT_SETUP_FILE_SNIPPET`. > We can use this to specify an external, additional file, which adds > further customizations, e.g. PS1, could be others too > And right at the end of `ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS`, add > the contents of that file: > > `cat BR2_ENVIRONMENT_SETUP_FILE_SNIPPET >> $(ENVIRONMENT_SETUP_FILE)` > > If this new config value is empty, we only have the original version of > the environment-setup file. I wouldn't really like to overengineer things like that. I mean, every company that needs heavy customization of this script could either generate it from scratch in a post-build script or mangling the environment-setup installed one. This script should serve people that don't really need to know the internals and should be a simple plain good starting point. If the PS1 thing is so bothering we can remove it, but I strongly disagree. I want to stress out that is not intended to be a fancy thing, it only serves the purpose to make it obvious that the user is not running a normal his normal shell. For this reason, I see perfectly reasonable to have a different PS1. > Also, I've added cleanup code(see below) to the variables inside the > `environment-setup` script: > > * take advantage of the fact that we've updated the PATH, so don't use > absolute paths > * long absolute paths makes verbose builds difficult to read/follow > * use the CROSS_COMPILE variable in the definition of AR, CC, etc > > This results in a more compact/readable code. > > All the best, > Mircea > > > diff --git a/package/environment-setup/environment-setup.mk > b/package/environment-setup/environment-setup.mk > index fc74594459..b057c4fa34 100644 > --- a/package/environment-setup/environment-setup.mk > +++ b/package/environment-setup/environment-setup.mk > @@ -5,14 +5,16 @@ > > ################################################################################ > > ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup > +ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP = > 's+$(TARGET_CROSS)+\$${CROSS_COMPILE}+g' > +ENVIRONMENT_SETUP_PATH_SED_EXP = 's+$(HOST_DIR)/bin/++g' > ENVIRONMENT_SETUP_HOST_DIR_SED_EXP = 's+$(HOST_DIR)+\$$SDK_PATH+g' > > define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS > cp package/environment-setup/environment-setup $(ENVIRONMENT_SETUP_FILE) > + printf "export \"CROSS_COMPILE=$(GNU_TARGET_NAME)-\"\n" >> > $(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) \ > @@ -21,7 +23,7 @@ define ENVIRONMENT_SETUP_INSTALL_TARGET_CMDS > --sysconfdir=/etc \ > --localstatedir=/var \ > --program-prefix=\"\n" >> $(ENVIRONMENT_SETUP_FILE) > - $(SED) $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) $(ENVIRONMENT_SETUP_FILE) > + $(SED) $(ENVIRONMENT_SETUP_CROSS_COMPILE_SED_EXP) -e > $(ENVIRONMENT_SETUP_PATH_SED_EXP) -e > $(ENVIRONMENT_SETUP_HOST_DIR_SED_EXP) $(ENVIRONMENT_SETUP_FILE) > printf > "PS1=\"\[\e[32m\]buildroot-$(BR2_VERSION)\[\e[m\]:\[\e[34m\]\w\[\e[m\]\$$ > \"\n" \ > >> $(ENVIRONMENT_SETUP_FILE) > endef Good suggestions, will do. -- Profile: http://it.linkedin.com/in/compagnucciangelo
Hello, > If the PS1 thing is so bothering we can remove it, but I strongly > disagree. Please drop it. If somebody wants to change PS1, than it can be moved to a wrapper script. But keep in the environment script only the strict necessary. Best regards, Slydder
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 9a6461277e..81f45bfaaf 100644 --- a/package/Config.in +++ b/package/Config.in @@ -1953,6 +1953,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..fc74594459 --- /dev/null +++ b/package/environment-setup/environment-setup.mk @@ -0,0 +1,29 @@ +################################################################################ +# +# environment-setup +# +################################################################################ + +ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup +ENVIRONMENT_SETUP_HOST_DIR_SED_EXP = '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 \"$$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_DIR_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))