2
0

depends.sh 39 KB

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