diff --git a/cross-compiler.Dockerfile b/cross-compiler.Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/scripts/create-cross-compiler/README.md b/scripts/create-cross-compiler/README.md new file mode 100644 index 0000000..e88104f --- /dev/null +++ b/scripts/create-cross-compiler/README.md @@ -0,0 +1,45 @@ +# Creating cross-compilers +This folder contains configuration, scripts and docker images used in the creation of cross-compilers and a cross-compilation environment. The intended use case is that these scripts can be used to very easilly create an environment where we can build software for different platforms. Docker is being used to create a contained reproducable environment. + +For these scripts and instructions to work you only need docker and the bare minimum of shell scripting support. + +## How to use: +1. Have this repository available on your local machine +2. Build the cross compiler & create a cross build environment. + ``cd scripts/create-cross-compiler`` + ``./create-armv6-rpi-linux-gnueabihf.sh`` + The resulting cross compiler is stored in the "build-tools" folder. There will also be a docker image created that can be used in the process of building. +3. Do some cross compiling +```` +docker run -ti \ + -v :/workspace \ + bmr-cross-compiler +```` + +How to build the software: +```` +cd /workspace +conan remote remove conancenter +conan remote add conan-upload https://artifacts.4beumer.nl/repository/conan-bmrdev/ +conan remote add conan-remote https://artifacts.4beumer.nl/repository/conan-center-proxy/ + +conan build . -of build-cross \ + -s compiler.cppstd=23 \ + -s build_type=Debug \ + --build=missing \ + --profile:build=default \ + --profile:host=/x-tools/armv6-rpi-linux-gnueabihf/conan.profile + +cmake --preset conan-debug . +cmake --build ./build-cross +cmake --install ./build-cross --prefix=/workspace/build-cross-install +```` + + * Configuration needs to be provided. (environment variable: CROSS_TARGET_INFO_PATH). + * Destination location needs to be provided (environment variable: CROSS_TARGET_DST_PATH). + * Use docker volume functionality to link directories to the docker container. + ``docker run -ti -e CROSS_TARGET_INFO_PATH=/config -e CROSS_TARGET_DST_PATH=/dst -v ./armv6-rpi-linux:/config -v ./dst:/dst `` + + + + diff --git a/support/create-cross-compiler/create-cross-compiler.Dockerfile b/scripts/create-cross-compiler/build-cross-compiler.Dockerfile similarity index 100% rename from support/create-cross-compiler/create-cross-compiler.Dockerfile rename to scripts/create-cross-compiler/build-cross-compiler.Dockerfile diff --git a/support/create-cross-compiler/armv6-rpi-linux/conan_profile b/scripts/create-cross-compiler/configurations/armv6-rpi-linux-gnueabihf/conan.profile similarity index 100% rename from support/create-cross-compiler/armv6-rpi-linux/conan_profile rename to scripts/create-cross-compiler/configurations/armv6-rpi-linux-gnueabihf/conan.profile diff --git a/support/create-cross-compiler/armv6-rpi-linux/ct-ng.config b/scripts/create-cross-compiler/configurations/armv6-rpi-linux-gnueabihf/ct-ng.config similarity index 100% rename from support/create-cross-compiler/armv6-rpi-linux/ct-ng.config rename to scripts/create-cross-compiler/configurations/armv6-rpi-linux-gnueabihf/ct-ng.config diff --git a/scripts/create-cross-compiler/create-armv6-rpi-linux-gnueabihf.sh b/scripts/create-cross-compiler/create-armv6-rpi-linux-gnueabihf.sh new file mode 100755 index 0000000..6115ec1 --- /dev/null +++ b/scripts/create-cross-compiler/create-armv6-rpi-linux-gnueabihf.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# Prepare a directory that will contain the cross compiler +mkdir -p ../../build-tools/x-tools + +# Build docker image responsible for building the cross compiler +docker build \ + -t bmr-build-cross-compiler \ + -f build-cross-compiler.Dockerfile . + +# Perform building of cross compiler +docker run -ti \ + -e CROSS_TARGET_INFO_PATH=/extern-config \ + -e CROSS_TARGET_DST_PATH=/extern-dst \ + -v ./configurations/armv6-rpi-linux-gnueabihf:/extern-config \ + -v ../../build-tools/x-tools:/extern-dst \ + bmr-build-cross-compiler + +# Build docker image to be used for cross compiling +docker build \ + -t bmr-cross-compiler \ + --build-arg CROSS_COMPILER=armv6-rpi-linux-gnueabihf \ + -f cross-compiler.Dockerfile ../.. + diff --git a/support/create-cross-compiler/scripts/create-cross-compiler.py b/scripts/create-cross-compiler/scripts/create-cross-compiler.py similarity index 69% rename from support/create-cross-compiler/scripts/create-cross-compiler.py rename to scripts/create-cross-compiler/scripts/create-cross-compiler.py index a170bf9..c06292d 100644 --- a/support/create-cross-compiler/scripts/create-cross-compiler.py +++ b/scripts/create-cross-compiler/scripts/create-cross-compiler.py @@ -40,6 +40,18 @@ os.chdir('/crosstool') runcmd("su crosstoolng -c 'ct-ng source'") runcmd("su crosstoolng -c 'ct-ng build'") -runcmd("cp -rv " + cross_destdir + "/* " + cross_destination_path + "/") +# Determine directory of the cross compiler built, then copy the conan profile into it. + +cross_compiler_built = None +if True: + entries = os.listdir(cross_destdir) + if len(entries) == 1: + cross_compiler_built = entries[0] + +if cross_compiler_built is None: + raise Exception("ERROR... Something went wrong determining where the cross compiler build result is stored.") + +runcmd("cp -r " + cross_destdir + "/* " + cross_destination_path + "/") +runcmd("cp " + cross_target_info_path + '/conan.profile ' + cross_destination_path + '/' + cross_compiler_built + '/conan.profile') sys.exit(0) \ No newline at end of file diff --git a/support/create-cross-compiler/scripts/entrypoint.sh b/scripts/create-cross-compiler/scripts/entrypoint.sh similarity index 100% rename from support/create-cross-compiler/scripts/entrypoint.sh rename to scripts/create-cross-compiler/scripts/entrypoint.sh diff --git a/support/create-cross-compiler/README.md b/support/create-cross-compiler/README.md deleted file mode 100644 index b1b219a..0000000 --- a/support/create-cross-compiler/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Creating cross-compilers -This folder contains configuration, scripts and docker images that are used for creating cross-compilers. The intended use case is to build C and C++ software for various platforms. Docker is being used to provide a common environment and isolating the build process. - -## How to use: -1. Clone the repository to a location of your liking. -2. Create a docker image containing crosstool-ng. - ``cd support/create-cross-compiler`` - ``docker build -t -f create-cross-compiler.Dockerfile .`` -3. Use the docker image to create the cross comiler. - * Configuration needs to be provided. (environment variable: CROSS_TARGET_INFO_PATH). - * Destination location needs to be provided (environment variable: CROSS_TARGET_DST_PATH). - * Use docker volume functionality to link directories to the docker container. - ``docker run -ti -e CROSS_TARGET_INFO_PATH=/config -e CROSS_TARGET_DST_PATH=/dst -v ./armv6-rpi-linux:/config -v ./dst:/dst `` - - - - diff --git a/support/create-cross-compiler/create-cross-compiler-armv6-rpi-linux.sh b/support/create-cross-compiler/create-cross-compiler-armv6-rpi-linux.sh deleted file mode 100644 index 02efaac..0000000 --- a/support/create-cross-compiler/create-cross-compiler-armv6-rpi-linux.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -mkdir -p ../../build-tools/x-tools - -docker build \ - -t bmr-create-cross-compiler \ - -f create-cross-compiler.Dockerfile . - -docker run -ti \ - -e CROSS_TARGET_INFO_PATH=/extern-config \ - -e CROSS_TARGET_DST_PATH=/extern-dst \ - -v ./armv6-rpi-linux:/extern-config \ - -v ../../build-tools/x-tools:/extern-dst bmr-create-cross-compiler