package/environment-setup: new package
authorAngelo Compagnucci <angelo.compagnucci@gmail.com>
Tue, 27 Oct 2020 14:01:40 +0000 (09:01 -0500)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Tue, 3 Nov 2020 21:28:17 +0000 (22:28 +0100)
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.

Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com>
Tested-by: Michael Trimarchi <michael@amarulasolutions.com>
Tested-by: Adam Duskett <aduskett@gmail.com>
Signed-off-by: Maury Anderson <maury.anderson@collins.com>
Signed-off-by: Matt Weber <matthew.weber@rockwellcollins.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
docs/manual/using-buildroot-toolchain.txt
package/Config.in.host
package/environment-setup/Config.in.host [new file with mode: 0644]
package/environment-setup/environment-setup [new file with mode: 0644]
package/environment-setup/environment-setup.mk [new file with mode: 0644]

index 0c0c35fceda1b907d896b3d2dce42d1602d70da6..7a8b0c4c78051b747af75daa249c117ab9ef4dd2 100644 (file)
@@ -32,3 +32,16 @@ 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
 you to just prepare the SDK with +make prepare-sdk+ without actually
 generating a tarball.
+
+For your convenience, by selecting the option
++BR2_PACKAGE_HOST_ENVIRONMENT_SETUP+, you can get a
++setup-environment+ script installed in +output/host/+ and therefore
+in your SDK.  This script can be sourced with
++. your/sdk/path/environment-setup+ to export a number of environment
+variables that will help cross-compile your projects using the
+Buildroot SDK: the +PATH+ will contain the SDK binaries, standard
+_autotools_ variables will be defined with the appropriate values, and
++CONFIGURE_FLAGS+ will contain basic +./configure+ options to
+cross-compile _autotools_ projects. Note however that once this script
+is sourced, the environment is setup only for cross-compilation, and
+no longer for native compilation.
index 546f1c226deca96fd39109ba875ab504aac699b8..c69c756f3a7c19275a8fcba2a01934318770f97a 100644 (file)
@@ -19,6 +19,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"
diff --git a/package/environment-setup/Config.in.host b/package/environment-setup/Config.in.host
new file mode 100644 (file)
index 0000000..c67e375
--- /dev/null
@@ -0,0 +1,6 @@
+config BR2_PACKAGE_HOST_ENVIRONMENT_SETUP
+       bool "host 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 (file)
index 0000000..6846361
--- /dev/null
@@ -0,0 +1,16 @@
+cat <<'EOF'
+ _           _ _     _                 _
+| |__  _   _(_) | __| |_ __ ___   ___ | |_
+| '_ \| | | | | |/ _` | '__/ _ \ / _ \| __|
+| |_) | |_| | | | (_| | | | (_) | (_) | |_
+|_.__/ \__,_|_|_|\__,_|_|  \___/ \___/ \__|
+
+       Making embedded Linux easy!
+
+Some tips:
+* PATH now contains the SDK utilities
+* Standard autotools variables (CC, LD, CFLAGS) are 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 (file)
index 0000000..98b976a
--- /dev/null
@@ -0,0 +1,31 @@
+################################################################################
+#
+# environment-setup
+#
+################################################################################
+
+ENVIRONMENT_SETUP_FILE = $(HOST_DIR)/environment-setup
+
+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) 's%$(HOST_DIR)%\$$SDK_PATH%g' \
+               -e 's%$(HOST_DIR)/bin/%%g' \
+               -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))