forked from google/zetasql
-
Notifications
You must be signed in to change notification settings - Fork 9
/
pack_zetasql.sh
executable file
·202 lines (160 loc) · 5.3 KB
/
pack_zetasql.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# install zetasql compiled header files and libs
set -eE
#=== FUNCTION ================================================================
# NAME: usage
# DESCRIPTION: Display usage information.
#===============================================================================
function usage ()
{
echo "Usage : $0 [options] [--]
Options:
-h Display this message
-d Linux distribution name, e.g centos, ubuntu, default empty
-p Pick PIC libraries only, OFF by default
-i Request install to given directory after pack"
} # ---------- end of function usage ----------
#-----------------------------------------------------------------------
# Handle command line arguments
#-----------------------------------------------------------------------
INSTALL_DIR=
# linux distribution name
DISTRO=
PICK_PIC=OFF
while getopts ":hi:d:p:" opt
do
case $opt in
h ) usage; exit 0 ;;
d ) DISTRO=$OPTARG ;;
p ) PICK_PIC=$OPTARG ;;
i )
INSTALL_DIR=$OPTARG
mkdir -p "$INSTALL_DIR"
INSTALL_DIR=$(cd "$INSTALL_DIR" 2>/dev/null && pwd)
;;
* ) echo -e "\n Option does not exist : OPTARG\n"
usage; exit 1 ;;
esac # --- end of case ---
done
shift $((OPTIND-1))
if [[ "$PICK_PIC" == 'ON' ]] ; then
LIB_PATTERN='*.pic.a'
else
LIB_PATTERN='*.a'
fi
pushd "$(dirname "$0")"
pushd "$(git rev-parse --show-toplevel)"
VERSION=${TAG:-$(git rev-parse --short HEAD)}
ROOT=$(pwd)
export ROOT
export ZETASQL_LIB_NAME="libzetasql-$VERSION"
export PREFIX="$ROOT/${ZETASQL_LIB_NAME}"
# different module of zetasql build different library, we first find all need libraries and copy
# them into tmp-lib(this don't include thirdparty libraries), then repack into single archive
rm -rf tmp-lib libzetasql.mri "${PREFIX}"
mkdir -p tmp-lib
mkdir -p "${PREFIX}"
mkdir -p "${PREFIX}"/lib
install_lib() {
local file
file=$1
local libname
libname=lib$(echo "$file" | tr '/' '_' | sed -e 's/lib//' )
if [[ "$PICK_PIC" == 'ON' ]]; then
libname=$(echo "$libname" | sed -e 's/\.pic\.a$/.a/')
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
INSTALL_BIN="install"
else
INSTALL_BIN="ginstall"
fi
${INSTALL_BIN} -Dv "$file" "$ROOT/tmp-lib/$libname"
}
install_gen_include_file() {
local file
file=$1
local outfile
outfile=$(echo "$file" | sed -e 's/^.*proto\///')
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
INSTALL_BIN="install"
else
INSTALL_BIN="ginstall"
fi
${INSTALL_BIN} -Dv "$file" "$PREFIX/include/$outfile"
}
install_external_lib() {
local file
file=$1
local libname
libname=$(basename "$file")
if [[ "$PICK_PIC" == 'ON' ]]; then
libname=$(echo "$libname" | sed -e 's/\.pic\.a$/.a/')
fi
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
INSTALL_BIN="install"
else
INSTALL_BIN="ginstall"
fi
${INSTALL_BIN} -Dv "$file" "$PREFIX/lib/$libname"
}
export -f install_gen_include_file
export -f install_lib
export -f install_external_lib
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
INSTALL_BIN="install"
else
INSTALL_BIN="ginstall"
fi
pushd bazel-bin/
find zetasql -type f -iname "$LIB_PATTERN" -exec bash -c 'install_lib $0' {} \;
# external lib headers
pushd "$(realpath .)/../../../../../external/com_googlesource_code_re2"
find re2 -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \;
popd
pushd "$(realpath .)/../../../../../external/com_googleapis_googleapis"
find google -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \;
popd
pushd "$(realpath .)/../../../../../external/com_google_file_based_test_driver"
find file_based_test_driver -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \;
popd
# external lib
pushd external
find icu -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \;
find com_googlesource_code_re2 -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \;
find com_googleapis_googleapis -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \;
find com_google_file_based_test_driver -type f -iname "$LIB_PATTERN" -exec bash -c 'install_external_lib $0' {} \;
popd
# zetasql generated files: protobuf & template generated files
find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \;
find zetasql -iregex ".*/_virtual_includes/.*\.h\$" -exec bash -c 'install_gen_include_file $0' {} \;
popd # bazel-bin
# header files from source
find zetasql -type f -iname "*.h" -exec ${INSTALL_BIN} -Dv {} "$PREFIX"/include/{} \;
if [[ "$OSTYPE" == "linux-gnu"* ]]
then
echo 'create libzetasql.a' >> libzetasql.mri
find tmp-lib/ -iname "*.a" -type f -exec bash -c 'echo "addlib $0" >> libzetasql.mri' {} \;
echo "save" >> libzetasql.mri
echo "end" >> libzetasql.mri
ar -M <libzetasql.mri
ranlib libzetasql.a
mv libzetasql.a "$PREFIX/lib/"
else
libtool -static -o libzetasql.a tmp-lib/*.a
mv libzetasql.a "$PREFIX/lib"
fi
if [[ $OSTYPE = 'darwin'* ]]; then
OUT_FILE="${ZETASQL_LIB_NAME}-darwin-$(uname -m).tar.gz"
else
OUT_FILE="${ZETASQL_LIB_NAME}-$OSTYPE-$(uname -m)-$DISTRO.tar.gz"
fi
tar czf "$OUT_FILE" "$ZETASQL_LIB_NAME"/
if [ -n "$INSTALL_DIR" ] ; then
tar xzf "$OUT_FILE" -C "$INSTALL_DIR" --strip-components=1
fi
popd
popd