| 1 |
#!/bin/bash |
| 2 |
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT |
| 3 |
# license. See LICENSE file in the project root for full license |
| 4 |
# information. |
| 5 |
|
| 6 |
# Tested on RPi2 debian verion 7.8 |
| 7 |
|
| 8 |
install_root="/home/jenkins" |
| 9 |
build_root=$(cd "$(dirname "$0")/.." && pwd) |
| 10 |
cd $build_root |
| 11 |
|
| 12 |
# ----------------------------------------------------------------------------- |
| 13 |
# -- helper subroutines |
| 14 |
# ----------------------------------------------------------------------------- |
| 15 |
checkExists() { |
| 16 |
if hash $1 2>/dev/null; |
| 17 |
then |
| 18 |
return 1 |
| 19 |
else |
| 20 |
echo "$1" not found. Please make sure that "$1" is installed and available in the path. |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
} |
| 24 |
# ----------------------------------------------------------------------------- |
| 25 |
# -- Check for environment pre-requisites. This script requires -- that |
| 26 |
# the following programs work: -- curl build-essential(g++,gcc,make) |
| 27 |
# cmake git |
| 28 |
# ----------------------------------------------------------------------------- |
| 29 |
checkExists g++ |
| 30 |
checkExists gcc |
| 31 |
checkExists make |
| 32 |
checkExists cmake |
| 33 |
checkExists git |
| 34 |
|
| 35 |
# ----------------------------------------------------------------------------- |
| 36 |
# -- Check for RPiTools directory. |
| 37 |
# ----------------------------------------------------------------------------- |
| 38 |
if [ ! -d "$install_root/RPiTools" ]; |
| 39 |
then |
| 40 |
echo ---------- Raspberry Pi tool-chain absent ---------- |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
# ----------------------------------------------------------------------------- |
| 45 |
# -- Set environment variable |
| 46 |
# ----------------------------------------------------------------------------- |
| 47 |
cd $install_root/RPiTools/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/arm-linux-gnueabihf |
| 48 |
export RPI_ROOT=$(pwd) |
| 49 |
|
| 50 |
mkdir $build_root/cmake |
| 51 |
cd $build_root/cmake |
| 52 |
|
| 53 |
# ----------------------------------------------------------------------------- |
| 54 |
# -- Create toolchain-rpi.cmake |
| 55 |
# ----------------------------------------------------------------------------- |
| 56 |
echo ---------- Creating toolchain cmake file ---------- |
| 57 |
FILE="$build_root/cmake/toolchain-rpi.cmake" |
| 58 |
|
| 59 |
/bin/cat <<EOM >$FILE |
| 60 |
INCLUDE(CMakeForceCompiler) |
| 61 |
|
| 62 |
SET(CMAKE_SYSTEM_NAME Linux) # this one is important |
| 63 |
SET(CMAKE_SYSTEM_VERSION 1) # this one not so much |
| 64 |
|
| 65 |
# this is the location of the amd64 toolchain targeting the Raspberry Pi |
| 66 |
SET(CMAKE_C_COMPILER ${RPI_ROOT}/../bin/arm-linux-gnueabihf-gcc) |
| 67 |
|
| 68 |
# this is the file system root of the target |
| 69 |
SET(CMAKE_FIND_ROOT_PATH ${RPI_ROOT}) |
| 70 |
|
| 71 |
# search for programs in the build host directories |
| 72 |
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 73 |
|
| 74 |
# for libraries and headers in the target directories |
| 75 |
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 76 |
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 77 |
EOM |
| 78 |
|
| 79 |
# ----------------------------------------------------------------------------- |
| 80 |
# -- Build uAMQP |
| 81 |
# ----------------------------------------------------------------------------- |
| 82 |
echo ---------- Building the SDK by executing build.sh script ---------- |
| 83 |
cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain-rpi.cmake -DcompileOption_C:STRING="--sysroot=$RPI_ROOT" |
| 84 |
make |
| 85 |
[ $? -eq 0 ] || exit $? |