depends.sh 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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 "check gcc/g++/gdb/make"
  24. echo "depends 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, 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. # cross build for arm, install the cross build tool chain.
  44. if [ $SRS_ARM_UBUNTU12 = YES ]; then
  45. $SrsArmCC --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  46. echo "install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi"
  47. require_sudoer "sudo apt-get install -y --force-yes gcc-arm-linux-gnueabi g++-arm-linux-gnueabi"
  48. sudo apt-get install -y --force-yes gcc-arm-linux-gnueabi g++-arm-linux-gnueabi; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  49. echo "install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi success"
  50. fi
  51. fi
  52. # cross build for mips, user must installed the tool chain.
  53. if [ $SRS_MIPS_UBUNTU12 = YES ]; then
  54. $SrsArmCC --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  55. echo "user must install the tool chain: $SrsArmCC"
  56. return 2
  57. fi
  58. fi
  59. OS_IS_UBUNTU=YES
  60. echo "Ubuntu detected, install tools if needed"
  61. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  62. echo "install gcc"
  63. require_sudoer "sudo apt-get install -y --force-yes gcc"
  64. sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  65. echo "install gcc success"
  66. fi
  67. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  68. echo "install g++"
  69. require_sudoer "sudo apt-get install -y --force-yes g++"
  70. sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  71. echo "install g++ success"
  72. fi
  73. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  74. echo "install make"
  75. require_sudoer "sudo apt-get install -y --force-yes make"
  76. sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  77. echo "install make success"
  78. fi
  79. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  80. echo "install patch"
  81. require_sudoer "sudo apt-get install -y --force-yes patch"
  82. sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  83. echo "install patch success"
  84. fi
  85. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  86. echo "install unzip"
  87. require_sudoer "sudo apt-get install -y --force-yes unzip"
  88. sudo apt-get install -y --force-yes unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  89. echo "install unzip success"
  90. fi
  91. if [ $SRS_NGINX = YES ]; then
  92. if [[ ! -f /usr/include/pcre.h ]]; then
  93. echo "install libpcre3-dev"
  94. require_sudoer "sudo apt-get install -y --force-yes libpcre3-dev"
  95. sudo apt-get install -y --force-yes libpcre3-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  96. echo "install libpcre3-dev success"
  97. fi
  98. fi
  99. if [ $SRS_FFMPEG_TOOL = YES ]; then
  100. autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  101. echo "install autoconf"
  102. require_sudoer "sudo apt-get install -y --force-yes autoconf"
  103. sudo apt-get install -y --force-yes autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  104. echo "install autoconf success"
  105. fi
  106. libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  107. echo "install libtool"
  108. require_sudoer "sudo apt-get install -y --force-yes libtool"
  109. sudo apt-get install -y --force-yes libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  110. echo "install libtool success"
  111. fi
  112. if [[ ! -f /usr/include/zlib.h ]]; then
  113. echo "install zlib1g-dev"
  114. require_sudoer "sudo apt-get install -y --force-yes zlib1g-dev"
  115. sudo apt-get install -y --force-yes zlib1g-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  116. echo "install zlib1g-dev success"
  117. fi
  118. fi
  119. echo "Ubuntu install tools success"
  120. return 0
  121. }
  122. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  123. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  124. Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Ubuntu prepare failed, ret=$ret"; exit $ret; fi
  125. fi
  126. #####################################################################################
  127. # for Centos, auto install tools by yum
  128. #####################################################################################
  129. OS_IS_CENTOS=NO
  130. function Centos_prepare()
  131. {
  132. if [[ ! -f /etc/redhat-release ]]; then
  133. return 0;
  134. fi
  135. # cross build for arm, install the cross build tool chain.
  136. if [ $SRS_CROSS_BUILD = YES ]; then
  137. echo "embeded(arm/mips) is invalid for CentOS"
  138. return 1
  139. fi
  140. OS_IS_CENTOS=YES
  141. echo "Centos detected, install tools if needed"
  142. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  143. echo "install gcc"
  144. require_sudoer "sudo yum install -y gcc"
  145. sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  146. echo "install gcc success"
  147. fi
  148. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  149. echo "install gcc-c++"
  150. require_sudoer "sudo yum install -y gcc-c++"
  151. sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  152. echo "install gcc-c++ success"
  153. fi
  154. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  155. echo "install make"
  156. require_sudoer "sudo yum install -y make"
  157. sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  158. echo "install make success"
  159. fi
  160. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  161. echo "install patch"
  162. require_sudoer "sudo yum install -y patch"
  163. sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  164. echo "install patch success"
  165. fi
  166. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  167. echo "install unzip"
  168. require_sudoer "sudo yum install -y unzip"
  169. sudo yum install -y unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  170. echo "install unzip success"
  171. fi
  172. if [ $SRS_NGINX = YES ]; then
  173. if [[ ! -f /usr/include/pcre.h ]]; then
  174. echo "install pcre-devel"
  175. require_sudoer "sudo yum install -y pcre-devel"
  176. sudo yum install -y pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  177. echo "install pcre-devel success"
  178. fi
  179. fi
  180. if [ $SRS_FFMPEG_TOOL = YES ]; then
  181. automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  182. echo "install automake"
  183. require_sudoer "sudo yum install -y automake"
  184. sudo yum install -y automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  185. echo "install automake success"
  186. fi
  187. autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  188. echo "install autoconf"
  189. require_sudoer "sudo yum install -y autoconf"
  190. sudo yum install -y autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  191. echo "install autoconf success"
  192. fi
  193. libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  194. echo "install libtool"
  195. require_sudoer "sudo yum install -y libtool"
  196. sudo yum install -y libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  197. echo "install libtool success"
  198. fi
  199. if [[ ! -f /usr/include/zlib.h ]]; then
  200. echo "install zlib-devel"
  201. require_sudoer "sudo yum install -y zlib-devel"
  202. sudo yum install -y zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  203. echo "install zlib-devel success"
  204. fi
  205. fi
  206. echo "Centos install tools success"
  207. return 0
  208. }
  209. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  210. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  211. Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "CentOS prepare failed, ret=$ret"; exit $ret; fi
  212. fi
  213. #####################################################################################
  214. # for Centos, auto install tools by yum
  215. #####################################################################################
  216. OS_IS_OSX=NO
  217. function OSX_prepare()
  218. {
  219. uname -s|grep Darwin >/dev/null 2>&1
  220. ret=$?; if [[ 0 -ne $ret ]]; then
  221. if [ $SRS_OSX = YES ]; then
  222. echo "OSX check failed, actual is `uname -s`"
  223. exit 1;
  224. fi
  225. return 0;
  226. fi
  227. # cross build for arm, install the cross build tool chain.
  228. if [ $SRS_CROSS_BUILD = YES ]; then
  229. echo "embeded(arm/mips) is invalid for OSX"
  230. return 1
  231. fi
  232. OS_IS_OSX=YES
  233. echo "OSX detected, install tools if needed"
  234. # requires the osx when os
  235. if [ $OS_IS_OSX = YES ]; then
  236. if [ $SRS_OSX = NO ]; then
  237. echo "OSX detected, must specifies the --osx"
  238. exit 1
  239. fi
  240. fi
  241. brew --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  242. echo "install brew"
  243. echo "ruby -e \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)\""
  244. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  245. echo "install brew success"
  246. fi
  247. gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  248. echo "install gcc"
  249. echo "brew install gcc"
  250. brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  251. echo "install gcc success"
  252. fi
  253. g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  254. echo "install gcc-c++"
  255. echo "brew install gcc-c++"
  256. brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  257. echo "install gcc-c++ success"
  258. fi
  259. make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  260. echo "install make"
  261. echo "brew install make"
  262. brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  263. echo "install make success"
  264. fi
  265. patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  266. echo "install patch"
  267. echo "brew install patch"
  268. brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  269. echo "install patch success"
  270. fi
  271. unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  272. echo "install unzip"
  273. echo "brew install unzip"
  274. brew install unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  275. echo "install unzip success"
  276. fi
  277. if [ $SRS_NGINX = YES ]; then
  278. if [[ ! -f /usr/local/include/pcre.h ]]; then
  279. echo "install pcre"
  280. echo "brew install pcre"
  281. brew install pcre; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  282. echo "install pcre success"
  283. fi
  284. fi
  285. if [ $SRS_FFMPEG_TOOL = YES ]; then
  286. automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  287. echo "install automake"
  288. echo "brew install automake"
  289. brew install automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  290. echo "install automake success"
  291. fi
  292. autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  293. echo "install autoconf"
  294. echo "brew install autoconf"
  295. brew install autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  296. echo "install autoconf success"
  297. fi
  298. which libtool >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  299. echo "install libtool"
  300. echo "brew install libtool"
  301. brew install libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  302. echo "install libtool success"
  303. fi
  304. brew info zlib >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  305. echo "install zlib"
  306. echo "brew install zlib"
  307. brew install zlib; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  308. echo "install zlib success"
  309. fi
  310. fi
  311. echo "OSX install tools success"
  312. return 0
  313. }
  314. # donot prepare tools, for srs-librtmp depends only gcc and g++.
  315. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  316. OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi
  317. fi
  318. # the sed command
  319. function sed_utility() {
  320. if [ $OS_IS_OSX = YES ]; then
  321. sed -i '' "$@"
  322. else
  323. sed -i "$@"
  324. fi
  325. ret=$?; if [[ $ret -ne 0 ]]; then
  326. if [ $OS_IS_OSX = YES ]; then
  327. echo "sed -i '' \"$@\""
  328. else
  329. echo "sed -i \"$@\""
  330. fi
  331. return $ret
  332. fi
  333. }
  334. SED="sed_utility" && echo "SED is $SED"
  335. #####################################################################################
  336. # check the os.
  337. #####################################################################################
  338. # user must specifies something what a fuck, we suppport following os:
  339. # centos/ubuntu/osx,
  340. # cross build for embeded system, for example, mips or arm,
  341. # directly build on arm/mips, for example, pi or cubie,
  342. # export srs-librtmp
  343. # others is invalid.
  344. if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_EXPORT_LIBRTMP_PROJECT = NO ]]; then
  345. if [[ $SRS_PI = NO && $SRS_CUBIE = NO && $SRS_CROSS_BUILD = NO ]]; then
  346. echo "what a fuck, os not supported."
  347. exit 1
  348. fi
  349. fi
  350. #####################################################################################
  351. # st-1.9
  352. #####################################################################################
  353. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  354. # check the cross build flag file, if flag changed, need to rebuild the st.
  355. _ST_MAKE=linux-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_EPOLL"
  356. # for osx, use darwin for st, donot use epoll.
  357. if [ $OS_IS_OSX = YES ]; then
  358. _ST_MAKE=darwin-debug && _ST_EXTRA_CFLAGS="-DMD_HAVE_KQUEUE"
  359. fi
  360. # memory leak for linux-optimized
  361. # @see: https://github.com/ossrs/srs/issues/197
  362. if [ $SRS_CROSS_BUILD = YES ]; then
  363. # ok, arm specified, if the flag filed does not exists, need to rebuild.
  364. if [[ -f ${SRS_OBJS}/_flag.st.cross.build.tmp && -f ${SRS_OBJS}/st/libst.a ]]; then
  365. echo "st-1.9t for arm is ok.";
  366. else
  367. # TODO: FIXME: patch the bug.
  368. # patch st for arm, @see: https://github.com/ossrs/srs/wiki/v1_CN_SrsLinuxArm#st-arm-bug-fix
  369. echo "build st-1.9t for arm";
  370. (
  371. rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} &&
  372. unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && chmod +w * &&
  373. patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
  374. patch -p0 < ../../3rdparty/patches/3.st.osx.kqueue.patch &&
  375. patch -p0 < ../../3rdparty/patches/4.st.disable.examples.patch &&
  376. patch -p0 < ../../3rdparty/patches/6.st.osx10.14.build.patch &&
  377. make ${_ST_MAKE} CC=${SrsArmCC} AR=${SrsArmAR} LD=${SrsArmLD} RANDLIB=${SrsArmRANDLIB} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" &&
  378. cd .. && rm -rf st && ln -sf st-1.9/obj st &&
  379. cd .. && touch ${SRS_OBJS}/_flag.st.cross.build.tmp
  380. )
  381. fi
  382. else
  383. if [[ ! -f ${SRS_OBJS}/_flag.st.cross.build.tmp && -f ${SRS_OBJS}/st/libst.a ]]; then
  384. echo "st-1.9t is ok.";
  385. else
  386. # patch st for arm, @see: https://github.com/ossrs/srs/wiki/v1_CN_SrsLinuxArm#st-arm-bug-fix
  387. echo "build st-1.9t";
  388. (
  389. rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} &&
  390. unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && chmod +w * &&
  391. patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
  392. patch -p0 < ../../3rdparty/patches/3.st.osx.kqueue.patch &&
  393. patch -p0 < ../../3rdparty/patches/4.st.disable.examples.patch &&
  394. patch -p0 < ../../3rdparty/patches/6.st.osx10.14.build.patch &&
  395. make ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" &&
  396. cd .. && rm -rf st && ln -sf st-1.9/obj st &&
  397. cd .. && rm -f ${SRS_OBJS}/_flag.st.cross.build.tmp
  398. )
  399. fi
  400. fi
  401. # check status
  402. ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
  403. if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "build st-1.9 static lib failed."; exit -1; fi
  404. fi
  405. #####################################################################################
  406. # http-parser-2.1
  407. #####################################################################################
  408. # check the cross build flag file, if flag changed, need to rebuild the st.
  409. if [ $SRS_HTTP_CORE = YES ]; then
  410. # ok, arm specified, if the flag filed does not exists, need to rebuild.
  411. if [ $SRS_CROSS_BUILD = YES ]; then
  412. if [[ -f ${SRS_OBJS}/_flag.st.hp.tmp && -f ${SRS_OBJS}/hp/http_parser.h && -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then
  413. echo "http-parser-2.1 for arm is ok.";
  414. else
  415. echo "build http-parser-2.1 for arm";
  416. (
  417. rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip &&
  418. cd http-parser-2.1 &&
  419. patch -p0 < ../../3rdparty/patches/2.http.parser.patch &&
  420. make CC=${SrsArmCC} AR=${SrsArmAR} package &&
  421. cd .. && rm -rf hp && ln -sf http-parser-2.1 hp &&
  422. cd .. && touch ${SRS_OBJS}/_flag.st.hp.tmp
  423. )
  424. fi
  425. else
  426. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  427. if [[ ! -f ${SRS_OBJS}/_flag.st.hp.tmp && -f ${SRS_OBJS}/hp/http_parser.h && -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then
  428. echo "http-parser-2.1 is ok.";
  429. else
  430. echo "build http-parser-2.1";
  431. (
  432. rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip &&
  433. cd http-parser-2.1 &&
  434. patch -p0 < ../../3rdparty/patches/2.http.parser.patch &&
  435. # Patch build error for https://github.com/ossrs/srs/pull/1312#issuecomment-480243404
  436. patch -p0 < ../../3rdparty/patches/7.http.parser.patch &&
  437. make package &&
  438. cd .. && rm -rf hp && ln -sf http-parser-2.1 hp &&
  439. cd .. && rm -f ${SRS_OBJS}/_flag.st.hp.tmp
  440. )
  441. fi
  442. fi
  443. # check status
  444. ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi
  445. if [[ ! -f ${SRS_OBJS}/hp/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
  446. if [[ ! -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
  447. fi
  448. #####################################################################################
  449. # nginx for HLS, nginx-1.5.0
  450. #####################################################################################
  451. function write_nginx_html5()
  452. {
  453. cat<<END > ${html_file}
  454. <video autoplay controls autobuffer type="application/vnd.apple.mpegurl"
  455. src="${hls_stream}">
  456. </video>
  457. END
  458. }
  459. # create the nginx dir, for http-server if not build nginx
  460. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  461. mkdir -p ${SRS_OBJS}/nginx
  462. fi
  463. # make nginx
  464. __SRS_BUILD_NGINX=NO; if [ $SRS_CROSS_BUILD = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi
  465. if [ $__SRS_BUILD_NGINX = YES ]; then
  466. if [[ -f ${SRS_OBJS}/nginx/sbin/nginx ]]; then
  467. echo "nginx-1.5.7 is ok.";
  468. else
  469. echo "build nginx-1.5.7";
  470. (
  471. rm -rf ${SRS_OBJS}/nginx-1.5.7 && cd ${SRS_OBJS} &&
  472. unzip -q ../3rdparty/nginx-1.5.7.zip && cd nginx-1.5.7 &&
  473. ./configure --prefix=`pwd`/_release && make ${SRS_JOBS} && make install &&
  474. cd .. && rm -rf nginx && ln -sf nginx-1.5.7/_release nginx
  475. )
  476. fi
  477. # check status
  478. ret=$?; if [[ $ret -ne 0 ]]; then echo "build nginx-1.5.7 failed, ret=$ret"; exit $ret; fi
  479. if [ ! -f ${SRS_OBJS}/nginx/sbin/nginx ]; then echo "build nginx-1.5.7 failed."; exit -1; fi
  480. # use current user to config nginx,
  481. # srs will write ts/m3u8 file use current user,
  482. # nginx default use nobody, so cannot read the ts/m3u8 created by srs.
  483. cp ${SRS_OBJS}/nginx/conf/nginx.conf ${SRS_OBJS}/nginx/conf/nginx.conf.bk
  484. $SED "s/^.user nobody;/user `whoami`;/g" ${SRS_OBJS}/nginx/conf/nginx.conf
  485. fi
  486. # the demo dir.
  487. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  488. # create forward dir
  489. mkdir -p ${SRS_OBJS}/nginx/html/live &&
  490. mkdir -p ${SRS_OBJS}/nginx/html/forward/live
  491. # generate default html pages for android.
  492. html_file=${SRS_OBJS}/nginx/html/live/demo.html && hls_stream=demo.m3u8 && write_nginx_html5
  493. html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  494. html_file=${SRS_OBJS}/nginx/html/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
  495. html_file=${SRS_OBJS}/nginx/html/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
  496. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
  497. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
  498. html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
  499. # copy players to nginx html dir.
  500. rm -rf ${SRS_OBJS}/nginx/html/players &&
  501. ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players &&
  502. rm -f ${SRS_OBJS}/nginx/crossdomain.xml &&
  503. ln -sf `pwd`/research/players/crossdomain.xml ${SRS_OBJS}/nginx/html/crossdomain.xml
  504. # for favicon.ico
  505. rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
  506. ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico
  507. # nginx.html to detect whether nginx is alive
  508. echo "nginx is ok" > ${SRS_OBJS}/nginx/html/nginx.html
  509. fi
  510. #####################################################################################
  511. # cherrypy for http hooks callback, CherryPy-3.2.4
  512. #####################################################################################
  513. if [ $SRS_HTTP_CALLBACK = YES ]; then
  514. if [[ -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]]; then
  515. echo "CherryPy-3.2.4 is ok.";
  516. else
  517. echo "install CherryPy-3.2.4";
  518. (
  519. rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS} &&
  520. unzip -q ../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 &&
  521. python setup.py install --user
  522. )
  523. fi
  524. # check status
  525. ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi
  526. if [ ! -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
  527. fi
  528. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  529. echo "link players to cherrypy static-dir"
  530. rm -rf research/api-server/static-dir/players &&
  531. ln -sf `pwd`/research/players research/api-server/static-dir/players &&
  532. rm -f research/api-server/static-dir/crossdomain.xml &&
  533. ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml &&
  534. rm -rf research/api-server/static-dir/live &&
  535. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
  536. ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
  537. rm -rf research/api-server/static-dir/forward &&
  538. mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
  539. ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
  540. ret=$?; if [[ $ret -ne 0 ]]; then echo "[warn] link players to cherrypy static-dir failed"; fi
  541. fi
  542. #####################################################################################
  543. # generate demo index.html
  544. #####################################################################################
  545. # if nginx enalbed, generate nginx index file.
  546. if [ $__SRS_BUILD_NGINX = YES ]; then
  547. rm -f ${SRS_OBJS}/nginx/html/index.html &&
  548. ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
  549. fi
  550. # if http-server enalbed, use srs embeded http-server
  551. if [ $SRS_HTTP_SERVER = YES ]; then
  552. rm -f ${SRS_OBJS}/nginx/html/index.html &&
  553. ln -sf `pwd`/research/players/srs-http-server_index.html ${SRS_OBJS}/nginx/html/index.html
  554. fi
  555. # if api-server enabled, generate for api server.
  556. if [ $SRS_HTTP_CALLBACK = YES ]; then
  557. rm -f ${SRS_OBJS}/nginx/html/index.html &&
  558. ln -sf `pwd`/research/players/api-server_index.html ${SRS_OBJS}/nginx/html/index.html
  559. fi
  560. #####################################################################################
  561. # openssl, for rtmp complex handshake
  562. #####################################################################################
  563. # extra configure options
  564. CONFIGURE_TOOL="./config"
  565. if [ $SRS_CROSS_BUILD = YES ]; then
  566. CONFIGURE_TOOL="./Configure linux-armv4"
  567. fi
  568. if [ $SRS_OSX = YES ]; then
  569. CONFIGURE_TOOL="./Configure darwin64-`uname -m`-cc"
  570. fi
  571. OPENSSL_HOTFIX="-DOPENSSL_NO_HEARTBEATS"
  572. # @see http://www.openssl.org/news/secadv/20140407.txt
  573. # Affected users should upgrade to OpenSSL 1.0.1g. Users unable to immediately
  574. # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
  575. if [ $SRS_SSL = YES ]; then
  576. if [ $SRS_USE_SYS_SSL = YES ]; then
  577. echo "warning: donot compile ssl, use system ssl"
  578. else
  579. # check the cross build flag file, if flag changed, need to rebuild the st.
  580. if [ $SRS_CROSS_BUILD = YES ]; then
  581. # ok, arm specified, if the flag filed does not exists, need to rebuild.
  582. if [[ -f ${SRS_OBJS}/_flag.ssl.cross.build.tmp && -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
  583. echo "openssl-1.0.1f for arm is ok.";
  584. else
  585. echo "build openssl-1.0.1f for arm";
  586. (
  587. rm -rf ${SRS_OBJS}/openssl-1.0.1f && cd ${SRS_OBJS} &&
  588. unzip -q ../3rdparty/openssl-1.0.1f.zip && cd openssl-1.0.1f &&
  589. $CONFIGURE_TOOL --prefix=`pwd`/_release -no-shared no-asm $OPENSSL_HOTFIX &&
  590. make CC=${SrsArmCC} GCC=${SrsArmGCC} AR="${SrsArmAR} r" \
  591. LD=${SrsArmLD} LINK=${SrsArmGCC} RANDLIB=${SrsArmRANDLIB} &&
  592. make install_sw &&
  593. cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
  594. cd .. && touch ${SRS_OBJS}/_flag.ssl.cross.build.tmp
  595. )
  596. fi
  597. else
  598. # cross build not specified, if exists flag, need to rebuild for no-arm platform.
  599. if [[ ! -f ${SRS_OBJS}/_flag.ssl.cross.build.tmp && -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
  600. echo "openssl-1.0.1f is ok.";
  601. else
  602. echo "build openssl-1.0.1f";
  603. (
  604. rm -rf ${SRS_OBJS}/openssl-1.0.1f && cd ${SRS_OBJS} &&
  605. unzip -q ../3rdparty/openssl-1.0.1f.zip && cd openssl-1.0.1f &&
  606. $CONFIGURE_TOOL --prefix=`pwd`/_release -no-shared $OPENSSL_HOTFIX &&
  607. make && make install_sw &&
  608. cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
  609. cd .. && rm -f ${SRS_OBJS}/_flag.ssl.cross.build.tmp
  610. )
  611. fi
  612. fi
  613. # check status
  614. ret=$?; if [[ $ret -ne 0 ]]; then echo "build openssl-1.0.1f failed, ret=$ret"; exit $ret; fi
  615. if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "build openssl-1.0.1f failed."; exit -1; fi
  616. fi
  617. fi
  618. #####################################################################################
  619. # live transcoding, ffmpeg-4.1, x264-core157, lame-3.99.5, libaacplus-2.0.2.
  620. #####################################################################################
  621. if [ $SRS_FFMPEG_TOOL = YES ]; then
  622. if [[ -f /usr/local/bin/ffmpeg && ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
  623. mkdir -p ${SRS_OBJS}/ffmpeg/bin && ln -sf /usr/local/bin/ffmpeg ${SRS_OBJS}/ffmpeg/bin/ffmpeg
  624. fi
  625. if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
  626. echo "ffmpeg-4.1 is ok.";
  627. else
  628. echo "build ffmpeg-4.1";
  629. (
  630. cd ${SRS_OBJS} && pwd_dir=`pwd` &&
  631. rm -rf ffmepg.src && mkdir -p ffmpeg.src && cd ffmpeg.src &&
  632. rm -f build_ffmpeg.sh && ln -sf ../../auto/build_ffmpeg.sh && . build_ffmpeg.sh &&
  633. cd ${pwd_dir} && rm -rf ffmpeg && ln -sf ffmpeg.src/_release ffmpeg
  634. )
  635. fi
  636. # check status
  637. ret=$?; if [[ $ret -ne 0 ]]; then echo "build ffmpeg-4.1 failed, ret=$ret"; exit $ret; fi
  638. if [ ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]; then echo "build ffmpeg-4.1 failed."; exit -1; fi
  639. fi
  640. #####################################################################################
  641. # build research code, librtmp
  642. #####################################################################################
  643. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
  644. if [ $SRS_RESEARCH = YES ]; then
  645. mkdir -p ${SRS_OBJS}/research
  646. (cd ${SRS_WORKDIR}/research/hls && make ${SRS_JOBS} && mv ts_info ../../${SRS_OBJS_DIR}/research)
  647. ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/hls failed, ret=$ret"; exit $ret; fi
  648. (cd research/ffempty && make ${SRS_JOBS} && mv ffempty ../../${SRS_OBJS_DIR}/research)
  649. ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/ffempty failed, ret=$ret"; exit $ret; fi
  650. fi
  651. fi
  652. if [ $SRS_LIBRTMP = YES ]; then
  653. mkdir -p ${SRS_OBJS}/research
  654. # librtmp
  655. (cd ${SRS_WORKDIR}/research/librtmp && mkdir -p objs && ln -sf `pwd`/objs ../../${SRS_OBJS_DIR}/research/librtmp)
  656. ret=$?; if [[ $ret -ne 0 ]]; then echo "link research/librtmp failed, ret=$ret"; exit $ret; fi
  657. fi
  658. #####################################################################################
  659. # build utest code
  660. #####################################################################################
  661. if [ $SRS_UTEST = YES ]; then
  662. if [[ -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]]; then
  663. echo "gtest-1.6.0 is ok.";
  664. else
  665. echo "build gtest-1.6.0";
  666. (
  667. rm -rf ${SRS_OBJS}/gtest-1.6.0 && cd ${SRS_OBJS} &&
  668. unzip -q ../3rdparty/gtest-1.6.0.zip &&
  669. rm -rf gtest && ln -sf gtest-1.6.0 gtest
  670. )
  671. fi
  672. # check status
  673. ret=$?; if [[ $ret -ne 0 ]]; then echo "build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi
  674. if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "build gtest-1.6.0 failed."; exit -1; fi
  675. fi
  676. #####################################################################################
  677. # build gperf code
  678. #####################################################################################
  679. if [ $SRS_GPERF = YES ]; then
  680. if [[ -f ${SRS_OBJS}/gperf/bin/pprof ]]; then
  681. echo "gperftools-2.1 is ok.";
  682. else
  683. echo "build gperftools-2.1";
  684. (
  685. rm -rf ${SRS_OBJS}/gperftools-2.1 && cd ${SRS_OBJS} &&
  686. unzip -q ../3rdparty/gperftools-2.1.zip && cd gperftools-2.1 &&
  687. ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install &&
  688. cd .. && rm -rf gperf && ln -sf gperftools-2.1/_release gperf &&
  689. rm -rf pprof && ln -sf gperf/bin/pprof pprof
  690. )
  691. fi
  692. # check status
  693. ret=$?; if [[ $ret -ne 0 ]]; then echo "build gperftools-2.1 failed, ret=$ret"; exit $ret; fi
  694. if [ ! -f ${SRS_OBJS}/gperf/bin/pprof ]; then echo "build gperftools-2.1 failed."; exit -1; fi
  695. fi
  696. #####################################################################################
  697. # generated the test script
  698. #####################################################################################
  699. rm -rf ${SRS_OBJS}/srs.test && ln -sf `pwd`/scripts/srs.test objs/srs.test