aboutsummaryrefslogtreecommitdiff
path: root/profiling/buildpipe.sh
blob: cacee8728c0673a9b7f30003bc9db4222ebd50be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
#
# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
# SPDX-License-Identifier: MIT
#

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  TARGET="$(readlink "$SOURCE")"
  if [[ $TARGET == /* ]]; then
    # "SOURCE '$SOURCE' is an absolute symlink to '$TARGET'"
    SOURCE="$TARGET"
  else
    DIR="$( dirname "$SOURCE" )"
    # "SOURCE '$SOURCE' is a relative symlink to '$TARGET' (relative to '$DIR')"
    SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  fi
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

CMD=$( basename "$0" )

usage() {
  echo "Usage: $CMD [options]"
  echo "Options:        -t(type) <Debug or Release>"
  echo "                -c(lean) build"
  echo "                -s(tatic libraries) <1 or 0>"
  echo "                -w(indows) build"
  exit 1
}
# defaults
TYPE=Release
CLEAN=0
STATIC=0
WINDOWS=0

# Parse the command line
while getopts "whct:s:" opt; do
  case "$opt" in
    h|\?) usage;;
    t) TYPE=$OPTARG;;
    c) CLEAN=1;;
    s) STATIC=$OPTARG;;
    w) WINDOWS=1;;
  esac
done
shift $((OPTIND - 1))

if [ $CLEAN == 1 ]; then
    echo "removing ${DIR}/build"
    rm -rf "${DIR}"/build
fi

BUILD_DIR="build"
[ -d build ] || ( mkdir build || exit )
echo $WINDOWS
if [ "$WINDOWS" -eq "1" ]; then
    echo "doing windows"
    cd $BUILD_DIR || exit
    [ -d windows ] || mkdir windows
    BUILD_DIR=$BUILD_DIR/windows
    cd "$DIR" || exit
fi
# lower case TYPE in a posix compliant manner
LC_TYPE=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]')
if [ "${LC_TYPE}" == "debug" ]; then
    DEBUGDIR=("$DIR/$BUILD_DIR/debug")
    # shellcheck disable=SC2128
    [ -d "$DEBUGDIR" ] || (cd ${BUILD_DIR} && ( mkdir debug || exit ) && cd ..)
    # shellcheck disable=SC2128
    BUILD_DIR=$DEBUGDIR
else
    RELEASEDIR=("$DIR/$BUILD_DIR/release")
    # shellcheck disable=SC2128
    [ -d "$RELEASEDIR" ] || (cd "${BUILD_DIR}" && ( mkdir release || exit ) && cd ..)
    # shellcheck disable=SC2128
    BUILD_DIR=$RELEASEDIR
fi

echo "Build Directory: ${BUILD_DIR}"

CMAKE=cmake
CMARGS="-DCMAKE_BUILD_TYPE=$TYPE \
        -DBUILD_STATIC_PIPE_LIBS=$STATIC \
        -DBUILD_PIPE_ONLY=1"
if [ "$WINDOWS" -eq "1" ]; then
    CMARGS="$CMARGS \
           -DCMAKE_TOOLCHAIN_FILE=${DIR}/toolchain-x86-ubuntu-mingw64.cmake"
fi
MAKE="make"

cd "${BUILD_DIR}" || exit
pwd
( eval $CMAKE "$CMARGS" "$DIR" && eval ${MAKE} "$MAKEFLAGS" )