2
0

depends.sh 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. # for Centos, auto install tools by yum
  282. #####################################################################################
  283. # We must use a bash function instead of variable.
  284. function sed_utility() {
  285. if [ $OS_IS_OSX = YES ]; then
  286. sed -i '' "$@"
  287. else
  288. sed -i "$@"
  289. fi
  290. ret=$?; if [[ $ret -ne 0 ]]; then
  291. if [ $OS_IS_OSX = YES ]; then
  292. echo "sed -i '' \"$@\""
  293. else
  294. echo "sed -i \"$@\""
  295. fi
  296. return $ret
  297. fi
  298. }
  299. SED="sed_utility" && echo "SED is $SED"
  300. function _srs_link_file()
  301. {
  302. tmp_dir=$1; if [[ $tmp_dir != *'/' ]]; then tmp_dir+='/'; fi
  303. tmp_dest=$2; if [[ $tmp_dest != *'/' ]]; then tmp_dest+='/'; fi
  304. tmp_prefix=$3; if [[ $tmp_prefix != *'/' ]]; then tmp_prefix+='/'; fi
  305. echo "LINK files at dir: $tmp_dir, dest: $tmp_dest, prefix: $tmp_prefix, pwd: `pwd`"
  306. for file in `(cd $tmp_dir && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '*.log')`; do
  307. basefile=`basename $file` &&
  308. #echo "ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile" &&
  309. ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile;
  310. done
  311. }
  312. #####################################################################################
  313. # check the os.
  314. #####################################################################################
  315. # Only supports:
  316. # linux, centos/ubuntu as such,
  317. # cross build for embeded system, for example, mips or arm,
  318. # directly build on arm/mips, for example, pi or cubie,
  319. # export srs-librtmp
  320. # others is invalid.
  321. if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_CROSS_BUILD = NO ]]; then
  322. echo "Your OS `uname -s` is not supported."
  323. exit 1
  324. fi
  325. #####################################################################################
  326. # state-threads
  327. #####################################################################################
  328. # check the cross build flag file, if flag changed, need to rebuild the st.
  329. _ST_MAKE=linux-debug && _ST_EXTRA_CFLAGS="-O0" && _ST_OBJ="LINUX_`uname -r`_DBG"
  330. if [[ $SRS_VALGRIND == YES ]]; then
  331. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND"
  332. fi
  333. # for osx, use darwin for st, donot use epoll.
  334. if [[ $SRS_OSX == YES ]]; then
  335. _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_OBJ="DARWIN_`uname -r`_DBG"
  336. fi
  337. # For Ubuntu, the epoll detection might be fail.
  338. if [[ $OS_IS_UBUNTU == YES ]]; then
  339. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL"
  340. fi
  341. # Whether enable debug stats.
  342. if [[ $SRS_DEBUG_STATS == YES ]]; then
  343. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS"
  344. fi
  345. # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676
  346. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMALLOC_STACK"
  347. # Pass the global extra flags.
  348. if [[ $SRS_EXTRA_FLAGS != '' ]]; then
  349. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
  350. fi
  351. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  352. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ]]; then
  353. echo "The state-threads is ok.";
  354. else
  355. echo "Building state-threads.";
  356. (
  357. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs &&
  358. # Create a hidden directory .src
  359. cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src &&
  360. # Link source files under .src
  361. _srs_link_file .src/ ./ ./ &&
  362. for dir in `(cd .src && find . -maxdepth 1 -type d|grep '\./')`; do
  363. dir=`basename $dir` && mkdir -p $dir && _srs_link_file .src/$dir/ $dir/ ../
  364. done &&
  365. # Link source files under .src/xxx, the first child dir.
  366. for dir in `(cd .src && find . -maxdepth 1 -type d|grep '\./'|grep -v Linux|grep -v Darwin)`; do
  367. mkdir -p $dir &&
  368. for file in `(cd .src/$dir && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d')`; do
  369. ln -sf ../.src/$dir/$file $dir/$file;
  370. done;
  371. done &&
  372. # Build source code.
  373. make ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \
  374. CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} &&
  375. cd .. && rm -rf st && ln -sf st-srs/${_ST_OBJ} st
  376. )
  377. fi
  378. # check status
  379. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi
  380. # Always update the links.
  381. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf st && ln -sf st-srs/${_ST_OBJ} st)
  382. (cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st)
  383. if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi
  384. #####################################################################################
  385. # nginx for HLS, nginx-1.5.0
  386. #####################################################################################
  387. function write_nginx_html5()
  388. {
  389. cat<<END > ${html_file}
  390. <video width="100%" autoplay controls autobuffer type="application/vnd.apple.mpegurl"
  391. src="${hls_stream}">
  392. </video>
  393. END
  394. }
  395. # create the nginx dir, for http-server if not build nginx
  396. mkdir -p ${SRS_OBJS}/nginx
  397. # the demo dir.
  398. # create forward dir
  399. mkdir -p ${SRS_OBJS}/nginx/html/live &&
  400. html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  401. # copy players to nginx html dir.
  402. rm -rf ${SRS_OBJS}/nginx/html/players &&
  403. ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players
  404. # for favicon.ico
  405. rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
  406. ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico
  407. # For srs-console.
  408. rm -rf ${SRS_OBJS}/nginx/html/console &&
  409. ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console
  410. # For SRS signaling.
  411. rm -rf ${SRS_OBJS}/nginx/html/demos &&
  412. ln -sf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/demos
  413. # For home page index.html
  414. rm -rf ${SRS_OBJS}/nginx/html/index.html &&
  415. ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html
  416. # nginx.html to detect whether nginx is alive
  417. echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html
  418. #####################################################################################
  419. # Generate default self-sign certificate for HTTPS server, test only.
  420. #####################################################################################
  421. if [[ ! -f conf/server.key || ! -f conf/server.crt ]]; then
  422. openssl genrsa -out conf/server.key 2048
  423. 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"
  424. echo "Generate test-only self-sign certificate files"
  425. fi
  426. #####################################################################################
  427. # cherrypy for http hooks callback, CherryPy-3.2.4
  428. #####################################################################################
  429. if [[ $SRS_CHERRYPY == YES ]]; then
  430. # Detect python or python2
  431. python --version >/dev/null 2>&1 && SYS_PYTHON=python;
  432. python2 --version >/dev/null 2>&1 && SYS_PYTHON=python2;
  433. # Install cherrypy for api server.
  434. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then
  435. echo "CherryPy-3.2.4 is ok.";
  436. else
  437. echo "Installing CherryPy-3.2.4";
  438. (
  439. rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  440. unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 &&
  441. $SYS_PYTHON setup.py install --user --prefix=''
  442. )
  443. fi
  444. # check status
  445. ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi
  446. if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
  447. echo "Link players to cherrypy static-dir"
  448. rm -rf research/api-server/static-dir/players &&
  449. ln -sf `pwd`/research/players research/api-server/static-dir/players &&
  450. rm -rf research/api-server/static-dir/live &&
  451. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
  452. ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
  453. rm -rf research/api-server/static-dir/forward &&
  454. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
  455. ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
  456. ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi
  457. fi
  458. #####################################################################################
  459. # openssl, for rtmp complex handshake and HLS encryption.
  460. #####################################################################################
  461. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
  462. echo "Warning: Use system libssl, without compiling openssl."
  463. fi
  464. # @see http://www.openssl.org/news/secadv/20140407.txt
  465. # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately
  466. # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
  467. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then
  468. OPENSSL_OPTIONS="-no-shared -no-threads -DOPENSSL_NO_HEARTBEATS"
  469. OPENSSL_CONFIG="./config"
  470. # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain
  471. if [[ $SRS_CROSS_BUILD == YES ]]; then
  472. OPENSSL_CONFIG="./Configure linux-generic32"
  473. if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi
  474. if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi
  475. elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then
  476. # Try to use exists libraries.
  477. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then
  478. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib &&
  479. ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a &&
  480. mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig)
  481. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include &&
  482. ln -sf /usr/local/ssl/include/openssl)
  483. fi
  484. # Warning if not use the system ssl.
  485. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then
  486. echo "Warning: Local openssl is on, ignore system openssl"
  487. fi
  488. fi
  489. # For RTC, we should use ASM to improve performance, not a little improving.
  490. if [[ $SRS_RTC == NO || $SRS_NASM == NO ]]; then
  491. OPENSSL_OPTIONS="$OPENSSL_OPTIONS -no-asm"
  492. echo "Warning: NASM is off, performance is hurt"
  493. fi
  494. # Mac OS X can have issues (its often a neglected platform).
  495. # @see https://wiki.openssl.org/index.php/Compilation_and_Installation
  496. if [[ $SRS_OSX == YES ]]; then
  497. export KERNEL_BITS=64;
  498. fi
  499. # Use 1.0 if required.
  500. if [[ $SRS_SSL_1_0 == YES ]]; then
  501. OPENSSL_AR="$SRS_TOOL_AR -r" # For openssl 1.0, MUST specifies the args for ar or build faild.
  502. OPENSSL_CANDIDATE="openssl-OpenSSL_1_0_2u" && OPENSSL_UNZIP="tar xf ../../3rdparty/$OPENSSL_CANDIDATE.tar.gz"
  503. else
  504. OPENSSL_AR="$SRS_TOOL_AR"
  505. OPENSSL_CANDIDATE="openssl-1.1-fit" && OPENSSL_UNZIP="cp -R ../../3rdparty/$OPENSSL_CANDIDATE ."
  506. fi
  507. #
  508. # https://wiki.openssl.org/index.php/Compilation_and_Installation#Configure_Options
  509. # Already defined: -no-shared -no-threads -no-asm
  510. # Should enable: -no-dtls -no-dtls1 -no-ssl3
  511. # 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
  512. # Note that we do not disable more features, because no file could be removed.
  513. #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"
  514. #
  515. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  516. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/$OPENSSL_CANDIDATE/_release/lib/libssl.a ]]; then
  517. echo "The $OPENSSL_CANDIDATE is ok.";
  518. else
  519. echo "Building $OPENSSL_CANDIDATE.";
  520. (
  521. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_CANDIDATE} && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  522. ${OPENSSL_UNZIP} && cd $OPENSSL_CANDIDATE && ${OPENSSL_CONFIG} --prefix=`pwd`/_release $OPENSSL_OPTIONS &&
  523. make CC=${SRS_TOOL_CC} AR="${OPENSSL_AR}" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} ${SRS_JOBS} && make install_sw &&
  524. cd .. && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl
  525. )
  526. fi
  527. # Which lib we use.
  528. OPENSSL_LIB="$OPENSSL_CANDIDATE/_release"
  529. if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then
  530. OPENSSL_LIB="openssl"
  531. fi
  532. # check status
  533. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build $OPENSSL_CANDIDATE failed, ret=$ret"; exit $ret; fi
  534. # Always update the links.
  535. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf openssl && ln -sf $OPENSSL_CANDIDATE/_release openssl)
  536. (cd ${SRS_OBJS} && rm -rf openssl && ln -sf ${SRS_PLATFORM}/${OPENSSL_LIB} openssl)
  537. if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build $OPENSSL_CANDIDATE failed."; exit -1; fi
  538. fi
  539. #####################################################################################
  540. # srtp
  541. #####################################################################################
  542. SRTP_OPTIONS=""
  543. # To eliminate warnings, see https://stackoverflow.com/a/34208904/17679565
  544. # was built for newer macOS version (11.6) than being linked (11.0)
  545. if [[ $SRS_OSX == YES ]]; then
  546. export MACOSX_DEPLOYMENT_TARGET=11.0
  547. echo "Set MACOSX_DEPLOYMENT_TARGET to avoid warnings"
  548. fi
  549. # If use ASM for SRTP, we enable openssl(with ASM).
  550. if [[ $SRS_SRTP_ASM == YES ]]; then
  551. SRTP_OPTIONS="--enable-openssl"
  552. SRTP_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/openssl/lib/pkgconfig ./configure"
  553. else
  554. SRTP_CONFIGURE="./configure"
  555. fi
  556. if [[ $SRS_CROSS_BUILD == YES ]]; then
  557. SRTP_OPTIONS="$SRTP_OPTIONS --host=$SRS_CROSS_BUILD_HOST"
  558. fi
  559. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  560. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/_release/lib/libsrtp2.a ]]; then
  561. echo "The libsrtp-2-fit is ok.";
  562. else
  563. echo "Building libsrtp-2-fit.";
  564. (
  565. rm -rf ${SRS_OBJS}/srtp2 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  566. rm -rf libsrtp-2-fit && cp -R ../../3rdparty/libsrtp-2-fit . && cd libsrtp-2-fit &&
  567. patch -p0 crypto/math/datatypes.c ../../../3rdparty/patches/srtp/gcc10-01.patch &&
  568. $SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=`pwd`/_release &&
  569. make ${SRS_JOBS} && make install &&
  570. cd .. && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2
  571. )
  572. fi
  573. # check status
  574. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build libsrtp-2-fit failed, ret=$ret"; exit $ret; fi
  575. # Always update the links.
  576. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srtp2 && ln -sf libsrtp-2-fit/_release srtp2)
  577. (cd ${SRS_OBJS} && rm -rf srtp2 && ln -sf ${SRS_PLATFORM}/libsrtp-2-fit/_release srtp2)
  578. if [ ! -f ${SRS_OBJS}/srtp2/lib/libsrtp2.a ]; then echo "Build libsrtp-2-fit static lib failed."; exit -1; fi
  579. #####################################################################################
  580. # libopus, for WebRTC to transcode AAC with Opus.
  581. #####################################################################################
  582. # For cross build, we use opus of FFmpeg, so we don't build the libopus.
  583. if [[ $SRS_RTC == YES && $SRS_CROSS_BUILD == NO ]]; then
  584. # Only build static libraries if no shared FFmpeg.
  585. if [[ $SRS_SHARED_FFMPEG == NO ]]; then
  586. OPUS_OPTIONS="--disable-shared --disable-doc"
  587. fi
  588. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1/_release/lib/libopus.a ]]; then
  589. echo "The opus-1.3.1 is ok.";
  590. else
  591. echo "Building opus-1.3.1.";
  592. (
  593. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/opus-1.3.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  594. tar xf ../../3rdparty/opus-1.3.1.tar.gz && cd opus-1.3.1 &&
  595. ./configure --prefix=`pwd`/_release --enable-static $OPUS_OPTIONS &&
  596. make ${SRS_JOBS} && make install &&
  597. cd .. && rm -rf opus && ln -sf opus-1.3.1/_release opus
  598. )
  599. fi
  600. # check status
  601. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build opus-1.3.1 failed, ret=$ret"; exit $ret; fi
  602. # Always update the links.
  603. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf opus && ln -sf opus-1.3.1/_release opus)
  604. (cd ${SRS_OBJS} && rm -rf opus && ln -sf ${SRS_PLATFORM}/opus-1.3.1/_release opus)
  605. if [ ! -f ${SRS_OBJS}/opus/lib/libopus.a ]; then echo "Build opus-1.3.1 failed."; exit -1; fi
  606. fi
  607. #####################################################################################
  608. # ffmpeg-fit, for WebRTC to transcode AAC with Opus.
  609. #####################################################################################
  610. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  611. FFMPEG_OPTIONS=""
  612. if [[ $SRS_CROSS_BUILD == YES ]]; then
  613. FFMPEG_CONFIGURE=./configure
  614. else
  615. FFMPEG_CONFIGURE="env PKG_CONFIG_PATH=$(cd ${SRS_OBJS}/${SRS_PLATFORM} && pwd)/opus/lib/pkgconfig ./configure"
  616. fi
  617. # Disable all asm for FFmpeg, to compatible with ARM CPU.
  618. FFMPEG_OPTIONS="--disable-asm --disable-x86asm --disable-inline-asm"
  619. # Only build static libraries if no shared FFmpeg.
  620. if [[ $SRS_SHARED_FFMPEG == YES ]]; then
  621. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-shared"
  622. fi
  623. # For cross-build.
  624. if [[ $SRS_CROSS_BUILD == YES ]]; then
  625. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-cross-compile --target-os=linux"
  626. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --arch=$SRS_CROSS_BUILD_ARCH";
  627. if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cpu=$SRS_CROSS_BUILD_CPU"; fi
  628. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cross-prefix=$SRS_CROSS_BUILD_PREFIX"
  629. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --cc=${SRS_TOOL_CC} --cxx=${SRS_TOOL_CXX} --ar=${SRS_TOOL_AR} --ld=${_ST_LD}"
  630. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=opus --enable-encoder=opus"
  631. else
  632. FFMPEG_OPTIONS="$FFMPEG_OPTIONS --enable-decoder=libopus --enable-encoder=libopus --enable-libopus"
  633. fi
  634. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit/_release/lib/libavcodec.a ]]; then
  635. echo "The ffmpeg-4-fit is ok.";
  636. else
  637. echo "Building ffmpeg-4-fit.";
  638. (
  639. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit &&
  640. # Create a hidden directory .src
  641. cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4-fit && cp -R ../../../3rdparty/ffmpeg-4-fit/* . &&
  642. # Build source code.
  643. $FFMPEG_CONFIGURE \
  644. --prefix=`pwd`/_release --pkg-config=pkg-config \
  645. --pkg-config-flags="--static" --extra-libs="-lpthread" --extra-libs="-lm" \
  646. --disable-everything ${FFMPEG_OPTIONS} \
  647. --disable-programs --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages \
  648. --disable-avdevice --disable-avformat --disable-swscale --disable-postproc --disable-avfilter --disable-network \
  649. --disable-dct --disable-dwt --disable-error-resilience --disable-lsp --disable-lzo --disable-faan --disable-pixelutils \
  650. --disable-hwaccels --disable-devices --disable-audiotoolbox --disable-videotoolbox --disable-cuvid \
  651. --disable-d3d11va --disable-dxva2 --disable-ffnvcodec --disable-nvdec --disable-nvenc --disable-v4l2-m2m --disable-vaapi \
  652. --disable-vdpau --disable-appkit --disable-coreimage --disable-avfoundation --disable-securetransport --disable-iconv \
  653. --disable-lzma --disable-sdl2 --enable-decoder=aac --enable-decoder=aac_fixed --enable-decoder=aac_latm \
  654. --enable-encoder=aac &&
  655. # See https://www.laoyuyu.me/2019/05/23/android/clang_compile_ffmpeg/
  656. if [[ $SRS_CROSS_BUILD == YES ]]; then
  657. sed -i -e 's/#define getenv(x) NULL/\/\*#define getenv(x) NULL\*\//g' config.h &&
  658. sed -i -e 's/#define HAVE_GMTIME_R 0/#define HAVE_GMTIME_R 1/g' config.h &&
  659. sed -i -e 's/#define HAVE_LOCALTIME_R 0/#define HAVE_LOCALTIME_R 1/g' config.h
  660. fi &&
  661. make ${SRS_JOBS} && make install &&
  662. cd .. && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg
  663. )
  664. fi
  665. # check status
  666. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build ffmpeg-4-fit failed, ret=$ret"; exit $ret; fi
  667. # Always update the links.
  668. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf ffmpeg && ln -sf ffmpeg-4-fit/_release ffmpeg)
  669. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg-4-fit/_release ffmpeg)
  670. if [ ! -f ${SRS_OBJS}/ffmpeg/lib/libavcodec.a ]; then echo "Build ffmpeg-4-fit failed."; exit -1; fi
  671. fi
  672. #####################################################################################
  673. # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2.
  674. #####################################################################################
  675. # Guess whether the ffmpeg is.
  676. SYSTEMP_FFMPEG_BIN=/usr/local/bin/ffmpeg
  677. if [[ ! -f $SYSTEMP_FFMPEG_BIN ]]; then SYSTEMP_FFMPEG_BIN=/usr/local/ffmpeg/bin/ffmpeg; fi
  678. # Always link the ffmpeg tools if exists.
  679. if [[ -f $SYSTEMP_FFMPEG_BIN && ! -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  680. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin &&
  681. ln -sf $SYSTEMP_FFMPEG_BIN ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg &&
  682. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  683. fi
  684. if [ $SRS_FFMPEG_TOOL = YES ]; then
  685. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg ]]; then
  686. echo "ffmpeg-4.1 is ok.";
  687. else
  688. echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}"
  689. echo -e "${RED} Please copy it from srs-docker${BLACK}"
  690. echo -e "${RED} or download from http://ffmpeg.org/download.html${BLACK}"
  691. echo -e "${RED} or disable it by --without-ffmpeg${BLACK}"
  692. exit -1;
  693. fi
  694. # Always update the links.
  695. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  696. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  697. fi
  698. fi
  699. #####################################################################################
  700. # SRT module, https://github.com/ossrs/srs/issues/1147#issuecomment-577469119
  701. #####################################################################################
  702. if [[ $SRS_SRT == YES ]]; then
  703. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/srt/lib/libsrt.a ]]; then
  704. echo "libsrt-1-fit is ok.";
  705. else
  706. echo "Build srt-1-fit"
  707. (
  708. if [[ ! -d ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/pkgconfig ]]; then
  709. echo "OpenSSL pkgconfig no found, build srt-1-fit failed.";
  710. exit -1;
  711. fi
  712. # Always disable c++11 for libsrt, because only the srt-app requres it.
  713. LIBSRT_OPTIONS="--disable-app --enable-static --enable-c++11=0"
  714. if [[ $SRS_SHARED_SRT == YES ]]; then
  715. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=1"
  716. else
  717. LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0"
  718. fi
  719. # Start build libsrt.
  720. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/srt-1-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  721. cp -R ../../3rdparty/srt-1-fit srt-1-fit && cd srt-1-fit &&
  722. PKG_CONFIG_PATH=../openssl/lib/pkgconfig ./configure --prefix=`pwd`/_release $LIBSRT_OPTIONS &&
  723. make ${SRS_JOBS} && make install &&
  724. cd .. && rm -rf srt && ln -sf srt-1-fit/_release srt &&
  725. # If exists lib64 of libsrt, link it to lib
  726. if [[ -d srt/lib64 ]]; then
  727. cd srt && ln -sf lib64 lib
  728. fi
  729. )
  730. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build srt-1-fit failed, ret=$ret"; exit $ret; fi
  731. fi
  732. # Always update the links.
  733. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf srt && ln -sf srt-1-fit/_release srt)
  734. (cd ${SRS_OBJS} && rm -rf srt && ln -sf ${SRS_PLATFORM}/srt-1-fit/_release srt)
  735. if [ ! -f ${SRS_OBJS}/srt/lib/libsrt.a ]; then echo "Build srt-1-fit failed."; exit -1; fi
  736. fi
  737. #####################################################################################
  738. # build utest code
  739. #####################################################################################
  740. if [ $SRS_UTEST = YES ]; then
  741. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest-fit/googletest/include/gtest/gtest.h ]]; then
  742. echo "The gtest-fit is ok.";
  743. else
  744. echo "Build gtest-fit";
  745. (
  746. cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest-fit && cp -R ../../3rdparty/gtest-fit gtest-fit
  747. rm -rf gtest && ln -sf gtest-fit/googletest gtest
  748. )
  749. fi
  750. # check status
  751. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-fit failed, ret=$ret"; exit $ret; fi
  752. # Always update the links.
  753. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf gtest && ln -sf gtest-fit/googletest gtest)
  754. (cd ${SRS_OBJS} && rm -rf gtest && ln -sf ${SRS_PLATFORM}/gtest-fit/googletest gtest)
  755. if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "Build gtest-fit failed."; exit -1; fi
  756. fi
  757. #####################################################################################
  758. # build gperf code
  759. #####################################################################################
  760. if [ $SRS_GPERF = YES ]; then
  761. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gperf/bin/pprof ]]; then
  762. echo "The gperftools-2-fit is ok.";
  763. else
  764. echo "Build gperftools-2-fit";
  765. (
  766. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2-fit && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  767. cp -R ../../3rdparty/gperftools-2-fit . && cd gperftools-2-fit &&
  768. ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install &&
  769. cd .. && rm -rf gperf && ln -sf gperftools-2-fit/_release gperf &&
  770. rm -rf pprof && ln -sf gperf/bin/pprof pprof
  771. )
  772. fi
  773. # check status
  774. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2-fit failed, ret=$ret"; exit $ret; fi
  775. # Always update the links.
  776. (cd ${SRS_OBJS} && rm -rf pprof && ln -sf ${SRS_PLATFORM}/gperf/bin/pprof pprof)
  777. (cd ${SRS_OBJS} && rm -rf gperf && ln -sf ${SRS_PLATFORM}/gperftools-2-fit/_release gperf)
  778. if [ ! -f ${SRS_OBJS}/pprof ]; then echo "Build gperftools-2-fit failed."; exit -1; fi
  779. fi