Skip to content

Commit 88fe964

Browse files
committed
tmp
1 parent 4ba8372 commit 88fe964

File tree

4 files changed

+172
-8
lines changed

4 files changed

+172
-8
lines changed

script/__util.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ function util_cleanws() {
180180
echo "$@" | sed 's/^ *//;s/[[:space:]][[:space:]]*/ /g;s/ *$//'
181181
}
182182

183+
function util_remove_substr() {
184+
local substr=$1
185+
shift
186+
local str=$*
187+
echo "$str" | sed "s/$substr//g"
188+
}
189+
183190
function util_filter() {
184191
local pat=$1
185192
shift

script/_common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ export COMMON_LIBRARY_VERSION_LIST="
7171
1.1.1d
7272
1.40.0
7373
7.68.0
74-
3.12.2
74+
3.11.4
7575
"
7676
export COMMON_LIBRARY_URL_LIST="
7777
https://www.openssl.org/source/openssl-1.1.1d.tar.gz
7878
https://github.com/nghttp2/nghttp2/releases/download/v1.40.0/nghttp2-1.40.0.tar.gz
7979
https://curl.haxx.se/download/curl-7.68.0.tar.gz
80-
https://github.com/protocolbuffers/protobuf/releases/download/v3.12.2/protobuf-all-3.12.2.tar.gz
80+
https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protobuf-cpp-3.11.4.tar.gz
8181
"
8282

8383
util_create_dir "$COMMON_INPUT_DIR"

script/ios-protobuf.sh

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,138 @@
1818
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
# SOFTWARE.
21+
# SOFTWARE.
22+
23+
#!/bin/sh
24+
25+
echo "###############################################################################" >/dev/null
26+
echo "# Script Summary: #" >/dev/null
27+
echo "# Author: yu.zuo #" >/dev/null
28+
echo "# Update Date: 2020.05.28 #" >/dev/null
29+
echo "# Script version: 1.0.0 #" >/dev/null
30+
echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null
31+
echo "# #" >/dev/null
32+
echo "# Brief introduction: #" >/dev/null
33+
echo "# Build ios protobuf shell script. #" >/dev/null
34+
echo "# #" >/dev/null
35+
echo "# Prerequisites: #" >/dev/null
36+
echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null
37+
echo "# #" >/dev/null
38+
echo "# Reference: #" >/dev/null
39+
echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null
40+
echo "###############################################################################" >/dev/null
41+
42+
# set -x
43+
44+
protobuf_zip_file=""
45+
protobuf_zip_file_no_suffix=""
46+
protobuf_zip_file_path=""
47+
protobuf_zip_file_no_suffix_path=""
48+
protobuf_input_dir=""
49+
protobuf_output_dir=""
50+
protobuf_command=protoc
51+
52+
function ios_protobuf_printf_variable() {
53+
log_var_print "protobuf_input_dir = $protobuf_input_dir"
54+
log_var_print "protobuf_output_dir = $protobuf_output_dir"
55+
log_var_print "protobuf_zip_file = $protobuf_zip_file"
56+
log_var_print "protobuf_zip_file_no_suffix = $protobuf_zip_file_no_suffix"
57+
log_var_print "protobuf_zip_file_path = $protobuf_zip_file_path"
58+
log_var_print "protobuf_zip_file_no_suffix_path = $protobuf_zip_file_no_suffix_path"
59+
}
60+
61+
function ios_protobuf_pre_tool_check() {
62+
63+
local protobuf_version=$(protoc --version)
64+
util_is_in "$COMMON_LIBRARY_VERSION" "$protobuf_version" || common_die "Protobuf is not installed on the system, see the protobuf installation instructions. (ref: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md)"
65+
66+
protobuf_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}"
67+
protobuf_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}"
68+
69+
protobuf_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}"
70+
protobuf_zip_file_no_suffix=$(util_remove_substr "cpp-" ${protobuf_zip_file%.tar.gz})
71+
protobuf_zip_file_path="${protobuf_input_dir}/${protobuf_zip_file}"
72+
protobuf_zip_file_no_suffix_path="${protobuf_input_dir}/${protobuf_zip_file_no_suffix}"
73+
74+
util_create_dir "${protobuf_input_dir}"
75+
util_create_dir "${protobuf_output_dir}"
76+
77+
ios_protobuf_printf_variable
78+
79+
}
80+
81+
function ios_protobuf_pre_download_zip() {
82+
local library_id=$1
83+
util_download_file "$COMMON_DOWNLOAD_ADRESS" "$protobuf_zip_file_path"
84+
}
85+
86+
function ios_protobuf_build_unzip() {
87+
local library_id=$1
88+
util_unzip "$protobuf_zip_file_path" "${protobuf_input_dir}" "$protobuf_zip_file_no_suffix"
89+
}
90+
91+
function ios_protobuf_build_config_make() {
92+
local library_id=$1
93+
local library_arch=$2
94+
95+
local library_arch_path="${protobuf_output_dir}/${library_arch}"
96+
util_remove_dir "$library_arch_path"
97+
util_create_dir "${library_arch_path}/log"
98+
99+
ios_set_sysroot "${library_arch}"
100+
ios_set_cpu_feature "${COMMON_LIBRARY_NAME}" "${library_arch}" "${IOS_API}" "${IOS_SYSROOT}"
101+
102+
ios_printf_arch_variable
103+
104+
pushd .
105+
cd "$protobuf_zip_file_no_suffix_path"
106+
107+
if [[ "${library_arch}" == "x86-64" ]]; then
108+
109+
./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --with-protoc=protobuf_command >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!"
110+
111+
elif [[ "${library_arch}" == "armv7" ]]; then
112+
113+
./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --with-protoc=protobuf_command >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!"
114+
115+
elif [[ "${library_arch}" == "arm64" ]]; then
116+
117+
# for test
118+
export CFLAGS='-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Wno-ignored-optimization-argument -DIOS -fembed-bitcode -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include'
119+
export CPPFLAGS=${CFLAGS}
120+
121+
./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --with-protoc=protobuf_command >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!"
122+
123+
elif [[ "${library_arch}" == "arm64e" ]]; then
124+
125+
./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --with-protoc=protobuf_command >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!"
126+
127+
else
128+
common_die "not support $library_arch"
129+
fi
130+
131+
make clean >>"${library_arch_path}/log/output.log"
132+
if make -j$(util_get_cpu_count) >>"${library_arch_path}/log/output.log" 2>&1; then
133+
if make check >>"${library_arch_path}/log/output.log" 2>&1; then
134+
make install >>"${library_arch_path}/log/output.log" 2>&1
135+
fi
136+
fi
137+
138+
popd
139+
}
140+
141+
function ios_protobuf_archive() {
142+
local library_id=$1
143+
local static_library_list=()
144+
for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do
145+
local static_library_file_path="${protobuf_output_dir}/${IOS_ARCHS[i]}/lib/lib${COMMON_LIBRARY_NAME}.a"
146+
if [ -f "$static_library_file_path" ]; then
147+
static_library_list[${#static_library_list[@]}]="$static_library_file_path"
148+
fi
149+
done
150+
if [ 0 -lt ${#static_library_list[@]} ]; then
151+
util_remove_dir "${protobuf_output_dir}/lipo"
152+
util_create_dir "${protobuf_output_dir}/lipo"
153+
lipo ${static_library_list[@]} -create -output "${protobuf_output_dir}/lipo/lib${COMMON_LIBRARY_NAME}-universal.a"
154+
fi
155+
}

script/test.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,31 @@ echo "##########################################################################
123123
# test
124124

125125
# 测试if双条件
126-
count1=0
127-
count2=1
128-
if test $count1 -gt 0 && test $count2 -gt 0 ; then
129-
echo "ok"
130-
fi
126+
# count1=0
127+
# count2=1
128+
# if test $count1 -gt 0 && test $count2 -gt 0 ; then
129+
# echo "ok"
130+
# fi
131+
132+
# 测试是否包含指定字符串
133+
# var="libprotoc 3.11.4"
134+
# var=$(protoc --version)
135+
# util_is_in "3.11.4" "$var" && echo "contain" || echo "not contain"
136+
# util_is_in "3.11.5" "$var" && echo "contain" || echo "not contain"
137+
# protobuf_version=$(protoc --version)
138+
# COMMON_LIBRARY_VERSION=3.6.57
139+
# util_is_in "$COMMON_LIBRARY_VERSION" "$protobuf_version" || common_die "Protobuf is not installed on the system, see the protobuf installation instructions. (ref: https://github.com/protocolbuffers/protobuf/blob/master/src/README.md)"
140+
141+
# 测试转义
142+
# util_c_escape "123[\\][\"][\'][\][\"\"]123"
143+
# function util_remove_substr() {
144+
# echo "protobuf-cpp-3.11.4" | sed 's/cpp-//g'
145+
# }
146+
# util_remove_substr
147+
# function util_remove_substr2() {
148+
# local sub=$1
149+
# shift
150+
# local str=$*
151+
# echo "$str" | sed "s/$sub//g"
152+
# }
153+
# util_remove_substr2 "cpp-" "protobuf-cpp-3.11.4"

0 commit comments

Comments
 (0)