forked from google/sentencepiece
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompile_ios.sh
executable file
·146 lines (121 loc) · 4.11 KB
/
compile_ios.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
#!/bin/bash
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Builds protobuf 3 for iOS.
set -e
if [[ -n MACOSX_DEPLOYMENT_TARGET ]]; then
export MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion)
fi
SCRIPT_DIR=$(dirname $0)
ARCHS="ARMV7 ARMV7S ARM64 I386 X86_64"
USAGE="usage: compile_ios.sh [-A architecture] [-P protoc] [-L protobuf_lib] [-F protobuf_cxxflags]
A script to build protobuf for ios.
This script can only be run on MacOS host platforms.
Options:
-A architecture
Target platforms to compile. The default is: $ARCHS.
-P protoc
Host protoc path. The default is: protoc
-L protobuf_lib
Target protobuf lib to link. Must provide for cross compiling.
-F protobuf_cxxflags
Target protobuf cxxflags deliverd to compiler."
while
ARG="${1-}"
case "$ARG" in
-*) case "$ARG" in -*A*) ARCHS="${2?"$USAGE"}"; shift; esac
case "$ARG" in -*P*) PROTOC="${2?"$USAGE"}"; shift; esac
case "$ARG" in -*L*) PROTOBUF_LIBS="${2?"$USAGE"}"; shift; esac
case "$ARG" in -*F*) PROTOBUF_CFLAGS="${2?"$USAGE"}"; shift; esac
case "$ARG" in -*[!APLF]*) echo "$USAGE" >&2; exit 2;; esac;;
"") break;;
*) echo "$USAGE" >&2; exit 2;;
esac
do
shift
done
HOST_PROTOBUF="/Users/resec/edo/tensorflow/tensorflow/contrib/makefile/gen/protobuf-host"
PROTOC="$HOST_PROTOBUF/bin/protoc"
PROTOBUF_CFLAGS="-I$HOST_PROTOBUF/include"
PROTOBUF_LIBS="/Users/resec/edo/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios/lib"
GENDIR=$(pwd)/gen/ios/
LIBDIR=${GENDIR}lib
mkdir -p ${LIBDIR}
OSX_VERSION="darwin14.0.0"
IPHONEOS_PLATFORM=$(xcrun --sdk iphoneos --show-sdk-platform-path)
IPHONEOS_SYSROOT=$(xcrun --sdk iphoneos --show-sdk-path)
IPHONESIMULATOR_PLATFORM=$(xcrun --sdk iphonesimulator --show-sdk-platform-path)
IPHONESIMULATOR_SYSROOT=$(xcrun --sdk iphonesimulator --show-sdk-path)
MIN_SDK_VERSION=9.0
CXXFLAGS="-Os -std=c++11 -Wall"
./autogen.sh
if [ $? -ne 0 ]
then
echo "./autogen.sh command failed."
exit 1
fi
for ARCH in `echo "${ARCHS}" | tr "[:upper:]" "[:lower:]"`; do
case "$ARCH" in
i386|x86_64)
ARCH_PREFIX="${LIBDIR}/iossim_${ARCH}"
ARCH_SYSROOT="${IPHONESIMULATOR_SYSROOT}"
ARCH_MIN_SDK_VERSION="-mios-simulator-version-min=${MIN_SDK_VERSION}"
ARCH_LDFLAGS= #"-L${ARCH_SYSROOT}/usr/lib"
;;
*)
ARCH_PREFIX="${LIBDIR}/ios_${ARCH}"
ARCH_SYSROOT="${IPHONEOS_SYSROOT}"
ARCH_MIN_SDK_VERSION="-miphoneos-version-min=${MIN_SDK_VERSION}"
ARCH_LDFLAGS=
;;
esac
case "$ARCH" in
arm64)
ARCH_HOST="arm";;
*)
ARCH_HOST="${ARCH}-apple-${OSX_VERSION}";;
esac
HOST_PROTOBUF="/Users/resec/edo/tensorflow/tensorflow/contrib/makefile/gen/protobuf-host"
TARGET_PROTOBUF="/Users/resec/edo/tensorflow/tensorflow/contrib/makefile/gen/protobuf_ios"
PROTOC="$HOST_PROTOBUF/bin/protoc"
PROTOBUF_CFLAGS="-I$HOST_PROTOBUF/include -D_THREAD_SAFE"
PROTOBUF_LIBS="-L$TARGET_PROTOBUF/lib -lprotobuf -D_THREAD_SAFE"
rm -rf src/.deps
./configure \
--prefix="${ARCH_PREFIX}" \
--exec-prefix="${ARCH_PREFIX}" \
"IOS=IOS" \
"ARCH=${ARCH}" \
"MIN_SDK_VERSION=${ARCH_MIN_SDK_VERSION}" \
"SYSROOT=${ARCH_SYSROOT}" \
"ARCH_LDFLAGS=${ARCH_LDFLAGS}" \
"PROTOC=${PROTOC}" \
"PROTOBUF_CFLAGS=${PROTOBUF_CFLAGS}" \
"PROTOBUF_LIBS=${PROTOBUF_LIBS}"
make clean
rm -rf $ARCH_PREFIX
make -j"${JOB_COUNT}"
if [ $? -ne 0 ]; then
echo "${ARCH} compilation failed."
exit 1
fi
make install
ARCH_LIBS="${ARCH_LIBS} ${ARCH_PREFIX}/lib/libsentencepiece.a"
done
echo ${ARCH_LIBS}
lipo \
${ARCH_LIBS} \
-create \
-output ${LIBDIR}/libsentencepiece.a