-
Notifications
You must be signed in to change notification settings - Fork 10
/
librimeBuild.sh
executable file
·168 lines (140 loc) · 5.26 KB
/
librimeBuild.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
#!/bin/bash
set -ex
RIME_ROOT="$(cd "$(dirname "$0")"; pwd)"
echo ${RIME_ROOT}
# librime dependences build
if [[ ! -d ${RIME_ROOT}/.boost ]]
then
mkdir ${RIME_ROOT}/.boost
cp -R ${RIME_ROOT}/boost-iosx/dest ${RIME_ROOT}/.boost
fi
export BOOST_ROOT=$RIME_ROOT/.boost/dest
# temp directory for librime lib and headers
RIME_LIB=${RIME_ROOT}/lib
RIME_INCLUDE=${RIME_ROOT}/include
rm -rf ${RIME_LIB} ${RIME_INCLUDE} && mkdir -p ${RIME_LIB} ${RIME_INCLUDE}
deps=("libglog" "libleveldb" "libmarisa" "libopencc" "libyaml-cpp")
function prepare_library() {
LIBRIME_VARIANT=$1
LIBRIME_ROOT=${RIME_ROOT}/${LIBRIME_VARIANT}
LIBRIME_INCLUDE=${RIME_INCLUDE}/${LIBRIME_VARIANT}
cd ${LIBRIME_ROOT}
git submodule update --init
if [[ ! -f ${RIME_ROOT}/${LIBRIME_VARIANT}.patch.apply ]]
then
touch ${RIME_ROOT}/${LIBRIME_VARIANT}.patch.apply
git apply ${RIME_ROOT}/librime.patch >/dev/null 2>&1
fi
# install octagram plugin
rm -rf ${LIBRIME_ROOT}/plugins/octagram
${LIBRIME_ROOT}/install-plugins.sh lotem/librime-octagram
(cd ${LIBRIME_ROOT}/plugins/octagram && sed -i "" 's/add_subdirectory(tools)//' CMakeLists.txt)
# install lua plugin
rm -rf ${LIBRIME_ROOT}/plugins/lua
${LIBRIME_ROOT}/install-plugins.sh imfuxiao/librime-lua@main
# install charcode
#rm -rf ${RIME_ROOT}/librime/plugins/librime-charcode
#${RIME_ROOT}/librime/install-plugins.sh rime/librime-charcode
#extern void rime_require_module_charcode();\
# rime_require_module_charcode();\
# install predict
# rm -rf ${LIBRIME_ROOT}/plugins/predict
# ${LIBRIME_ROOT}/install-plugins.sh rime/librime-predict
# (
# cd ${LIBRIME_ROOT}/plugins/predict
# sed -i '' '/add_subdirectory(tools)/d' CMakeLists.txt
# )
# 添加插件模块依赖
sed -i "" '/#if RIME_BUILD_SHARED_LIBS/,/#endif/c\
#if RIME_BUILD_SHARED_LIBS\
#define rime_declare_module_dependencies()\
#else\
extern void rime_require_module_core();\
extern void rime_require_module_dict();\
extern void rime_require_module_gears();\
extern void rime_require_module_levers();\
extern void rime_require_module_lua();\
extern void rime_require_module_octagram();\
// link to default modules explicitly when building static library.\
static void rime_declare_module_dependencies() {\
rime_require_module_core();\
rime_require_module_dict();\
rime_require_module_gears();\
rime_require_module_levers();\
rime_require_module_lua();\
rime_require_module_octagram();\
}\
#endif\
' ${LIBRIME_ROOT}/src/rime_api.cc
# build deps
# first time: for ios
# rm -rf ${LIBRIME_ROOT}/lib/*.a
make xcode/ios/deps/clean
make xcode/ios/deps
for file in ${deps[@]}
do
cp -f ${LIBRIME_ROOT}/lib/${file}.a ${RIME_LIB}/${file}.a
done
# second time: for simulator
# rm -rf ${LIBRIME_ROOT}/lib/*.a
make xcode/simulator/deps/clean
make xcode/simulator/deps
for file in ${deps[@]}
do
cp -f ${LIBRIME_ROOT}/lib/${file}.a ${RIME_LIB}/${file}_simulator.a
done
mkdir -p ${LIBRIME_INCLUDE}
cp ${LIBRIME_ROOT}/src/*.h ${LIBRIME_INCLUDE}
# librime build
# PLATFORM value means
# OS64: to build for iOS (arm64 only)
# OS64COMBINED: to build for iOS & iOS Simulator (FAT lib) (arm64, x86_64)
# SIMULATOR64: to build for iOS simulator 64 bit (x86_64)
# SIMULATORARM64: to build for iOS simulator 64 bit (arm64)
# MAC: to build for macOS (x86_64)
# librime build: iOS simulator 64 bit (x86_64)
export PLATFORM=SIMULATOR64
rm -rf ${LIBRIME_ROOT}/build ${LIBRIME_ROOT}/dist
make xcode/ios/dist
cp -f ${LIBRIME_ROOT}/dist/lib/librime.a ${RIME_LIB}/${LIBRIME_VARIANT}_simulator_x86_64.a
# librime build: iOS simulator 64 bit (arm64)
export PLATFORM=SIMULATORARM64
rm -rf ${LIBRIME_ROOT}/build ${LIBRIME_ROOT}/dist
make xcode/ios/dist
cp -f ${LIBRIME_ROOT}/dist/lib/librime.a ${RIME_LIB}/${LIBRIME_VARIANT}_simulator_arm64.a
# librime build: arm64
export PLATFORM=OS64
rm -rf ${LIBRIME_ROOT}/build ${LIBRIME_ROOT}/dist
make xcode/ios/dist
cp -f ${LIBRIME_ROOT}/dist/lib/librime.a ${RIME_LIB}/${LIBRIME_VARIANT}.a
# transform *.a to xcframework
rm -rf ${RIME_ROOT}/Frameworks/${LIBRIME_VARIANT}.xcframework
lipo ${RIME_LIB}/${LIBRIME_VARIANT}_simulator_x86_64.a ${RIME_LIB}/${LIBRIME_VARIANT}_simulator_arm64.a -create -output ${RIME_LIB}/${LIBRIME_VARIANT}_simulator.a
xcodebuild -create-xcframework \
-library ${RIME_LIB}/${LIBRIME_VARIANT}_simulator.a \
-headers ${LIBRIME_INCLUDE} \
-library ${RIME_LIB}/${LIBRIME_VARIANT}.a \
-headers ${LIBRIME_INCLUDE} \
-output ${RIME_ROOT}/Frameworks/${LIBRIME_VARIANT}.xcframework
# clean
rm -rf ${RIME_ROOT}/lib/${LIBRIME_VARIANT}*.a
}
prepare_library "librime"
for file in ${deps[@]}
do
rm -rf ${RIME_ROOT}/Frameworks/${file}.xcframework
if [ "$file" == "libyaml-cpp" ]
then
xcodebuild -create-xcframework \
-library ${RIME_ROOT}/lib/${file}.a \
-headers ${RIME_ROOT}/librime/deps/yaml-cpp/include \
-library ${RIME_ROOT}/lib/${file}_simulator.a \
-headers ${RIME_ROOT}/librime/deps/yaml-cpp/include \
-output ${RIME_ROOT}/Frameworks/${file}.xcframework
else
xcodebuild -create-xcframework \
-library ${RIME_ROOT}/lib/${file}.a \
-library ${RIME_ROOT}/lib/${file}_simulator.a \
-output ${RIME_ROOT}/Frameworks/${file}.xcframework
fi
done