mirror of
https://github.com/google/cpu_features.git
synced 2025-04-27 23:22:31 +02:00
tools: Rework cross compilation scripts
- Use stderr for issues - Add usage to run_integration.sh (-h or --help) - deduce toolchain and qemu config from TARGET - Bump QEMU from 2.11.1 to 5.2.0 - fix qemu build on Archlinux - Bump Linaro: toolchain 7.2-2017.11 -> 7.5-2019.12 sysroot 2.25-2017.11 -> 2.25-2019.12 - Bump codescape from 2017.10-08 to 2020.06-01 - migrate from mips-r2-hard to mips-r6-hard
This commit is contained in:
parent
239c2e5660
commit
8971bf0b0e
@ -1,209 +1,364 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
readonly SCRIPT_FOLDER=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
set -eo pipefail
|
||||||
readonly PROJECT_FOLDER="${SCRIPT_FOLDER}/.."
|
|
||||||
readonly ARCHIVE_FOLDER=~/cpu_features_archives
|
|
||||||
readonly QEMU_INSTALL=${ARCHIVE_FOLDER}/qemu
|
|
||||||
readonly DEFAULT_CMAKE_ARGS=" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON"
|
|
||||||
|
|
||||||
function extract() {
|
function extract() {
|
||||||
|
echo "Extracting ${1}..."
|
||||||
case $1 in
|
case $1 in
|
||||||
*.tar.bz2) tar xjf "$1" ;;
|
*.tar.bz2) tar xjf "$1" ;;
|
||||||
*.tar.xz) tar xJf "$1" ;;
|
*.tar.xz) tar xJf "$1" ;;
|
||||||
*.tar.gz) tar xzf "$1" ;;
|
*.tar.gz) tar xzf "$1" ;;
|
||||||
*)
|
*)
|
||||||
echo "don't know how to extract '$1'..."
|
>&2 echo "don't know how to extract '$1'..."
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpackifnotexists() {
|
function unpack() {
|
||||||
mkdir -p "${ARCHIVE_FOLDER}"
|
mkdir -p "${ARCHIVE_DIR}"
|
||||||
cd "${ARCHIVE_FOLDER}" || exit
|
cd "${ARCHIVE_DIR}" || exit 2
|
||||||
local URL=$1
|
local -r URL=$1
|
||||||
local RELATIVE_FOLDER=$2
|
local -r RELATIVE_DIR=$2
|
||||||
local DESTINATION="${ARCHIVE_FOLDER}/${RELATIVE_FOLDER}"
|
local -r DESTINATION="${ARCHIVE_DIR}/${RELATIVE_DIR}"
|
||||||
if [[ ! -d "${DESTINATION}" ]] ; then
|
if [[ ! -d "${DESTINATION}" ]] ; then
|
||||||
local ARCHIVE_NAME=$(echo ${URL} | sed 's/.*\///')
|
echo "Downloading ${URL}..."
|
||||||
test -f "${ARCHIVE_NAME}" || wget -q "${URL}"
|
local -r ARCHIVE_NAME=$(basename "${URL}")
|
||||||
|
test -f "${ARCHIVE_NAME}" || wget --no-verbose "${URL}"
|
||||||
extract "${ARCHIVE_NAME}"
|
extract "${ARCHIVE_NAME}"
|
||||||
rm -f "${ARCHIVE_NAME}"
|
rm -f "${ARCHIVE_NAME}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function installqemuifneeded() {
|
function install_qemu() {
|
||||||
local VERSION=${QEMU_VERSION:=2.11.1}
|
if [[ "${QEMU_ARCH}" == "DISABLED" ]]; then
|
||||||
local ARCHES=${QEMU_ARCHES:=arm aarch64 i386 x86_64 mips mipsel mips64 mips64el}
|
>&2 echo 'QEMU is disabled !'
|
||||||
local TARGETS=${QEMU_TARGETS:=$(echo "$ARCHES" | sed 's#$# #;s#\([^ ]*\) #\1-linux-user #g')}
|
return 0
|
||||||
|
fi
|
||||||
|
local -r QEMU_VERSION=${QEMU_VERSION:=5.2.0}
|
||||||
|
local -r QEMU_TARGET=${QEMU_ARCH}-linux-user
|
||||||
|
|
||||||
if echo "${VERSION} ${TARGETS}" | cmp --silent ${QEMU_INSTALL}/.build -; then
|
if echo "${QEMU_VERSION} ${QEMU_TARGET}" | cmp --silent "${QEMU_INSTALL}/.build" -; then
|
||||||
echo "qemu ${VERSION} up to date!"
|
echo "qemu ${QEMU_VERSION} up to date!"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "VERSION: ${VERSION}"
|
echo "QEMU_VERSION: ${QEMU_VERSION}"
|
||||||
echo "TARGETS: ${TARGETS}"
|
echo "QEMU_TARGET: ${QEMU_TARGET}"
|
||||||
|
|
||||||
rm -rf ${QEMU_INSTALL}
|
rm -rf "${QEMU_INSTALL}"
|
||||||
|
|
||||||
# Checking for a tarball before downloading makes testing easier :-)
|
# Checking for a tarball before downloading makes testing easier :-)
|
||||||
local QEMU_URL="http://wiki.qemu-project.org/download/qemu-${VERSION}.tar.xz"
|
local -r QEMU_URL="http://wiki.qemu-project.org/download/qemu-${QEMU_VERSION}.tar.xz"
|
||||||
local QEMU_FOLDER="qemu-${VERSION}"
|
local -r QEMU_DIR="qemu-${QEMU_VERSION}"
|
||||||
unpackifnotexists ${QEMU_URL} ${QEMU_FOLDER}
|
unpack ${QEMU_URL} ${QEMU_DIR}
|
||||||
cd ${QEMU_FOLDER} || exit
|
cd ${QEMU_DIR} || exit 2
|
||||||
|
|
||||||
|
# Qemu (meson based build) depends on: pkgconf, libglib2.0, python3, ninja
|
||||||
./configure \
|
./configure \
|
||||||
--prefix="${QEMU_INSTALL}" \
|
--prefix=${QEMU_INSTALL} \
|
||||||
--target-list="${TARGETS}" \
|
--target-list=${QEMU_TARGET} \
|
||||||
--disable-docs \
|
--audio-drv-list= \
|
||||||
--disable-sdl \
|
--disable-brlapi \
|
||||||
--disable-gtk \
|
--disable-curl \
|
||||||
--disable-gnutls \
|
|
||||||
--disable-gcrypt \
|
|
||||||
--disable-nettle \
|
|
||||||
--disable-curses \
|
--disable-curses \
|
||||||
--static
|
--disable-docs \
|
||||||
|
--disable-gcrypt \
|
||||||
|
--disable-gnutls \
|
||||||
|
--disable-gtk \
|
||||||
|
--disable-libnfs \
|
||||||
|
--disable-libssh \
|
||||||
|
--disable-nettle \
|
||||||
|
--disable-opengl \
|
||||||
|
--disable-sdl \
|
||||||
|
--disable-virglrenderer \
|
||||||
|
--disable-vte \
|
||||||
|
--enable-modules
|
||||||
|
|
||||||
make -j4
|
# --static Not supported on Archlinux
|
||||||
|
# so we use --enable-modules
|
||||||
|
|
||||||
|
# wrapper on ninja
|
||||||
|
make -j8
|
||||||
make install
|
make install
|
||||||
|
|
||||||
echo "$VERSION $TARGETS" > ${QEMU_INSTALL}/.build
|
echo "$QEMU_VERSION $QEMU_TARGET" > "${QEMU_INSTALL}/.build"
|
||||||
}
|
}
|
||||||
|
|
||||||
function assert_defined(){
|
function assert_defined(){
|
||||||
local VALUE=${1}
|
if [[ -z "${!1}" ]]; then
|
||||||
: "${VALUE?"${1} needs to be defined"}"
|
>&2 echo "Variable '${1}' must be defined"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function integrate() {
|
function clean_build() {
|
||||||
cd "${PROJECT_FOLDER}"
|
# Cleanup previous build
|
||||||
case "${OS}" in
|
rm -rf "${BUILD_DIR}"
|
||||||
"Windows_NT") CMAKE_BUILD_ARGS="--config Debug --target ALL_BUILD"
|
mkdir -p "${BUILD_DIR}"
|
||||||
CMAKE_TEST_FILES="${BUILD_DIR}/test/Debug/*_test.exe"
|
|
||||||
DEMO=${BUILD_DIR}/Debug/list_cpu_features.exe
|
|
||||||
;;
|
|
||||||
*) CMAKE_BUILD_ARGS="--target all"
|
|
||||||
CMAKE_TEST_FILES="${BUILD_DIR}/test/*_test"
|
|
||||||
DEMO=${BUILD_DIR}/list_cpu_features
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Generating CMake configuration
|
|
||||||
cmake -H. -B"${BUILD_DIR}" ${DEFAULT_CMAKE_ARGS} "${CMAKE_ADDITIONAL_ARGS[@]}" -G"${CMAKE_GENERATOR:-Unix Makefiles}"
|
|
||||||
|
|
||||||
# Building
|
|
||||||
cmake --build "${BUILD_DIR}" ${CMAKE_BUILD_ARGS}
|
|
||||||
|
|
||||||
# Running tests if needed
|
|
||||||
if [[ "${QEMU_ARCH}" == "DISABLED" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
RUN_CMD=""
|
|
||||||
if [[ -n "${QEMU_ARCH}" ]]; then
|
|
||||||
installqemuifneeded
|
|
||||||
RUN_CMD="${QEMU_INSTALL}/bin/qemu-${QEMU_ARCH} ${QEMU_ARGS[@]}"
|
|
||||||
fi
|
|
||||||
for test_binary in ${CMAKE_TEST_FILES}; do
|
|
||||||
${RUN_CMD} ${test_binary}
|
|
||||||
done
|
|
||||||
${RUN_CMD} ${DEMO}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function expand_linaro_config() {
|
function expand_linaro_config() {
|
||||||
assert_defined TARGET
|
#ref: https://releases.linaro.org/components/toolchain/binaries/
|
||||||
local LINARO_ROOT_URL=https://releases.linaro.org/components/toolchain/binaries/7.2-2017.11
|
local -r LINARO_VERSION=7.5-2019.12
|
||||||
|
local -r LINARO_ROOT_URL=https://releases.linaro.org/components/toolchain/binaries/${LINARO_VERSION}
|
||||||
|
|
||||||
local GCC_URL=${LINARO_ROOT_URL}/${TARGET}/gcc-linaro-7.2.1-2017.11-x86_64_${TARGET}.tar.xz
|
local -r GCC_VERSION=7.5.0-2019.12
|
||||||
local GCC_RELATIVE_FOLDER="gcc-linaro-7.2.1-2017.11-x86_64_${TARGET}"
|
local -r GCC_URL=${LINARO_ROOT_URL}/${TARGET}/gcc-linaro-${GCC_VERSION}-x86_64_${TARGET}.tar.xz
|
||||||
unpackifnotexists "${GCC_URL}" "${GCC_RELATIVE_FOLDER}"
|
local -r GCC_RELATIVE_DIR="gcc-linaro-${GCC_VERSION}-x86_64_${TARGET}"
|
||||||
|
unpack "${GCC_URL}" "${GCC_RELATIVE_DIR}"
|
||||||
|
|
||||||
local SYSROOT_URL=${LINARO_ROOT_URL}/${TARGET}/sysroot-glibc-linaro-2.25-2017.11-${TARGET}.tar.xz
|
local -r SYSROOT_VERSION=2.25-2019.12
|
||||||
local SYSROOT_RELATIVE_FOLDER=sysroot-glibc-linaro-2.25-2017.11-${TARGET}
|
local -r SYSROOT_URL=${LINARO_ROOT_URL}/${TARGET}/sysroot-glibc-linaro-${SYSROOT_VERSION}-${TARGET}.tar.xz
|
||||||
unpackifnotexists "${SYSROOT_URL}" "${SYSROOT_RELATIVE_FOLDER}"
|
local -r SYSROOT_RELATIVE_DIR=sysroot-glibc-linaro-${SYSROOT_VERSION}-${TARGET}
|
||||||
|
unpack "${SYSROOT_URL}" "${SYSROOT_RELATIVE_DIR}"
|
||||||
|
|
||||||
local SYSROOT_FOLDER=${ARCHIVE_FOLDER}/${SYSROOT_RELATIVE_FOLDER}
|
local -r SYSROOT_DIR=${ARCHIVE_DIR}/${SYSROOT_RELATIVE_DIR}
|
||||||
local GCC_FOLDER=${ARCHIVE_FOLDER}/${GCC_RELATIVE_FOLDER}
|
local -r STAGING_DIR=${ARCHIVE_DIR}/${SYSROOT_RELATIVE_DIR}-stage
|
||||||
|
local -r GCC_DIR=${ARCHIVE_DIR}/${GCC_RELATIVE_DIR}
|
||||||
|
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_SYSTEM_NAME=Linux)
|
# Write a Toolchain file
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_SYSTEM_PROCESSOR=${TARGET})
|
# note: This is manadatory to use a file in order to have the CMake variable
|
||||||
|
# 'CMAKE_CROSSCOMPILING' set to TRUE.
|
||||||
|
# ref: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-linux
|
||||||
|
cat >"$TOOLCHAIN_FILE" <<EOL
|
||||||
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
|
set(CMAKE_SYSTEM_PROCESSOR ${TARGET})
|
||||||
|
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_SYSROOT=${SYSROOT_FOLDER})
|
set(CMAKE_SYSROOT ${SYSROOT_DIR})
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_C_COMPILER=${GCC_FOLDER}/bin/${TARGET}-gcc)
|
set(CMAKE_STAGING_PREFIX ${STAGING_DIR})
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_CXX_COMPILER=${GCC_FOLDER}/bin/${TARGET}-g++)
|
|
||||||
|
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER)
|
set(tools ${GCC_DIR})
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY)
|
set(CMAKE_C_COMPILER \${tools}/bin/${TARGET}-gcc)
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY)
|
set(CMAKE_CXX_COMPILER \${tools}/bin/${TARGET}-g++)
|
||||||
|
|
||||||
QEMU_ARGS+=(-L ${SYSROOT_FOLDER})
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
QEMU_ARGS+=(-E LD_LIBRARY_PATH=/lib)
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
|
EOL
|
||||||
|
CMAKE_ADDITIONAL_ARGS+=( -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" )
|
||||||
|
QEMU_ARGS+=( -L "${SYSROOT_DIR}" )
|
||||||
|
QEMU_ARGS+=( -E LD_LIBRARY_PATH=/lib )
|
||||||
}
|
}
|
||||||
|
|
||||||
function expand_codescape_config() {
|
function expand_codescape_config() {
|
||||||
assert_defined TARGET
|
# ref: https://codescape.mips.com/components/toolchain/2020.06-01/downloads.html
|
||||||
local DATE=2017.10-08
|
# ref: https://codescape.mips.com/components/toolchain/2019.02-04/downloads.html
|
||||||
local CODESCAPE_URL=https://codescape.mips.com/components/toolchain/${DATE}/Codescape.GNU.Tools.Package.${DATE}.for.MIPS.MTI.Linux.CentOS-5.x86_64.tar.gz
|
local -r DATE=2020.06-01
|
||||||
local GCC_URL=${CODESCAPE_URL}
|
#local -r DATE=2019.02-04
|
||||||
local GCC_RELATIVE_FOLDER="mips-mti-linux-gnu/${DATE}"
|
local -r CODESCAPE_URL=https://codescape.mips.com/components/toolchain/${DATE}/Codescape.GNU.Tools.Package.${DATE}.for.MIPS.MTI.Linux.CentOS-6.x86_64.tar.gz
|
||||||
unpackifnotexists "${GCC_URL}" "${GCC_RELATIVE_FOLDER}"
|
#local -r CODESCAPE_URL=https://codescape.mips.com/components/toolchain/${DATE}/Codescape.GNU.Tools.Package.${DATE}.for.MIPS.IMG.Linux.CentOS-6.x86_64.tar.gz
|
||||||
|
local -r GCC_URL=${CODESCAPE_URL}
|
||||||
|
local -r GCC_RELATIVE_DIR="mips-mti-linux-gnu/${DATE}"
|
||||||
|
#local -r GCC_RELATIVE_DIR="mips-img-linux-gnu/${DATE}"
|
||||||
|
unpack "${GCC_URL}" "${GCC_RELATIVE_DIR}"
|
||||||
|
|
||||||
local GCC_FOLDER=${ARCHIVE_FOLDER}/${GCC_RELATIVE_FOLDER}
|
local -r GCC_DIR=${ARCHIVE_DIR}/${GCC_RELATIVE_DIR}
|
||||||
local MIPS_FLAGS=""
|
local MIPS_FLAGS=""
|
||||||
local LIBC_FOLDER_SUFFIX=""
|
local LIBC_DIR_SUFFIX=""
|
||||||
local FLAVOUR=""
|
local FLAVOUR=""
|
||||||
case "${TARGET}" in
|
case "${TARGET}" in
|
||||||
"mips32") MIPS_FLAGS="-EB -mabi=32"; FLAVOUR="mips-r2-hard"; LIBC_FOLDER_SUFFIX="lib" ;;
|
"mips32")
|
||||||
"mips32el") MIPS_FLAGS="-EL -mabi=32"; FLAVOUR="mipsel-r2-hard"; LIBC_FOLDER_SUFFIX="lib" ;;
|
MIPS_FLAGS="-EB -mips32r6 -mabi=32"
|
||||||
"mips64") MIPS_FLAGS="-EB -mabi=64"; FLAVOUR="mips-r2-hard"; LIBC_FOLDER_SUFFIX="lib64" ;;
|
FLAVOUR="mips-r6-hard"
|
||||||
"mips64el") MIPS_FLAGS="-EL -mabi=64"; FLAVOUR="mipsel-r2-hard"; LIBC_FOLDER_SUFFIX="lib64" ;;
|
#MIPS_FLAGS="-EB -mips32r2 -mabi=32"
|
||||||
*) echo 'unknown mips platform'; exit 1;;
|
#FLAVOUR="mips-r2-hard"
|
||||||
|
LIBC_DIR_SUFFIX="lib"
|
||||||
|
;;
|
||||||
|
"mips32el")
|
||||||
|
MIPS_FLAGS="-EL -mips32r6 -mabi=32"
|
||||||
|
FLAVOUR="mipsel-r6-hard"
|
||||||
|
#MIPS_FLAGS="-EL -mips32r2 -mabi=32"
|
||||||
|
#FLAVOUR="mipsel-r2-hard"
|
||||||
|
LIBC_DIR_SUFFIX="lib"
|
||||||
|
;;
|
||||||
|
"mips64")
|
||||||
|
MIPS_FLAGS="-EB -mips64r6 -mabi=64"
|
||||||
|
FLAVOUR="mips-r6-hard"
|
||||||
|
#FLAVOUR="mips-r2-hard"
|
||||||
|
LIBC_DIR_SUFFIX="lib64"
|
||||||
|
;;
|
||||||
|
"mips64el")
|
||||||
|
MIPS_FLAGS="-EL -mips64r6 -mabi=64"
|
||||||
|
FLAVOUR="mipsel-r6-hard"
|
||||||
|
#FLAVOUR="mipsel-r2-hard"
|
||||||
|
LIBC_DIR_SUFFIX="lib64"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
>&2 echo 'unknown mips platform'
|
||||||
|
exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
local -r SYSROOT_DIR=${GCC_DIR}/sysroot
|
||||||
|
local -r STAGING_DIR=${SYSROOT_DIR}-stage
|
||||||
|
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_FIND_ROOT_PATH=${GCC_FOLDER})
|
# Write a Toolchain file
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_SYSTEM_NAME=Linux)
|
# note: This is manadatory to use a file in order to have the CMake variable
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_SYSTEM_PROCESSOR=${TARGET})
|
# 'CMAKE_CROSSCOMPILING' set to TRUE.
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_C_COMPILER=mips-mti-linux-gnu-gcc)
|
# ref: https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-linux
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_CXX_COMPILER=mips-mti-linux-gnu-g++)
|
cat >"${TOOLCHAIN_FILE}" <<EOL
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_C_COMPILER_ARG1="${MIPS_FLAGS}")
|
set(CMAKE_SYSTEM_NAME Linux)
|
||||||
CMAKE_ADDITIONAL_ARGS+=(-DCMAKE_CXX_COMPILER_ARG1="${MIPS_FLAGS}")
|
set(CMAKE_SYSTEM_PROCESSOR ${TARGET})
|
||||||
|
|
||||||
local SYSROOT_FOLDER=${GCC_FOLDER}/sysroot/${FLAVOUR}
|
set(CMAKE_SYSROOT ${SYSROOT_DIR})
|
||||||
|
set(CMAKE_STAGING_PREFIX ${STAGING_DIR})
|
||||||
|
|
||||||
# Keeping only the sysroot of interest to save on travis cache.
|
set(tools ${GCC_DIR})
|
||||||
if [[ "${CONTINUOUS_INTEGRATION}" = "true" ]]; then
|
|
||||||
for folder in ${GCC_FOLDER}/sysroot/*; do
|
|
||||||
if [[ "${folder}" != "${SYSROOT_FOLDER}" ]]; then
|
|
||||||
rm -rf ${folder}
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
local LIBC_FOLDER=${GCC_FOLDER}/mips-mti-linux-gnu/lib/${FLAVOUR}/${LIBC_FOLDER_SUFFIX}
|
set(CMAKE_C_COMPILER \${tools}/bin/mips-mti-linux-gnu-gcc)
|
||||||
QEMU_ARGS+=(-L ${SYSROOT_FOLDER})
|
#set(CMAKE_C_COMPILER \${tools}/bin/mips-img-linux-gnu-gcc)
|
||||||
QEMU_ARGS+=(-E LD_PRELOAD=${LIBC_FOLDER}/libstdc++.so.6:${LIBC_FOLDER}/libgcc_s.so.1)
|
set(CMAKE_C_FLAGS "${MIPS_FLAGS}")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_COMPILER \${tools}/bin/mips-mti-linux-gnu-g++)
|
||||||
|
#set(CMAKE_CXX_COMPILER \${tools}/bin/mips-img-linux-gnu-g++)
|
||||||
|
set(CMAKE_CXX_FLAGS "${MIPS_FLAGS}")
|
||||||
|
|
||||||
|
set(CMAKE_FIND_ROOT_PATH ${GCC_DIR})
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||||
|
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||||
|
EOL
|
||||||
|
|
||||||
|
CMAKE_ADDITIONAL_ARGS+=( -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" )
|
||||||
|
QEMU_ARGS+=( -L "${SYSROOT_DIR}/${FLAVOUR}" )
|
||||||
|
local -r LIBC_DIR=${GCC_DIR}/mips-mti-linux-gnu/lib/${FLAVOUR}/${LIBC_DIR_SUFFIX}
|
||||||
|
#local -r LIBC_DIR=${GCC_DIR}/mips-img-linux-gnu/lib/${FLAVOUR}/${LIBC_DIR_SUFFIX}
|
||||||
|
QEMU_ARGS+=( -E LD_PRELOAD="${LIBC_DIR}/libstdc++.so.6:${LIBC_DIR}/libgcc_s.so.1" )
|
||||||
}
|
}
|
||||||
|
|
||||||
function expand_environment_and_integrate() {
|
function build() {
|
||||||
assert_defined PROJECT_FOLDER
|
cd "${PROJECT_DIR}" || exit 2
|
||||||
|
set -x
|
||||||
|
clean_build
|
||||||
|
cmake -S. -B"${BUILD_DIR}" "${CMAKE_DEFAULT_ARGS[@]}" "${CMAKE_ADDITIONAL_ARGS[@]}"
|
||||||
|
cmake --build "${BUILD_DIR}" --target all -j8 -v
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
assert_defined QEMU_ARCH
|
||||||
|
if [[ "${QEMU_ARCH}" == "DISABLED" ]]; then
|
||||||
|
>&2 echo "QEMU is disabled for ${TARGET}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
install_qemu
|
||||||
|
RUN_CMD="${QEMU_INSTALL}/bin/qemu-${QEMU_ARCH} ${QEMU_ARGS[*]}"
|
||||||
|
|
||||||
|
cd "${BUILD_DIR}" || exit 2
|
||||||
|
set -x
|
||||||
|
for test_binary in "${BUILD_DIR}"/list_cpu_feature* ; do
|
||||||
|
${RUN_CMD} "${test_binary}"
|
||||||
|
done
|
||||||
|
set +x
|
||||||
|
}
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
local -r NAME=$(basename "$0")
|
||||||
|
echo -e "$NAME - Build using a cross toolchain.
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
\t$NAME [-h|--help] [toolchain|build|qemu|test|all]
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
\tCross compile using a cross toolchain.
|
||||||
|
|
||||||
|
\tYou MUST define the following variables before running this script:
|
||||||
|
\t* TARGET:
|
||||||
|
\t\tx86_64
|
||||||
|
\t\taarch64-linux-gnu aarch64_be-linux-gnu
|
||||||
|
\t\tarm-linux-gnueabihf armv8l-linux-gnueabihf arm-linux-gnueabi
|
||||||
|
\t\tarmeb-linux-gnueabihf armeb-linux-gnueabi
|
||||||
|
\t\tmips32 mips32el
|
||||||
|
\t\tmips64 mips64el
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
\t-h --help: show this help text
|
||||||
|
\ttoolchain: download, unpack toolchain and generate CMake toolchain file
|
||||||
|
\tbuild: toolchain + build the project using the toolchain file (note: remove previous build dir)
|
||||||
|
\tqemu: download, unpack and build qemu
|
||||||
|
\ttest: qemu + run all executable using qemu (note: don't build !)
|
||||||
|
\tall: build + test (default)
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
* Using export:
|
||||||
|
export TARGET=aarch64-linux-gnu
|
||||||
|
$0
|
||||||
|
|
||||||
|
* One-liner:
|
||||||
|
TARGET=aarch64-linux-gnu $0"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main
|
||||||
|
function main() {
|
||||||
|
case ${1} in
|
||||||
|
-h | --help)
|
||||||
|
usage; exit ;;
|
||||||
|
esac
|
||||||
|
|
||||||
assert_defined TARGET
|
assert_defined TARGET
|
||||||
|
|
||||||
BUILD_DIR="${PROJECT_FOLDER}/cmake_build/${TARGET}"
|
declare -r PROJECT_DIR="$(cd -P -- "$(dirname -- "$0")/.." && pwd -P)"
|
||||||
mkdir -p "${BUILD_DIR}"
|
declare -r ARCHIVE_DIR="${PROJECT_DIR}/build_cross/archives"
|
||||||
|
declare -r BUILD_DIR="${PROJECT_DIR}/build_cross/${TARGET}"
|
||||||
|
declare -r TOOLCHAIN_FILE=${ARCHIVE_DIR}/toolchain_${TARGET}.cmake
|
||||||
|
|
||||||
declare -a CONFIG_NAMES=()
|
echo "Target: '${TARGET}'"
|
||||||
declare -a QEMU_ARGS=()
|
|
||||||
|
echo "Project dir: '${PROJECT_DIR}'"
|
||||||
|
echo "Archive dir: '${ARCHIVE_DIR}'"
|
||||||
|
echo "Build dir: '${BUILD_DIR}'"
|
||||||
|
echo "toolchain file: '${TOOLCHAIN_FILE}'"
|
||||||
|
|
||||||
|
declare -a CMAKE_DEFAULT_ARGS=( -G ${CMAKE_GENERATOR:-"Ninja"} )
|
||||||
declare -a CMAKE_ADDITIONAL_ARGS=()
|
declare -a CMAKE_ADDITIONAL_ARGS=()
|
||||||
|
|
||||||
case ${TOOLCHAIN} in
|
declare -a QEMU_ARGS=()
|
||||||
LINARO) expand_linaro_config ;;
|
case ${TARGET} in
|
||||||
CODESCAPE) expand_codescape_config ;;
|
x86_64)
|
||||||
NATIVE) QEMU_ARCH="" ;;
|
declare -r QEMU_ARCH=x86_64 ;;
|
||||||
*) echo "Unknown toolchain '${TOOLCHAIN}'..."; exit 1;;
|
arm-linux-gnueabihf | armv8l-linux-gnueabihf | arm-linux-gnueabi)
|
||||||
|
expand_linaro_config
|
||||||
|
declare -r QEMU_ARCH=arm ;;
|
||||||
|
armeb-linux-gnueabihf | armeb-linux-gnueabi)
|
||||||
|
expand_linaro_config
|
||||||
|
declare -r QEMU_ARCH=DISABLED ;;
|
||||||
|
aarch64-linux-gnu)
|
||||||
|
expand_linaro_config
|
||||||
|
declare -r QEMU_ARCH=aarch64 ;;
|
||||||
|
aarch64_be-linux-gnu)
|
||||||
|
expand_linaro_config
|
||||||
|
declare -r QEMU_ARCH=DISABLED ;;
|
||||||
|
mips32)
|
||||||
|
expand_codescape_config
|
||||||
|
declare -r QEMU_ARCH=mips ;;
|
||||||
|
mips32el)
|
||||||
|
expand_codescape_config
|
||||||
|
declare -r QEMU_ARCH=mipsel ;;
|
||||||
|
mips64)
|
||||||
|
expand_codescape_config
|
||||||
|
declare -r QEMU_ARCH=mips64 ;;
|
||||||
|
mips64el)
|
||||||
|
expand_codescape_config
|
||||||
|
declare -r QEMU_ARCH=mips64el ;;
|
||||||
|
*)
|
||||||
|
>&2 echo "Unknown TARGET '${TARGET}'..."
|
||||||
|
exit 1 ;;
|
||||||
|
esac
|
||||||
|
declare -r QEMU_INSTALL=${ARCHIVE_DIR}/qemu-${QEMU_ARCH}
|
||||||
|
|
||||||
|
case ${1} in
|
||||||
|
toolchain)
|
||||||
|
exit ;;
|
||||||
|
build)
|
||||||
|
build ;;
|
||||||
|
qemu)
|
||||||
|
install_qemu ;;
|
||||||
|
test)
|
||||||
|
run_test ;;
|
||||||
|
*)
|
||||||
|
build
|
||||||
|
run_test ;;
|
||||||
esac
|
esac
|
||||||
integrate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "${CONTINUOUS_INTEGRATION}" = "true" ]; then
|
main "${1:-all}"
|
||||||
QEMU_ARCHES=${QEMU_ARCH}
|
|
||||||
expand_environment_and_integrate
|
|
||||||
fi
|
|
||||||
|
@ -1,84 +1,58 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
source "$(dirname -- "$0")"/run_integration.sh
|
|
||||||
|
|
||||||
# Toolchains for little-endian, 64-bit ARMv8 for GNU/Linux systems
|
# Toolchains for little-endian, 64-bit ARMv8 for GNU/Linux systems
|
||||||
function set_aarch64-linux-gnu() {
|
function set_aarch64-linux-gnu() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=aarch64-linux-gnu
|
||||||
TARGET=aarch64-linux-gnu
|
|
||||||
QEMU_ARCH=aarch64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for little-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
# Toolchains for little-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
||||||
function set_arm-linux-gnueabihf() {
|
function set_arm-linux-gnueabihf() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=arm-linux-gnueabihf
|
||||||
TARGET=arm-linux-gnueabihf
|
|
||||||
QEMU_ARCH=arm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for little-endian, 32-bit ARMv8 for GNU/Linux systems
|
# Toolchains for little-endian, 32-bit ARMv8 for GNU/Linux systems
|
||||||
function set_armv8l-linux-gnueabihf() {
|
function set_armv8l-linux-gnueabihf() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=armv8l-linux-gnueabihf
|
||||||
TARGET=armv8l-linux-gnueabihf
|
|
||||||
QEMU_ARCH=arm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for little-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
# Toolchains for little-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
||||||
function set_arm-linux-gnueabi() {
|
function set_arm-linux-gnueabi() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=arm-linux-gnueabi
|
||||||
TARGET=arm-linux-gnueabi
|
|
||||||
QEMU_ARCH=arm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for big-endian, 64-bit ARMv8 for GNU/Linux systems
|
# Toolchains for big-endian, 64-bit ARMv8 for GNU/Linux systems
|
||||||
function set_aarch64_be-linux-gnu() {
|
function set_aarch64_be-linux-gnu() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=aarch64_be-linux-gnu
|
||||||
TARGET=aarch64_be-linux-gnu
|
|
||||||
QEMU_ARCH=DISABLED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for big-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
# Toolchains for big-endian, hard-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
||||||
function set_armeb-linux-gnueabihf() {
|
function set_armeb-linux-gnueabihf() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=armeb-linux-gnueabihf
|
||||||
TARGET=armeb-linux-gnueabihf
|
|
||||||
QEMU_ARCH=DISABLED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Toolchains for big-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
# Toolchains for big-endian, soft-float, 32-bit ARMv7 (and earlier) for GNU/Linux systems
|
||||||
function set_armeb-linux-gnueabi() {
|
function set_armeb-linux-gnueabi() {
|
||||||
TOOLCHAIN=LINARO
|
export TARGET=armeb-linux-gnueabi
|
||||||
TARGET=armeb-linux-gnueabi
|
|
||||||
QEMU_ARCH=DISABLED
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_mips32() {
|
function set_mips32() {
|
||||||
TOOLCHAIN=CODESCAPE
|
export TARGET=mips32
|
||||||
TARGET=mips32
|
|
||||||
QEMU_ARCH=mips
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_mips32el() {
|
function set_mips32el() {
|
||||||
TOOLCHAIN=CODESCAPE
|
export TARGET=mips32el
|
||||||
TARGET=mips32el
|
|
||||||
QEMU_ARCH=mipsel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_mips64() {
|
function set_mips64() {
|
||||||
TOOLCHAIN=CODESCAPE
|
export TARGET=mips64
|
||||||
TARGET=mips64
|
|
||||||
QEMU_ARCH=mips64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_mips64el() {
|
function set_mips64el() {
|
||||||
TOOLCHAIN=CODESCAPE
|
export TARGET=mips64el
|
||||||
TARGET=mips64el
|
|
||||||
QEMU_ARCH=mips64el
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_native() {
|
function set_x86_64() {
|
||||||
TOOLCHAIN=NATIVE
|
export TARGET=x86_64
|
||||||
TARGET=native
|
|
||||||
QEMU_ARCH=""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ENVIRONMENTS="
|
ENVIRONMENTS="
|
||||||
@ -93,14 +67,13 @@ ENVIRONMENTS="
|
|||||||
set_mips32el
|
set_mips32el
|
||||||
set_mips64
|
set_mips64
|
||||||
set_mips64el
|
set_mips64el
|
||||||
set_native
|
set_x86_64
|
||||||
"
|
"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CMAKE_GENERATOR="Ninja"
|
|
||||||
|
|
||||||
for SET_ENVIRONMENT in ${ENVIRONMENTS}; do
|
for SET_ENVIRONMENT in ${ENVIRONMENTS}; do
|
||||||
|
echo "testing ${SET_ENVIRONMENT}"
|
||||||
${SET_ENVIRONMENT}
|
${SET_ENVIRONMENT}
|
||||||
expand_environment_and_integrate
|
./"$(dirname -- "$0")"/run_integration.sh
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user