forked from ibmruntimes/zoslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·122 lines (106 loc) · 2.91 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
###############################################################################
# Licensed Materials - Property of IBM
# ZOSLIB
# (C) Copyright IBM Corp. 2022. All Rights Reserved.
# US Government Users Restricted Rights - Use, duplication
# or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
###############################################################################
usage() {
cat <<END
$0
Builds zoslib, uses xlclang/xlclang++ by default, unless CC is set.
Options:
-c Clean build
-h Display this message
-r Release build (default is Debug)
-D Debug build (default)
-s Shared libray build (default is Static)
-S Static libray build (default)
-t Build and run tests
END
exit 1
}
SCRIPT_DIR="$( cd "$(dirname "$0")" >/dev/null 2>&1 && pwd -P )"
BLD_TYPE="Debug"
IS_CLEAN=0
SHARED="OFF"
RUN_TESTS="OFF"
CCTEST="cctest_a"
envcc=$CC && envcxx=$CXX && envlink=$LINK
if [ -f "${SCRIPT_DIR}/build.cache" ]; then
source "${SCRIPT_DIR}/build.cache"
if ! test -z "$envcc"; then
# environment variables CC, CXX, LINK override those in build.cache:
if [[ "$envcc" != "$CC" ]]; then
export CC=$envcc && export CXX=$envcxx && export LINK=$envlink
IS_CLEAN=1
fi
fi
elif test -z "$CC"; then
export CC=xlclang && export CXX=xlclang++ && export LINK=xlclang++
IS_CLEAN=1
fi
nargs=0
while getopts "chrstDS" o; do
case "${o}" in
c) IS_CLEAN=1
((nargs++))
;;
r) BLD_TYPE="Release"
((nargs++))
;;
D) BLD_TYPE="Debug"
((nargs++))
;;
s) SHARED="ON"
CCTEST=cctest_so
((nargs++))
;;
S) SHARED="OFF"
CCTEST=cctest_a
((nargs++))
;;
t) RUN_TESTS="ON"
((nargs++))
;;
*) usage
;;
esac
done
# getopts ignores a token if not prefixed with -, e.g.: s instead of -s
[[ "$#" != "$nargs" ]] && usage
/bin/cat > build.cache <<EOF
CC=$CC
CXX=$CXX
ASM=$CC
LINK=$CXX
BLD_TYPE=$BLD_TYPE
SHARED=$SHARED
RUN_TESTS=$RUN_TESTS
CCTEST=$CCTEST
EOF
[[ "$V" == "1" ]] && set -x
set -e
if((IS_CLEAN==1)); then
/bin/rm -rf CMakeFiles CMakeCache.txt
test -d build && rm -rf build/* || mkdir build
/bin/rm -rf install
else
! test -d build && mkdir build
fi
# make 4.1 doesn't pass the -j down to sub-make, so set it in MAKEFLAGS:
if ! test -z "$NUM_JOBS"; then
export MAKEFLAGS="-j ${NUM_JOBS} $MAKEFLAGS"
fi
! test -d build && echo "build: directory doesn't exist." && exit -1
pushd build
cmake .. -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_ASM_COMPILER=${CC} -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=${BLD_TYPE} -DBUILD_SHARED_LIBS=${SHARED}
cmake --build . --target install
! test -d ../install && mv install .. || /bin/cp -R install/* ../install/ && /bin/rm -rf install
popd
if [[ "${RUN_TESTS}" == "ON" ]]; then
export GTEST_OUTPUT="xml:zoslib.xml"
[[ "$SHARED" == "ON" ]] && export LIBPATH=`pwd`/install/lib:$LIBPATH
install/bin/$CCTEST
fi