prebuild.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/bash
  2. # Copyright (c) 2024 Huawei Device Co., Ltd.
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # 执行该脚本时需进入到脚本所在目录
  15. ROOT_DIR=$(pwd)
  16. API_VERSION=12 # 三方库对应API版本,用于记录SDK路径,必须和"compileSdkVersion"字段表示的API版本保持一致
  17. SDK_DIR=$ROOT_DIR/../ohos-sdk-$API_VERSION/linux/$API_VERSION # SDK路径(流水线环境中SDK路径)
  18. LYCIUM_TOOLS_URL=https://gitee.com/openharmony-sig/tpc_c_cplusplus.git
  19. LYCIUM_ROOT_DIR=$ROOT_DIR/tpc_c_cplusplus
  20. LYCIUM_TOOLS_DIR=$LYCIUM_ROOT_DIR/lycium
  21. LYCIUM_THIRDPARTY_DIR=$LYCIUM_ROOT_DIR/thirdparty
  22. DEPENDS_DIR=$ROOT_DIR/doc # 依赖库编译脚本在仓库中的位置
  23. FFMPEG_NAME=FFmpeg-ff4.0 # 依赖库名
  24. LIBYUV_NAME=libyuv-ijk # 依赖库名
  25. SOUNDTOUCH_NAME=soundtouch-ijk # 依赖库名
  26. OPESSL_NAME=openssl_1_1_1w # FFmpeg的依赖库名,需和依赖库一起安装
  27. CI_OUTPUT_DIR=$ROOT_DIR/../out/tpc/ # hap/har安装目录
  28. LIBS_NAME=("FFmpeg-ff4.0" "libyuv-ijk" "soundtouch-ijk" "openssl_1_1_1w")
  29. PACKAGE_NAME=("FFmpeg-ff4.0-ijk0.8.8-20210426-001.tar.gz" "yuv-ijk-r0.2.1-dev.zip" "soundtouch-ijk-r0.1.2-dev.zip" "openssl-OpenSSL_1_1_1w.zip")
  30. function prepare_lycium_tools()
  31. {
  32. local commands=("gcc" "make" "cmake" "pkg-config" "autoconf" "autoreconf" "automake" "patch" "libtool" "autopoint" "gperf" \
  33. "tcl8.6-dev" "wget" "unzip" "gccgo-go" "flex " "bison" "premake4" "python3" "python3-pip" \
  34. "ninja-build" "meson" "sox" "gfortran" "subversion" "build-essential" "module-assistant" " gcc-multilib" \
  35. "g++-multilib" "libltdl7-dev" "cabextract" "libboost-all-dev" "libxml2-utils" "gettext" "libxml-libxml-perl" \
  36. "libxml2" "libxml2-dev" "libxml-parser-perl" "texinfo" "libtool-bin" "xmlto" "po4a" "yasm" "nasm" "xutils-dev" \
  37. "libx11-dev" "xtrans-dev" "gfortran-arm-linux-gnueabi" "gfortran-aarch64-linux-gnu")
  38. apt update >> /dev/null
  39. for cmd in ${commands[@]}
  40. do
  41. which $cmd >> /dev/null
  42. if [ $? -ne 0 ]
  43. then
  44. echo "install $cmd"
  45. apt install $cmd -y >> /dev/null
  46. fi
  47. done
  48. }
  49. function prepare_lycium()
  50. {
  51. if [ -d $LYCIUM_ROOT_DIR ]
  52. then
  53. rm -rf $LYCIUM_ROOT_DIR
  54. fi
  55. git clone $LYCIUM_TOOLS_URL -b support_x86 --depth=1
  56. if [ $? -ne 0 ]
  57. then
  58. return 1
  59. fi
  60. cd $LYCIUM_TOOLS_DIR/Buildtools
  61. tar -zxvf toolchain.tar.gz
  62. if [ $? -ne 0 ]
  63. then
  64. echo "unpack sdk toolchain failed!!"
  65. cd $OLDPWD
  66. return 1
  67. fi
  68. cp toolchain/* $SDK_DIR/native/llvm/bin/
  69. prepare_lycium_tools
  70. ret=$?
  71. cd $OLDPWD
  72. return $ret
  73. }
  74. function copy_depends()
  75. {
  76. local dir=$1
  77. local name=$2
  78. if [ -d $LYCIUM_THIRDPARTY_DIR/$name ]
  79. then
  80. rm -rf $LYCIUM_THIRDPARTY_DIR/$name
  81. fi
  82. cp -arf $dir/$name $LYCIUM_THIRDPARTY_DIR/
  83. }
  84. function prepare_depends()
  85. {
  86. copy_depends $DEPENDS_DIR $LIBYUV_NAME
  87. copy_depends $DEPENDS_DIR $SOUNDTOUCH_NAME
  88. }
  89. function check_sdk()
  90. {
  91. if [ ! -d $SDK_DIR ]
  92. then
  93. return 1
  94. fi
  95. export OHOS_SDK=$SDK_DIR
  96. return 0
  97. }
  98. function check_copy_shasum()
  99. {
  100. local libpath=$1
  101. local pack_name=$2
  102. local libname=$3
  103. cd $LYCIUM_THIRDPARTY_DIR/$libpath
  104. if [ ! -f ./SHA512SUM ]
  105. then
  106. sha512sum $pack_name > ./SHA512SUM
  107. fi
  108. cp ./SHA512SUM $LYCIUM_TOOLS_DIR/usr/$libname/
  109. cd $OLDPWD
  110. }
  111. function install_shasum()
  112. {
  113. check_copy_shasum $FFMPEG_NAME ${PACKAGE_NAME[0]} $FFMPEG_NAME
  114. check_copy_shasum $LIBYUV_NAME ${PACKAGE_NAME[1]} yuv
  115. check_copy_shasum $SOUNDTOUCH_NAME ${PACKAGE_NAME[2]} soundtouch
  116. check_copy_shasum $OPESSL_NAME ${PACKAGE_NAME[3]} $OPESSL_NAME
  117. }
  118. function start_build()
  119. {
  120. local result=0
  121. cd $LYCIUM_TOOLS_DIR
  122. if [ $? -ne 0 ]
  123. then
  124. return 1
  125. fi
  126. bash build.sh $FFMPEG_NAME $LIBYUV_NAME $SOUNDTOUCH_NAME
  127. result=$?
  128. cd $OLDPWD
  129. return $result
  130. }
  131. function install_depends()
  132. {
  133. local install_dir=$ROOT_DIR/ijkplayer/src/main/cpp/third_party/
  134. cp -arf $LYCIUM_TOOLS_DIR/usr/$FFMPEG_NAME $install_dir/ffmpeg/ffmpeg
  135. if [ $? -ne 0 ]
  136. then
  137. echo "FFmpeg build failed!"
  138. return 1
  139. fi
  140. cp -arf $LYCIUM_TOOLS_DIR/usr/yuv $install_dir/yuv
  141. if [ $? -ne 0 ]
  142. then
  143. echo "yuv build failed!"
  144. return 1
  145. fi
  146. cp -arf $LYCIUM_TOOLS_DIR/usr/$OPESSL_NAME $install_dir/openssl
  147. if [ $? -ne 0 ]
  148. then
  149. echo "FFmpeg depends openssl build failed!"
  150. return 1
  151. fi
  152. cp -arf $LYCIUM_TOOLS_DIR/usr/soundtouch $install_dir/soundtouch
  153. if [ $? -ne 0 ]
  154. then
  155. echo "soundtouch build failed!"
  156. return 1
  157. fi
  158. if [ -d $CI_OUTPUT_DIR ]
  159. then
  160. cp -arf $LYCIUM_TOOLS_DIR/usr/$FFMPEG_NAME $CI_OUTPUT_DIR
  161. cp -arf $LYCIUM_TOOLS_DIR/usr/yuv $CI_OUTPUT_DIR
  162. cp -arf $LYCIUM_TOOLS_DIR/usr/$OPESSL_NAME $CI_OUTPUT_DIR
  163. cp -arf $LYCIUM_TOOLS_DIR/usr/soundtouch $CI_OUTPUT_DIR
  164. fi
  165. return 0
  166. }
  167. function prebuild()
  168. {
  169. check_sdk
  170. if [ $? -ne 0 ]
  171. then
  172. echo "ERROR: check_sdk failed!!!"
  173. return 1
  174. fi
  175. prepare_lycium
  176. if [ $? -ne 0 ]
  177. then
  178. echo "ERROR: prepare_lycium failed!!!"
  179. return 1
  180. fi
  181. prepare_depends
  182. start_build
  183. if [ $? -ne 0 ]
  184. then
  185. echo "ERROR: start_build failed!!!"
  186. return 1
  187. fi
  188. install_shasum
  189. install_depends
  190. if [ $? -ne 0 ]
  191. then
  192. echo "ERROR: install depends failed!!!"
  193. return 1
  194. fi
  195. echo "prebuild success!!"
  196. return 0
  197. }
  198. prebuild $*
  199. ret=$?
  200. echo "ret = $ret"
  201. exit $ret
  202. #EOF