blob: 611b7b96e0d5841b9e4d6f95ccc61ca6536434f5 [file] [log] [blame]
Jim Flynnbbfe6032020-07-20 16:57:44 +01001#!/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
19RDIR="$( dirname "$SOURCE" )"
20DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
21
22CMD=$( basename $0 )
23
24usage() {
25 echo "Usage: $CMD [options]"
26 echo "Options: -t(type) <Debug or Release>"
27 echo " -c(lean) build"
28 echo " -s(tatic libraries) <1 or 0>"
29 echo " -w(indows) build"
30 exit 1
31}
32# defaults
33TYPE=Release
34CLEAN=0
35STATIC=0
36WINDOWS=0
37
38# Parse the command line
39while getopts "whct:s:" opt; do
40 case "$opt" in
41 h|\?) usage;;
42 t) TYPE=$OPTARG;;
43 c) CLEAN=1;;
44 s) STATIC=$OPTARG;;
45 w) WINDOWS=1;;
46 esac
47done
48shift $((OPTIND - 1))
49
50if [ $CLEAN == 1 ]; then
51 echo "removing ${DIR}/build"
52 rm -rf ${DIR}/build
53fi
54
55BUILD_DIR="build"
56[ -d build ] || mkdir build
57echo $WINDOWS
58if [ "$WINDOWS" -eq "1" ]; then
59 echo "doing windows"
60 cd $BUILD_DIR
61 [ -d windows ] || mkdir windows
62 BUILD_DIR=$BUILD_DIR/windows
63 cd $DIR
64fi
65# lower case TYPE in a posix compliant manner
66LC_TYPE=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]')
67if [ ${LC_TYPE} == "debug" ]; then
68 DEBUGDIR=($DIR/$BUILD_DIR/debug)
69 [ -d $DEBUGDIR ] || (cd ${BUILD_DIR} && mkdir debug && cd ..)
70 BUILD_DIR=$DEBUGDIR
71else
72 RELEASEDIR=($DIR/$BUILD_DIR/release)
73 [ -d $RELEASEDIR ] || (cd ${BUILD_DIR} && mkdir release && cd ..)
74 BUILD_DIR=$RELEASEDIR
75fi
76
77echo "Build Directory: ${BUILD_DIR}"
78
79CMAKE=cmake
80CMARGS="-DCMAKE_BUILD_TYPE=$TYPE \
81 -DBUILD_STATIC_PIPE_LIBS=$STATIC \
82 -DBUILD_PIPE_ONLY=1"
83if [ "$WINDOWS" -eq "1" ]; then
84 CMARGS="$CMARGS \
85 -DCMAKE_TOOLCHAIN_FILE=${DIR}/toolchain-x86-ubuntu-mingw64.cmake"
86fi
87MAKE=make
88
89cd ${BUILD_DIR}
90pwd
91( eval $CMAKE $CMARGS $DIR && eval ${MAKE} $MAKEFLAGS )