aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2018-02-14 14:34:46 +0100
committerGuillaume Chatelet <gchatelet@google.com>2018-02-14 14:34:46 +0100
commit5a9819ce82dab2499a8aecfd77a1e95c9f21cb24 (patch)
tree3d4ede70b89ef8841c4ac6ae92b3a45167ebb833 /scripts
parent54e27126e6f33c07904931ecd30884b6cca8719b (diff)
downloadcpu_features-5a9819ce82dab2499a8aecfd77a1e95c9f21cb24.tar.gz
Update cross compilation scripts.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/run_integration.sh123
-rwxr-xr-xscripts/setup_qemu.sh40
-rwxr-xr-xscripts/setup_toolchain.sh23
3 files changed, 99 insertions, 87 deletions
diff --git a/scripts/run_integration.sh b/scripts/run_integration.sh
index 7b16091..065f250 100755
--- a/scripts/run_integration.sh
+++ b/scripts/run_integration.sh
@@ -1,44 +1,119 @@
#!/bin/bash
-export BUILD_DIR=cmake_build
-export CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON -H. -B${BUILD_DIR}"
+set -e
+set -x
+
+###############################################################################
+# Ensures qemu is compiled in $HOME/qemu.
+# Input:
+# - QEMU_VERSION, the version of qemu to use.
+# - QEMU_ARCHES, the list of architectures qemu should support.
+function setup_qemu() {
+ local VERSION=${QEMU_VERSION:=2.11.0}
+ local ARCHES=${QEMU_ARCHES:=arm aarch64 i386 x86_64 mipsel}
+ local TARGETS=${QEMU_TARGETS:=$(echo $ARCHES | sed 's#$# #;s#\([^ ]*\) #\1-softmmu \1-linux-user #g')}
+
+ if echo "$VERSION $TARGETS" | cmp --silent $HOME/qemu/.build -; then
+ echo "qemu $VERSION up to date!"
+ return 0
+ fi
+
+ echo "VERSION: $VERSION"
+ echo "TARGETS: $TARGETS"
+
+ cd $HOME
+ rm -rf qemu
+
+ # Checking for a tarball before downloading makes testing easier :-)
+ test -f "qemu-$VERSION.tar.xz" || wget "http://wiki.qemu-project.org/download/qemu-$VERSION.tar.xz"
+ tar -xJf "qemu-$VERSION.tar.xz"
+ cd "qemu-$VERSION"
+
+ ./configure \
+ --prefix="$HOME/qemu" \
+ --target-list="$TARGETS" \
+ --disable-docs \
+ --disable-sdl \
+ --disable-gtk \
+ --disable-gnutls \
+ --disable-gcrypt \
+ --disable-nettle \
+ --disable-curses \
+ --static
+
+ make -j4
+ make install
+
+ echo "$VERSION $TARGETS" > $HOME/qemu/.build
+}
+
+###############################################################################
+# Ensures the linaro toolchain is available in $HOME/toolchains.
+# Input:
+# - LINARO_URL, the url of the of the x86_64 gcc tarball.
+function get_linaro_toolchain_folder() {
+ local LINARO_URL_NO_HTTPS=${LINARO_URL#https:}
+ local ARCHIVE_NAME=${LINARO_URL_NO_HTTPS##/*/}
+ local TOOLCHAIN_NAME=${ARCHIVE_NAME%.tar.*}
+ local TOOLCHAIN_HOME=${HOME}/toolchains
+ local TOOLCHAIN_FOLDER="${TOOLCHAIN_HOME}/${TOOLCHAIN_NAME}"
+ if [[ ! -d "${TOOLCHAIN_FOLDER}" ]] ; then
+ mkdir -p "${TOOLCHAIN_HOME}"
+ cd "${TOOLCHAIN_HOME}"
+ wget ${LINARO_URL}
+ tar -xJf ${ARCHIVE_NAME}
+ rm ${ARCHIVE_NAME}
+ fi
+ echo ${TOOLCHAIN_FOLDER}
+}
+
+###############################################################################
SCRIPT_FOLDER=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
-PROJECT_FOLDER=${SCRIPT_FOLDER}/..
+PROJECT_FOLDER="${SCRIPT_FOLDER}/.."
cd ${PROJECT_FOLDER}
-if [[ -n "${CROSS_COMPILE}" ]]; then
+BUILD_DIR="${PROJECT_FOLDER}/cmake_build"
+CMAKE_PATH="${PATH}"
+CMAKE_ARGS="-H. -B${BUILD_DIR}"
+CMAKE_ARGS+=" -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON"
+
+#
+# Setup toolchain if necessary.
+#
+if [[ -n "${LINARO_URL}" ]]; then
# Cross compilation
- : "${TOOLCHAIN_NAME:?Need to set TOOLCHAIN_NAME non-empty}"
: "${TARGET:?Need to set TARGET non-empty}"
- : "${QEMU_ARCH:?Need to set QEMU_ARCH non-empty}"
- ${SCRIPT_FOLDER}/setup_qemu.sh
- ${SCRIPT_FOLDER}/setup_toolchain.sh
- export TOOLCHAIN=${HOME}/toolchains/${TOOLCHAIN_NAME}
- export PATH=${TOOLCHAIN}/bin:${HOME}/qemu/bin:${PATH}
- export CMAKE_TOOLCHAIN_FILE=cmake/${TARGET}.cmake
+ TOOLCHAIN=`get_linaro_toolchain_folder`
+ CMAKE_TOOLCHAIN_FILE=cmake/${TARGET}.cmake
if [[ ! -f ${CMAKE_TOOLCHAIN_FILE} ]]; then
echo "Missing cmake toolchain file : $CMAKE_TOOLCHAIN_FILE"
exit 1
fi
- # Generate makefile
- cmake ${CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
- # Compile
- cmake --build ${BUILD_DIR} --target all
+ CMAKE_ARGS+=" -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
+ CMAKE_PATH="${TOOLCHAIN}/bin:${PATH}"
+fi
+
+# Generate makefile
+PATH=${CMAKE_PATH} cmake ${CMAKE_ARGS}
+# Compile
+PATH=${CMAKE_PATH} cmake --build ${BUILD_DIR} --target all
+
+#
+# Tests
+#
+if [[ -n "${QEMU_ARCH}" ]]; then
# Run tests
- export QEMU=qemu-${QEMU_ARCH}
- export QEMU_LD_PREFIX=${TOOLCHAIN}/${TARGET}/libc
+ QEMU_PATH="${HOME}/qemu/bin:${PATH}"
+ : "${QEMU_ARCH:?Need to set QEMU_ARCH non-empty}"
+ setup_qemu
+ QEMU="qemu-${QEMU_ARCH} -L ${TOOLCHAIN}/${TARGET}/libc"
for test_binary in ${BUILD_DIR}/test/*_test; do
- ${QEMU} ${test_binary}
+ PATH=${QEMU_PATH} ${QEMU} ${test_binary}
done
# Run demo program
- ${QEMU} ${BUILD_DIR}/list_cpu_features
+ PATH=${QEMU_PATH} ${QEMU} ${BUILD_DIR}/list_cpu_features
else
- # Native compilation
- # Generate makefile
- cmake ${CMAKE_ARGS}
- # Compile
- cmake --build ${BUILD_DIR} --target all
# Run tests
CTEST_OUTPUT_ON_FAILURE=1 cmake --build ${BUILD_DIR} --target test
# Run demo program
diff --git a/scripts/setup_qemu.sh b/scripts/setup_qemu.sh
deleted file mode 100755
index 8b850cc..0000000
--- a/scripts/setup_qemu.sh
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/bash
-
-set -e
-
-VERSION=${QEMU_VERSION:=2.11.0}
-ARCHES=${QEMU_ARCHES:=arm aarch64 i386 x86_64 mipsel}
-TARGETS=${QEMU_TARGETS:=$(echo $ARCHES | sed 's#$# #;s#\([^ ]*\) #\1-softmmu \1-linux-user #g')}
-
-if echo "$VERSION $TARGETS" | cmp --silent $HOME/qemu/.build -; then
- echo "qemu $VERSION up to date!"
- exit 0
-fi
-
-echo "VERSION: $VERSION"
-echo "TARGETS: $TARGETS"
-
-cd $HOME
-rm -rf qemu
-
-# Checking for a tarball before downloading makes testing easier :-)
-test -f "qemu-$VERSION.tar.xz" || wget "http://wiki.qemu-project.org/download/qemu-$VERSION.tar.xz"
-tar -xJf "qemu-$VERSION.tar.xz"
-cd "qemu-$VERSION"
-
-./configure \
- --prefix="$HOME/qemu" \
- --target-list="$TARGETS" \
- --disable-docs \
- --disable-sdl \
- --disable-gtk \
- --disable-gnutls \
- --disable-gcrypt \
- --disable-nettle \
- --disable-curses \
- --static
-
-make -j4
-make install
-
-echo "$VERSION $TARGETS" > $HOME/qemu/.build
diff --git a/scripts/setup_toolchain.sh b/scripts/setup_toolchain.sh
deleted file mode 100755
index de20537..0000000
--- a/scripts/setup_toolchain.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-set -e
-
-: "${TOOLCHAIN_NAME:?Need to set TOOLCHAIN_NAME non-empty}"
-: "${TARGET:?Need to set TARGET non-empty}"
-
-
-if [[ -d "$HOME/toolchains/${TOOLCHAIN_NAME}/${TARGET}" ]] ; then
- echo "toolchain ${TOOLCHAIN_NAME} ${TARGET} exists!"
- exit 0
-fi
-
-export ARCHIVE_NAME=${TOOLCHAIN_NAME}.tar.xz
-
-echo "TOOLCHAIN: $TOOLCHAIN_NAME"
-echo "TARGET : $TARGET"
-
-mkdir -p $HOME/toolchains
-cd $HOME/toolchains
-
-test -f "${ARCHIVE_NAME}" || wget https://releases.linaro.org/components/toolchain/binaries/latest/${TARGET}/${ARCHIVE_NAME}
-tar -xJf ${ARCHIVE_NAME}
-rm ${ARCHIVE_NAME}