├── .gitignore ├── README.md ├── document ├── simple-build-ios-and-android-script.emmx └── simple-build-ios-and-android-script.html └── script ├── __color_log.sh ├── __util.sh ├── _common.sh ├── android-common.sh ├── android-curl.sh ├── android-nghttp2.sh ├── android-openssl.sh ├── android-protobuf.sh ├── android.sh ├── ios-common.sh ├── ios-curl.sh ├── ios-nghttp2.sh ├── ios-openssl.sh ├── ios-protobuf.sh ├── ios.sh └── test.sh /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | input/* 3 | output/* 4 | 5 | *.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple-build-ios-and-android-script 2 | ## 1. Documentation 3 | ### Introduction 4 | > #### A common build project for building mobile platform native libraries. 5 | ### Target users 6 | > #### Mobile platform C&&C++ native library. 7 | ### Build target library list: 8 | > | id | name | version | dependent libraries | note | 9 | > | :- | :--- | :------ | :------------------ | :--- | 10 | > | 1 | openssl | 1.1.1d | - | Configure is perl script | 11 | > | 2 | nghttp2 | 1.40.0 | - | - | 12 | > | 3 | curl | 7.68.0 | openssl,nghttp2 | - | 13 | > | 3 | protobuf | 3.11.4 | - | - | 14 | > #### iOS Platform static library(.a) support list: 15 | > | id | armv7 | armv7s | arm64 | arm64e | x86 | x86-64 | note | 16 | > | :- | :---- | :----- | :---- | :----- | :-- | :----- | :--- | 17 | > | 1 | yes | no | yes | yes | no | yes | - | 18 | > | 2 | yes | no | yes | yes | no | yes | - | 19 | > | 3 | yes | no | yes | yes | no | yes | - | 20 | > | 4 | yes | no | yes | yes | no | yes | - | 21 | > #### iOS Platform dynamic library(.dylib) support list: 22 | > `TODO: ` 23 | > #### iOS Platform static framework(.framework) support list: 24 | > `TODO: ` 25 | > #### iOS Platform dynamic framework(.framework) support list: 26 | > `TODO: ` 27 | > #### Android Platform static library(.a) support list: 28 | > | id | armeabi-v7a | arm64-v8a | x86 | x86-64 | note | 29 | > | :- | :---------- | :-------- | :-- | :----- | :--- | 30 | > | 1 | yes | yes | yes | yes | - | 31 | > | 2 | yes | yes | yes | yes | - | 32 | > | 3 | yes | yes | yes | yes | - | 33 | > | 4 | yes | yes | yes | yes | - | 34 | > #### Android Platform dynamic library(.so) support list: 35 | > | id | armeabi-v7a | arm64-v8a | x86 | x86-64 | note | 36 | > | :- | :---------- | :-------- | :-- | :----- | :--- | 37 | > | 1 | yes | yes | yes | yes | - | 38 | > | 2 | yes | yes | yes | yes | - | 39 | > | 3 | yes | no | yes | yes | - | 40 | > | 4 | no | yes | no | no | - | 41 | > #### Android Platform support lists: 42 | ### Extended instructions 43 | > #### Use the entry script to build the target library. 44 | > #### ios.sh is the ios platform entry script. 45 | > #### android.sh is the android platform entry script. 46 | > #### Advanced use: 47 | > | target version | test result | 48 | > | :---- | :---- | 49 | > | default | pass | 50 | > | higher | generally pass | 51 | > | low | maybe not pass | 52 | ### Contribution notes 53 | > #### Adding subscripts requires some experience in scripting and project building. 54 | > #### Adding subscripts can generally be a contributor to the project. 55 | > #### Adding subscript details: 56 | > * Update parameters: 57 | > + `COMMON_LIBRARY_ID_LIST` 58 | > + `COMMON_LIBRARY_NAME_LIST` 59 | > + `COMMON_LIBRARY_VERSION_LIST` 60 | > + `COMMON_LIBRARY_URL_LIST` 61 | > * Update method: 62 | > + `common_get_library_id_from_name` 63 | > * script: 64 | > + Usage agreement: 65 | > - A script method or function needs to use the keyword `function`. 66 | > - Global variables need to use the keyword `export` and are combined with uppercase alphanumeric and underlined characters. 67 | > - Script methods or local variables within functions use the keyword `local`. 68 | > - Methods within the common.sh script need to use the prefix `common_`. 69 | > - ios-*.sh script methods need to use the prefix `ios_`. 70 | > - android-*.sh script methods need to use the prefix `android_`. 71 | > - Methods in the util. Sh script require the prefix `util_`. 72 | > - Methods within the subscript need to use the prefix `xxx_`. 73 | > - Composite scripts require the use of composite prefixes. 74 | > + Method implementation: 75 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_printf_variable`: (optional) 76 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_pre_tool_check`: (must) 77 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_pre_download_zip`: (must) 78 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_build_unzip`: (must) 79 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_build_config_make`: (must) 80 | > - `${COMMON_PLATFORM_TYPE}_${COMMON_LIBRARY_NAME}_archive`: (must) 81 | > * Contribution notes: 82 | > + AsteriskZuo: Create the project and complete the main frame design. 83 | ## 2. Architecture design 84 | ### Programming language 85 | > #### bash shell script 86 | ### Build platform: 87 | > #### MaoOS 88 | > #### Linux: **`TODO: `** 89 | ### Target platform: 90 | > #### iOS 91 | > #### Android 92 | ### Core ideas: 93 | > * Plug-in programming: 94 | > + You can build the target library by writing a corresponding subscript and adding parameters. 95 | > * Dynamic call: 96 | > + Similar to C++ polymorphism. 97 | > * High reusability: 98 | > + All code blocks are encapsulated using methods (functions). 99 | > * Dependent detection: 100 | > + Build target library dependency detection: 101 | > - manual build 102 | > - auto build all dependency target library: **`TODO: `** 103 | > * To reconstruct the configure: **`TODO: `** 104 | ### Project structure: 105 | > * Input: 106 | > + Source directory: 107 | > - GNU make project: 108 | > - cmake project: No build script is required. The iOS platform has a better way, and the Android platform directly introduces cmakelist files. 109 | > + Build tools: 110 | > - iOS independent compiler tool chain 111 | > - Android independent compiler tool chain. 112 | > - More ... 113 | > * Output: 114 | > + Interim interim documents: 115 | > - Temporary intermediate file. 116 | > - Build the library product. 117 | > + Build library products: 118 | > * Script: 119 | > + Entry script: 120 | > - ios.sh: iOS platform entry script. 121 | > - android.sh: Android platform entry script. 122 | > + Tool script: 123 | > - util.sh: Provide various basic functions. 124 | > - log.sh: Provide various basic functions. 125 | > - common.sh: Provide common functions for iOS and Android platforms. 126 | > - ios-common.sh: Provide common functions for iOS platform. 127 | > - android-common.sh: Provide common functions of Android platform. 128 | > + Subscript(plug-in script): 129 | > - ios-openssl.sh: 130 | > - android-openssl.sh: 131 | > - ios-curl.sh: 132 | > - android-curl.sh: 133 | > - More ... 134 | ## 3. Problems to be solved 135 | ### Only current list item builds are supported. 136 | ### Project-made versions can be built, but may not be built properly for lower versions. 137 | ### Building the dependencies of the target project requires manual construction. 138 | ## 4. Reference 139 | > [openssl_for_ios_and_android](https://github.com/AsteriskZuo/openssl_for_ios_and_android) 140 | ## 5. Document 141 | > [simple-build-ios-and-android-script](./document/simple-build-ios-and-android-script.html) -------------------------------------------------------------------------------- /document/simple-build-ios-and-android-script.emmx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsteriskZuo/simple-build-ios-and-android-script/e6599f115e5b311e356eb11bf715e942c2fd978a/document/simple-build-ios-and-android-script.emmx -------------------------------------------------------------------------------- /script/__color_log.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/__util.sh 26 | 27 | echo "###############################################################################" >/dev/null 28 | echo "# Script Summary: #" >/dev/null 29 | echo "# Author: AsteriskZuo #" >/dev/null 30 | echo "# Update Date: 2020.05.28 #" >/dev/null 31 | echo "# Script version: 1.0.0 #" >/dev/null 32 | echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null 33 | echo "# #" >/dev/null 34 | echo "# Brief introduction: #" >/dev/null 35 | echo "# Build iOS and Android C&&C++ common library. #" >/dev/null 36 | echo "# #" >/dev/null 37 | echo "# Prerequisites: #" >/dev/null 38 | echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null 39 | echo "# #" >/dev/null 40 | echo "# Reference: #" >/dev/null 41 | echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null 42 | echo "###############################################################################" >/dev/null 43 | 44 | echo "# 基本语法介绍: 45 | # 符号含义: 46 | # \\033[0m 关闭所有属性 47 | # \\033[1m 设置高亮度 48 | # \\033[4m 下划线 49 | # \\033[5m 闪烁 50 | # \\033[7m 反显 51 | # \\033[8m 消隐 52 | # \\033[30m 至 \\33[37m 设置前景色 53 | # \\033[40m 至 \\33[47m 设置背景色 54 | # \\033[nA 光标上移n行 55 | # \\033[nB 光标下移n行 56 | # \\033[nC 光标右移n行 57 | # \\033[nD 光标左移n行 58 | # \\033[y;xH设置光标位置 59 | # \\033[2J 清屏 60 | # \\033[K 清除从光标到行尾的内容 61 | # \\033[s 保存光标位置 62 | # \\033[u 恢复光标位置 63 | # \\033[?25l 隐藏光标 64 | # \\033[?25h 显示光标 65 | # 字体颜色:30 - 39 66 | # 30:黑 67 | # 31:红 68 | # 32:绿 69 | # 33:黄 70 | # 34:深蓝 71 | # 35:紫色 72 | # 36:天蓝 73 | # 37:白色 74 | # 字体背景颜色:40 — 49 75 | # 40:黑 76 | # 41:深红 77 | # 42:绿 78 | # 43:黄色 79 | # 44:蓝色 80 | # 45:紫色 81 | # 46:深绿 82 | # 47:白色 83 | " >/dev/null 84 | 85 | echo "###############################################################################" >/dev/null 86 | echo "#### Variable declarations partition #####" >/dev/null 87 | echo "###############################################################################" >/dev/null 88 | 89 | LOG_VAR_BOLD="1" 90 | LOG_VAR_UNDERLINE="4" 91 | LOG_VAR_BLINK="5" 92 | LOG_VAR_CONVERT="7" 93 | LOG_VAR_HIDE="8" 94 | 95 | #foreground color 96 | LOG_VAR_FG_GREY="30" 97 | LOG_VAR_FG_RED="31" 98 | LOG_VAR_FG_GREEN="32" 99 | LOG_VAR_FG_YELLOW="33" 100 | LOG_VAR_FG_BLUE="34" 101 | LOG_VAR_FG_VIOLET="35" 102 | LOG_VAR_FG_SKY_BLUE="36" 103 | LOG_VAR_FG_WHITE="37" 104 | 105 | #background color 106 | LOG_VAR_BG_BLACK="40" 107 | LOG_VAR_BG_RED="41" 108 | LOG_VAR_BG_GREEN="42" 109 | LOG_VAR_BG_YELLOW="43" 110 | LOG_VAR_BG_BLUE="44" 111 | LOG_VAR_BG_VIOLET="45" 112 | LOG_VAR_BG_SKYBLUE="46" 113 | LOG_VAR_BG_WHITE="47" 114 | 115 | echo "###############################################################################" >/dev/null 116 | echo "#### Function implementation partition #####" >/dev/null 117 | echo "###############################################################################" >/dev/null 118 | 119 | # log_xxx_print function is very easily replaced by echo command-line 120 | 121 | function log_basic_print() { 122 | # background: ${1} 123 | # foreground: ${2} 124 | # sytle: ${3} 125 | # log content: ${4} 126 | echo "\\033[${1};${2};${3}m${@:4}\\033[0m" 127 | } 128 | function log_basic_print_without_bg() { 129 | # foreground: ${1} 130 | # sytle: ${2} 131 | # log content: ${3} 132 | echo "\\033[${1};${2}m${@:3}\\033[0m" 133 | } 134 | function log_head_print() { 135 | local FOREGROUND=$LOG_VAR_FG_YELLOW 136 | local FONT=$LOG_VAR_BLINK 137 | echo "\\033[${FOREGROUND};${FONT}m${@}\\033[0m" 138 | } 139 | function log_var_print() { 140 | local FOREGROUND=$LOG_VAR_FG_SKY_BLUE 141 | local FONT=$LOG_VAR_BLINK 142 | echo " var \\033[${FOREGROUND};${FONT}m${@}\\033[0m" 143 | } 144 | function log_var_split_print() { 145 | # changed original content for space char 146 | # Multiple Spaces merge into one space. 147 | local FOREGROUND=$LOG_VAR_FG_SKY_BLUE 148 | local FONT=$LOG_VAR_BLINK 149 | local KEY=$(echo $@ | sed "s/\\=.*$//g") 150 | # VALUE=$(echo $@ | sed "s/^.*\\=//g") 151 | local VALUE=${@#*=} 152 | echo " \\033[${FOREGROUND};${FONT}m${KEY} \\033[${LOG_VAR_FG_YELLOW}m= \\033[${FOREGROUND}m${VALUE}\\033[0m" 153 | } 154 | function log_debug_print() { 155 | # high | blue 156 | 157 | # changed original content 158 | # log_basic_print_without_bg ${LOG_VAR_FG_BLUE} ${LOG_VAR_BLINK} $@ 159 | 160 | # not changed original content 161 | local FOREGROUND=$LOG_VAR_FG_BLUE 162 | local FONT=$LOG_VAR_BLINK 163 | local CURRENT_DATETIME 164 | util_get_current_datetime CURRENT_DATETIME 165 | echo "[$CURRENT_DATETIME] \\033[${FOREGROUND};${FONT}m${@}\\033[0m" 166 | } 167 | function log_info_print() { 168 | # high | green 169 | # log_basic_print_without_bg ${LOG_VAR_FG_GREEN} ${LOG_VAR_BLINK} $@ 170 | local FOREGROUND=$LOG_VAR_FG_GREEN 171 | local FONT=$LOG_VAR_BLINK 172 | util_get_current_datetime CURRENT_DATETIME 173 | echo "[$CURRENT_DATETIME] \\033[${FOREGROUND};${FONT}m${@}\\033[0m" 174 | } 175 | function log_warning_print() { 176 | # high | bold | purple 177 | # log_basic_print_without_bg ${LOG_VAR_FG_VIOLET} ${LOG_VAR_BOLD} $@ 178 | local FOREGROUND=$LOG_VAR_FG_VIOLET 179 | local FONT=$LOG_VAR_BOLD 180 | echo "\\033[${FOREGROUND};${FONT}m${@}\\033[0m" 181 | } 182 | function log_error_print() { 183 | # high | bold | red 184 | # log_basic_print_without_bg ${LOG_VAR_FG_RED} ${LOG_VAR_BOLD} $@ 185 | local FOREGROUND=$LOG_VAR_FG_RED 186 | local FONT=$LOG_VAR_BOLD 187 | echo "\\033[${FOREGROUND};${FONT}m${@}\\033[0m" 188 | } 189 | function log_fatal_print() { 190 | # high | bold | red | blink 191 | # log_basic_print ${LOG_VAR_BG_GREEN} ${LOG_VAR_FG_RED} ${LOG_VAR_BOLD} $@ 192 | local FOREGROUND=$LOG_VAR_FG_RED 193 | local BACKGROUND=$LOG_VAR_BG_GREEN 194 | local FONT=$LOG_VAR_BOLD 195 | echo "\\033[${FOREGROUND};${BACKGROUND};${FONT}m${@}\\033[0m" 196 | } 197 | function log_print() { 198 | # log content: ${1} 199 | echo $@ 200 | } 201 | -------------------------------------------------------------------------------- /script/__util.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 and Android C&&C++ common library. #" >/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 | function util_init_log() { 43 | if test -t 1 && which tput >/dev/null 2>&1; then 44 | ncolors=$(tput colors) 45 | if test -n "$ncolors" && test $ncolors -ge 8; then 46 | bold_color=$(tput bold) 47 | warn_color=$(tput setaf 3) 48 | error_color=$(tput setaf 1) 49 | reset_color=$(tput sgr0) 50 | fi 51 | # 72 used instead of 80 since that's the default of pr 52 | ncols=$(tput cols) 53 | fi 54 | : ${ncols:=72} 55 | } 56 | 57 | function util_die() { 58 | echo "$error_color$bold_color$@$reset_color" && exit 1 59 | } 60 | 61 | function util_debug() { 62 | PS4='+line:${LINENO} ' 63 | set -x 64 | } 65 | 66 | function util_get_cpu_count() { 67 | if [ "$(uname)" == "Darwin" ]; then 68 | echo $(sysctl -n hw.physicalcpu) 69 | else 70 | echo $(nproc) 71 | fi 72 | } 73 | 74 | function util_get_mac_version() { 75 | local var=$(sw_vers | grep ProductVersion) 76 | echo "${var#*:}" 77 | } 78 | 79 | function util_print_current_datetime() { 80 | echo $(date +%Y-%m-%d\ %H:%M:%S) 81 | } 82 | 83 | function util_get_current_datetime() { 84 | local lv_var=$1 85 | eval $lv_var='$(date +%Y-%m-%d\ %H:%M:%S)' 86 | } 87 | 88 | function util_dir_is_empty() { 89 | local lv_dir=$1 90 | local lv_result=$2 91 | local lv_file_list=($(ls $lv_dir)) 92 | if [ 0 -lt ${#lv_file_list[@]} ]; then 93 | eval $lv_result="no" 94 | else 95 | eval $lv_result="yes" 96 | fi 97 | } 98 | 99 | function util_append() { 100 | local var=$1 101 | shift 102 | eval "$var=\"\$$var$*\"" 103 | } 104 | 105 | function util_prepend() { 106 | local var=$1 107 | shift 108 | eval "$var=\"$*\$$var\"" 109 | } 110 | 111 | function util_reverse() { 112 | eval ' 113 | reverse_out= 114 | for v in $'$1'; do 115 | reverse_out="$v $reverse_out" 116 | done 117 | '$1'=$reverse_out 118 | ' 119 | } 120 | 121 | function util_get_dir_from_filename() { 122 | local var=$1 123 | echo "${var%/*}" 124 | } 125 | 126 | function util_get_script_dir() { 127 | echo "$(cd -P "$(dirname "$0")" && pwd)" 128 | } 129 | 130 | function util_get_input_dir() { 131 | local var=$(util_get_script_dir) 132 | local ret=$(util_get_dir_from_filename "$var") 133 | util_append ret "/input" 134 | echo "$ret" 135 | } 136 | 137 | function util_get_output_dir() { 138 | local var=$(util_get_script_dir) 139 | local ret=$(util_get_dir_from_filename "$var") 140 | util_append ret "/output" 141 | echo "$ret" 142 | } 143 | 144 | function util_is_in() { 145 | local value=$1 146 | shift 147 | for var in $*; do 148 | [ $var = $value ] && return 0 149 | done 150 | return 1 151 | } 152 | 153 | function util_get_list_item() { 154 | local index=$1 # from 1 start 155 | local i=1 156 | shift 157 | for var in $*; do 158 | if [ "$i" = "$index" ]; then 159 | echo "$var" && return 0 160 | fi 161 | ((i++)) 162 | done 163 | return 1 164 | } 165 | 166 | function util_toupper() { 167 | echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 168 | } 169 | 170 | function util_tolower() { 171 | echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 172 | } 173 | 174 | function util_c_escape() { 175 | echo "$*" | sed 's/["\\]/\\\0/g' 176 | } 177 | 178 | function util_sh_quote() { 179 | local v=$(echo "$1" | sed "s/'/'\\\\''/g") 180 | test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'" 181 | echo "$v" 182 | } 183 | 184 | function util_cleanws() { 185 | echo "$@" | sed 's/^ *//;s/[[:space:]][[:space:]]*/ /g;s/ *$//' 186 | } 187 | 188 | function util_remove_substr() { 189 | local substr=$1 190 | shift 191 | local str=$* 192 | echo "$str" | sed "s/$substr//g" 193 | } 194 | 195 | function util_filter() { 196 | local pat=$1 197 | shift 198 | for v; do 199 | eval "case '$v' in $pat) printf '%s ' '$v' ;; esac" 200 | done 201 | } 202 | 203 | function util_filter_out() { 204 | local pat=$1 205 | shift 206 | for v; do 207 | eval "case '$v' in $pat) ;; *) printf '%s ' '$v' ;; esac" 208 | done 209 | } 210 | 211 | function util_create_dir() { 212 | mkdir -p "$1" 213 | } 214 | 215 | function util_remove_dir() { 216 | rm -rf "$1" 217 | } 218 | 219 | function util_download_file() { 220 | local url=$1 221 | local zip=$2 222 | local ret="yes" 223 | if [ ! -r ${zip} ]; then 224 | curl -SL "$url" -o "$zip" || ret="no" 225 | if [ "no" = $ret ]; then 226 | rm -rf "$zip" && util_die "download zip ${zip} fail." 227 | fi 228 | fi 229 | } 230 | 231 | function util_unzip() { 232 | local zip=$1 233 | local dir=$2 234 | local file=$3 235 | if [ -d "${dir}/${file}" ]; then 236 | rm -rf "${dir}/${file}" 237 | fi 238 | local ret="yes" 239 | tar -x -C "$dir" -f "$zip" || ret="no" 240 | if [ "no" = ret ]; then 241 | rm -rf "$zip" && util_die "unzip ${zip} fail." 242 | fi 243 | } 244 | 245 | function util_load_script() { 246 | source $1 || util_die "load script $1 fail." 247 | } 248 | 249 | util_init_log 250 | -------------------------------------------------------------------------------- /script/_common.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/__color_log.sh 26 | 27 | echo "###############################################################################" >/dev/null 28 | echo "# Script Summary: #" >/dev/null 29 | echo "# Author: AsteriskZuo #" >/dev/null 30 | echo "# Update Date: 2020.05.28 #" >/dev/null 31 | echo "# Script version: 1.0.0 #" >/dev/null 32 | echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null 33 | echo "# #" >/dev/null 34 | echo "# Brief introduction: #" >/dev/null 35 | echo "# Build iOS and Android C&&C++ common library. #" >/dev/null 36 | echo "# #" >/dev/null 37 | echo "# Prerequisites: #" >/dev/null 38 | echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null 39 | echo "# #" >/dev/null 40 | echo "# Reference: #" >/dev/null 41 | echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null 42 | echo "###############################################################################" >/dev/null 43 | 44 | echo "###############################################################################" >/dev/null 45 | echo "#### Global Variable Partition #####" >/dev/null 46 | echo "###############################################################################" >/dev/null 47 | 48 | export COMMON_SCRIPT_NAME="$0" 49 | export COMMON_SCRIPT_DIR=$(util_get_script_dir) 50 | export COMMON_INPUT_DIR=$(util_get_input_dir) 51 | export COMMON_OUTPUT_DIR=$(util_get_output_dir) 52 | export COMMON_PLATFORM_TYPE="" 53 | export COMMON_LIBRARY_ID="" 54 | export COMMON_LIBRARY_NAME="" 55 | export COMMON_LIBRARY_VERSION="" 56 | export COMMON_DOWNLOAD_ADRESS="" 57 | 58 | export COMMON_LIBRARY_ID_LIST=" 59 | 1 60 | 2 61 | 3 62 | 4 63 | " 64 | export COMMON_LIBRARY_NAME_LIST=" 65 | openssl 66 | nghttp2 67 | curl 68 | protobuf 69 | " 70 | export COMMON_LIBRARY_VERSION_LIST=" 71 | 1.1.1d 72 | 1.40.0 73 | 7.68.0 74 | 3.11.4 75 | " 76 | export COMMON_LIBRARY_URL_LIST=" 77 | https://www.openssl.org/source/openssl-1.1.1d.tar.gz 78 | https://github.com/nghttp2/nghttp2/releases/download/v1.40.0/nghttp2-1.40.0.tar.gz 79 | https://curl.haxx.se/download/curl-7.68.0.tar.gz 80 | https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protobuf-cpp-3.11.4.tar.gz 81 | " 82 | 83 | util_create_dir "$COMMON_INPUT_DIR" 84 | util_create_dir "$COMMON_OUTPUT_DIR" 85 | 86 | echo "###############################################################################" >/dev/null 87 | echo "#### Function Partition #####" >/dev/null 88 | echo "###############################################################################" >/dev/null 89 | 90 | function common_printf_variable() { 91 | log_var_print "COMMON_SCRIPT_NAME = $COMMON_SCRIPT_NAME" 92 | log_var_print "COMMON_SCRIPT_DIR = $COMMON_SCRIPT_DIR" 93 | log_var_print "COMMON_INPUT_DIR = $COMMON_INPUT_DIR" 94 | log_var_print "COMMON_OUTPUT_DIR = $COMMON_OUTPUT_DIR" 95 | log_var_print "COMMON_PLATFORM_TYPE = $COMMON_PLATFORM_TYPE" 96 | log_var_print "COMMON_LIBRARY_ID = $COMMON_LIBRARY_ID" 97 | log_var_print "COMMON_LIBRARY_NAME = $COMMON_LIBRARY_NAME" 98 | log_var_print "COMMON_LIBRARY_VERSION = $COMMON_LIBRARY_VERSION" 99 | log_var_print "COMMON_DOWNLOAD_ADRESS = $COMMON_DOWNLOAD_ADRESS" 100 | log_var_print "COMMON_LIBRARY_ID_LIST = ${COMMON_LIBRARY_ID_LIST}" 101 | log_var_print "COMMON_LIBRARY_NAME_LIST = ${COMMON_LIBRARY_NAME_LIST}" 102 | log_var_print "COMMON_LIBRARY_VERSION_LIST = ${COMMON_LIBRARY_VERSION_LIST}" 103 | log_var_print "COMMON_LIBRARY_URL_LIST = ${COMMON_LIBRARY_URL_LIST}" 104 | } 105 | 106 | function common_help() { 107 | log_info_print " 108 | 109 | Usage: $0 [options] 110 | Options: [defaults in brackets after descriptions] 111 | 112 | Help options: 113 | --help|-h print this message 114 | --name[=?] Build the library name, which must be one of the options in the \${COMMON_LIBRARY_NAME_LIST} list. 115 | 116 | " 117 | exit 0 118 | } 119 | 120 | function common_get_library_id_from_name() { 121 | local name=$1 122 | case $name in 123 | openssl) 124 | echo "1" 125 | ;; 126 | nghttp2) 127 | echo "2" 128 | ;; 129 | curl) 130 | echo "3" 131 | ;; 132 | protobuf) 133 | echo "4" 134 | ;; 135 | *) 136 | echo "not support" 137 | ;; 138 | esac 139 | } 140 | 141 | function common_get_library_name_from_id() { 142 | echo "$(util_get_list_item $1 $COMMON_LIBRARY_NAME_LIST)" 143 | } 144 | 145 | function common_get_library_version_from_id() { 146 | echo "$(util_get_list_item $1 $COMMON_LIBRARY_VERSION_LIST)" 147 | } 148 | 149 | function common_get_library_url_from_id() { 150 | echo "$(util_get_list_item $1 $COMMON_LIBRARY_URL_LIST)" 151 | } 152 | 153 | function common_die() { 154 | log_error_print "$1" && exit 1 155 | } 156 | 157 | echo "###############################################################################" >/dev/null 158 | echo "#### Flow Function Partition #####" >/dev/null 159 | echo "###############################################################################" >/dev/null 160 | 161 | function common_pre_tool_check() { 162 | local library_id=$1 163 | } 164 | 165 | function common_pre_download_zip() { 166 | local library_id=$1 167 | } 168 | 169 | function common_build_unzip() { 170 | local library_id=$1 171 | } 172 | 173 | function common_build_config_make() { 174 | local library_id=$1 175 | local arch=$2 176 | } 177 | 178 | function common_archive() { 179 | local library_name=$1 180 | } 181 | 182 | function common_build_make() { 183 | local library_arch_path=$1 184 | shift 185 | for make_param in $*; do 186 | echo "[info][make_${make_param}_start]" >>"${library_arch_path}/log/output.log" 187 | make $make_param >>"${library_arch_path}/log/output.log" 2>&1 || common_die "make $make_param error!" 188 | done 189 | } 190 | -------------------------------------------------------------------------------- /script/android-common.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/_common.sh 26 | 27 | echo "###############################################################################" >/dev/null 28 | echo "# Script Summary: #" >/dev/null 29 | echo "# Author: AsteriskZuo #" >/dev/null 30 | echo "# Update Date: 2020.05.28 #" >/dev/null 31 | echo "# Script version: 1.0.0 #" >/dev/null 32 | echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null 33 | echo "# #" >/dev/null 34 | echo "# Brief introduction: #" >/dev/null 35 | echo "# Build iOS and Android C&&C++ common library. #" >/dev/null 36 | echo "# #" >/dev/null 37 | echo "# Prerequisites: #" >/dev/null 38 | echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null 39 | echo "# #" >/dev/null 40 | echo "# Reference: #" >/dev/null 41 | echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null 42 | echo "###############################################################################" >/dev/null 43 | 44 | echo "###############################################################################" >/dev/null 45 | echo "#### Global Variable Partition #####" >/dev/null 46 | echo "###############################################################################" >/dev/null 47 | 48 | export COMMON_PLATFORM_TYPE="android" 49 | export ANDROID_ARCHS=("armeabi-v7a" "arm64-v8a" "x86" "x86-64") 50 | export ANDROID_TRIPLES=("arm-linux-androideabi" "aarch64-linux-android" "i686-linux-android" "x86_64-linux-android") 51 | export ANDROID_API=23 52 | 53 | # for test 54 | # ANDROID_ARCHS=("armeabi-v7a") 55 | # ANDROID_TRIPLES=("arm-linux-androideabi") 56 | # ANDROID_API=23 57 | 58 | echo "###############################################################################" >/dev/null 59 | echo "#### Function Partition #####" >/dev/null 60 | echo "###############################################################################" >/dev/null 61 | 62 | function android_get_toolchain() { 63 | HOST_OS=$(uname -s) 64 | case ${HOST_OS} in 65 | Darwin) HOST_OS=darwin ;; 66 | Linux) HOST_OS=linux ;; 67 | FreeBsd) HOST_OS=freebsd ;; 68 | CYGWIN* | *_NT-*) HOST_OS=cygwin ;; 69 | esac 70 | 71 | HOST_ARCH=$(uname -m) 72 | case ${HOST_ARCH} in 73 | i?86) HOST_ARCH=x86 ;; 74 | x86_64 | amd64) HOST_ARCH=x86_64 ;; 75 | esac 76 | 77 | echo "${HOST_OS}-${HOST_ARCH}" 78 | } 79 | 80 | function android_get_build_host() { 81 | local arch=$1 82 | case ${arch} in 83 | armeabi-v7a) 84 | echo "arm-linux-androideabi" 85 | ;; 86 | arm64-v8a) 87 | echo "aarch64-linux-android" 88 | ;; 89 | x86) 90 | echo "i686-linux-android" 91 | ;; 92 | x86-64) 93 | echo "x86_64-linux-android" 94 | ;; 95 | esac 96 | } 97 | 98 | function android_get_clang_target_host() { 99 | local arch=$1 100 | local api=$2 101 | case ${arch} in 102 | armeabi-v7a) 103 | echo "armv7a-linux-androideabi${api}" 104 | ;; 105 | arm64-v8a) 106 | echo "aarch64-linux-android${api}" 107 | ;; 108 | x86) 109 | echo "i686-linux-android${api}" 110 | ;; 111 | x86-64) 112 | echo "x86_64-linux-android${api}" 113 | ;; 114 | esac 115 | } 116 | 117 | function android_set_toolchain_bin() { 118 | export PATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/$(android_get_toolchain)/bin:$PATH 119 | echo PATH=$PATH 120 | } 121 | 122 | function android_set_toolchain() { 123 | local name=$1 124 | local arch=$2 125 | local api=$3 126 | local build_host=$(android_get_build_host "$arch") 127 | local clang_target_host=$(android_get_clang_target_host "$arch" "$api") 128 | 129 | export AR=${build_host}-ar 130 | export CC=${clang_target_host}-clang 131 | export CXX=${clang_target_host}-clang++ 132 | export AS=${build_host}-as 133 | export LD=${build_host}-ld 134 | export RANLIB=${build_host}-ranlib 135 | export STRIP=${build_host}-strip 136 | } 137 | 138 | function android_get_common_includes() { 139 | local toolchain=$(android_get_toolchain) 140 | echo "-I${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${toolchain}/sysroot/usr/include -I${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${toolchain}/sysroot/usr/local/include" 141 | } 142 | function android_get_common_linked_libraries() { 143 | local api=$1 144 | local arch=$2 145 | local toolchain=$(android_get_toolchain) 146 | local build_host=$(android_get_build_host "$arch") 147 | echo "-L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${toolchain}/${build_host}/lib -L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${toolchain}/sysroot/usr/lib/${build_host}/${api} -L${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${toolchain}/lib" 148 | } 149 | 150 | function android_set_cpu_feature() { 151 | local name=$1 152 | local arch=$2 153 | local api=$3 154 | case ${arch} in 155 | armeabi-v7a) 156 | export CFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wno-unused-function -fno-integrated-as -fstrict-aliasing -fPIC -DANDROID -D__ANDROID_API__=${api} -Os -ffunction-sections -fdata-sections $(android_get_common_includes)" 157 | export CXXFLAGS="-std=c++14 -Os -ffunction-sections -fdata-sections" 158 | export LDFLAGS="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -Wl,--fix-cortex-a8 -Wl,--gc-sections -Os -ffunction-sections -fdata-sections $(android_get_common_linked_libraries ${api} ${arch})" 159 | export CPPFLAGS=${CFLAGS} 160 | ;; 161 | arm64-v8a) 162 | export CFLAGS="-march=armv8-a -Wno-unused-function -fno-integrated-as -fstrict-aliasing -fPIC -DANDROID -D__ANDROID_API__=${api} -Os -ffunction-sections -fdata-sections $(android_get_common_includes)" 163 | export CXXFLAGS="-std=c++14 -Os -ffunction-sections -fdata-sections" 164 | export LDFLAGS="-march=armv8-a -Wl,--gc-sections -Os -ffunction-sections -fdata-sections $(android_get_common_linked_libraries ${api} ${arch})" 165 | export CPPFLAGS=${CFLAGS} 166 | ;; 167 | x86) 168 | export CFLAGS="-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32 -Wno-unused-function -fno-integrated-as -fstrict-aliasing -fPIC -DANDROID -D__ANDROID_API__=${api} -Os -ffunction-sections -fdata-sections $(android_get_common_includes)" 169 | export CXXFLAGS="-std=c++14 -Os -ffunction-sections -fdata-sections" 170 | export LDFLAGS="-march=i686 -Wl,--gc-sections -Os -ffunction-sections -fdata-sections $(android_get_common_linked_libraries ${api} ${arch})" 171 | export CPPFLAGS=${CFLAGS} 172 | ;; 173 | x86-64) 174 | export CFLAGS="-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fno-integrated-as -fstrict-aliasing -fPIC -DANDROID -D__ANDROID_API__=${api} -Os -ffunction-sections -fdata-sections $(android_get_common_includes)" 175 | export CXXFLAGS="-std=c++14 -Os -ffunction-sections -fdata-sections" 176 | export LDFLAGS="-march=x86-64 -Wl,--gc-sections -Os -ffunction-sections -fdata-sections $(android_get_common_linked_libraries ${api} ${arch})" 177 | export CPPFLAGS=${CFLAGS} 178 | ;; 179 | *) 180 | common_die "not support $arch" 181 | ;; 182 | esac 183 | } 184 | 185 | function android_printf_variable() { 186 | log_var_print "ANDROID_ARCHS = ${ANDROID_ARCHS[@]}" 187 | log_var_print "ANDROID_TRIPLES = ${ANDROID_TRIPLES[@]}" 188 | log_var_print "ANDROID_API = $ANDROID_API" 189 | } 190 | 191 | function android_printf_arch_variable() { 192 | log_var_print "AR = $AR" 193 | log_var_print "CC = $CC" 194 | log_var_print "CXX = $CXX" 195 | log_var_print "AS = $AS" 196 | log_var_print "LD = $LD" 197 | log_var_print "RANLIB = $RANLIB" 198 | log_var_print "STRIP = $STRIP" 199 | log_var_print "CFLAGS = $CFLAGS" 200 | log_var_print "CXXFLAGS = $CXXFLAGS" 201 | log_var_print "LDFLAGS = $LDFLAGS" 202 | log_var_print "CPPFLAGS = $CPPFLAGS" 203 | } 204 | 205 | function android_help() { 206 | common_help 207 | } 208 | 209 | function android_get_shell_script_path() { 210 | echo "${COMMON_SCRIPT_DIR}/$(util_tolower $COMMON_PLATFORM_TYPE)-${COMMON_LIBRARY_NAME}.sh" 211 | } 212 | 213 | echo "###############################################################################" >/dev/null 214 | echo "#### Flow Function Partition #####" >/dev/null 215 | echo "###############################################################################" >/dev/null 216 | 217 | function android_pre_tool_check() { 218 | log_info_print "android_pre_tool_check $1 start..." 219 | local library_id=$1 220 | local pre_tool_check="android_${COMMON_LIBRARY_NAME}_pre_tool_check" 221 | common_pre_tool_check "$library_id" 222 | eval ${pre_tool_check} "$library_id" 223 | log_info_print "android_pre_tool_check $1 end..." 224 | } 225 | 226 | function android_pre_download_zip() { 227 | log_info_print "android_pre_download_zip $1 start..." 228 | local library_id=$1 229 | local pre_download_zip="android_${COMMON_LIBRARY_NAME}_pre_download_zip" 230 | common_pre_download_zip "$library_id" 231 | eval ${pre_download_zip} "$library_id" 232 | log_info_print "android_pre_download_zip $1 end..." 233 | } 234 | 235 | function android_build_unzip() { 236 | log_info_print "android_build_unzip $1 $2 start..." 237 | local library_id=$1 238 | local library_arch=$2 239 | local build_unzip="android_${COMMON_LIBRARY_NAME}_build_unzip" 240 | common_build_unzip "$library_id" 241 | eval ${build_unzip} "$library_id" 242 | log_info_print "android_build_unzip $1 $2 end..." 243 | } 244 | 245 | function android_build_config_make() { 246 | log_info_print "android_build_config_make $1 $2 start..." 247 | local library_id=$1 248 | local library_arch=$2 249 | local build_config_make="android_${COMMON_LIBRARY_NAME}_build_config_make" 250 | common_build_config_make "$library_id" "$library_arch" 251 | android_set_toolchain "${COMMON_LIBRARY_NAME}" "${library_arch}" "${ANDROID_API}" 252 | android_set_cpu_feature "${COMMON_LIBRARY_NAME}" "${library_arch}" "${ANDROID_API}" 253 | eval ${build_config_make} "$library_id" "$library_arch" 254 | log_info_print "android_build_config_make $1 $2 end..." 255 | } 256 | 257 | function android_archive() { 258 | log_info_print "android_archive $1 start..." 259 | local library_id=$1 260 | local archive="android_${COMMON_LIBRARY_NAME}_archive" 261 | common_archive "$library_id" 262 | eval ${archive} "$library_id" 263 | log_info_print "android_archive $1 end..." 264 | } 265 | -------------------------------------------------------------------------------- /script/android-curl.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 android curl 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 | curl_zip_file="" 45 | curl_zip_file_no_suffix="" 46 | curl_zip_file_path="" 47 | curl_zip_file_no_suffix_path="" 48 | curl_input_dir="" 49 | curl_output_dir="" 50 | openssl_output_dir="" 51 | nghttp2_output_dir="" 52 | 53 | function android_curl_printf_variable() { 54 | log_var_print "curl_input_dir = $curl_input_dir" 55 | log_var_print "curl_output_dir = $curl_output_dir" 56 | log_var_print "curl_zip_file = $curl_zip_file" 57 | log_var_print "curl_zip_file_no_suffix = $curl_zip_file_no_suffix" 58 | log_var_print "curl_zip_file_path = $curl_zip_file_path" 59 | log_var_print "curl_zip_file_no_suffix_path = $curl_zip_file_no_suffix_path" 60 | log_var_print "openssl_output_dir = $openssl_output_dir" 61 | log_var_print "nghttp2_output_dir = $nghttp2_output_dir" 62 | } 63 | 64 | function android_curl_pre_tool_check() { 65 | 66 | openssl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/$(common_get_library_name_from_id 1)" 67 | if [ ! -d "${openssl_output_dir}" ]; then 68 | common_die "Please build the openssl library first!" 69 | fi 70 | nghttp2_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/$(common_get_library_name_from_id 2)" 71 | if [ ! -d "${nghttp2_output_dir}" ]; then 72 | common_die "Please build the nghttp2 library first!" 73 | fi 74 | 75 | curl_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 76 | curl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 77 | 78 | curl_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 79 | curl_zip_file_no_suffix=${curl_zip_file%.tar.gz} 80 | curl_zip_file_path="${curl_input_dir}/${curl_zip_file}" 81 | curl_zip_file_no_suffix_path="${curl_input_dir}/${curl_zip_file_no_suffix}" 82 | 83 | util_create_dir "${curl_input_dir}" 84 | util_create_dir "${curl_output_dir}" 85 | 86 | android_curl_printf_variable 87 | 88 | } 89 | 90 | function android_curl_pre_download_zip() { 91 | local library_id=$1 92 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$curl_zip_file_path" 93 | } 94 | 95 | function android_curl_build_unzip() { 96 | local library_id=$1 97 | util_unzip "$curl_zip_file_path" "${curl_input_dir}" "$curl_zip_file_no_suffix" 98 | } 99 | 100 | function android_curl_build_config_make() { 101 | local library_id=$1 102 | local library_arch=$2 103 | 104 | local library_arch_path="${curl_output_dir}/${library_arch}" 105 | util_remove_dir "$library_arch_path" 106 | util_create_dir "${library_arch_path}/log" 107 | 108 | openssl_output_arch_lib_dir="${openssl_output_dir}/${library_arch}/lib" 109 | if [ ! -d "${openssl_output_arch_lib_dir}" ]; then 110 | common_die "Please build the openssl ${library_arch} library first!" 111 | fi 112 | nghttp2_output_arch_lib_dir="${nghttp2_output_dir}/${library_arch}/lib" 113 | if [ ! -d "${nghttp2_output_arch_lib_dir}" ]; then 114 | common_die "Please build the nghttp2 ${library_arch} library first!" 115 | fi 116 | 117 | export LDFLAGS="${LDFLAGS} -L${openssl_output_arch_lib_dir} -L${nghttp2_output_arch_lib_dir}" 118 | 119 | android_printf_arch_variable 120 | 121 | pushd . 122 | cd "$curl_zip_file_no_suffix_path" 123 | 124 | if [[ "${library_arch}" == "x86-64" ]]; then 125 | 126 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 127 | 128 | elif [[ "${library_arch}" == "x86" ]]; then 129 | 130 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 131 | 132 | elif [[ "${library_arch}" == "armeabi-v7a" ]]; then 133 | 134 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 135 | 136 | elif [[ "${library_arch}" == "arm64-v8a" ]]; then 137 | 138 | # --enable-shared need nghttp2 cpp compile 139 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 140 | 141 | else 142 | common_die "not support $library_arch" 143 | fi 144 | 145 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 146 | 147 | popd 148 | } 149 | 150 | function android_curl_archive() { 151 | local library_name=$1 152 | } 153 | -------------------------------------------------------------------------------- /script/android-nghttp2.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 android nghttp2 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 | nghttp2_zip_file="" 45 | nghttp2_zip_file_no_suffix="" 46 | nghttp2_zip_file_path="" 47 | nghttp2_zip_file_no_suffix_path="" 48 | nghttp2_input_dir="" 49 | nghttp2_output_dir="" 50 | 51 | function android_nghttp2_printf_variable() { 52 | log_var_print "nghttp2_input_dir = $nghttp2_input_dir" 53 | log_var_print "nghttp2_output_dir = $nghttp2_output_dir" 54 | log_var_print "nghttp2_zip_file = $nghttp2_zip_file" 55 | log_var_print "nghttp2_zip_file_no_suffix = $nghttp2_zip_file_no_suffix" 56 | log_var_print "nghttp2_zip_file_path = $nghttp2_zip_file_path" 57 | log_var_print "nghttp2_zip_file_no_suffix_path = $nghttp2_zip_file_no_suffix_path" 58 | } 59 | 60 | function android_nghttp2_pre_tool_check() { 61 | 62 | nghttp2_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 63 | nghttp2_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 64 | 65 | nghttp2_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 66 | nghttp2_zip_file_no_suffix=${nghttp2_zip_file%.tar.gz} 67 | nghttp2_zip_file_path="${nghttp2_input_dir}/${nghttp2_zip_file}" 68 | nghttp2_zip_file_no_suffix_path="${nghttp2_input_dir}/${nghttp2_zip_file_no_suffix}" 69 | 70 | util_create_dir "${nghttp2_input_dir}" 71 | util_create_dir "${nghttp2_output_dir}" 72 | 73 | android_nghttp2_printf_variable 74 | 75 | } 76 | 77 | function android_nghttp2_pre_download_zip() { 78 | local library_id=$1 79 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$nghttp2_zip_file_path" 80 | } 81 | 82 | function android_nghttp2_build_unzip() { 83 | local library_id=$1 84 | util_unzip "$nghttp2_zip_file_path" "${nghttp2_input_dir}" "$nghttp2_zip_file_no_suffix" 85 | } 86 | 87 | function android_nghttp2_build_config_make() { 88 | local library_id=$1 89 | local library_arch=$2 90 | 91 | local library_arch_path="${nghttp2_output_dir}/${library_arch}" 92 | util_remove_dir "$library_arch_path" 93 | util_create_dir "${library_arch_path}/log" 94 | 95 | android_printf_arch_variable 96 | 97 | pushd . 98 | cd "$nghttp2_zip_file_no_suffix_path" 99 | 100 | if [[ "${library_arch}" == "x86-64" ]]; then 101 | 102 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 103 | 104 | elif [[ "${library_arch}" == "x86" ]]; then 105 | 106 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 107 | 108 | elif [[ "${library_arch}" == "armeabi-v7a" ]]; then 109 | 110 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 111 | 112 | elif [[ "${library_arch}" == "arm64-v8a" ]]; then 113 | 114 | # --disable-lib-only need xml2 supc++ stdc++14 115 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 116 | 117 | else 118 | common_die "not support $library_arch" 119 | fi 120 | 121 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 122 | 123 | popd 124 | } 125 | 126 | function android_nghttp2_archive() { 127 | local library_name=$1 128 | } 129 | -------------------------------------------------------------------------------- /script/android-openssl.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 android openssl 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 | openssl_zip_file="" 45 | openssl_zip_file_no_suffix="" 46 | openssl_zip_file_path="" 47 | openssl_zip_file_no_suffix_path="" 48 | openssl_input_dir="" 49 | openssl_output_dir="" 50 | 51 | function android_openssl_printf_variable() { 52 | log_var_print "openssl_input_dir = $openssl_input_dir" 53 | log_var_print "openssl_output_dir = $openssl_output_dir" 54 | log_var_print "openssl_zip_file = $openssl_zip_file" 55 | log_var_print "openssl_zip_file_no_suffix = $openssl_zip_file_no_suffix" 56 | log_var_print "openssl_zip_file_path = $openssl_zip_file_path" 57 | log_var_print "openssl_zip_file_no_suffix_path = $openssl_zip_file_no_suffix_path" 58 | } 59 | 60 | function android_openssl_pre_tool_check() { 61 | 62 | export ANDROID_NDK_HOME=${ANDROID_NDK_ROOT} 63 | 64 | openssl_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 65 | openssl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 66 | 67 | openssl_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 68 | openssl_zip_file_no_suffix=${openssl_zip_file%.tar.gz} 69 | openssl_zip_file_path="${openssl_input_dir}/${openssl_zip_file}" 70 | openssl_zip_file_no_suffix_path="${openssl_input_dir}/${openssl_zip_file_no_suffix}" 71 | 72 | util_create_dir "${openssl_input_dir}" 73 | util_create_dir "${openssl_output_dir}" 74 | 75 | android_openssl_printf_variable 76 | 77 | } 78 | 79 | function android_openssl_pre_download_zip() { 80 | local library_id=$1 81 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$openssl_zip_file_path" 82 | } 83 | 84 | function android_openssl_build_unzip() { 85 | local library_id=$1 86 | util_unzip "$openssl_zip_file_path" "${openssl_input_dir}" "$openssl_zip_file_no_suffix" 87 | } 88 | 89 | function android_openssl_build_config_make() { 90 | local library_id=$1 91 | local library_arch=$2 92 | 93 | local library_arch_path="${openssl_output_dir}/${library_arch}" 94 | util_remove_dir "$library_arch_path" 95 | util_create_dir "${library_arch_path}/log" 96 | 97 | android_printf_arch_variable 98 | 99 | pushd . 100 | cd "$openssl_zip_file_no_suffix_path" 101 | 102 | if [[ "${library_arch}" == "x86-64" ]]; then 103 | 104 | ./Configure android-x86_64 --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 105 | 106 | elif [[ "${library_arch}" == "x86" ]]; then 107 | 108 | ./Configure android-x86 --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 109 | 110 | elif [[ "${library_arch}" == "armeabi-v7a" ]]; then 111 | 112 | ./Configure android-arm --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 113 | 114 | elif [[ "${library_arch}" == "arm64-v8a" ]]; then 115 | 116 | ./Configure android-arm64 --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 117 | 118 | else 119 | common_die "not support $library_arch" 120 | fi 121 | 122 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install_sw" "install_ssldirs" 123 | 124 | popd 125 | } 126 | 127 | function android_openssl_archive() { 128 | local library_name=$1 129 | } 130 | -------------------------------------------------------------------------------- /script/android-protobuf.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 android 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 | 51 | function android_protobuf_printf_variable() { 52 | log_var_print "protobuf_input_dir = $protobuf_input_dir" 53 | log_var_print "protobuf_output_dir = $protobuf_output_dir" 54 | log_var_print "protobuf_zip_file = $protobuf_zip_file" 55 | log_var_print "protobuf_zip_file_no_suffix = $protobuf_zip_file_no_suffix" 56 | log_var_print "protobuf_zip_file_path = $protobuf_zip_file_path" 57 | log_var_print "protobuf_zip_file_no_suffix_path = $protobuf_zip_file_no_suffix_path" 58 | } 59 | 60 | function android_protobuf_pre_tool_check() { 61 | 62 | local protobuf_version=$(protoc --version) 63 | 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)" 64 | 65 | protobuf_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 66 | protobuf_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 67 | 68 | protobuf_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 69 | protobuf_zip_file_no_suffix=$(util_remove_substr "cpp-" ${protobuf_zip_file%.tar.gz}) 70 | protobuf_zip_file_path="${protobuf_input_dir}/${protobuf_zip_file}" 71 | protobuf_zip_file_no_suffix_path="${protobuf_input_dir}/${protobuf_zip_file_no_suffix}" 72 | 73 | util_create_dir "${protobuf_input_dir}" 74 | util_create_dir "${protobuf_output_dir}" 75 | 76 | android_protobuf_printf_variable 77 | 78 | } 79 | 80 | function android_protobuf_pre_download_zip() { 81 | local library_id=$1 82 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$protobuf_zip_file_path" 83 | } 84 | 85 | function android_protobuf_build_unzip() { 86 | local library_id=$1 87 | util_unzip "$protobuf_zip_file_path" "${protobuf_input_dir}" "$protobuf_zip_file_no_suffix" 88 | } 89 | 90 | function android_protobuf_build_config_make() { 91 | local library_id=$1 92 | local library_arch=$2 93 | 94 | local library_arch_path="${protobuf_output_dir}/${library_arch}" 95 | util_remove_dir "$library_arch_path" 96 | util_create_dir "${library_arch_path}/log" 97 | 98 | export LDFLAGS="$LDFLAGS -Wunused-command-line-argument -llog" 99 | 100 | android_printf_arch_variable 101 | 102 | pushd . 103 | cd "$protobuf_zip_file_no_suffix_path" 104 | 105 | # git submodule update --init --recursive 106 | if [[ "${library_arch}" == "x86-64" ]]; then 107 | 108 | # scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto , so use --disable-shared 109 | ./configure --host=$(android_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}" == "x86" ]]; then 112 | 113 | # scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto , so use --disable-shared 114 | ./configure --host=$(android_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!" 115 | 116 | elif [[ "${library_arch}" == "armeabi-v7a" ]]; then 117 | 118 | # scc_info_FileDescriptorProto_google_2fprotobuf_2fdescriptor_2eproto , so use --disable-shared 119 | ./configure --host=$(android_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!" 120 | 121 | elif [[ "${library_arch}" == "arm64-v8a" ]]; then 122 | 123 | ./configure --host=$(android_get_build_host "${library_arch}") --prefix="${library_arch_path}" --with-protoc=protobuf_command >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 124 | 125 | else 126 | common_die "not support $library_arch" 127 | fi 128 | 129 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 130 | 131 | popd 132 | } 133 | 134 | function android_protobuf_archive() { 135 | local library_name=$1 136 | } 137 | -------------------------------------------------------------------------------- /script/android.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/android-common.sh 26 | 27 | log_head_print "###############################################################################" 28 | log_head_print "# Script Summary: #" 29 | log_head_print "# Author: AsteriskZuo #" 30 | log_head_print "# Update Date: 2020.05.28 #" 31 | log_head_print "# Script version: 1.0.0 #" 32 | log_head_print "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" 33 | log_head_print "# #" 34 | log_head_print "# Brief introduction: #" 35 | log_head_print "# Build iOS and Android C&&C++ common library. #" 36 | log_head_print "# #" 37 | log_head_print "# Prerequisites: #" 38 | log_head_print "# GNU bash (version 3.2.57 test success on macOS) #" 39 | log_head_print "# #" 40 | log_head_print "# Reference: #" 41 | log_head_print "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" 42 | log_head_print "###############################################################################" 43 | 44 | set -u 45 | # util_debug 46 | 47 | opt_count=$# 48 | opt=$* 49 | 50 | if [ "Darwin" != $(uname -s) ]; then 51 | common_die "This is not MacOS." 52 | fi 53 | 54 | if [ ! $opt ]; then 55 | android_help 56 | fi 57 | 58 | for opt; do 59 | optval="${opt#*=}" 60 | case "$opt" in 61 | --help | -h) 62 | android_help 63 | ;; 64 | --name=*) 65 | if util_is_in $optval $COMMON_LIBRARY_NAME_LIST; then 66 | export COMMON_LIBRARY_NAME=($optval) 67 | export COMMON_LIBRARY_ID="$(common_get_library_id_from_name "$COMMON_LIBRARY_NAME")" 68 | export COMMON_LIBRARY_VERSION=$(common_get_library_version_from_id $COMMON_LIBRARY_ID) 69 | export COMMON_DOWNLOAD_ADRESS=$(common_get_library_url_from_id $COMMON_LIBRARY_ID) 70 | else 71 | common_die "${optval} is not in list. please refer \${COMMON_LIBRARY_NAME_LIST}" 72 | fi 73 | ;; 74 | *) 75 | android_help 76 | ;; 77 | esac 78 | done 79 | 80 | common_printf_variable 81 | android_printf_variable 82 | 83 | util_load_script "$(android_get_shell_script_path ${COMMON_LIBRARY_ID})" 84 | 85 | log_warning_print "build ${COMMON_LIBRARY_ID} ${COMMON_LIBRARY_NAME} ${COMMON_LIBRARY_VERSION} start..." 86 | 87 | android_set_toolchain_bin 88 | android_pre_tool_check "${COMMON_LIBRARY_ID}" 89 | android_pre_download_zip "${COMMON_LIBRARY_ID}" 90 | for ((i = 0; i < ${#ANDROID_ARCHS[@]}; i++)); do 91 | android_build_unzip "${COMMON_LIBRARY_ID}" "${ANDROID_ARCHS[i]}" 92 | android_build_config_make "${COMMON_LIBRARY_ID}" "${ANDROID_ARCHS[i]}" 93 | done 94 | android_archive "${COMMON_LIBRARY_ID}" 95 | 96 | log_warning_print "build ${COMMON_LIBRARY_ID} ${COMMON_LIBRARY_NAME} ${COMMON_LIBRARY_VERSION} end..." 97 | -------------------------------------------------------------------------------- /script/ios-common.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/_common.sh 26 | 27 | echo "###############################################################################" >/dev/null 28 | echo "# Script Summary: #" >/dev/null 29 | echo "# Author: AsteriskZuo #" >/dev/null 30 | echo "# Update Date: 2020.05.28 #" >/dev/null 31 | echo "# Script version: 1.0.0 #" >/dev/null 32 | echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null 33 | echo "# #" >/dev/null 34 | echo "# Brief introduction: #" >/dev/null 35 | echo "# Build iOS and Android C&&C++ common library. #" >/dev/null 36 | echo "# #" >/dev/null 37 | echo "# Prerequisites: #" >/dev/null 38 | echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null 39 | echo "# #" >/dev/null 40 | echo "# Reference: #" >/dev/null 41 | echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null 42 | echo "###############################################################################" >/dev/null 43 | 44 | echo "###############################################################################" >/dev/null 45 | echo "#### Global Variable Partition #####" >/dev/null 46 | echo "###############################################################################" >/dev/null 47 | 48 | export COMMON_PLATFORM_TYPE="ios" 49 | export IOS_ARCHS=("armv7" "arm64" "arm64e" "x86-64") 50 | export IOS_TRIPLES=("armv7-ios-darwin" "aarch64-ios-darwin" "aarch64-ios-darwin" "x86_64-ios-darwin") 51 | export IOS_API=8.0 52 | export IOS_SYSROOT="" 53 | 54 | # for test 55 | # IOS_ARCHS=("arm64") 56 | # IOS_TRIPLES=("aarch64-ios-darwin") 57 | # IOS_API=8.0 58 | 59 | echo "###############################################################################" >/dev/null 60 | echo "#### Function Partition #####" >/dev/null 61 | echo "###############################################################################" >/dev/null 62 | 63 | function ios_get_sdk_name() { 64 | local arch=$1 65 | case ${arch} in 66 | armv7 | armv7s | arm64 | arm64e) 67 | echo "iphoneos" 68 | ;; 69 | x86 | x86-64) 70 | echo "iphonesimulator" 71 | ;; 72 | esac 73 | } 74 | 75 | function ios_get_sdk_path() { 76 | local arch=$1 77 | echo "$(xcrun --sdk $(ios_get_sdk_name $arch) --show-sdk-path)" 78 | } 79 | 80 | function ios_set_sysroot() { 81 | local arch=$1 82 | IOS_SYSROOT="$(ios_get_sdk_path $arch)" 83 | } 84 | 85 | function ios_get_build_host() { 86 | local arch=$1 87 | case ${arch} in 88 | armv7) 89 | echo "armv7-ios-darwin" 90 | ;; 91 | arm64) 92 | echo "aarch64-ios-darwin" 93 | ;; 94 | arm64e) 95 | echo "aarch64-ios-darwin" 96 | ;; 97 | x86) 98 | echo "x86-ios-darwin" 99 | ;; 100 | x86-64) 101 | echo "x86_64-ios-darwin" 102 | ;; 103 | esac 104 | } 105 | 106 | function ios_set_cpu_feature() { 107 | local name=$1 108 | local arch=$2 109 | local api=$3 110 | local sysroot=$4 111 | case ${arch} in 112 | armv7) 113 | export CC="xcrun -sdk iphoneos clang -arch armv7" 114 | export CXX="xcrun -sdk iphoneos clang++ -arch armv7" 115 | export CFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -fembed-bitcode -miphoneos-version-min=${api} -isysroot ${sysroot} -I${sysroot}/usr/include" 116 | export LDFLAGS="-arch armv7 -target armv7-ios-darwin -march=armv7 -fembed-bitcode -isysroot ${sysroot} -L${sysroot}/usr/lib " 117 | export CXXFLAGS="-std=c++14 -arch armv7 -target armv7-ios-darwin -march=armv7 -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${api} -I${sysroot}/usr/include" 118 | ;; 119 | arm64) 120 | export CC="xcrun -sdk iphoneos clang -arch arm64" 121 | export CXX="xcrun -sdk iphoneos clang++ -arch arm64" 122 | export CFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -Wno-unused-function -fstrict-aliasing -Oz -Wno-ignored-optimization-argument -DIOS -fembed-bitcode -miphoneos-version-min=${api} -isysroot ${sysroot} -I${sysroot}/usr/include" 123 | export LDFLAGS="-arch arm64 -target aarch64-ios-darwin -march=armv8 -fembed-bitcode -isysroot ${sysroot} -L${sysroot}/usr/lib " 124 | export CXXFLAGS="-std=c++14 -arch arm64 -target aarch64-ios-darwin -march=armv8 -mcpu=generic -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${api} -I${sysroot}/usr/include" 125 | ;; 126 | arm64e) 127 | # -march=armv8.3 ??? 128 | export CC="xcrun -sdk iphoneos clang -arch arm64e" 129 | export CXX="xcrun -sdk iphoneos clang++ -arch arm64e" 130 | export CFLAGS="-arch arm64e -target aarch64-ios-darwin -Wno-unused-function -fstrict-aliasing -DIOS -fembed-bitcode -miphoneos-version-min=${api} -isysroot ${sysroot} -I${sysroot}/usr/include" 131 | export LDFLAGS="-arch arm64e -target aarch64-ios-darwin -fembed-bitcode -isysroot ${sysroot} -L${sysroot}/usr/lib " 132 | export CXXFLAGS="-std=c++14 -arch arm64e -target aarch64-ios-darwin -fstrict-aliasing -fembed-bitcode -DIOS -miphoneos-version-min=${api} -I${sysroot}/usr/include" 133 | ;; 134 | x86) 135 | export CC="xcrun -sdk iphonesimulator clang -arch x86" 136 | export CXX="xcrun -sdk iphonesimulator clang++ -arch x86" 137 | export CFLAGS="-arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -DIOS -mios-simulator-version-min=${api} -isysroot ${sysroot} -I${sysroot}/usr/include" 138 | export LDFLAGS="-arch x86 -target x86-ios-darwin -march=i386 -isysroot ${sysroot} -L${sysroot}/usr/lib " 139 | export CXXFLAGS="-std=c++14 -arch x86 -target x86-ios-darwin -march=i386 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -DIOS -mios-simulator-version-min=${api} -I${sysroot}/usr/include" 140 | ;; 141 | x86-64) 142 | export CC="xcrun -sdk iphonesimulator clang -arch x86_64" 143 | export CXX="xcrun -sdk iphonesimulator clang++ -arch x86_64" 144 | export CFLAGS="-arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -Wno-unused-function -fstrict-aliasing -O2 -Wno-ignored-optimization-argument -DIOS -mios-simulator-version-min=${api} -isysroot ${sysroot} -I${sysroot}/usr/include" 145 | export LDFLAGS="-arch x86_64 -target x86_64-ios-darwin -march=x86-64 -isysroot ${sysroot} -L${sysroot}/usr/lib " 146 | export CXXFLAGS="-std=c++14 -arch x86_64 -target x86_64-ios-darwin -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel -fstrict-aliasing -DIOS -mios-simulator-version-min=${api} -I${sysroot}/usr/include" 147 | ;; 148 | *) 149 | common_die "not support $arch" 150 | ;; 151 | esac 152 | } 153 | 154 | function ios_printf_variable() { 155 | log_var_print "IOS_ARCHS = ${IOS_ARCHS[@]}" 156 | log_var_print "IOS_TRIPLES = ${IOS_TRIPLES[@]}" 157 | log_var_print "IOS_API = $IOS_API" 158 | } 159 | 160 | function ios_printf_arch_variable() { 161 | log_var_print "IOS_SYSROOT = $IOS_SYSROOT" 162 | log_var_print "CC = $CC" 163 | log_var_print "CXX = $CXX" 164 | log_var_print "CFLAGS = $CFLAGS" 165 | log_var_print "CXXFLAGS = $CXXFLAGS" 166 | log_var_print "LDFLAGS = $LDFLAGS" 167 | } 168 | 169 | function ios_help() { 170 | common_help 171 | } 172 | 173 | function ios_get_shell_script_path() { 174 | echo "${COMMON_SCRIPT_DIR}/$(util_tolower $COMMON_PLATFORM_TYPE)-${COMMON_LIBRARY_NAME}.sh" 175 | } 176 | 177 | echo "###############################################################################" >/dev/null 178 | echo "#### Flow Function Partition #####" >/dev/null 179 | echo "###############################################################################" >/dev/null 180 | 181 | function ios_pre_tool_check() { 182 | log_info_print "ios_pre_tool_check $1 start..." 183 | local library_id=$1 184 | local pre_tool_check="ios_${COMMON_LIBRARY_NAME}_pre_tool_check" 185 | common_pre_tool_check "$library_id" 186 | eval ${pre_tool_check} "$library_id" 187 | log_info_print "ios_pre_tool_check $1 end..." 188 | } 189 | 190 | function ios_pre_download_zip() { 191 | log_info_print "ios_pre_download_zip $1 start..." 192 | local library_id=$1 193 | local pre_download_zip="ios_${COMMON_LIBRARY_NAME}_pre_download_zip" 194 | common_pre_download_zip "$library_id" 195 | eval ${pre_download_zip} "$library_id" 196 | log_info_print "ios_pre_download_zip $1 end..." 197 | } 198 | 199 | function ios_build_unzip() { 200 | log_info_print "ios_build_unzip $1 $2 start..." 201 | local library_id=$1 202 | local library_arch=$2 203 | local build_unzip="ios_${COMMON_LIBRARY_NAME}_build_unzip" 204 | common_build_unzip "$library_id" 205 | eval ${build_unzip} "$library_id" 206 | log_info_print "ios_build_unzip $1 $2 end..." 207 | } 208 | 209 | function ios_build_config_make() { 210 | log_info_print "ios_build_config_make $1 $2 start..." 211 | local library_id=$1 212 | local library_arch=$2 213 | local build_config_make="ios_${COMMON_LIBRARY_NAME}_build_config_make" 214 | common_build_config_make "$library_id" "$library_arch" 215 | ios_set_sysroot "${library_arch}" 216 | ios_set_cpu_feature "${COMMON_LIBRARY_NAME}" "${library_arch}" "${IOS_API}" "${IOS_SYSROOT}" 217 | eval ${build_config_make} "$library_id" "$library_arch" 218 | log_info_print "ios_build_config_make $1 $2 end..." 219 | } 220 | 221 | function ios_archive() { 222 | log_info_print "ios_archive $1 start..." 223 | local library_id=$1 224 | local archive="ios_${COMMON_LIBRARY_NAME}_archive" 225 | common_archive "$library_id" 226 | eval ${archive} "$library_id" 227 | log_info_print "ios_archive $1 end..." 228 | } 229 | -------------------------------------------------------------------------------- /script/ios-curl.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 curl 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 | curl_zip_file="" 45 | curl_zip_file_no_suffix="" 46 | curl_zip_file_path="" 47 | curl_zip_file_no_suffix_path="" 48 | curl_input_dir="" 49 | curl_output_dir="" 50 | nghttp2_output_dir="" 51 | openssl_output_dir="" 52 | 53 | function ios_curl_printf_variable() { 54 | log_var_print "curl_input_dir = $curl_input_dir" 55 | log_var_print "curl_output_dir = $curl_output_dir" 56 | log_var_print "curl_zip_file = $curl_zip_file" 57 | log_var_print "curl_zip_file_no_suffix = $curl_zip_file_no_suffix" 58 | log_var_print "curl_zip_file_path = $curl_zip_file_path" 59 | log_var_print "curl_zip_file_no_suffix_path = $curl_zip_file_no_suffix_path" 60 | log_var_print "nghttp2_output_dir = $nghttp2_output_dir" 61 | log_var_print "openssl_output_dir = $openssl_output_dir" 62 | } 63 | 64 | function ios_curl_pre_tool_check() { 65 | 66 | openssl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/$(common_get_library_name_from_id 1)" 67 | if [ ! -d "${openssl_output_dir}" ]; then 68 | common_die "Please build the openssl library first!" 69 | fi 70 | nghttp2_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/$(common_get_library_name_from_id 2)" 71 | if [ ! -d "${nghttp2_output_dir}" ]; then 72 | common_die "Please build the nghttp2 library first!" 73 | fi 74 | 75 | curl_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 76 | curl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 77 | 78 | curl_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 79 | curl_zip_file_no_suffix=${curl_zip_file%.tar.gz} 80 | curl_zip_file_path="${curl_input_dir}/${curl_zip_file}" 81 | curl_zip_file_no_suffix_path="${curl_input_dir}/${curl_zip_file_no_suffix}" 82 | 83 | util_create_dir "${curl_input_dir}" 84 | util_create_dir "${curl_output_dir}" 85 | 86 | ios_curl_printf_variable 87 | 88 | } 89 | 90 | function ios_curl_pre_download_zip() { 91 | local library_id=$1 92 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$curl_zip_file_path" 93 | } 94 | 95 | function ios_curl_build_unzip() { 96 | local library_id=$1 97 | util_unzip "$curl_zip_file_path" "${curl_input_dir}" "$curl_zip_file_no_suffix" 98 | } 99 | 100 | function ios_curl_build_config_make() { 101 | local library_id=$1 102 | local library_arch=$2 103 | 104 | local library_arch_path="${curl_output_dir}/${library_arch}" 105 | util_remove_dir "$library_arch_path" 106 | util_create_dir "${library_arch_path}/log" 107 | 108 | openssl_output_arch_lib_dir="${openssl_output_dir}/${library_arch}/lib" 109 | if [ ! -d "${openssl_output_arch_lib_dir}" ]; then 110 | common_die "Please build the openssl ${library_arch} library first!" 111 | fi 112 | nghttp2_output_arch_lib_dir="${nghttp2_output_dir}/${library_arch}/lib" 113 | if [ ! -d "${nghttp2_output_arch_lib_dir}" ]; then 114 | common_die "Please build the nghttp2 ${library_arch} library first!" 115 | fi 116 | 117 | export LDFLAGS="${LDFLAGS} -L${openssl_output_arch_lib_dir} -L${nghttp2_output_arch_lib_dir}" 118 | 119 | ios_printf_arch_variable 120 | 121 | pushd . 122 | cd "$curl_zip_file_no_suffix_path" 123 | 124 | if [[ "${library_arch}" == "x86-64" ]]; then 125 | 126 | ./Configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --enable-static --enable-ipv6 --without-libidn2 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 127 | 128 | elif [[ "${library_arch}" == "armv7" ]]; then 129 | 130 | ./Configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --enable-static --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 131 | 132 | elif [[ "${library_arch}" == "arm64" ]]; then 133 | 134 | ./Configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --enable-static --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 135 | 136 | elif [[ "${library_arch}" == "arm64e" ]]; then 137 | 138 | ./Configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --enable-static --enable-ipv6 --with-ssl="${openssl_output_dir}/${library_arch}" --with-nghttp2="${nghttp2_output_dir}/${library_arch}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 139 | 140 | else 141 | common_die "not support $library_arch" 142 | fi 143 | 144 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 145 | 146 | popd 147 | } 148 | 149 | function ios_curl_archive() { 150 | local library_id=$1 151 | local static_library_list=() 152 | for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do 153 | local static_library_file_path="${curl_output_dir}/${IOS_ARCHS[i]}/lib/lib${COMMON_LIBRARY_NAME}.a" 154 | if [ -f "$static_library_file_path" ]; then 155 | static_library_list[${#static_library_list[@]}]="$static_library_file_path" 156 | fi 157 | done 158 | if [ 0 -lt ${#static_library_list[@]} ]; then 159 | util_remove_dir "${curl_output_dir}/lipo" 160 | util_create_dir "${curl_output_dir}/lipo" 161 | lipo ${static_library_list[@]} -create -output "${curl_output_dir}/lipo/lib${COMMON_LIBRARY_NAME}-universal.a" 162 | fi 163 | } 164 | -------------------------------------------------------------------------------- /script/ios-nghttp2.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 nghttp2 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 | nghttp2_zip_file="" 45 | nghttp2_zip_file_no_suffix="" 46 | nghttp2_zip_file_path="" 47 | nghttp2_zip_file_no_suffix_path="" 48 | nghttp2_input_dir="" 49 | nghttp2_output_dir="" 50 | 51 | function ios_nghttp2_printf_variable() { 52 | log_var_print "nghttp2_input_dir = $nghttp2_input_dir" 53 | log_var_print "nghttp2_output_dir = $nghttp2_output_dir" 54 | log_var_print "nghttp2_zip_file = $nghttp2_zip_file" 55 | log_var_print "nghttp2_zip_file_no_suffix = $nghttp2_zip_file_no_suffix" 56 | log_var_print "nghttp2_zip_file_path = $nghttp2_zip_file_path" 57 | log_var_print "nghttp2_zip_file_no_suffix_path = $nghttp2_zip_file_no_suffix_path" 58 | } 59 | 60 | function ios_nghttp2_pre_tool_check() { 61 | 62 | nghttp2_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 63 | nghttp2_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 64 | 65 | nghttp2_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 66 | nghttp2_zip_file_no_suffix=${nghttp2_zip_file%.tar.gz} 67 | nghttp2_zip_file_path="${nghttp2_input_dir}/${nghttp2_zip_file}" 68 | nghttp2_zip_file_no_suffix_path="${nghttp2_input_dir}/${nghttp2_zip_file_no_suffix}" 69 | 70 | util_create_dir "${nghttp2_input_dir}" 71 | util_create_dir "${nghttp2_output_dir}" 72 | 73 | ios_nghttp2_printf_variable 74 | 75 | } 76 | 77 | function ios_nghttp2_pre_download_zip() { 78 | local library_id=$1 79 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$nghttp2_zip_file_path" 80 | } 81 | 82 | function ios_nghttp2_build_unzip() { 83 | local library_id=$1 84 | util_unzip "$nghttp2_zip_file_path" "${nghttp2_input_dir}" "$nghttp2_zip_file_no_suffix" 85 | } 86 | 87 | function ios_nghttp2_build_config_make() { 88 | local library_id=$1 89 | local library_arch=$2 90 | 91 | local library_arch_path="${nghttp2_output_dir}/${library_arch}" 92 | util_remove_dir "$library_arch_path" 93 | util_create_dir "${library_arch_path}/log" 94 | 95 | ios_printf_arch_variable 96 | 97 | pushd . 98 | cd "$nghttp2_zip_file_no_suffix_path" 99 | 100 | if [[ "${library_arch}" == "x86-64" ]]; then 101 | 102 | ./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 103 | 104 | elif [[ "${library_arch}" == "armv7" ]]; then 105 | 106 | ./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 107 | 108 | elif [[ "${library_arch}" == "arm64" ]]; then 109 | 110 | ./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 111 | 112 | elif [[ "${library_arch}" == "arm64e" ]]; then 113 | 114 | ./configure --host=$(ios_get_build_host "${library_arch}") --prefix="${library_arch_path}" --disable-shared --disable-app --disable-threads --enable-lib-only >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 115 | 116 | else 117 | common_die "not support $library_arch" 118 | fi 119 | 120 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 121 | 122 | popd 123 | } 124 | 125 | function ios_nghttp2_archive() { 126 | local library_id=$1 127 | local static_library_list=() 128 | for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do 129 | local static_library_file_path="${nghttp2_output_dir}/${IOS_ARCHS[i]}/lib/lib${COMMON_LIBRARY_NAME}.a" 130 | if [ -f "$static_library_file_path" ]; then 131 | static_library_list[${#static_library_list[@]}]="$static_library_file_path" 132 | fi 133 | done 134 | if [ 0 -lt ${#static_library_list[@]} ]; then 135 | util_remove_dir "${nghttp2_output_dir}/lipo" 136 | util_create_dir "${nghttp2_output_dir}/lipo" 137 | lipo ${static_library_list[@]} -create -output "${nghttp2_output_dir}/lipo/lib${COMMON_LIBRARY_NAME}-universal.a" 138 | fi 139 | } 140 | -------------------------------------------------------------------------------- /script/ios-openssl.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 openssl 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 | openssl_zip_file="" 45 | openssl_zip_file_no_suffix="" 46 | openssl_zip_file_path="" 47 | openssl_zip_file_no_suffix_path="" 48 | openssl_input_dir="" 49 | openssl_output_dir="" 50 | 51 | function ios_openssl_printf_variable() { 52 | log_var_print "openssl_input_dir = $openssl_input_dir" 53 | log_var_print "openssl_output_dir = $openssl_output_dir" 54 | log_var_print "openssl_zip_file = $openssl_zip_file" 55 | log_var_print "openssl_zip_file_no_suffix = $openssl_zip_file_no_suffix" 56 | log_var_print "openssl_zip_file_path = $openssl_zip_file_path" 57 | log_var_print "openssl_zip_file_no_suffix_path = $openssl_zip_file_no_suffix_path" 58 | } 59 | 60 | function ios_openssl_pre_tool_check() { 61 | 62 | openssl_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 63 | openssl_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 64 | 65 | openssl_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 66 | openssl_zip_file_no_suffix=${openssl_zip_file%.tar.gz} 67 | openssl_zip_file_path="${openssl_input_dir}/${openssl_zip_file}" 68 | openssl_zip_file_no_suffix_path="${openssl_input_dir}/${openssl_zip_file_no_suffix}" 69 | 70 | util_create_dir "${openssl_input_dir}" 71 | util_create_dir "${openssl_output_dir}" 72 | 73 | ios_openssl_printf_variable 74 | 75 | } 76 | 77 | function ios_openssl_pre_download_zip() { 78 | local library_id=$1 79 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$openssl_zip_file_path" 80 | } 81 | 82 | function ios_openssl_build_unzip() { 83 | local library_id=$1 84 | util_unzip "$openssl_zip_file_path" "${openssl_input_dir}" "$openssl_zip_file_no_suffix" 85 | } 86 | 87 | function ios_openssl_build_config_make() { 88 | local library_id=$1 89 | local library_arch=$2 90 | 91 | local library_arch_path="${openssl_output_dir}/${library_arch}" 92 | util_remove_dir "$library_arch_path" 93 | util_create_dir "${library_arch_path}/log" 94 | 95 | ios_printf_arch_variable 96 | 97 | pushd . 98 | cd "$openssl_zip_file_no_suffix_path" 99 | 100 | # openssl1.1.1d can be set normally, 1.1.0f does not take effect 101 | # sed -ie "s!-fno-common!-fno-common -fembed-bitcode !" "Makefile" 102 | if [[ "${library_arch}" == "x86-64" ]]; then 103 | 104 | ./Configure darwin64-x86_64-cc no-shared --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 105 | 106 | elif [[ "${library_arch}" == "armv7" ]]; then 107 | 108 | ./Configure iphoneos-cross no-shared --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 109 | 110 | elif [[ "${library_arch}" == "arm64" ]]; then 111 | 112 | ./Configure iphoneos-cross no-shared --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 113 | 114 | elif [[ "${library_arch}" == "arm64e" ]]; then 115 | 116 | ./Configure iphoneos-cross no-shared --prefix="${library_arch_path}" >"${library_arch_path}/log/output.log" 2>&1 || common_die "configure error!" 117 | 118 | else 119 | common_die "not support $library_arch" 120 | fi 121 | 122 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install_sw" "install_ssldirs" 123 | 124 | popd 125 | } 126 | 127 | function ios_openssl_archive() { 128 | local library_id=$1 129 | local static_library_ssl_list=() 130 | local static_library_crypto_list=() 131 | for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do 132 | local static_library_file_path_ssl="${openssl_output_dir}/${IOS_ARCHS[i]}/lib/libssl.a" 133 | if [ -f "$static_library_file_path_ssl" ]; then 134 | static_library_ssl_list[${#static_library_ssl_list[@]}]="$static_library_file_path_ssl" 135 | fi 136 | local static_library_file_path_crypto="${openssl_output_dir}/${IOS_ARCHS[i]}/lib/libcrypto.a" 137 | if [ -f "$static_library_file_path_crypto" ]; then 138 | static_library_crypto_list[${#static_library_crypto_list[@]}]="$static_library_file_path_crypto" 139 | fi 140 | done 141 | if test ${#static_library_ssl_list[@]} -gt 0 && test ${#static_library_crypto_list[@]} -gt 0; then 142 | util_remove_dir "${openssl_output_dir}/lipo" 143 | util_create_dir "${openssl_output_dir}/lipo" 144 | lipo ${static_library_ssl_list[@]} -create -output "${openssl_output_dir}/lipo/libssl-universal.a" 145 | lipo ${static_library_crypto_list[@]} -create -output "${openssl_output_dir}/lipo/libcrypto-universal.a" 146 | fi 147 | } 148 | -------------------------------------------------------------------------------- /script/ios-protobuf.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | echo "###############################################################################" >/dev/null 26 | echo "# Script Summary: #" >/dev/null 27 | echo "# Author: AsteriskZuo #" >/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 | # protobuf-3.11.4 need mac version > 10.3 64 | local mac_version=$(util_get_mac_version) 65 | local mac_version_list=($(echo ${mac_version} | sed "s/\./ /g")) 66 | if test ${#mac_version_list[@]} -lt 3; then 67 | common_die "get mac version error!" 68 | fi 69 | export MACOSX_DEPLOYMENT_TARGET="${mac_version_list[0]}.${mac_version_list[1]}" 70 | 71 | local protobuf_version=$(protoc --version) 72 | 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)" 73 | 74 | protobuf_input_dir="${COMMON_INPUT_DIR}/${COMMON_LIBRARY_NAME}" 75 | protobuf_output_dir="${COMMON_OUTPUT_DIR}/${COMMON_PLATFORM_TYPE}/${COMMON_LIBRARY_NAME}" 76 | 77 | protobuf_zip_file="${COMMON_DOWNLOAD_ADRESS##*/}" 78 | protobuf_zip_file_no_suffix=$(util_remove_substr "cpp-" ${protobuf_zip_file%.tar.gz}) 79 | protobuf_zip_file_path="${protobuf_input_dir}/${protobuf_zip_file}" 80 | protobuf_zip_file_no_suffix_path="${protobuf_input_dir}/${protobuf_zip_file_no_suffix}" 81 | 82 | util_create_dir "${protobuf_input_dir}" 83 | util_create_dir "${protobuf_output_dir}" 84 | 85 | ios_protobuf_printf_variable 86 | 87 | } 88 | 89 | function ios_protobuf_pre_download_zip() { 90 | local library_id=$1 91 | util_download_file "$COMMON_DOWNLOAD_ADRESS" "$protobuf_zip_file_path" 92 | } 93 | 94 | function ios_protobuf_build_unzip() { 95 | local library_id=$1 96 | util_unzip "$protobuf_zip_file_path" "${protobuf_input_dir}" "$protobuf_zip_file_no_suffix" 97 | } 98 | 99 | function ios_protobuf_build_config_make() { 100 | local library_id=$1 101 | local library_arch=$2 102 | 103 | local library_arch_path="${protobuf_output_dir}/${library_arch}" 104 | util_remove_dir "$library_arch_path" 105 | util_create_dir "${library_arch_path}/log" 106 | 107 | ios_printf_arch_variable 108 | 109 | pushd . 110 | cd "$protobuf_zip_file_no_suffix_path" 111 | 112 | if [[ "${library_arch}" == "x86-64" ]]; then 113 | 114 | ./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!" 115 | 116 | elif [[ "${library_arch}" == "armv7" ]]; then 117 | 118 | ./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!" 119 | 120 | elif [[ "${library_arch}" == "arm64" ]]; then 121 | 122 | ./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!" 123 | 124 | elif [[ "${library_arch}" == "arm64e" ]]; then 125 | 126 | ./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!" 127 | 128 | else 129 | common_die "not support $library_arch" 130 | fi 131 | 132 | common_build_make "${library_arch_path}" "clean" "-j$(util_get_cpu_count)" "install" 133 | 134 | popd 135 | } 136 | 137 | function ios_protobuf_archive() { 138 | local library_id=$1 139 | local static_library_list=() 140 | for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do 141 | local static_library_file_path="${protobuf_output_dir}/${IOS_ARCHS[i]}/lib/lib${COMMON_LIBRARY_NAME}.a" 142 | if [ -f "$static_library_file_path" ]; then 143 | static_library_list[${#static_library_list[@]}]="$static_library_file_path" 144 | fi 145 | done 146 | if [ 0 -lt ${#static_library_list[@]} ]; then 147 | util_remove_dir "${protobuf_output_dir}/lipo" 148 | util_create_dir "${protobuf_output_dir}/lipo" 149 | lipo ${static_library_list[@]} -create -output "${protobuf_output_dir}/lipo/lib${COMMON_LIBRARY_NAME}-universal.a" 150 | fi 151 | } 152 | -------------------------------------------------------------------------------- /script/ios.sh: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | # Copyright (c) 2020 asteriskzuo 4 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | 12 | # The above copyright notice and this permission notice shall be included in all 13 | # copies or substantial portions of the Software. 14 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | 23 | #!/bin/sh 24 | 25 | source $(cd -P "$(dirname "$0")" && pwd)/ios-common.sh 26 | 27 | log_head_print "###############################################################################" 28 | log_head_print "# Script Summary: #" 29 | log_head_print "# Author: AsteriskZuo #" 30 | log_head_print "# Update Date: 2020.05.28 #" 31 | log_head_print "# Script version: 1.0.0 #" 32 | log_head_print "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" 33 | log_head_print "# #" 34 | log_head_print "# Brief introduction: #" 35 | log_head_print "# Build iOS and Android C&&C++ common library. #" 36 | log_head_print "# #" 37 | log_head_print "# Prerequisites: #" 38 | log_head_print "# GNU bash (version 3.2.57 test success on macOS) #" 39 | log_head_print "# #" 40 | log_head_print "# Reference: #" 41 | log_head_print "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" 42 | log_head_print "###############################################################################" 43 | 44 | set -u 45 | # util_debug 46 | 47 | opt_count=$# 48 | opt=$* 49 | 50 | if [ "Darwin" != $(uname -s) ]; then 51 | common_die "This is not MacOS." 52 | fi 53 | 54 | if [ ! $opt ]; then 55 | ios_help 56 | fi 57 | 58 | for opt; do 59 | optval="${opt#*=}" 60 | case "$opt" in 61 | --help | -h) 62 | ios_help 63 | ;; 64 | --name=*) 65 | if util_is_in $optval $COMMON_LIBRARY_NAME_LIST; then 66 | export COMMON_LIBRARY_NAME=($optval) 67 | export COMMON_LIBRARY_ID="$(common_get_library_id_from_name "$COMMON_LIBRARY_NAME")" 68 | export COMMON_LIBRARY_VERSION=$(common_get_library_version_from_id $COMMON_LIBRARY_ID) 69 | export COMMON_DOWNLOAD_ADRESS=$(common_get_library_url_from_id $COMMON_LIBRARY_ID) 70 | else 71 | common_die "${optval} is not in list. please refer \${COMMON_LIBRARY_NAME_LIST}" 72 | fi 73 | ;; 74 | *) 75 | ios_help 76 | ;; 77 | esac 78 | done 79 | 80 | common_printf_variable 81 | ios_printf_variable 82 | 83 | util_load_script "$(ios_get_shell_script_path ${COMMON_LIBRARY_ID})" 84 | 85 | log_warning_print "build ${COMMON_LIBRARY_ID} ${COMMON_LIBRARY_NAME} ${COMMON_LIBRARY_VERSION} start..." 86 | 87 | ios_pre_tool_check "${COMMON_LIBRARY_ID}" 88 | ios_pre_download_zip "${COMMON_LIBRARY_ID}" 89 | for ((i = 0; i < ${#IOS_ARCHS[@]}; i++)); do 90 | ios_build_unzip "${COMMON_LIBRARY_ID}" "${IOS_ARCHS[i]}" 91 | ios_build_config_make "${COMMON_LIBRARY_ID}" "${IOS_ARCHS[i]}" 92 | done 93 | ios_archive "${COMMON_LIBRARY_ID}" 94 | 95 | log_warning_print "build ${COMMON_LIBRARY_ID} ${COMMON_LIBRARY_NAME} ${COMMON_LIBRARY_VERSION} end..." 96 | -------------------------------------------------------------------------------- /script/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | source $(cd -P "$(dirname "$0")" && pwd)/_common.sh 4 | 5 | echo "###############################################################################" >/dev/null 6 | echo "# Script Summary: #" >/dev/null 7 | echo "# Author: AsteriskZuo #" >/dev/null 8 | echo "# Update Date: 2020.05.28 #" >/dev/null 9 | echo "# Script version: 1.0.0 #" >/dev/null 10 | echo "# Url: https://github.com/AsteriskZuo/simple-build-ios-and-android-script #" >/dev/null 11 | echo "# #" >/dev/null 12 | echo "# Brief introduction: #" >/dev/null 13 | echo "# This is test script. #" >/dev/null 14 | echo "# #" >/dev/null 15 | echo "# Prerequisites: #" >/dev/null 16 | echo "# GNU bash (version 3.2.57 test success on macOS) #" >/dev/null 17 | echo "# #" >/dev/null 18 | echo "# Reference: #" >/dev/null 19 | echo "# Url: https://github.com/AsteriskZuo/openssl_for_ios_and_android #" >/dev/null 20 | echo "###############################################################################" >/dev/null 21 | 22 | # 获取当前执行脚本所在绝对目录 23 | # echo "$(cd -P "$(dirname "$0")" && pwd)" 24 | # echo "$(cd -P "$(dirname "$0")"; pwd)" 25 | 26 | # 字符串常规操作 27 | # ref: http://c.biancheng.net/view/1120.html 28 | # ${string: start :length} 从 string 字符串的左边第 start 个字符开始,向右截取 length 个字符。 29 | # ${string: start} 从 string 字符串的左边第 start 个字符开始截取,直到最后。 30 | # ${string: 0-start :length} 从 string 字符串的右边第 start 个字符开始,向右截取 length 个字符。 31 | # ${string: 0-start} 从 string 字符串的右边第 start 个字符开始截取,直到最后。 32 | # ${string#*chars} 从 string 字符串第一次出现 *chars 的位置开始,截取 *chars 右边的所有字符。 33 | # ${string##*chars} 从 string 字符串最后一次出现 *chars 的位置开始,截取 *chars 右边的所有字符。 34 | # ${string%*chars} 从 string 字符串第一次出现 *chars 的位置开始,截取 *chars 左边的所有字符。 35 | # ${string%%*chars} 从 string 字符串最后一次出现 *chars 的位置开始,截取 *chars 左边的所有字符 36 | # url="http://c.biancheng.net/view/1120.html" 37 | # echo $(util_get_dir_from_filename "$url") 38 | 39 | # 获取输入和输出绝对目录 40 | # util_get_input_dir 41 | # util_get_output_dir 42 | 43 | # list=("1" "2" "3" "4") 44 | # echo $v 45 | # list=" 46 | # 1 47 | # 2 48 | # 3 49 | # 4 50 | # " 51 | # name="2" 52 | # util_filter "$list 53 | 54 | # 测试遍历数组 55 | # COMPONENT_LIST=" 56 | # 1wer 57 | # 2wer 58 | # 3sdfsdf 59 | # 4rwer 60 | # " 61 | # for n in $COMPONENT_LIST; do 62 | # echo "n=$n" 63 | # done 64 | # ret=$(util_get_list_item 3 $COMPONENT_LIST) 65 | # echo "ret=$ret" 66 | # common_get_library_name_from_id 4 67 | 68 | # 测试间接调用方法 69 | # function func_name() 70 | # { 71 | # echo $1 72 | # } 73 | # var="func_name" 74 | # eval $var "hahah" 75 | # COMMON_DOWNLOAD_ADRESS="https://github.com/protocolbuffers/protobuf/releases/download/v3.12.2/protobuf-all-3.12.2.tar.gz" 76 | # url_file_name=${COMMON_DOWNLOAD_ADRESS##*/} 77 | # unzip_output_dir=${url_file_name%.tar.gz} 78 | # echo "url_file_name=$url_file_name" 79 | # echo "unzip_output_dir=$unzip_output_dir" 80 | 81 | # 测试逻辑运算符 82 | # COMPONENT_LIST=" 83 | # 1wer 84 | # 2wer 85 | # 3sdfsdf 86 | # 4rwer 87 | # " 88 | # ITEM="1234" 89 | # function die() { 90 | # echo "error" 91 | # exit 1 92 | # } 93 | # util_is_in "$ITEM" "$COMPONENT_LIST" || common_die "error1" 94 | # echo "lalala" 95 | # util_is_in "$ITEM" "$COMPONENT_LIST" || common_die 'sdfsdf ${COMPONENT_LIST}' 96 | # echo "lskdjfksd" 97 | 98 | # 测试 log_info_print 99 | # log_info_print "123" 100 | # var="1234" 101 | # log_info_print "12 ${var}" 102 | # set -u 103 | # function test_param() { 104 | # local ssss=$1 105 | # echo "sdfe" >/dev/null 106 | # } 107 | # test_param "sdf" 108 | 109 | # PS4='Line ${LINENO}: ' 110 | # set -x 111 | # function sdfsdff() { 112 | # echo "haha" 113 | # } 114 | # echo "sssdf" 115 | 116 | # 测试调试行数 117 | # PS4='[line:${LINENO}]' 118 | # set -x 119 | # echo sdfsd 120 | # function test () { 121 | # echo "hjss" 122 | # } 123 | # test 124 | 125 | # 测试if双条件 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" 154 | 155 | # 测试protobuf 156 | # VAR=7 157 | # case $VAR in 158 | # [456]) echo 1 159 | # ;; 160 | # 2|3) echo 2 or 3 161 | # ;; 162 | # *) echo default 163 | # ;; 164 | # esac 165 | # var=$(sw_vers | grep ProductVersion) 166 | # echo "var=$var" 167 | # MACOSX_DEPLOYMENT_TARGET="${var#*:}" 168 | # MACOSX_DEPLOYMENT_TARGET=$(util_get_mac_version) 169 | # MACOSX_DEPLOYMENT_TARGET="10.15" 170 | # echo ${MACOSX_DEPLOYMENT_TARGET-10.0} 171 | # case ${MACOSX_DEPLOYMENT_TARGET-10.0} in 172 | # 10.[0123]) 173 | # echo 1 174 | # # func_append compile_command " $wl-bind_at_load" 175 | # # func_append finalize_command " $wl-bind_at_load" 176 | # ;; 177 | # esac 178 | 179 | # 测试分割字符串 180 | # MACOSX_DEPLOYMENT_TARGET="10.15.2" 181 | # ALL_VERSION=($(echo ${MACOSX_DEPLOYMENT_TARGET} | sed "s/\./ /g")) 182 | # echo "ALL_VERSION=${ALL_VERSION[@]}" 183 | # mac_version=$(util_get_mac_version) 184 | # mac_version_list=($(echo ${mac_version} | sed "s/\./ /g")) 185 | # if test ${#mac_version_list[@]} -lt 3; then 186 | # common_die "get mac version error!" 187 | # fi 188 | # echo "mac_version_list=${mac_version_list[@]}" 189 | 190 | # 测试函数参数 191 | # function test_fun_name() { 192 | # local var=$1 193 | # eval $var 194 | # } 195 | # test_fun_name "ls" 196 | # test_fun_name ls 197 | 198 | # 测试数组 199 | # list=" 200 | # 1 201 | # '2 3' 202 | # xxx 203 | # " 204 | # function test_list() { 205 | # index=$1 206 | # shift 207 | # for var in $*; do 208 | # echo "var=$var" 209 | # ((i++)) 210 | # done 211 | # } 212 | # test_list $list 213 | 214 | # 测试进度条 215 | # ref: https://www.cnblogs.com/chuyiwang/p/9675279.html 216 | #!/bin/bash
b='' 217 | # for ((i=0;$i<=100;i++)) 218 | # do 219 | # let jinshu=$i*5 220 | # printf "[%-100s]%d%%\r" $b $jinshu 221 | # sleep 0.1 222 | # b=#$b 223 | # done 224 | # echo 225 | 226 | # printf "%-10s %-8s %-4s\n" 姓名 性别 体重kg 227 | # printf "%-10s %-8s %-4.2f\n" 郭靖 男 66.1234 228 | # printf "%-10s %-8s %-4.2f\n" 杨过 男 48.6543 229 | # printf "%-10s %-8s %-4.2f\n" 郭芙 女 47.9876 --------------------------------------------------------------------------------