2
0

depends.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. if [ $SRS_CUBIE = YES ]; then
  32. echo "For cubieboard, please use ubuntu prepare."
  33. else
  34. uname -v|grep Ubuntu >/dev/null 2>&1
  35. ret=$?; if [[ 0 -ne $ret ]]; then
  36. # for debian, we think it's ubuntu also.
  37. # for example, the wheezy/sid which is debian armv7 linux, can not identified by uname -v.
  38. if [[ ! -f /etc/debian_version ]]; then
  39. return 0;
  40. fi
  41. fi
  42. fi
  43. OS_IS_UBUNTU=YES
  44. echo "Installing tools for Ubuntu."
  45. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  46. echo "Installing gcc."
  47. require_sudoer "sudo apt-get install -y --force-yes gcc"
  48. sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  49. echo "The gcc is installed."
  50. fi
  51. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  52. echo "Installing g++."
  53. require_sudoer "sudo apt-get install -y --force-yes g++"
  54. sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  55. echo "The g++ is installed."
  56. fi
  57. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  58. echo "Installing make."
  59. require_sudoer "sudo apt-get install -y --force-yes make"
  60. sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  61. echo "The make is installed."
  62. fi
  63. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  64. echo "Installing patch."
  65. require_sudoer "sudo apt-get install -y --force-yes patch"
  66. sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  67. echo "The patch is installed."
  68. fi
  69. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  70. echo "Installing unzip."
  71. require_sudoer "sudo apt-get install -y --force-yes unzip"
  72. sudo apt-get install -y --force-yes unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  73. echo "The unzip is installed."
  74. fi
  75. if [[ $SRS_VALGRIND == YES ]]; then
  76. valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  77. echo "Installing valgrind."
  78. require_sudoer "sudo apt-get install -y --force-yes valgrind"
  79. sudo apt-get install -y --force-yes valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  80. echo "The valgrind is installed."
  81. fi
  82. fi
  83. if [[ $SRS_VALGRIND == YES ]]; then
  84. if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
  85. echo "Installing valgrind-dev."
  86. require_sudoer "sudo apt-get install -y --force-yes valgrind-dbg"
  87. sudo apt-get install -y --force-yes valgrind-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  88. echo "The valgrind-dev is installed."
  89. fi
  90. fi
  91. echo "Tools for Ubuntu are installed."
  92. return 0
  93. }
  94. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  95. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  96. Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for ubuntu failed, ret=$ret"; exit $ret; fi
  97. fi
  98. #####################################################################################
  99. # for Centos, auto install tools by yum
  100. #####################################################################################
  101. OS_IS_CENTOS=NO
  102. function Centos_prepare()
  103. {
  104. if [[ ! -f /etc/redhat-release ]]; then
  105. return 0;
  106. fi
  107. OS_IS_CENTOS=YES
  108. echo "Installing tools for Centos."
  109. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  110. echo "Installing gcc."
  111. require_sudoer "sudo yum install -y gcc"
  112. sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  113. echo "The gcc is installed."
  114. fi
  115. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  116. echo "Installing gcc-c++."
  117. require_sudoer "sudo yum install -y gcc-c++"
  118. sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  119. echo "The gcc-c++ is installed."
  120. fi
  121. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  122. echo "Installing make."
  123. require_sudoer "sudo yum install -y make"
  124. sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  125. echo "The make is installed."
  126. fi
  127. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  128. echo "Installing patch."
  129. require_sudoer "sudo yum install -y patch"
  130. sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  131. echo "The patch is installed."
  132. fi
  133. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  134. echo "Installing unzip."
  135. require_sudoer "sudo yum install -y unzip"
  136. sudo yum install -y unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  137. echo "The unzip is installed."
  138. fi
  139. if [[ $SRS_VALGRIND == YES ]]; then
  140. valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  141. echo "Installing valgrind."
  142. require_sudoer "sudo yum install -y valgrind"
  143. sudo yum install -y valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  144. echo "The valgrind is installed."
  145. fi
  146. fi
  147. if [[ $SRS_VALGRIND == YES ]]; then
  148. if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then
  149. echo "Installing valgrind-devel."
  150. require_sudoer "sudo yum install -y valgrind-devel"
  151. sudo yum install -y valgrind-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  152. echo "The valgrind-devel is installed."
  153. fi
  154. fi
  155. echo "Tools for Centos are installed."
  156. return 0
  157. }
  158. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  159. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  160. Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for CentOS failed, ret=$ret"; exit $ret; fi
  161. fi
  162. #####################################################################################
  163. # For OSX, auto install tools by brew
  164. #####################################################################################
  165. OS_IS_OSX=NO
  166. function OSX_prepare()
  167. {
  168. uname -s|grep Darwin >/dev/null 2>&1
  169. ret=$?; if [[ 0 -ne $ret ]]; then
  170. if [ $SRS_OSX = YES ]; then
  171. echo "OSX check failed, actual is `uname -s`"
  172. exit 1;
  173. fi
  174. return 0;
  175. fi
  176. # cross build for arm, install the cross build tool chain.
  177. if [ $SRS_CROSS_BUILD = YES ]; then
  178. echo "embeded(arm/mips) is invalid for OSX"
  179. return 1
  180. fi
  181. OS_IS_OSX=YES
  182. echo "OSX detected, install tools if needed"
  183. # requires the osx when os
  184. if [ $OS_IS_OSX = YES ]; then
  185. if [ $SRS_OSX = NO ]; then
  186. echo "OSX detected, must specifies the --osx"
  187. exit 1
  188. fi
  189. fi
  190. brew --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  191. echo "install brew"
  192. echo "ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\""
  193. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  194. echo "install brew success"
  195. fi
  196. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  197. echo "install gcc"
  198. echo "brew install gcc"
  199. brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  200. echo "install gcc success"
  201. fi
  202. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  203. echo "install gcc-c++"
  204. echo "brew install gcc-c++"
  205. brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  206. echo "install gcc-c++ success"
  207. fi
  208. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  209. echo "install make"
  210. echo "brew install make"
  211. brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  212. echo "install make success"
  213. fi
  214. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  215. echo "install patch"
  216. echo "brew install patch"
  217. brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  218. echo "install patch success"
  219. fi
  220. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  221. echo "install unzip"
  222. echo "brew install unzip"
  223. brew install unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  224. echo "install unzip success"
  225. fi
  226. echo "OSX install tools success"
  227. return 0
  228. }
  229. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  230. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  231. OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi
  232. fi
  233. #####################################################################################
  234. # for Centos, auto install tools by yum
  235. #####################################################################################
  236. # We must use a bash function instead of variable.
  237. function sed_utility() {
  238. if [ $OS_IS_OSX = YES ]; then
  239. sed -i '' "$@"
  240. else
  241. sed -i "$@"
  242. fi
  243. ret=$?; if [[ $ret -ne 0 ]]; then
  244. if [ $OS_IS_OSX = YES ]; then
  245. echo "sed -i '' \"$@\""
  246. else
  247. echo "sed -i \"$@\""
  248. fi
  249. return $ret
  250. fi
  251. }
  252. SED="sed_utility" && echo "SED is $SED"
  253. #####################################################################################
  254. # check the os.
  255. #####################################################################################
  256. # Only supports:
  257. # linux, centos/ubuntu as such,
  258. # cross build for embeded system, for example, mips or arm,
  259. # directly build on arm/mips, for example, pi or cubie,
  260. # export srs-librtmp
  261. # others is invalid.
  262. if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_EXPORT_LIBRTMP_PROJECT = NO ]]; then
  263. if [[ $SRS_PI = NO && $SRS_CUBIE = NO && $SRS_CROSS_BUILD = NO ]]; then
  264. echo "Your OS `uname -s` is not supported."
  265. exit 1
  266. fi
  267. fi
  268. #####################################################################################
  269. # state-threads
  270. #####################################################################################
  271. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  272. # check the cross build flag file, if flag changed, need to rebuild the st.
  273. _ST_MAKE=linux-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_EPOLL" && _ST_LD=${SRS_TOOL_LD} && _ST_OBJ="LINUX_*"
  274. if [[ $SRS_VALGRIND == YES ]]; then
  275. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND"
  276. fi
  277. # for osx, use darwin for st, donot use epoll.
  278. if [[ $SRS_OSX == YES ]]; then
  279. _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE" && _ST_LD=${SRS_TOOL_CC} && _ST_OBJ="DARWIN_*"
  280. fi
  281. # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676
  282. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMALLOC_STACK"
  283. # Pass the global extra flags.
  284. if [[ $SRS_EXTRA_FLAGS != '' ]]; then
  285. _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS"
  286. fi
  287. # Patched ST from https://github.com/ossrs/state-threads/tree/srs
  288. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st/libst.a ]]; then
  289. echo "The state-threads is ok.";
  290. else
  291. echo "Building state-threads.";
  292. (
  293. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs &&
  294. # Create a hidden directory .src
  295. cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src &&
  296. # Link source files under .src
  297. for file in `(cd .src && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d')`; do
  298. ln -sf .src/$file $file;
  299. done &&
  300. # Link source files under .src/xxx, the first child dir.
  301. for dir in `(cd .src && find . -maxdepth 1 -type d|grep '\./'|grep -v Linux|grep -v Darwin)`; do
  302. mkdir -p $dir &&
  303. for file in `(cd .src/$dir && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d')`; do
  304. ln -sf ../.src/$dir/$file $dir/$file;
  305. done;
  306. done &&
  307. # Build source code.
  308. make ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \
  309. CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${_ST_LD} RANDLIB=${SRS_TOOL_RANDLIB} &&
  310. cd .. && rm -f st && ln -sf st-srs/${_ST_OBJ} st
  311. )
  312. fi
  313. # check status
  314. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi
  315. # Always update the links.
  316. (cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st)
  317. if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi
  318. fi
  319. #####################################################################################
  320. # nginx for HLS, nginx-1.5.0
  321. #####################################################################################
  322. function write_nginx_html5()
  323. {
  324. cat<<END > ${html_file}
  325. <video autoplay controls autobuffer type="application/vnd.apple.mpegurl"
  326. src="${hls_stream}">
  327. </video>
  328. END
  329. }
  330. # create the nginx dir, for http-server if not build nginx
  331. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  332. mkdir -p ${SRS_OBJS}/nginx
  333. fi
  334. # the demo dir.
  335. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  336. # create forward dir
  337. mkdir -p ${SRS_OBJS}/nginx/html/live &&
  338. mkdir -p ${SRS_OBJS}/nginx/html/forward/live
  339. # generate default html pages for android.
  340. html_file=${SRS_OBJS}/nginx/html/live/demo.html && hls_stream=demo.m3u8 && write_nginx_html5
  341. html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  342. html_file=${SRS_OBJS}/nginx/html/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
  343. html_file=${SRS_OBJS}/nginx/html/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
  344. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  345. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
  346. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
  347. # copy players to nginx html dir.
  348. rm -rf ${SRS_OBJS}/nginx/html/players &&
  349. ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players
  350. # For srs-console.
  351. rm -rf ${SRS_OBJS}/nginx/html/console &&
  352. ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console
  353. # for favicon.ico
  354. rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
  355. ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico
  356. # For home page index.html
  357. rm -rf ${SRS_OBJS}/nginx/html/index.html &&
  358. ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html
  359. # nginx.html to detect whether nginx is alive
  360. echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html
  361. fi
  362. #####################################################################################
  363. # cherrypy for http hooks callback, CherryPy-3.2.4
  364. #####################################################################################
  365. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  366. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then
  367. echo "CherryPy-3.2.4 is ok.";
  368. else
  369. echo "Installing CherryPy-3.2.4";
  370. (
  371. rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  372. unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 &&
  373. python setup.py install --user
  374. )
  375. fi
  376. # check status
  377. ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi
  378. if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
  379. echo "Link players to cherrypy static-dir"
  380. rm -rf research/api-server/static-dir/players &&
  381. ln -sf `pwd`/research/players research/api-server/static-dir/players &&
  382. rm -f research/api-server/static-dir/crossdomain.xml &&
  383. ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml &&
  384. rm -rf research/api-server/static-dir/live &&
  385. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
  386. ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
  387. rm -rf research/api-server/static-dir/forward &&
  388. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
  389. ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
  390. ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi
  391. fi
  392. #####################################################################################
  393. # openssl, for rtmp complex handshake and HLS encryption.
  394. #####################################################################################
  395. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
  396. echo "Warning: Use system libssl, without compiling openssl."
  397. fi
  398. # @see http://www.openssl.org/news/secadv/20140407.txt
  399. # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately
  400. # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
  401. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then
  402. OPENSSL_OPTIONS="-no-shared -no-threads -no-asm -DOPENSSL_NO_HEARTBEATS"
  403. OPENSSL_CONFIG="./config"
  404. # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain
  405. if [[ $SRS_CROSS_BUILD == YES ]]; then
  406. OPENSSL_CONFIG="./Configure linux-armv4"
  407. elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then
  408. # Try to use exists libraries.
  409. if [[ -f /usr/local/ssl/lib/libssl.a ]]; then
  410. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib &&
  411. ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a &&
  412. mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig)
  413. (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include &&
  414. ln -sf /usr/local/ssl/include/openssl)
  415. fi
  416. fi
  417. # Which lib we use.
  418. OPENSSL_LIB="openssl-1.1.0e/_release"
  419. if [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/${OPENSSL_LIB}/lib/libssl.a ]]; then
  420. OPENSSL_LIB="openssl"
  421. fi
  422. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  423. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then
  424. echo "Openssl-1.1.0e is ok.";
  425. else
  426. echo "Building openssl-1.1.0e.";
  427. (
  428. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/openssl-1.1.0e && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  429. unzip -q ../../3rdparty/openssl-1.1.0e.zip && cd openssl-1.1.0e &&
  430. ${OPENSSL_CONFIG} --prefix=`pwd`/_release $OPENSSL_OPTIONS &&
  431. make CC=${SRS_TOOL_CC} AR="${SRS_TOOL_AR} -rs" LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB} && make install_sw &&
  432. cd .. && rm -rf openssl && ln -sf openssl-1.1.0e/_release openssl
  433. )
  434. fi
  435. # check status
  436. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build openssl-1.1.0e failed, ret=$ret"; exit $ret; fi
  437. # Always update the links.
  438. (cd ${SRS_OBJS} && rm -rf openssl && ln -sf ${SRS_PLATFORM}/${OPENSSL_LIB} openssl)
  439. if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "Build openssl-1.1.0e failed."; exit -1; fi
  440. fi
  441. #####################################################################################
  442. # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2.
  443. #####################################################################################
  444. # Always link the ffmpeg tools if exists.
  445. if [[ -f /usr/local/bin/ffmpeg && ! -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  446. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin &&
  447. ln -sf /usr/local/bin/ffmpeg ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg &&
  448. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  449. fi
  450. if [ $SRS_FFMPEG_TOOL = YES ]; then
  451. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg/bin/ffmpeg ]]; then
  452. echo "ffmpeg-4.1 is ok.";
  453. else
  454. echo -e "${RED}Error: No FFmpeg found at /usr/local/bin/ffmpeg${BLACK}"
  455. echo -e "${RED} Please copy it from srs-docker${BLACK}"
  456. echo -e "${RED} or download from http://ffmpeg.org/download.html${BLACK}"
  457. echo -e "${RED} or disable it by --without-ffmpeg${BLACK}"
  458. exit -1;
  459. fi
  460. # Always update the links.
  461. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg ]]; then
  462. (cd ${SRS_OBJS} && rm -rf ffmpeg && ln -sf ${SRS_PLATFORM}/ffmpeg)
  463. fi
  464. fi
  465. #####################################################################################
  466. # build research code, librtmp
  467. #####################################################################################
  468. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  469. if [ $SRS_RESEARCH = YES ]; then
  470. mkdir -p ${SRS_OBJS}/research
  471. (cd ${SRS_WORKDIR}/research/hls && make ${SRS_JOBS} && mv ts_info ../../${SRS_OBJS_DIR}/research)
  472. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build research/hls failed, ret=$ret"; exit $ret; fi
  473. (cd research/ffempty && make ${SRS_JOBS} && mv ffempty ../../${SRS_OBJS_DIR}/research)
  474. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build research/ffempty failed, ret=$ret"; exit $ret; fi
  475. fi
  476. fi
  477. if [[ $SRS_LIBRTMP == YES ]]; then
  478. mkdir -p ${SRS_OBJS}/research
  479. # librtmp
  480. (cd ${SRS_WORKDIR}/research/librtmp && mkdir -p objs &&
  481. rm -rf ../../${SRS_OBJS_DIR}/research/librtmp &&
  482. ln -sf `pwd`/objs ../../${SRS_OBJS_DIR}/research/librtmp)
  483. ret=$?; if [[ $ret -ne 0 ]]; then echo "Link research/librtmp failed, ret=$ret"; exit $ret; fi
  484. fi
  485. #####################################################################################
  486. # build utest code
  487. #####################################################################################
  488. if [ $SRS_UTEST = YES ]; then
  489. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gtest/include/gtest/gtest.h ]]; then
  490. echo "The gtest-1.6.0 is ok.";
  491. else
  492. echo "Build gtest-1.6.0";
  493. (
  494. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gtest-1.6.0 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  495. unzip -q ../../3rdparty/gtest-1.6.0.zip &&
  496. rm -rf gtest && ln -sf gtest-1.6.0 gtest
  497. )
  498. fi
  499. # check status
  500. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi
  501. # Always update the links.
  502. (cd ${SRS_OBJS} && rm -rf gtest && ln -sf ${SRS_PLATFORM}/gtest-1.6.0 gtest)
  503. if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "Build gtest-1.6.0 failed."; exit -1; fi
  504. fi
  505. #####################################################################################
  506. # build gperf code
  507. #####################################################################################
  508. if [ $SRS_GPERF = YES ]; then
  509. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/gperf/bin/pprof ]]; then
  510. echo "The gperftools-2.1 is ok.";
  511. else
  512. echo "Build gperftools-2.1";
  513. (
  514. rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/gperftools-2.1 && cd ${SRS_OBJS}/${SRS_PLATFORM} &&
  515. unzip -q ../../3rdparty/gperftools-2.1.zip && cd gperftools-2.1 &&
  516. ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install &&
  517. cd .. && rm -rf gperf && ln -sf gperftools-2.1/_release gperf &&
  518. rm -rf pprof && ln -sf gperf/bin/pprof pprof
  519. )
  520. fi
  521. # check status
  522. ret=$?; if [[ $ret -ne 0 ]]; then echo "Build gperftools-2.1 failed, ret=$ret"; exit $ret; fi
  523. # Always update the links.
  524. (cd ${SRS_OBJS} && rm -rf pprof && ln -sf ${SRS_PLATFORM}/gperf/bin/pprof pprof)
  525. if [ ! -f ${SRS_OBJS}/gperf/bin/pprof ]; then echo "Build gperftools-2.1 failed."; exit -1; fi
  526. fi