-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·106 lines (91 loc) · 2.23 KB
/
build.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
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
function ShowUsage()
{
cat <<EOT
$(basename "$0") options
[--builddir=<builddir>] - name of build directory
[--cxx=<path/to/cxx>] - path for CXX environment variable
[--cc=<path/to/cc>] - path for CC env variable
[--cmake=<options>] - option string to pass to CMake
[--concourse] - building in Concourse
EOT
return 0
}
BUILDDIR=build
PARAM_CC=
PARAM_CXX=
PARAM_CMAKE=
PARAM_CONCOURSE=
while test $# -gt 0; do
param="$1"
if test "${1::1}" = "-"; then
if test ${#1} -gt 2 -a "${1::2}" = "--" ; then
param="${1:2}"
else
param="${1:1}"
fi
else
break
fi
shift
case $param in
builddir=*)
BUILDDIR=$(echo "$param"|cut -f2 -d'=')
;;
cc=*)
PARAM_CC=$(echo "$param"|cut -f2 -d'=')
;;
cxx=*)
PARAM_CXX=$(echo "$param"|cut -f2 -d'=')
;;
cmake=*)
PARAM_CMAKE=$(echo "$param"|cut -f2- -d'=')
;;
concourse*)
PARAM_CONCOURSE=1
;;
help|h|?|-?)
ShowUsage
exit 0
;;
*)
echo "Error: Unknown parameter: $param"
ShowUsage
exit 2
;;
esac
done
echo "BUILDDIR=$BUILDDIR"
echo "PARAM_CC=$PARAM_CC"
echo "PARAM_CXX=$PARAM_CXX"
echo "PARAM_CMAKE=$PARAM_CMAKE"
# If running in a Concourse pipeline then validate the repo was cloned
if [ -n "$PARAM_CONCOURSE" ]; then
[ ! -d ./sockets-cpp-git ] && { echo "ERROR: repo not cloned!"; exit 1; }
# Change to the base directory of the repo
cd sockets-cpp-git || exit
fi
# Create build directory and switch to it
mkdir -p "$BUILDDIR"
cd "$BUILDDIR" || exit
# Configure via CMake
if [ -n "$PARAM_CXX" ] || [ -n "$PARAM_CC" ]; then
# Override CC and CXX
CC=$PARAM_CC CXX=$PARAM_CXX cmake "$PARAM_CMAKE" -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=ON ..
else
cmake "$PARAM_CMAKE" -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=ON ..
fi
ret=$?
[ $ret -ne 0 ] && exit $ret
# Build
make
ret=$?
[ $ret -ne 0 ] && exit $ret
export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
# Run tests
[ ! -x ./test/socketTests ] && { echo "ERROR: unit tests not built!"; exit 1; }
# Run unit tests
./test/socketTests
ret=$?
# Return result
exit $ret