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+ }
0 commit comments