-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.sh
49 lines (39 loc) · 1.18 KB
/
common.sh
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
#!/bin/bash
RUN_FROM=$(dirname "$0")
FB_ROOT=$(cd "${RUN_FROM}"; pwd)
BUILDDIR=""
PROJDIR=""
USED_ARGS=0
print_usage() {
echo "usage: $0 [<project dir> [<build dir>]] [<params ...>]"
}
check_proj_dir() {
if [[ ! -d $1 && ! -L $1 ]]; then
echo "ERROR: Project directory $1 does not exist."
print_usage
exit 1
fi
}
# Check if $1 is set and doesn't start with '-'
if [[ -n "$1" && ! "$1" =~ ^- ]]; then
check_proj_dir "$1"
PROJDIR="$1"
USED_ARGS=1
# Check if $2 is set and doesn't start with '-'
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
BUILDDIR="$2"
USED_ARGS=2
fi
fi
# Set default values if not provided
PROJDIR=${PROJDIR:-"${RUN_FROM}/projects"}
BUILDDIR=${BUILDDIR:-$( [[ "$PROJDIR" == "examples" ]] && echo "${RUN_FROM}/buildex" || echo "${RUN_FROM}/build" )}
check_proj_dir "$PROJDIR"
PROJDIR=$(cd "$PROJDIR"; pwd)
mkdir -p "$BUILDDIR"
BUILDDIR=$(cd "$BUILDDIR"; pwd)
echo "Using projects in: $PROJDIR"
echo "Generating build files in: $BUILDDIR"
echo "NOTE: The build files in $BUILDDIR should *NEVER* be modified directly. Make changes in cmake and re-run this script."
# Remove consumed arguments
shift $USED_ARGS