2
0

depends.sh 38 KB

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