1#!/bin/bash 2# 3# Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 4# SPDX-License-Identifier: MIT 5# 6 7SOURCE="${BASH_SOURCE[0]}" 8while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink 9 TARGET="$(readlink "$SOURCE")" 10 if [[ $TARGET == /* ]]; then 11 # "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'" 12 SOURCE="$TARGET" 13 else 14 DIR="$( dirname "$SOURCE" )" 15 # "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')" 16 SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located 17 fi 18done 19DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" 20 21CMD=$( basename "$0" ) 22 23usage() { 24 echo "Usage: $CMD [options]" 25 echo "Options: -t(type) <Debug or Release>" 26 echo " -c(lean) build" 27 echo " -s(tatic libraries) <1 or 0>" 28 echo " -w(indows) build" 29 exit 1 30} 31# defaults 32TYPE=Release 33CLEAN=0 34STATIC=0 35WINDOWS=0 36 37# Parse the command line 38while getopts "whct:s:" opt; do 39 case "$opt" in 40 h|\?) usage;; 41 t) TYPE=$OPTARG;; 42 c) CLEAN=1;; 43 s) STATIC=$OPTARG;; 44 w) WINDOWS=1;; 45 esac 46done 47shift $((OPTIND - 1)) 48 49if [ $CLEAN == 1 ]; then 50 echo "removing ${DIR}/build" 51 rm -rf "${DIR}"/build 52fi 53 54BUILD_DIR="build" 55[ -d build ] || ( mkdir build || exit ) 56echo $WINDOWS 57if [ "$WINDOWS" -eq "1" ]; then 58 echo "doing windows" 59 cd $BUILD_DIR || exit 60 [ -d windows ] || mkdir windows 61 BUILD_DIR=$BUILD_DIR/windows 62 cd "$DIR" || exit 63fi 64# lower case TYPE in a posix compliant manner 65LC_TYPE=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]') 66if [ "${LC_TYPE}" == "debug" ]; then 67 DEBUGDIR=("$DIR/$BUILD_DIR/debug") 68 # shellcheck disable=SC2128 69 [ -d "$DEBUGDIR" ] || (cd ${BUILD_DIR} && ( mkdir debug || exit ) && cd ..) 70 # shellcheck disable=SC2128 71 BUILD_DIR=$DEBUGDIR 72else 73 RELEASEDIR=("$DIR/$BUILD_DIR/release") 74 # shellcheck disable=SC2128 75 [ -d "$RELEASEDIR" ] || (cd "${BUILD_DIR}" && ( mkdir release || exit ) && cd ..) 76 # shellcheck disable=SC2128 77 BUILD_DIR=$RELEASEDIR 78fi 79 80echo "Build Directory: ${BUILD_DIR}" 81 82CMAKE=cmake 83CMARGS="-DCMAKE_BUILD_TYPE=$TYPE \ 84 -DBUILD_STATIC_PIPE_LIBS=$STATIC \ 85 -DBUILD_PIPE_ONLY=1" 86if [ "$WINDOWS" -eq "1" ]; then 87 CMARGS="$CMARGS \ 88 -DCMAKE_TOOLCHAIN_FILE=${DIR}/toolchain-x86-ubuntu-mingw64.cmake" 89fi 90MAKE="make" 91 92cd "${BUILD_DIR}" || exit 93pwd 94( eval $CMAKE "$CMARGS" "$DIR" && eval ${MAKE} "$MAKEFLAGS" ) 95