forked from awslabs/aws-c-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-deps.sh
executable file
·95 lines (80 loc) · 2.44 KB
/
build-deps.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
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
95
#!/usr/bin/env bash
# usage:
# ./build-deps.sh
# -c, --clean - remove any cached CMake config before building
# -i, --install <path> - sets the CMAKE_INSTALL_PREFIX, the root where the deps will be install
# -l, --local - Tells the script to look for local dependency source trees in the same parent as this repo
# <all other args> - will be passed to cmake as-is
set -e
set -x
# everything is relative to the directory this script is in
home_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# where to have cmake put its binaries
deps_dir=$home_dir/build/deps
# where deps will be installed
install_prefix=$deps_dir/install
# whether or not to look for local sources for deps, they should be in
# the same parent directory as this repo
prefer_local_deps=0
cmake_args=""
function install_dep {
local dep=$1
local commit_or_branch=$2
# if the local deps are preferred and the local dep exists, use it
if [ $prefer_local_deps -ne 0 ] && [ -d "$home_dir/../$dep" ]; then
pushd $home_dir/../$dep
echo "Using local repo: $home_dir/../$dep branch:" `git branch | grep \* | cut -d ' ' -f2` "commit: " `git rev-parse HEAD`
else # git clone the repo and build it
pushd $deps_dir
if [ -d $dep ]; then
cd $dep
git pull --rebase
else
git clone https://github.com/awslabs/$dep.git
cd $dep
fi
if [ -n "$commit_or_branch" ]; then
git checkout $commit_or_branch
fi
echo "Using git repo: $dep branch:" `git branch | grep \* | cut -d ' ' -f2` "commit: " `git rev-parse HEAD`
fi
mkdir -p dep-build
cd dep-build
cmake -GNinja $cmake_args -DCMAKE_PREFIX_PATH=$install_prefix -DCMAKE_INSTALL_PREFIX=$install_prefix ..
cmake --build . --target all
cmake --build . --target install
popd
}
cmake_args=()
while [[ $# -gt 0 ]]
do
arg="$1"
case $arg in
-c|--clean)
clean=1
shift
;;
-i|--install)
install_prefix=$2
shift
shift
;;
-l|--local|--prefer-local)
prefer_local_deps=1
shift
;;
*) # everything else
cmake_args="$cmake_args $arg" # unknown args are passed to cmake
shift
;;
esac
done
if [ $clean ]; then
rm -rf $deps_dir
fi
mkdir -p $deps_dir
install_dep aws-c-common
install_dep aws-c-cal
if [[ $OSTYPE != darwin* ]]; then
install_dep s2n
fi