2018-06-13 20:12:52 +02:00
|
|
|
#!/usr/bin/env bash
|
2017-04-26 21:21:27 +02:00
|
|
|
|
|
|
|
# This script operates in a current working directory. It downloads
|
|
|
|
# "crosstool-ng", installs the base package, and then configures and installs
|
|
|
|
# a toolchain based on the supplied prefix and configuration.
|
|
|
|
#
|
|
|
|
# Artifacts:
|
|
|
|
# - "crosstool-ng" data in the current working directory (can be deleted).
|
|
|
|
# - Configured Toolchain installed in the supplied <prefix>.
|
|
|
|
|
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
# Our base directory is the current working directory. All local artifacts will
|
|
|
|
# be generated underneath of here.
|
|
|
|
ROOT=${PWD}
|
|
|
|
|
2021-06-23 14:53:33 +02:00
|
|
|
usage() { echo "Usage: $0 -p <prefix> -c <config-path> -v <version>" 1>&2; exit 1; }
|
2017-04-26 21:21:27 +02:00
|
|
|
|
|
|
|
# Resolve our input parameters.
|
|
|
|
#
|
|
|
|
# Note: we use "readlink" to resolve them to absolute paths so we can freelhy
|
|
|
|
# change directories during installation.
|
|
|
|
CT_PREFIX=
|
|
|
|
CONFIG_PATH=
|
2021-06-23 14:53:33 +02:00
|
|
|
REV=
|
|
|
|
while getopts "p:c:v:" o; do
|
2017-04-26 21:21:27 +02:00
|
|
|
case "${o}" in
|
|
|
|
p)
|
|
|
|
CT_PREFIX=$(readlink -f ${OPTARG})
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
CONFIG_PATH=$(readlink -f ${OPTARG})
|
|
|
|
;;
|
2021-06-23 14:53:33 +02:00
|
|
|
v)
|
|
|
|
REV=${OPTARG}
|
|
|
|
;;
|
2017-04-26 21:21:27 +02:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
if [ -z ${CT_PREFIX} ]; then
|
|
|
|
echo "ERROR: You must supply an installation prefix (-p)."
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
if [ -z ${CONFIG_PATH} ] || [ ! -f ${CONFIG_PATH} ]; then
|
|
|
|
echo "ERROR: Missing config path (-c)."
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2021-06-23 14:53:33 +02:00
|
|
|
if [ -z ${REV} ]; then
|
2023-01-27 13:19:09 +01:00
|
|
|
echo "WARNING: No version selected, use default version: crosstool-ng-1.25.0 (-v)."
|
|
|
|
REV=crosstool-ng-1.25.0
|
2021-06-23 14:53:33 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-04-26 21:21:27 +02:00
|
|
|
##
|
|
|
|
# Build "crosstool-ng".
|
|
|
|
##
|
|
|
|
|
|
|
|
CTNG=${ROOT}/ct-ng
|
|
|
|
mkdir -p "${CTNG}"
|
|
|
|
cd "${CTNG}"
|
|
|
|
|
|
|
|
# Download and install the "crosstool-ng" source.
|
2021-06-23 14:53:33 +02:00
|
|
|
|
|
|
|
git clone https://github.com/crosstool-ng/crosstool-ng.git
|
|
|
|
cd crosstool-ng
|
|
|
|
git fetch --tags
|
|
|
|
|
|
|
|
# checkout
|
|
|
|
git checkout ${REV}
|
|
|
|
|
2023-01-30 08:26:57 +01:00
|
|
|
if [ ${REV} = "crosstool-ng-1.25.0" ]; then
|
|
|
|
patch scripts/build/companion_libs/050-zlib.sh -i /dockcross/crosstool-ng-zlib-target.patch
|
|
|
|
# Clean patch
|
|
|
|
rm /dockcross/crosstool-ng-zlib-target.patch
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2017-04-26 21:21:27 +02:00
|
|
|
# Bootstrap and install the tool.
|
|
|
|
BOOTSTRAP_PREFIX="${CTNG}/prefix"
|
|
|
|
./bootstrap
|
|
|
|
./configure \
|
|
|
|
--prefix "${BOOTSTRAP_PREFIX}"
|
2021-08-08 20:45:36 +02:00
|
|
|
make -j"$(nproc)"
|
2017-04-26 21:21:27 +02:00
|
|
|
make install
|
|
|
|
|
|
|
|
##
|
|
|
|
# Use "crosstool-ng" to build the toolchain.
|
|
|
|
##
|
|
|
|
|
|
|
|
# Override installation prefix, since we want to define it externally.
|
|
|
|
export CT_PREFIX
|
|
|
|
|
|
|
|
# Allow installation as root, since we aren't really worried about system
|
|
|
|
# damage b/c we're running in a container and this saves us the trouble of
|
|
|
|
# having to generate a crosstool user.
|
|
|
|
export CT_ALLOW_BUILD_AS_ROOT_SURE=1
|
|
|
|
|
|
|
|
# Create our build directory and copy our configuration into it.
|
|
|
|
BUILD="${ROOT}/toolchain"
|
|
|
|
mkdir -p "${BUILD}"
|
|
|
|
cd "${BUILD}"
|
|
|
|
|
|
|
|
cp "${CONFIG_PATH}" "${BUILD}/.config"
|
|
|
|
|
2020-05-21 13:39:55 +02:00
|
|
|
|
|
|
|
# As mentioned in ct-ng config, need to unset LD_LIBRARY_PATH.
|
|
|
|
unset LD_LIBRARY_PATH
|
2021-06-27 14:52:44 +02:00
|
|
|
# Fix build error on manylinux2014-aarch64
|
|
|
|
unset CC
|
|
|
|
unset CXX
|
2020-05-21 13:39:55 +02:00
|
|
|
|
2017-04-26 21:21:27 +02:00
|
|
|
# Build and install the toolchain!
|
2021-06-23 14:53:33 +02:00
|
|
|
# Print last 250 lines if build fail
|
2021-06-24 22:57:41 +02:00
|
|
|
"${BOOTSTRAP_PREFIX}/bin/ct-ng" build || (tail -250 build.log && exit 1)
|
2020-05-21 13:39:55 +02:00
|
|
|
|