2
0

depends.sh 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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. # utilities
  13. #####################################################################################
  14. function require_sudoer()
  15. {
  16. sudo echo "" >/dev/null 2>&1
  17. ret=$?; if [[ 0 -ne $ret ]]; then
  18. echo "\"$1\" require sudoer failed. ret=$ret";
  19. exit $ret;
  20. fi
  21. }
  22. # TODO: check gcc/g++
  23. echo "Checking gcc/g++/gdb/make."
  24. echo "Required tools are ok."
  25. #####################################################################################
  26. # for Ubuntu, auto install tools by apt-get
  27. #####################################################################################
  28. OS_IS_UBUNTU=NO
  29. function Ubuntu_prepare()
  30. {
  31. uname -v|grep Ubuntu >/dev/null 2>&1
  32. ret=$?; if [[ 0 -ne $ret ]]; then
  33. # for debian, we think it's ubuntu also.
  34. # for example, the wheezy/sid which is debian armv7 linux, can not identified by uname -v.
  35. if [[ ! -f /etc/debian_version ]]; then
  36. return 0;
  37. fi
  38. fi
  39. OS_IS_UBUNTU=YES
  40. echo "Installing tools for Ubuntu."
  41. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  42. echo "Installing gcc."
  43. require_sudoer "sudo apt-get install -y --force-yes gcc"
  44. sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  45. echo "The gcc is installed."
  46. fi
  47. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  48. echo "Installing g++."
  49. require_sudoer "sudo apt-get install -y --force-yes g++"
  50. sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  51. echo "The g++ is installed."
  52. fi
  53. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  54. echo "Installing make."
  55. require_sudoer "sudo apt-get install -y --force-yes make"
  56. sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  57. echo "The make is installed."
  58. fi
  59. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  60. echo "Installing patch."
  61. require_sudoer "sudo apt-get install -y --force-yes patch"
  62. sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  63. echo "The patch is installed."
  64. fi
  65. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  66. echo "Installing unzip."
  67. require_sudoer "sudo apt-get install -y --force-yes unzip"
  68. sudo apt-get install -y --force-yes unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  69. echo "The unzip is installed."
  70. fi
  71. if [[ $SRS_VALGRIND == YES ]]; then
  72. valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  73. echo "Installing valgrind."
  74. require_sudoer "sudo apt-get install -y --force-yes valgrind"
  75. sudo apt-get install -y --force-yes valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  76. echo "The valgrind is installed."
  77. fi
  78. fi
  79. if [[ $SRS_VALGRIND == YES ]]; then
  80. if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
  81. echo "Installing valgrind-dev."
  82. require_sudoer "sudo apt-get install -y --force-yes valgrind-dbg"
  83. sudo apt-get install -y --force-yes valgrind-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  84. echo "The valgrind-dev is installed."
  85. fi
  86. fi
  87. if [[ $SRS_SRT == YES ]]; then
  88. echo "SRT enable, install depend tools"
  89. tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  90. echo "Installing tcl."
  91. require_sudoer "sudo apt-get install -y --force-yes tcl"
  92. sudo apt-get install -y --force-yes tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  93. echo "The tcl is installed."
  94. fi
  95. cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  96. echo "Installing cmake."
  97. require_sudoer "sudo apt-get install -y --force-yes cmake"
  98. sudo apt-get install -y --force-yes cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  99. echo "The cmake is installed."
  100. fi
  101. fi
  102. pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  103. echo "Installing pkg-config."
  104. require_sudoer "sudo apt-get install -y --force-yes pkg-config"
  105. sudo apt-get install -y --force-yes pkg-config; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  106. echo "The pkg-config is installed."
  107. fi
  108. echo "Tools for Ubuntu are installed."
  109. return 0
  110. }
  111. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  112. Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for ubuntu failed, ret=$ret"; exit $ret; fi
  113. #####################################################################################
  114. # for Centos, auto install tools by yum
  115. #####################################################################################
  116. OS_IS_CENTOS=NO
  117. function Centos_prepare()
  118. {
  119. if [[ ! -f /etc/redhat-release ]]; then
  120. return 0;
  121. fi
  122. OS_IS_CENTOS=YES
  123. echo "Installing tools for Centos."
  124. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  125. echo "Installing gcc."
  126. require_sudoer "sudo yum install -y gcc"
  127. sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  128. echo "The gcc is installed."
  129. fi
  130. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  131. echo "Installing gcc-c++."
  132. require_sudoer "sudo yum install -y gcc-c++"
  133. sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  134. echo "The gcc-c++ is installed."
  135. fi
  136. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  137. echo "Installing make."
  138. require_sudoer "sudo yum install -y make"
  139. sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  140. echo "The make is installed."
  141. fi
  142. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  143. echo "Installing patch."
  144. require_sudoer "sudo yum install -y patch"
  145. sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  146. echo "The patch is installed."
  147. fi
  148. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  149. echo "Installing unzip."
  150. require_sudoer "sudo yum install -y unzip"
  151. sudo yum install -y unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  152. echo "The unzip is installed."
  153. fi
  154. if [[ $SRS_VALGRIND == YES ]]; then
  155. valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  156. echo "Installing valgrind."
  157. require_sudoer "sudo yum install -y valgrind"
  158. sudo yum install -y valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  159. echo "The valgrind is installed."
  160. fi
  161. fi
  162. if [[ $SRS_VALGRIND == YES ]]; then
  163. if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
  164. echo "Installing valgrind-devel."
  165. require_sudoer "sudo yum install -y valgrind-devel"
  166. sudo yum install -y valgrind-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  167. echo "The valgrind-devel is installed."
  168. fi
  169. fi
  170. if [[ $SRS_SRT == YES ]]; then
  171. echo "SRT enable, install depend tools"
  172. tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  173. echo "Installing tcl."
  174. require_sudoer "sudo yum install -y tcl"
  175. sudo yum install -y tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  176. echo "The tcl is installed."
  177. fi
  178. cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  179. echo "Installing cmake."
  180. require_sudoer "sudo yum install -y cmake"
  181. sudo yum install -y cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  182. echo "The cmake is installed."
  183. fi
  184. fi
  185. pkg-config --version --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  186. echo "Please install pkg-config"; exit -1;
  187. fi
  188. echo "Tools for Centos are installed."
  189. return 0
  190. }
  191. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  192. Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for CentOS failed, ret=$ret"; exit $ret; fi
  193. #####################################################################################
  194. # For OSX, auto install tools by brew
  195. #####################################################################################
  196. OS_IS_OSX=NO
  197. function OSX_prepare()
  198. {
  199. uname -s|grep Darwin >/dev/null 2>&1
  200. ret=$?; if [[ 0 -ne $ret ]]; then
  201. if [ $SRS_OSX = YES ]; then
  202. echo "OSX check failed, actual is `uname -s`"
  203. exit 1;
  204. fi
  205. return 0;
  206. fi
  207. # cross build for arm, install the cross build tool chain.
  208. if [ $SRS_CROSS_BUILD = YES ]; then
  209. echo "The embeded(arm/mips) is invalid for OSX"
  210. return 1
  211. fi
  212. OS_IS_OSX=YES
  213. # requires the osx when os
  214. if [ $OS_IS_OSX = YES ]; then
  215. if [ $SRS_OSX = NO ]; then
  216. echo "OSX detected, please use: ./configure --osx"
  217. exit 1
  218. fi
  219. fi
  220. echo "OSX detected, install tools if needed"
  221. brew --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  222. echo "install brew"
  223. echo "ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\""
  224. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  225. echo "install brew success"
  226. fi
  227. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  228. echo "install gcc"
  229. echo "brew install gcc"
  230. brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  231. echo "install gcc success"
  232. fi
  233. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  234. echo "install gcc-c++"
  235. echo "brew install gcc-c++"
  236. brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  237. echo "install gcc-c++ success"
  238. fi
  239. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  240. echo "install make"
  241. echo "brew install make"
  242. brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  243. echo "install make success"
  244. fi
  245. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  246. echo "install patch"
  247. echo "brew install patch"
  248. brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  249. echo "install patch success"
  250. fi
  251. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  252. echo "install unzip"
  253. echo "brew install unzip"
  254. brew install unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  255. echo "install unzip success"
  256. fi
  257. pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  258. echo "Please install pkg-config"; exit -1;
  259. fi
  260. if [[ $SRS_SRT == YES ]]; then
  261. echo "SRT enable, install depend tools"
  262. tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  263. echo "Installing tcl."
  264. echo "brew install tcl."
  265. brew install tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  266. echo "install tcl success"
  267. fi
  268. cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  269. echo "Installing cmake."
  270. echo "brew install cmake."
  271. brew install cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  272. echo "install cmake success"
  273. fi
  274. fi
  275. echo "OSX install tools success"
  276. return 0
  277. }
  278. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  279. OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi
  280. #####################################################################################
  281. # Whether CPU is loongarch
  282. #####################################################################################
  283. OS_IS_LOONGARCH=$(uname -p|grep -q loongarch && echo YES)
  284. #####################################################################################
  285. # for Centos, auto install tools by yum
  286. #####################################################################################
  287. # We must use a bash function instead of variable.
  288. function sed_utility() {
  289. if [ $OS_IS_OSX = YES ]; then
  290. sed -i '' "$@"
  291. else
  292. sed -i "$@"
  293. fi
  294. ret=$?; if [[ $ret -ne 0 ]]; then
  295. if [ $OS_IS_OSX = YES ]; then
  296. echo "sed -i '' \"$@\""
  297. else
  298. echo "sed -i \"$@\""
  299. fi
  300. return $ret
  301. fi
  302. }
  303. SED="sed_utility" && echo "SED is $SED"
  304. function _srs_link_file()
  305. {
  306. tmp_dir=$1; if [[ $tmp_dir != *'/' ]]; then tmp_dir+='/'; fi
  307. tmp_dest=$2; if [[ $tmp_dest != *'/' ]]; then tmp_dest+='/'; fi
  308. tmp_prefix=$3; if [[ $tmp_prefix != *'/' ]]; then tmp_prefix+='/'; fi
  309. echo "LINK files at dir: $tmp_dir, dest: $tmp_dest, prefix: $tmp_prefix, pwd: `pwd`"
  310. for file in `(cd $tmp_dir && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '*.log')`; do
  311. basefile=`basename $file` &&
  312. #echo "ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile" &&
  313. ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile;
  314. done
  315. }
  316. #####################################################################################
  317. # check the os.
  318. #####################################################################################
  319. # Only supports:
  320. # linux, centos/ubuntu as such,
  321. # cross build for embeded system, for example, mips or arm,
  322. # directly build on arm/mips, for example, pi or cubie,
  323. # export srs-librtmp
  324. # others is invalid.
  325. if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_CROSS_BUILD = NO ]]; then
  326. echo "Your OS `uname -s` is not supported."
  327. exit 1
  328. fi
  329. #####################################################################################
  330. # state-threads
  331. #####################################################################################
  332. # check the cross build flag file, if flag changed, need to rebuild the st.
  333. _ST_MAKE=linux-debug && _ST_OBJ="LINUX_`uname -r`_DBG"
  334. # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676
  335. _ST_EXTRA_CFLAGS="-DMALLOC_STACK"
  336. # For valgrind to detect memory issues.
  337. if [[ $SRS_VALGRIND == YES ]]; then
  338. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND"
  339. fi
  340. # for osx, use darwin for st, donot use epoll.
  341. if [[ $SRS_OSX == YES ]]; then
  342. _ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG"
  343. fi
  344. # For Ubuntu, the epoll detection might be fail.
  345. if [[ $OS_IS_UBUNTU == YES ]]; then
  346. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL"
  347. fi
  348. # Whether enable debug stats.
  349. if [[ $SRS_DEBUG_STATS == YES ]]; then
  350. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS"
  351. fi
  352. # Pass the global extra flags.
  353. if [[ $SRS_EXTRA_FLAGS != '' ]]; then
  354. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
  355. fi
  356. # Whether link as .so
  357. if [[ $SRS_SHARED_ST == YES ]]; then
  358. _ST_STATIC_ONLY=no;
  359. else
  360. _ST_STATIC_ONLY=yes;
  361. fi
  362. # The final args to make st.
  363. _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}"
  364. _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}"
  365. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  366. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ]]; then
  367. echo "The state-threads is ok.";
  368. else
  369. echo "Building state-threads.";
  370. (
  371. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs &&
  372. # Create a hidden directory .src
  373. cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src &&
  374. # Link source files under .src
  375. _srs_link_file .src/ ./ ./ &&
  376. # Build source code.
  377. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} &&
  378. cd .. && rm -rf st && ln -sf st-srs/${_ST_OBJ} st
  379. )
  380. fi
  381. # check status
  382. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi
  383. # Always update the links.
  384. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf st && ln -sf st-srs/${_ST_OBJ} st)
  385. (cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st)
  386. if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi
  387. #####################################################################################
  388. # nginx for HLS, nginx-1.5.0
  389. #####################################################################################
  390. function write_nginx_html5()
  391. {
  392. cat<<END > ${html_file}
  393. <video width="100%" autoplay controls autobuffer type="application/vnd.apple.mpegurl"
  394. src="${hls_stream}">
  395. </video>
  396. END
  397. }
  398. # create the nginx dir, for http-server if not build nginx
  399. mkdir -p ${SRS_OBJS}/nginx
  400. # the demo dir.
  401. # create forward dir
  402. mkdir -p ${SRS_OBJS}/nginx/html/live &&
  403. html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  404. # copy players to nginx html dir.
  405. rm -rf ${SRS_OBJS}/nginx/html/players &&
  406. ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players
  407. # for favicon.ico
  408. rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
  409. ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico
  410. # For srs-console.
  411. rm -rf ${SRS_OBJS}/nginx/html/console &&
  412. ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console
  413. # For SRS signaling.
  414. rm -rf ${SRS_OBJS}/nginx/html/demos &&
  415. ln -sf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/demos
  416. # For home page index.html
  417. rm -rf ${SRS_OBJS}/nginx/html/index.html &&
  418. ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html
  419. # nginx.html to detect whether nginx is alive
  420. echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html
  421. #####################################################################################
  422. # Generate default self-sign certificate for HTTPS server, test only.
  423. #####################################################################################
  424. if [[ ! -f conf/server.key || ! -f conf/server.crt ]]; then
  425. openssl genrsa -out conf/server.key 2048
  426. openssl req -new -x509 -key conf/server.key -out conf/server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net"
  427. echo "Generate test-only self-sign certificate files"
  428. fi
  429. #####################################################################################
  430. # cherrypy for http hooks callback, CherryPy-3.2.4
  431. #####################################################################################
  432. if [[ $SRS_CHERRYPY == YES ]]; then
  433. # Detect python or python2
  434. python --version >/dev/null 2>&1 && SYS_PYTHON=python;
  435. python2 --version >/dev/null 2>&1 && SYS_PYTHON=python2;
  436. # Install cherrypy for api server.
  437. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then
  438. echo "CherryPy-3.2.4 is ok.";
  439. else
  440. echo "Installing CherryPy-3.2.4";
  441. (
  442. rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  443. unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 &&
  444. $SYS_PYTHON setup.py install --user --prefix=''
  445. )
  446. fi
  447. # check status
  448. ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi
  449. if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
  450. echo "Link players to cherrypy static-dir"
  451. rm -rf research/api-server/static-dir/players &&
  452. ln -sf `pwd`/research/players research/api-server/static-dir/players &&
  453. rm -rf research/api-server/static-dir/live &&
  454. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
  455. ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
  456. rm -rf research/api-server/static-dir/forward &&
  457. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
  458. ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
  459. ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi
  460. fi
  461. #####################################################################################
  462. # openssl, for rtmp complex handshake and HLS encryption.
  463. #####################################################################################
  464. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
  465. echo "Warning: Use system libssl, without compiling openssl."
  466. fi
  467. # @see http://www.openssl.org/news/secadv/20140407.txt
  468. # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately
  469. # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
  470. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then
  471. OPENSSL_OPTIONS="-no-shared -no-threads -DOPENSSL_NO_HEARTBEATS"
  472. OPENSSL_CONFIG="./config"
  473. # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain
  474. if [[ $SRS_CROSS_BUILD == YES ]]; then
  475. OPENSSL_CONFIG="./Configure linux-generic32"
  476. if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi
  477. if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi
  478. if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then OPENSSL_CONFIG="./Configure linux-mips32"; fi
  479. elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then
  480. # Try to use exists libraries.
  481. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then
  482. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib &&
  483. ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a &&
  484. mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig)
  485. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include &&
  486. ln -sf /usr/local/ssl/include/openssl)
  487. fi
  488. # Warning if not use the system ssl.
  489. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then
  490. echo "Warning: Local openssl is on, ignore system openssl"
  491. fi
  492. fi
  493. # For RTC, we should use ASM to improve performance, not a little improving.
  494. if [[ $SRS_RTC == NO || $SRS_NASM == NO ]]; then
  495. OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm"
  496. echo "Warning: NASM is off, performance is hurt"
  497. fi
  498. # Mac OS X can have issues (its often a neglected platform).
  499. # @see https://wiki.openssl.org/index.php/Compilation_and_Installation
  500. if [[ $SRS_OSX == YES ]]; then
  501. export KERNEL_BITS=64;
  502. fi
  503. # Use 1.0 if required.
  504. if [[ $SRS_SSL_1_0 == YES ]]; then
  505. OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild.
  506. OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && OPENSSL_UNZIP="tar xf ../../3rdparty/$OPENSSL_CANDIDATE.tar.gz"
  507. else
  508. OPENSSL_AR="$SRS_TOOL_AR"
  509. OPENSSL_CANDIDATE="openssl-1.1-fit" && OPENSSL_UNZIP="cp -R ../../3rdparty/$OPENSSL_CANDIDATE ."
  510. fi
  511. #
  512. # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
  513. # Already defined: -no-shared -no-threads -no-asm
  514. # Should enable: -no-dtls -no-dtls1 -no-ssl3
  515. # 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
  516. # Note that we do not disable more features, because no file could be removed.
  517. #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"
  518. #
  519. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  520. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/$OPENSSL_CANDIDATE/_release/lib/libssl.a ]]; then
  521. echo "The $OPENSSL_CANDIDATE is ok.";
  522. else
  523. echo "Building $OPENSSL_CANDIDATE.";
  524. (
  525. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  526. ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=`pwd`/_release $OPENSSL_OPTIONS &&
  527. make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw &&
  528. cd .. && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl
  529. )
  530. fi
  531. # Which lib we use.
  532. OPENSSL_LIB="$OPENSSL_CANDIDATE/_release"
  533. if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then
  534. OPENSSL_LIB="openssl"
  535. fi
  536. # check status
  537. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi
  538. # Always update the links.
  539. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl)
  540. (cd ${SRS_OBJS} && rm -rf openssl && ln -sf ${SRS_PLATFORM}/${OPENSSL_LIB} openssl)
  541. if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build $OPENSSL_CANDIDATE failed."; exit -1; fi
  542. fi
  543. #####################################################################################
  544. # srtp
  545. #####################################################################################
  546. if [[ $SRS_RTC == YES ]]; then
  547. SRTP_OPTIONS=""
  548. # To eliminate warnings, see https://stackoverflow.com/a/34208904/17679565
  549. # was built for newer macOS version (11.6) than being linked (11.0)
  550. if [[ $SRS_OSX == YES ]]; then
  551. export MACOSX_DEPLOYMENT_TARGET=11.0
  552. echo "Set MACOSX_DEPLOYMENT_TARGET to avoid warnings"
  553. fi
  554. # If use ASM for SRTP, we enable openssl(with ASM).
  555. if [[ $SRS_SRTP_ASM == YES ]]; then
  556. SRTP_OPTIONS="--enable-openssl"
  557. SRTP_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/openssl/lib/pkgconfig ./configure"
  558. else
  559. SRTP_CONFIGURE="./configure"
  560. fi
  561. if [[ $SRS_CROSS_BUILD == YES ]]; then
  562. SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST"
  563. fi
  564. if [[ $OS_IS_LOONGARCH = YES ]]; then
  565. SRTP_OPTIONS="$SRTP_OPTIONS --build=loongarch64-unknown-linux-gnu"
  566. fi
  567. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  568. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/_release/lib/libsrtp2.a ]]; then
  569. echo "The libsrtp-2-fit is ok.";
  570. else
  571. echo "Building libsrtp-2-fit.";
  572. (
  573. rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  574. rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit &&
  575. patch -p0 crypto/math/datatypes.c ../../../3rdparty/patches/srtp/gcc10-01.patch &&
  576. $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release &&
  577. make ${SRS_JOBS} && make install &&
  578. cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2
  579. )
  580. fi
  581. # check status
  582. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp-2-fit failed, ret=$ret"; exit $ret; fi
  583. # Always update the links.
  584. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2)
  585. (cd ${SRS_OBJS} && rm -rf srtp2 && ln -sf ${SRS_PLATFORM}/libsrtp-2-fit/_release srtp2)
  586. if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit static lib failed."; exit -1; fi
  587. fi
  588. #####################################################################################
  589. # libopus, for WebRTC to transcode AAC with Opus.
  590. #####################################################################################
  591. # For cross build, we use opus of FFmpeg, so we don't build the libopus.
  592. if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then
  593. # Only build static libraries if no shared FFmpeg.
  594. if [[ $SRS_SHARED_FFMPEG == NO ]]; then
  595. OPUS_OPTIONS="--disable-shared --disable-doc"
  596. fi
  597. if [[ $OS_IS_LOONGARCH = YES ]]; then
  598. OPUS_OPTIONS="$OPUS_OPTIONS --build=loongarch64-unknown-linux-gnu"
  599. fi
  600. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1/_release/lib/libopus.a ]]; then
  601. echo "The opus-1.3.1 is ok.";
  602. else
  603. echo "Building opus-1.3.1.";
  604. (
  605. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  606. tar xf ../../3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 &&
  607. ./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS &&
  608. make ${SRS_JOBS} && make install &&
  609. cd .. && rm -rf opus && ln -sf opus-1.3.1/_release opus
  610. )
  611. fi
  612. # check status
  613. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build opus-1.3.1 failed, ret=$ret"; exit $ret; fi
  614. # Always update the links.
  615. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf opus && ln -sf opus-1.3.1/_release opus)
  616. (cd ${SRS_OBJS} && rm -rf opus && ln -sf ${SRS_PLATFORM}/opus-1.3.1/_release opus)
  617. if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi
  618. fi
  619. #####################################################################################
  620. # ffmpeg-fit, for WebRTC to transcode AAC with Opus.
  621. #####################################################################################
  622. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  623. FFMPEG_OPTIONS=""
  624. if [[ $SRS_CROSS_BUILD == YES ]]; then
  625. FFMPEG_CONFIGURE=./configure
  626. else
  627. FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/opus/lib/pkgconfig ./configure"
  628. fi
  629. # If disable nasm, disable all ASMs.
  630. nasm -v >/dev/null 2>&1 && NASM_BIN_OK=YES
  631. if [[ $NASM_BIN_OK != YES || $SRS_NASM == NO || $SRS_CROSS_BUILD == YES ]]; then
  632. FFMPEG_OPTIONS="--disable-asm --disable-x86asm --disable-inline-asm"
  633. fi
  634. # Only build static libraries if no shared FFmpeg.
  635. if [[ $SRS_SHARED_FFMPEG == YES ]]; then
  636. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-shared"
  637. fi
  638. # For cross-build.
  639. if [[ $SRS_CROSS_BUILD == YES ]]; then
  640. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-cross-compile --target-os=linux --disable-pthreads"
  641. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --arch=$SRS_CROSS_BUILD_ARCH";
  642. if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cpu=$SRS_CROSS_BUILD_CPU"; fi
  643. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cross-prefix=$SRS_CROSS_BUILD_PREFIX"
  644. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cc=${SRS_TOOL_CC} --cxx=${SRS_TOOL_CXX} --ar=${SRS_TOOL_AR} --ld=${SRS_TOOL_LD}"
  645. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=opus --enable-encoder=opus"
  646. else
  647. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus"
  648. fi
  649. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/_release/lib/libavcodec.a ]]; then
  650. echo "The ffmpeg-4-fit is ok.";
  651. else
  652. echo "Building ffmpeg-4-fit.";
  653. (
  654. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit &&
  655. # Create a hidden directory .src
  656. cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && cp -R ../../../3rdparty/ffmpeg-4-fit/* . &&
  657. # Build source code.
  658. $FFMPEG_CONFIGURE \
  659. --prefix=`pwd`/_release --pkg-config=pkg-config \
  660. --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \
  661. --disable-everything ${FFMPEG_OPTIONS} \
  662. --disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \
  663. --disable-avdevice --disable-avformat --disable-swscale --disable-postproc --disable-avfilter --disable-network \
  664. --disable-dct --disable-dwt --disable-error-resilience --disable-lsp --disable-lzo --disable-faan --disable-pixelutils \
  665. --disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuvid \
  666. --disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi \
  667. --disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv \
  668. --disable-lzma --disable-sdl2 --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm \
  669. --enable-encoder=aac &&
  670. # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/
  671. if [[ $SRS_CROSS_BUILD == YES ]]; then
  672. sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' config.h &&
  673. sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h &&
  674. sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h &&
  675. # For MIPS, which fail with:
  676. # ./libavutil/libm.h:54:32: error: static declaration of 'cbrt' follows non-static declaration
  677. # /root/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/include/math.h:163:13: note: previous declaration of 'cbrt' was here
  678. if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then
  679. sed -i -e 's/#define HAVE_CBRT 0/#define HAVE_CBRT 1/g' config.h &&
  680. sed -i -e 's/#define HAVE_CBRTF 0/#define HAVE_CBRTF 1/g' config.h &&
  681. sed -i -e 's/#define HAVE_COPYSIGN 0/#define HAVE_COPYSIGN 1/g' config.h &&
  682. sed -i -e 's/#define HAVE_ERF 0/#define HAVE_ERF 1/g' config.h &&
  683. sed -i -e 's/#define HAVE_HYPOT 0/#define HAVE_HYPOT 1/g' config.h &&
  684. sed -i -e 's/#define HAVE_RINT 0/#define HAVE_RINT 1/g' config.h &&
  685. sed -i -e 's/#define HAVE_LRINT 0/#define HAVE_LRINT 1/g' config.h &&
  686. sed -i -e 's/#define HAVE_LRINTF 0/#define HAVE_LRINTF 1/g' config.h &&
  687. sed -i -e 's/#define HAVE_ROUND 0/#define HAVE_ROUND 1/g' config.h &&
  688. sed -i -e 's/#define HAVE_ROUNDF 0/#define HAVE_ROUNDF 1/g' config.h &&
  689. sed -i -e 's/#define HAVE_TRUNC 0/#define HAVE_TRUNC 1/g' config.h &&
  690. sed -i -e 's/#define HAVE_TRUNCF 0/#define HAVE_TRUNCF 1/g' config.h
  691. fi
  692. fi &&
  693. make ${SRS_JOBS} && make install &&
  694. cd .. && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg
  695. )
  696. fi
  697. # check status
  698. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi
  699. # Always update the links.
  700. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg)
  701. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg-4-fit/_release ffmpeg)
  702. if [ ! -f ${SRS_OBJS}/ffmpeg/lib/libavcodec.a ]; then echo "Build ffmpeg-4-fit failed."; exit -1; fi
  703. fi
  704. #####################################################################################
  705. # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2.
  706. #####################################################################################
  707. # Guess whether the ffmpeg is.
  708. SYSTEMP_FFMPEG_BIN=/usr/local/bin/ffmpeg
  709. if [[ ! -f $SYSTEMP_FFMPEG_BIN ]]; then SYSTEMP_FFMPEG_BIN=/usr/local/ffmpeg/bin/ffmpeg; fi
  710. # Always link the ffmpeg tools if exists.
  711. if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  712. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin &&
  713. ln -sf $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg &&
  714. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  715. fi
  716. if [ $SRS_FFMPEG_TOOL = YES ]; then
  717. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg ]]; then
  718. echo "ffmpeg-4.1 is ok.";
  719. else
  720. echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}"
  721. echo -e "${RED} Please copy it from srs-docker${BLACK}"
  722. echo -e "${RED} or download from http://ffmpeg.org/download.html${BLACK}"
  723. echo -e "${RED} or disable it by --without-ffmpeg${BLACK}"
  724. exit -1;
  725. fi
  726. # Always update the links.
  727. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  728. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  729. fi
  730. fi
  731. #####################################################################################
  732. # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119
  733. #####################################################################################
  734. if [[ $SRS_SRT == YES ]]; then
  735. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/srt/lib/libsrt.a ]]; then
  736. echo "libsrt-1-fit is ok.";
  737. else
  738. echo "Build srt-1-fit"
  739. (
  740. if [[ ! -d ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/pkgconfig ]]; then
  741. echo "OpenSSL pkgconfig no found, build srt-1-fit failed.";
  742. exit -1;
  743. fi
  744. # Always disable c++11 for libsrt, because only the srt-app requres it.
  745. LIBSRT_OPTIONS="--disable-apps --enable-static --enable-c++11=0"
  746. if [[ $SRS_SHARED_SRT == YES ]]; then
  747. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1"
  748. else
  749. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0"
  750. fi
  751. # Start build libsrt.
  752. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  753. cp -R ../../3rdparty/srt-1-fit srt-1-fit && cd srt-1-fit &&
  754. PKG_CONFIG_PATH=../openssl/lib/pkgconfig ./configure --prefix=`pwd`/_release $LIBSRT_OPTIONS &&
  755. make ${SRS_JOBS} && make install &&
  756. cd .. && rm -rf srt && ln -sf srt-1-fit/_release srt &&
  757. # If exists lib64 of libsrt, link it to lib
  758. if [[ -d srt/lib64 ]]; then
  759. cd srt && ln -sf lib64 lib
  760. fi
  761. )
  762. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi
  763. fi
  764. # Always update the links.
  765. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srt && ln -sf srt-1-fit/_release srt)
  766. (cd ${SRS_OBJS} && rm -rf srt && ln -sf ${SRS_PLATFORM}/srt-1-fit/_release srt)
  767. if [ ! -f ${SRS_OBJS}/srt/lib/libsrt.a ]; then echo "Build srt-1-fit failed."; exit -1; fi
  768. fi
  769. #####################################################################################
  770. # build utest code
  771. #####################################################################################
  772. if [ $SRS_UTEST = YES ]; then
  773. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest-fit/googletest/include/gtest/gtest.h ]]; then
  774. echo "The gtest-fit is ok.";
  775. else
  776. echo "Build gtest-fit";
  777. (
  778. cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest-fit && cp -R ../../3rdparty/gtest-fit gtest-fit
  779. rm -rf gtest && ln -sf gtest-fit/googletest gtest
  780. )
  781. fi
  782. # check status
  783. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-fit failed, ret=$ret"; exit $ret; fi
  784. # Always update the links.
  785. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest && ln -sf gtest-fit/googletest gtest)
  786. (cd ${SRS_OBJS} && rm -rf gtest && ln -sf ${SRS_PLATFORM}/gtest-fit/googletest gtest)
  787. if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "Build gtest-fit failed."; exit -1; fi
  788. fi
  789. #####################################################################################
  790. # build gperf code
  791. #####################################################################################
  792. if [ $SRS_GPERF = YES ]; then
  793. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gperf/bin/pprof ]]; then
  794. echo "The gperftools-2-fit is ok.";
  795. else
  796. echo "Build gperftools-2-fit";
  797. (
  798. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  799. cp -R ../../3rdparty/gperftools-2-fit . && cd gperftools-2-fit &&
  800. ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install &&
  801. cd .. && rm -rf gperf && ln -sf gperftools-2-fit/_release gperf &&
  802. rm -rf pprof && ln -sf gperf/bin/pprof pprof
  803. )
  804. fi
  805. # check status
  806. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2-fit failed, ret=$ret"; exit $ret; fi
  807. # Always update the links.
  808. (cd ${SRS_OBJS} && rm -rf pprof && ln -sf ${SRS_PLATFORM}/gperf/bin/pprof pprof)
  809. (cd ${SRS_OBJS} && rm -rf gperf && ln -sf ${SRS_PLATFORM}/gperftools-2-fit/_release gperf)
  810. if [ ! -f ${SRS_OBJS}/pprof ]; then echo "Build gperftools-2-fit failed."; exit -1; fi
  811. fi