2
0

depends.sh 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. #!/bin/bash
  2. # variables, parent script must set it:
  3. # SRS_JOBS: the build jobs.
  4. # SrsArmMakeOptions: the arm make options for ubuntu12(armhf, v7cpu)
  5. #####################################################################################
  6. #####################################################################################
  7. # prepare the depends tools and libraries
  8. # DEPENDS: options.sh, only when user options parsed, the depends tools are known.
  9. #####################################################################################
  10. #####################################################################################
  11. #####################################################################################
  12. # Check OS and CPU architectures.
  13. #####################################################################################
  14. if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CYGWIN64 != YES ]]; then
  15. if [[ $SRS_CROSS_BUILD != YES && $SRS_GENERIC_LINUX != YES ]]; then
  16. echo "Your OS `uname -s` is not supported."
  17. if [[ $(uname -s) == "Linux" ]]; then
  18. echo "Please try --generic-linux=on for other Linux systems."
  19. fi
  20. exit 1
  21. fi
  22. fi
  23. # The absolute path of SRS_OBJS, for prefix and PKG_CONFIG_PATH
  24. SRS_DEPENDS_LIBS=$(mkdir -p $SRS_OBJS && cd $SRS_OBJS && pwd)
  25. echo -n "SRS_JOBS: $SRS_JOBS, SRS_DEPENDS_LIBS: ${SRS_DEPENDS_LIBS}"
  26. if [[ ! -z $OS_IS_LINUX ]]; then echo -n ", OS_IS_LINUX: $OS_IS_LINUX"; fi
  27. if [[ ! -z $OS_IS_OSX ]]; then echo -n ", OS_IS_OSX: $OS_IS_OSX"; fi
  28. if [[ ! -z $OS_IS_CYGWIN ]]; then echo -n ", OS_IS_CYGWIN: $OS_IS_CYGWIN"; fi
  29. if [[ ! -z $OS_IS_UBUNTU ]]; then echo -n ", OS_IS_UBUNTU: $OS_IS_UBUNTU"; fi
  30. if [[ ! -z $OS_IS_CENTOS ]]; then echo -n ", OS_IS_CENTOS: $OS_IS_CENTOS"; fi
  31. if [[ ! -z $SRS_CROSS_BUILD ]]; then echo -n ", SRS_CROSS_BUILD: $SRS_CROSS_BUILD"; fi
  32. if [[ ! -z $OS_IS_LOONGARCH64 ]]; then echo -n ", OS_IS_LOONGARCH64: $OS_IS_LOONGARCH64"; fi
  33. if [[ ! -z $OS_IS_MIPS64 ]]; then echo -n ", OS_IS_MIPS64: $OS_IS_MIPS64"; fi
  34. if [[ ! -z $OS_IS_LOONGSON ]]; then echo -n ", OS_IS_LOONGSON: $OS_IS_LOONGSON"; fi
  35. if [[ ! -z $OS_IS_X86_64 ]]; then echo -n ", OS_IS_X86_64: $OS_IS_X86_64"; fi
  36. if [[ ! -z $OS_IS_RISCV ]]; then echo -n ", OS_IS_RISCV: $OS_IS_RISCV"; fi
  37. echo ""
  38. #####################################################################################
  39. # Check dependency tools.
  40. #####################################################################################
  41. if [[ $SRS_OSX == YES ]]; then
  42. brew --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  43. echo "Please install brew at https://brew.sh/"; exit $ret;
  44. fi
  45. fi
  46. # Check perl, which is depended by automake for building libopus etc.
  47. perl --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  48. if [[ $OS_IS_CENTOS == YES ]]; then
  49. echo "Please install perl by:"
  50. echo " yum install -y perl"
  51. elif [[ $OS_IS_UBUNTU == YES ]]; then
  52. echo "Please install perl by:"
  53. echo " apt install -y perl"
  54. else
  55. echo "Please install perl"
  56. fi
  57. exit $ret;
  58. fi
  59. gcc --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  60. if [[ $OS_IS_CENTOS == YES ]]; then
  61. echo "Please install gcc by:"
  62. echo " yum install -y gcc"
  63. elif [[ $OS_IS_UBUNTU == YES ]]; then
  64. echo "Please install gcc by:"
  65. echo " apt install -y gcc"
  66. else
  67. echo "Please install gcc"
  68. fi
  69. exit $ret;
  70. fi
  71. g++ --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  72. if [[ $OS_IS_CENTOS == YES ]]; then
  73. echo "Please install g++ by:"
  74. echo " yum install -y gcc-c++"
  75. elif [[ $OS_IS_UBUNTU == YES ]]; then
  76. echo "Please install g++ by:"
  77. echo " apt install -y g++"
  78. else
  79. echo "Please install gcc-c++"
  80. fi
  81. exit $ret;
  82. fi
  83. make --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  84. if [[ $OS_IS_CENTOS == YES ]]; then
  85. echo "Please install make by:"
  86. echo " yum install -y make"
  87. elif [[ $OS_IS_UBUNTU == YES ]]; then
  88. echo "Please install make by:"
  89. echo " apt install -y make"
  90. else
  91. echo "Please install make"
  92. fi
  93. exit $ret;
  94. fi
  95. patch --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  96. if [[ $OS_IS_CENTOS == YES ]]; then
  97. echo "Please install patch by:"
  98. echo " yum install -y patch"
  99. elif [[ $OS_IS_UBUNTU == YES ]]; then
  100. echo "Please install patch by:"
  101. echo " apt install -y patch"
  102. else
  103. echo "Please install patch"
  104. fi
  105. exit $ret;
  106. fi
  107. unzip -v >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  108. if [[ $OS_IS_CENTOS == YES ]]; then
  109. echo "Please install unzip by:"
  110. echo " yum install -y unzip"
  111. elif [[ $OS_IS_UBUNTU == YES ]]; then
  112. echo "Please install unzip by:"
  113. echo " apt install -y unzip"
  114. else
  115. echo "Please install unzip"
  116. fi
  117. exit $ret;
  118. fi
  119. if [[ $SRS_VALGRIND == YES ]]; then
  120. valgrind --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  121. echo "Please install valgrind"; exit $ret;
  122. fi
  123. if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
  124. echo "Please install valgrind-dev"; exit $ret;
  125. fi
  126. fi
  127. # Check tclsh, which is depended by SRT.
  128. if [[ $SRS_SRT == YES ]]; then
  129. tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  130. if [[ $OS_IS_CENTOS == YES ]]; then
  131. echo "Please install tclsh by:"
  132. echo " yum install -y tcl"
  133. elif [[ $OS_IS_UBUNTU == YES ]]; then
  134. echo "Please install tclsh by:"
  135. echo " apt install -y tclsh"
  136. else
  137. echo "Please install tclsh"
  138. fi
  139. exit $ret;
  140. fi
  141. cmake --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  142. if [[ $OS_IS_CENTOS == YES ]]; then
  143. echo "Please install cmake by:"
  144. echo " yum install -y cmake"
  145. elif [[ $OS_IS_UBUNTU == YES ]]; then
  146. echo "Please install cmake by:"
  147. echo " apt install -y cmake"
  148. else
  149. echo "Please install cmake"
  150. fi
  151. exit $ret;
  152. fi
  153. fi
  154. pkg-config --version >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  155. echo "Please install pkg-config"; exit $ret;
  156. fi
  157. which ls >/dev/null 2>/dev/null; ret=$?; if [[ 0 -ne $ret ]]; then
  158. if [[ $OS_IS_CENTOS == YES ]]; then
  159. echo "Please install which by:"
  160. echo " yum install -y which"
  161. elif [[ $OS_IS_UBUNTU == YES ]]; then
  162. echo "Please install which by:"
  163. echo " apt install -y which"
  164. else
  165. echo "Please install which"
  166. fi
  167. exit $ret;
  168. fi
  169. #####################################################################################
  170. # Try to load cache if exists /usr/local/srs-cache
  171. #####################################################################################
  172. # Use srs-cache from base image. See https://github.com/ossrs/dev-docker/blob/ubuntu20-cache/Dockerfile
  173. # Note that the cache for cygwin is not under /usr/local, but copy to objs instead.
  174. if [[ -d /usr/local/srs-cache/srs/trunk/objs && $(pwd) != "/usr/local/srs-cache/srs/trunk" && $SRS_BUILD_CACHE == YES ]]; then
  175. SOURCE_DIR=$(ls -d /usr/local/srs-cache/srs/trunk/objs/Platform-SRS${SRS_MAJOR}-* 2>/dev/null|head -n 1)
  176. if [[ -d $SOURCE_DIR ]]; then
  177. TARGET_DIR=${SRS_OBJS}/${SRS_PLATFORM} &&
  178. echo "Build from cache, source=$SOURCE_DIR, target=$TARGET_DIR" &&
  179. rm -rf $TARGET_DIR && mkdir -p ${SRS_OBJS} && cp -R $SOURCE_DIR $TARGET_DIR &&
  180. du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-* &&
  181. du -sh /usr/local/srs-cache/srs/trunk/objs/Platform-*/* &&
  182. du -sh objs/Platform-* &&
  183. ls -lh objs
  184. fi
  185. fi
  186. #####################################################################################
  187. # Check for address sanitizer, see https://github.com/google/sanitizers
  188. #####################################################################################
  189. if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then
  190. echo 'int main() { return 0; }' > ${SRS_OBJS}/test_sanitizer.c &&
  191. gcc -fsanitize=address -fno-omit-frame-pointer -g -O0 ${SRS_OBJS}/test_sanitizer.c \
  192. -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1;
  193. ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer*
  194. if [[ $ret -ne 0 ]]; then
  195. echo "Please install libasan, see https://github.com/google/sanitizers";
  196. if [[ $OS_IS_CENTOS == YES ]]; then echo " sudo yum install -y libasan"; fi
  197. exit $ret;
  198. fi
  199. fi
  200. if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES && $SRS_SANITIZER_STATIC == NO ]]; then
  201. echo 'int main() { return 0; }' > ${SRS_OBJS}/test_sanitizer.c &&
  202. gcc -fsanitize=address -fno-omit-frame-pointer -static-libasan -g -O0 ${SRS_OBJS}/test_sanitizer.c \
  203. -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1;
  204. ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer*
  205. if [[ $ret -eq 0 ]]; then
  206. echo "link static-libasan"
  207. SRS_SANITIZER_STATIC=YES
  208. fi
  209. fi
  210. if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES && $SRS_SANITIZER_LOG == NO ]]; then
  211. echo "#include <sanitizer/asan_interface.h>" > ${SRS_OBJS}/test_sanitizer.c &&
  212. echo "int main() { return 0; }" >> ${SRS_OBJS}/test_sanitizer.c &&
  213. gcc -fsanitize=address -fno-omit-frame-pointer -g -O0 ${SRS_OBJS}/test_sanitizer.c \
  214. -o ${SRS_OBJS}/test_sanitizer 1>/dev/null 2>&1;
  215. ret=$?; rm -rf ${SRS_OBJS}/test_sanitizer*
  216. if [[ $ret -eq 0 ]]; then
  217. echo "libasan api found ok!";
  218. SRS_SANITIZER_LOG=YES
  219. fi
  220. fi
  221. #####################################################################################
  222. # state-threads
  223. #####################################################################################
  224. # check the cross build flag file, if flag changed, need to rebuild the st.
  225. _ST_MAKE=linux-debug && _ST_OBJ="LINUX_`uname -r`_DBG"
  226. # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676
  227. _ST_EXTRA_CFLAGS="-DMALLOC_STACK"
  228. # For valgrind to detect memory issues.
  229. if [[ $SRS_VALGRIND == YES ]]; then
  230. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND"
  231. fi
  232. # for osx, use darwin for st, donot use epoll.
  233. if [[ $SRS_OSX == YES ]]; then
  234. _ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG"
  235. fi
  236. # for windows/cygwin
  237. if [[ $SRS_CYGWIN64 = YES ]]; then
  238. _ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG"
  239. fi
  240. # For Ubuntu, the epoll detection might be fail.
  241. if [[ $OS_IS_UBUNTU == YES ]]; then
  242. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL"
  243. fi
  244. # Whether enable debug stats.
  245. if [[ $SRS_DEBUG_STATS == YES ]]; then
  246. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS"
  247. fi
  248. # Pass the global extra flags.
  249. if [[ $SRS_EXTRA_FLAGS != '' ]]; then
  250. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
  251. fi
  252. # Whether link as .so
  253. if [[ $SRS_SHARED_ST == YES ]]; then
  254. _ST_STATIC_ONLY=no;
  255. else
  256. _ST_STATIC_ONLY=yes;
  257. fi
  258. # The final args to make st.
  259. _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}"
  260. _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}"
  261. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  262. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/libst.a ]]; then
  263. rm -rf ${SRS_OBJS}/st && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ &&
  264. echo "The state-threads is ok."
  265. else
  266. echo "Building state-threads." &&
  267. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/st &&
  268. cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/ &&
  269. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} &&
  270. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st &&
  271. cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/st.h ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ &&
  272. cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ &&
  273. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ &&
  274. echo "The state-threads is ok."
  275. fi
  276. # check status
  277. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi
  278. #####################################################################################
  279. # nginx for HLS, nginx-1.5.0
  280. #####################################################################################
  281. function write_nginx_html5()
  282. {
  283. cat<<END > ${html_file}
  284. <video width="100%" autoplay controls autobuffer type="application/vnd.apple.mpegurl"
  285. src="${hls_stream}">
  286. </video>
  287. END
  288. }
  289. # create the nginx dir, for http-server if not build nginx
  290. mkdir -p ${SRS_OBJS}/nginx
  291. # the demo dir.
  292. # create forward dir
  293. mkdir -p ${SRS_OBJS}/nginx/html/live &&
  294. html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5 &&
  295. # copy players to nginx html dir.
  296. rm -rf ${SRS_OBJS}/nginx/html/players &&
  297. cp -rf $SRS_WORKDIR/research/players ${SRS_OBJS}/nginx/html/ &&
  298. # for favicon.ico
  299. rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
  300. cp -f $SRS_WORKDIR/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico &&
  301. # For srs-console.
  302. rm -rf ${SRS_OBJS}/nginx/html/console &&
  303. cp -rf $SRS_WORKDIR/research/console ${SRS_OBJS}/nginx/html/ &&
  304. # For SRS signaling.
  305. rm -rf ${SRS_OBJS}/nginx/html/demos &&
  306. cp -rf $SRS_WORKDIR/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/ &&
  307. # For home page index.html
  308. rm -rf ${SRS_OBJS}/nginx/html/index.html &&
  309. cp -f $SRS_WORKDIR/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html &&
  310. # nginx.html to detect whether nginx is alive
  311. echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html
  312. # check status
  313. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build web pages failed, ret=$ret"; exit $ret; fi
  314. #####################################################################################
  315. # Generate default self-sign certificate for HTTPS server, test only.
  316. #####################################################################################
  317. if [[ ! -f $SRS_WORKDIR/conf/server.key || ! -f $SRS_WORKDIR/conf/server.crt ]]; then
  318. openssl genrsa -out $SRS_WORKDIR/conf/server.key 2048 &&
  319. openssl req -new -x509 -key $SRS_WORKDIR/conf/server.key -out $SRS_WORKDIR/conf/server.crt -days 3650 \
  320. -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" &&
  321. echo "Generate test-only self-sign certificate files"
  322. fi
  323. #####################################################################################
  324. # openssl, for rtmp complex handshake and HLS encryption.
  325. #####################################################################################
  326. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
  327. echo "Warning: Use system libssl, without compiling openssl."
  328. fi
  329. # @see http://www.openssl.org/news/secadv/20140407.txt
  330. # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately
  331. # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
  332. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then
  333. OPENSSL_OPTIONS="-no-shared -no-threads -DOPENSSL_NO_HEARTBEATS"
  334. OPENSSL_CONFIG="./config"
  335. # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain
  336. if [[ $SRS_CROSS_BUILD == YES ]]; then
  337. OPENSSL_CONFIG="./Configure linux-generic32"
  338. if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi
  339. if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi
  340. if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then OPENSSL_CONFIG="./Configure linux-mips32"; fi
  341. elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib/libssl.a ]]; then
  342. # Try to use exists libraries.
  343. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then
  344. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib &&
  345. cp /usr/local/ssl/lib/libssl.a . && cp /usr/local/ssl/lib/libcrypto.a . &&
  346. mkdir -p /usr/local/ssl/lib/pkgconfig && cp -rf /usr/local/ssl/lib/pkgconfig .)
  347. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/include &&
  348. cp -rf /usr/local/ssl/include/openssl .)
  349. fi
  350. # Warning if not use the system ssl.
  351. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then
  352. echo "Warning: Local openssl is on, ignore system openssl"
  353. fi
  354. fi
  355. # Patch for loongarch mips64, disable ASM for build failed message as bellow:
  356. # Error: opcode not supported on this processor: mips3 (mips3)
  357. if [[ $OS_IS_MIPS64 == YES ]]; then OPENSSL_CONFIG="./Configure linux64-mips64"; fi
  358. if [[ $OS_IS_LOONGSON == YES ]]; then OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm"; fi
  359. # For RTC, we should use ASM to improve performance, not a little improving.
  360. if [[ $SRS_RTC == NO || $SRS_NASM == NO ]]; then
  361. OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm"
  362. echo "Warning: NASM is off, performance is hurt"
  363. fi
  364. # Mac OS X can have issues (its often a neglected platform).
  365. # @see https://wiki.openssl.org/index.php/Compilation_and_Installation
  366. if [[ $SRS_OSX == YES ]]; then
  367. export KERNEL_BITS=64;
  368. fi
  369. # Use 1.0 if required.
  370. if [[ $SRS_SSL_1_0 == YES ]]; then
  371. OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild.
  372. OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" &&
  373. OPENSSL_UNZIP="tar xf ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM}"
  374. else
  375. OPENSSL_AR="$SRS_TOOL_AR"
  376. OPENSSL_CANDIDATE="openssl-1.1-fit" &&
  377. OPENSSL_UNZIP="cp -R ${SRS_WORKDIR}/3rdparty/$OPENSSL_CANDIDATE ${SRS_OBJS}/${SRS_PLATFORM}/"
  378. fi
  379. #
  380. # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
  381. # Already defined: -no-shared -no-threads -no-asm
  382. # Should enable: -no-dtls -no-dtls1 -no-ssl3
  383. # Might able to disable: -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers
  384. # Note that we do not disable more features, because no file could be removed.
  385. #OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-ssl2 -no-comp -no-idea -no-hw -no-engine -no-dso -no-err -no-nextprotoneg -no-psk -no-srp -no-ec2m -no-weak-ssl-ciphers"
  386. #
  387. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  388. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl/lib/libssl.a ]]; then
  389. rm -rf ${SRS_OBJS}/openssl && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl ${SRS_OBJS}/ &&
  390. echo "The $OPENSSL_CANDIDATE is ok."
  391. else
  392. echo "Building $OPENSSL_CANDIDATE." &&
  393. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl \
  394. ${SRS_OBJS}/openssl &&
  395. ${OPENSSL_UNZIP} &&
  396. (
  397. cd ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} &&
  398. chmod +x ./config ./Configure &&
  399. ${OPENSSL_CONFIG} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/openssl $OPENSSL_OPTIONS
  400. ) &&
  401. make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" \
  402. LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} &&
  403. make -C ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} install_sw &&
  404. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/openssl ${SRS_OBJS}/ &&
  405. echo "The $OPENSSL_CANDIDATE is ok."
  406. fi
  407. # check status
  408. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi
  409. fi
  410. #####################################################################################
  411. # srtp
  412. #####################################################################################
  413. if [[ $SRS_RTC == YES && $SRS_USE_SYS_SRTP == YES ]]; then
  414. echo "Warning: Use system libsrtp, without compiling srtp."
  415. fi
  416. if [[ $SRS_RTC == YES && $SRS_USE_SYS_SRTP == NO ]]; then
  417. SRTP_OPTIONS=""
  418. # To eliminate warnings, see https://stackoverflow.com/a/34208904/17679565
  419. # was built for newer macOS version (11.6) than being linked (11.0)
  420. if [[ $SRS_OSX == YES ]]; then
  421. export MACOSX_DEPLOYMENT_TARGET=11.0
  422. echo "Set MACOSX_DEPLOYMENT_TARGET to avoid warnings"
  423. fi
  424. # If use ASM for SRTP, we enable openssl(with ASM).
  425. if [[ $SRS_SRTP_ASM == YES ]]; then
  426. SRTP_OPTIONS="--enable-openssl"
  427. SRTP_CONFIGURE="env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig ./configure"
  428. else
  429. SRTP_OPTIONS="--disable-openssl"
  430. SRTP_CONFIGURE="./configure"
  431. fi
  432. if [[ $SRS_CROSS_BUILD == YES ]]; then
  433. SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST"
  434. fi
  435. if [[ $OS_IS_LOONGARCH64 == YES ]]; then
  436. SRTP_OPTIONS="$SRTP_OPTIONS --build=loongarch64-unknown-linux-gnu"
  437. fi
  438. # Copy and patch source files, then build and install libsrtp.
  439. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2/lib/libsrtp2.a ]]; then
  440. rm -rf ${SRS_OBJS}/srtp2 &&
  441. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 ${SRS_OBJS} &&
  442. echo "The libsrtp-2-fit is ok."
  443. else
  444. echo "Building libsrtp-2-fit."
  445. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 \
  446. ${SRS_OBJS}/srtp2 &&
  447. cp -rf ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
  448. # For cygwin64, the patch is not available, so use sed instead.
  449. if [[ $SRS_CYGWIN64 == YES ]]; then
  450. sed -i 's/char bit_string/static char bit_string/g' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c
  451. else
  452. patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch
  453. fi &&
  454. # Patch the cpu arch guessing for RISCV.
  455. if [[ $OS_IS_RISCV == YES ]]; then
  456. patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch
  457. fi &&
  458. (
  459. cd ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit &&
  460. $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/srtp2
  461. ) &&
  462. # Sometimes it might fail because autoconf failed to generate crypto/include.config.h
  463. if [[ $SRS_CYGWIN64 == YES ]]; then
  464. SRS_PATCH_SOURCE=${SRS_WORKDIR}/3rdparty/patches/srtp/cygwin-crypto-include-config.h
  465. if [[ $SRS_SRTP_ASM == YES ]]; then
  466. SRS_PATCH_SOURCE=${SRS_WORKDIR}/3rdparty/patches/srtp/cygwin-gcm-crypto-include-config.h
  467. fi
  468. grep -q 'HAVE_UINT64_T 1' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/include/config.h ||
  469. cp -f $SRS_PATCH_SOURCE ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/include/config.h
  470. fi &&
  471. make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_JOBS} &&
  472. make -C ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit install &&
  473. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srtp2 ${SRS_OBJS}/ &&
  474. echo "The libsrtp-2-fit is ok."
  475. fi
  476. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp failed, ret=$ret"; exit $ret; fi
  477. fi
  478. #####################################################################################
  479. # libopus, for WebRTC to transcode AAC with Opus.
  480. #####################################################################################
  481. # For cross build, we use opus of FFmpeg, so we don't build the libopus.
  482. if [[ $SRS_RTC == YES && $SRS_USE_SYS_FFMPEG != YES && $SRS_FFMPEG_OPUS != YES ]]; then
  483. # Only build static libraries if no shared FFmpeg.
  484. if [[ $SRS_SHARED_FFMPEG != YES ]]; then
  485. OPUS_OPTIONS="--disable-shared --disable-doc"
  486. fi
  487. if [[ $OS_IS_LOONGARCH64 == YES ]]; then
  488. OPUS_OPTIONS="$OPUS_OPTIONS --build=loongarch64-unknown-linux-gnu"
  489. fi
  490. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus/lib/libopus.a ]]; then
  491. rm -rf ${SRS_OBJS}/opus && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/ &&
  492. echo "The opus-1.3.1 is ok."
  493. else
  494. echo "Building opus-1.3.1." &&
  495. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/opus &&
  496. tar xf ${SRS_WORKDIR}/3rdparty/opus-1.3.1.tar.gz -C ${SRS_OBJS}/${SRS_PLATFORM} &&
  497. (
  498. # Opus requires automake 1.15, and fails for automake 1.16+, so we run autoreconf to fix it.
  499. cd ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && autoreconf &&
  500. ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/opus --enable-static $OPUS_OPTIONS
  501. ) &&
  502. make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 ${SRS_JOBS} &&
  503. make -C ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 install &&
  504. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/opus ${SRS_OBJS}/ &&
  505. echo "The opus-1.3.1 is ok."
  506. fi
  507. if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi
  508. fi
  509. #####################################################################################
  510. # ffmpeg-fit, for WebRTC to transcode AAC with Opus.
  511. #####################################################################################
  512. if [[ $SRS_FFMPEG_FIT == YES && $SRS_USE_SYS_FFMPEG == YES ]]; then
  513. echo "Warning: Use system ffmpeg, without compiling ffmpeg."
  514. fi
  515. if [[ $SRS_FFMPEG_FIT == YES && $SRS_USE_SYS_FFMPEG == NO ]]; then
  516. FFMPEG_CONFIGURE="env SRS_FFMPEG_FIT=on"
  517. if [[ $SRS_FFMPEG_OPUS != YES ]]; then
  518. FFMPEG_CONFIGURE="$FFMPEG_CONFIGURE PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/opus/lib/pkgconfig"
  519. fi
  520. FFMPEG_CONFIGURE="$FFMPEG_CONFIGURE ./configure"
  521. # Disable all features, note that there are still some options need to be disabled.
  522. FFMPEG_OPTIONS="--disable-everything"
  523. # Disable all asm for FFmpeg, to compatible with ARM CPU.
  524. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-asm --disable-x86asm --disable-inline-asm"
  525. # Only build static libraries if no shared FFmpeg.
  526. if [[ $SRS_SHARED_FFMPEG == YES ]]; then
  527. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-shared"
  528. fi
  529. # For loongson/mips64, disable mips64r6, or build failed.
  530. if [[ $OS_IS_MIPS64 == YES && $OS_IS_LOONGSON == YES ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-mips64r6"; fi
  531. # For cross-build.
  532. if [[ $SRS_CROSS_BUILD == YES ]]; then
  533. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-cross-compile --target-os=linux --disable-pthreads"
  534. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --arch=$SRS_CROSS_BUILD_ARCH";
  535. if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cpu=$SRS_CROSS_BUILD_CPU"; fi
  536. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cross-prefix=$SRS_CROSS_BUILD_PREFIX"
  537. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cc=${SRS_TOOL_CC} --cxx=${SRS_TOOL_CXX} --ar=${SRS_TOOL_AR} --ld=${SRS_TOOL_LD}"
  538. fi
  539. # For audio codec opus, use FFmpeg native one, or external libopus.
  540. if [[ $SRS_FFMPEG_OPUS == YES ]]; then
  541. # TODO: FIXME: Note that the audio might be corrupted, see https://github.com/ossrs/srs/issues/3140
  542. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=opus --enable-encoder=opus"
  543. else
  544. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus"
  545. fi
  546. # Disable features of ffmpeg.
  547. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-avdevice --disable-avformat --disable-swscale --disable-postproc --disable-avfilter --disable-network"
  548. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-dwt --disable-error-resilience --disable-lsp --disable-lzo --disable-faan --disable-pixelutils"
  549. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuvid"
  550. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi"
  551. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv"
  552. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --disable-lzma --disable-sdl2"
  553. # Enable FFmpeg native AAC encoder and decoder.
  554. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm --enable-encoder=aac"
  555. # Enable FFmpeg native MP3 decoder, which depends on dct.
  556. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=mp3 --enable-dct"
  557. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg/lib/libavcodec.a ]]; then
  558. rm -rf ${SRS_OBJS}/ffmpeg && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg ${SRS_OBJS}/ &&
  559. echo "The ffmpeg-4-fit is ok."
  560. else
  561. echo "Building ffmpeg-4-fit." &&
  562. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg \
  563. ${SRS_OBJS}/ffmpeg &&
  564. cp -rf ${SRS_WORKDIR}/3rdparty/ffmpeg-4-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
  565. (
  566. cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit &&
  567. $FFMPEG_CONFIGURE --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/ffmpeg \
  568. --pkg-config=pkg-config --pkg-config-flags='--static' --extra-libs='-lpthread' --extra-libs='-lm' \
  569. ${FFMPEG_OPTIONS}
  570. ) &&
  571. # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/
  572. if [[ $SRS_CROSS_BUILD == YES ]]; then
  573. sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  574. sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  575. sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  576. # For MIPS, which fail with:
  577. # ./libavutil/libm.h:54:32: error: static declaration of 'cbrt' follows non-static declaration
  578. # /root/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/include/math.h:163:13: note: previous declaration of 'cbrt' was here
  579. if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" || $SRS_CROSS_BUILD_ARCH == "arm" ]]; then
  580. sed -i -e 's/#define HAVE_CBRT 0/#define HAVE_CBRT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  581. sed -i -e 's/#define HAVE_CBRTF 0/#define HAVE_CBRTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  582. sed -i -e 's/#define HAVE_COPYSIGN 0/#define HAVE_COPYSIGN 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  583. sed -i -e 's/#define HAVE_ERF 0/#define HAVE_ERF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  584. sed -i -e 's/#define HAVE_HYPOT 0/#define HAVE_HYPOT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  585. sed -i -e 's/#define HAVE_RINT 0/#define HAVE_RINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  586. sed -i -e 's/#define HAVE_LRINT 0/#define HAVE_LRINT 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  587. sed -i -e 's/#define HAVE_LRINTF 0/#define HAVE_LRINTF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  588. sed -i -e 's/#define HAVE_ROUND 0/#define HAVE_ROUND 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  589. sed -i -e 's/#define HAVE_ROUNDF 0/#define HAVE_ROUNDF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  590. sed -i -e 's/#define HAVE_TRUNC 0/#define HAVE_TRUNC 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  591. sed -i -e 's/#define HAVE_TRUNCF 0/#define HAVE_TRUNCF 1/g' ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/config.h &&
  592. echo "FFmpeg sed ok"
  593. fi
  594. fi &&
  595. make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit ${SRS_JOBS} &&
  596. make -C ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit install &&
  597. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/ffmpeg ${SRS_OBJS}/ &&
  598. echo "The ffmpeg-4-fit is ok."
  599. fi
  600. # check status
  601. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi
  602. fi
  603. #####################################################################################
  604. # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2.
  605. #####################################################################################
  606. # Guess where is the ffmpeg.
  607. SYSTEMP_FFMPEG_BIN=`which ffmpeg`
  608. # Always link the ffmpeg tools if exists.
  609. if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
  610. mkdir -p ${SRS_OBJS}/ffmpeg/bin &&
  611. cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/
  612. fi
  613. if [[ $SRS_FFMPEG_TOOL == YES ]]; then
  614. if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
  615. cp -f $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/ffmpeg/bin/ &&
  616. echo "ffmpeg-4.1 is ok.";
  617. else
  618. echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}"
  619. echo -e "${RED} Please copy it from srs-docker${BLACK}"
  620. echo -e "${RED} or download from http://ffmpeg.org/download.html${BLACK}"
  621. echo -e "${RED} or disable it by --without-ffmpeg${BLACK}"
  622. exit -1;
  623. fi
  624. fi
  625. #####################################################################################
  626. # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119
  627. #####################################################################################
  628. if [[ $SRS_SRT == YES && $SRS_USE_SYS_SRT == YES ]]; then
  629. echo "Warning: Use system libsrt, without compiling srt."
  630. fi
  631. if [[ $SRS_SRT == YES && $SRS_USE_SYS_SRT == NO ]]; then
  632. # Always disable c++11 for libsrt, because only the srt-app requres it.
  633. LIBSRT_OPTIONS="--enable-apps=0 --enable-static=1 --enable-c++11=0"
  634. if [[ $SRS_SHARED_SRT == YES ]]; then
  635. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1"
  636. else
  637. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0"
  638. fi
  639. # For windows build, over cygwin
  640. if [[ $SRS_CYGWIN64 == YES ]]; then
  641. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix"
  642. fi
  643. # For cross-build.
  644. if [[ $SRS_CROSS_BUILD == YES ]]; then
  645. TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC))
  646. SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/')
  647. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX"
  648. fi
  649. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib/libsrt.a ]]; then
  650. rm -rf ${SRS_OBJS}/srt && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/ &&
  651. echo "libsrt-1-fit is ok."
  652. else
  653. if [[ $SRS_USE_SYS_SSL != YES && ! -d ${SRS_OBJS}/openssl/lib/pkgconfig ]]; then
  654. echo "OpenSSL pkgconfig no found, build srt-1-fit failed."
  655. exit -1
  656. fi
  657. echo "Build srt-1-fit" &&
  658. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/srt &&
  659. cp -rf ${SRS_WORKDIR}/3rdparty/srt-1-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
  660. patch -p0 -R ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit/srtcore/api.cpp ${SRS_WORKDIR}/3rdparty/patches/srt/api.cpp-01.patch &&
  661. (
  662. cd ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit &&
  663. env PKG_CONFIG_PATH=${SRS_DEPENDS_LIBS}/openssl/lib/pkgconfig \
  664. ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/srt $LIBSRT_OPTIONS
  665. ) &&
  666. make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit ${SRS_JOBS} &&
  667. make -C ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit install &&
  668. # If exists lib64 of libsrt, copy it to lib
  669. if [[ -d ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib64 ]]; then
  670. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib64 ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt/lib
  671. fi &&
  672. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/srt ${SRS_OBJS}/ &&
  673. echo "libsrt-1-fit is ok."
  674. fi
  675. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi
  676. fi
  677. #####################################################################################
  678. # build utest code
  679. #####################################################################################
  680. if [[ $SRS_UTEST == YES ]]; then
  681. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest/googletest/include/gtest/gtest.h ]]; then
  682. rm -rf ${SRS_OBJS}/gtest && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/ &&
  683. echo "The gtest-fit is ok."
  684. else
  685. echo "Build gtest-fit" &&
  686. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/gtest &&
  687. cp -rf ${SRS_WORKDIR}/3rdparty/gtest-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest &&
  688. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gtest ${SRS_OBJS}/ &&
  689. echo "The gtest-fit is ok."
  690. fi
  691. # check status
  692. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi
  693. fi
  694. #####################################################################################
  695. # build gperf code
  696. #####################################################################################
  697. if [[ $SRS_GPERF == YES ]]; then
  698. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf/bin/pprof ]]; then
  699. rm -rf ${SRS_OBJS}/gperf && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf ${SRS_OBJS}/ &&
  700. cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ &&
  701. echo "The gperftools-2-fit is ok."
  702. else
  703. echo "Build gperftools-2-fit" &&
  704. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf \
  705. ${SRS_OBJS}/gperf ${SRS_OBJS}/pprof &&
  706. cp -rf ${SRS_WORKDIR}/3rdparty/gperftools-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
  707. (
  708. cd ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit &&
  709. ./configure --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdparty/gperf --enable-frame-pointers
  710. ) &&
  711. make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit ${SRS_JOBS} &&
  712. make -C ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit install &&
  713. cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/gperf ${SRS_OBJS}/ &&
  714. cp -f ${SRS_OBJS}/gperf/bin/pprof ${SRS_OBJS}/ &&
  715. echo "The gperftools-2-fit is ok."
  716. fi
  717. # check status
  718. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2-fit failed, ret=$ret"; exit $ret; fi
  719. fi