2
0

options.sh 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. #!/bin/bash
  2. ################################################################
  3. help=no
  4. # feature options
  5. SRS_HDS=NO
  6. SRS_SRT=NO
  7. SRS_RTC=YES
  8. SRS_CXX11=NO
  9. SRS_CXX14=NO
  10. SRS_NGINX=NO
  11. SRS_UTEST=NO
  12. # Always enable the bellow features.
  13. SRS_STREAM_CASTER=YES
  14. SRS_INGEST=YES
  15. SRS_SSL=YES
  16. SRS_SSL_1_0=NO
  17. SRS_SSL_LOCAL=NO
  18. SRS_HTTPS=YES
  19. SRS_STAT=YES
  20. SRS_TRANSCODE=YES
  21. SRS_HTTP_CALLBACK=YES
  22. SRS_HTTP_SERVER=YES
  23. SRS_HTTP_API=YES
  24. SRS_HTTP_CORE=YES
  25. SRS_HLS=YES
  26. SRS_DVR=YES
  27. SRS_CHERRYPY=NO
  28. #
  29. ################################################################
  30. # FFmpeg stub is the stub code in SRS for ingester or encoder.
  31. SRS_FFMPEG_STUB=NO
  32. # FFmpeg tool is the binary for FFmpeg tool, to exec ingest or transcode.
  33. SRS_FFMPEG_TOOL=NO
  34. # FFmpeg fit is the source code for RTC, to transcode audio or video in SRS.
  35. SRS_FFMPEG_FIT=RESERVED
  36. # arguments
  37. SRS_PREFIX=/usr/local/srs
  38. SRS_DEFAULT_CONFIG=conf/srs.conf
  39. SRS_JOBS=1
  40. SRS_STATIC=NO
  41. # If enabled, link shared libraries for libst.so which uses MPL license.
  42. # See https://ossrs.net/lts/zh-cn/license#state-threads
  43. SRS_SHARED_ST=NO
  44. # If enabled, link shared libraries for libsrt.so which uses MPL license.
  45. # See https://ossrs.net/lts/zh-cn/license#srt
  46. SRS_SHARED_SRT=NO
  47. # If enabled, link shared libraries for FFmpeg which is LGPL license.
  48. # See https://ossrs.net/lts/zh-cn/license#ffmpeg
  49. SRS_SHARED_FFMPEG=NO
  50. # whether enable the gcov
  51. SRS_GCOV=NO
  52. # whether enable the log verbose/info/trace level.
  53. # always enable the warn/error level.
  54. SRS_LOG_VERBOSE=NO
  55. SRS_LOG_INFO=NO
  56. SRS_LOG_TRACE=YES
  57. #
  58. ################################################################
  59. # Experts options.
  60. SRS_USE_SYS_SSL=NO # Use system ssl(-lssl) if required.
  61. SRS_VALGRIND=NO
  62. SRS_BUILD_TAG= # Set the object files tag name.
  63. SRS_CLEAN=YES # Whether do "make clean" when configure.
  64. SRS_SIMULATOR=NO # Whether enable RTC simulate API.
  65. #
  66. ################################################################
  67. # Performance options.
  68. SRS_GPERF=NO # Performance test: tcmalloc
  69. SRS_GPERF_MC=NO # Performance test: gperf memory check
  70. SRS_GPERF_MD=NO # Performance test: gperf memory defence
  71. SRS_GPERF_MP=NO # Performance test: gperf memory profile
  72. SRS_GPERF_CP=NO # Performance test: gperf cpu profile
  73. SRS_GPROF=NO # Performance test: gprof
  74. #
  75. ################################################################
  76. # Preset options
  77. SRS_X86_X64=NO # For x86_64 servers
  78. SRS_OSX=NO #For osx/macOS PC.
  79. SRS_CROSS_BUILD=NO #For cross build, for example, on Ubuntu.
  80. # For cross build, the cpu, for example(FFmpeg), --cpu=24kc
  81. SRS_CROSS_BUILD_CPU=
  82. # For cross build, the arch, for example(FFmpeg), --arch=aarch64
  83. SRS_CROSS_BUILD_ARCH=
  84. # For cross build, the host, for example(libsrtp), --host=aarch64-linux-gnu
  85. SRS_CROSS_BUILD_HOST=
  86. # For cross build, the cross prefix, for example(FFmpeg), --cross-prefix=aarch64-linux-gnu-
  87. SRS_CROSS_BUILD_PREFIX=
  88. #
  89. #####################################################################################
  90. # Toolchain for cross-build on Ubuntu for ARM or MIPS.
  91. SRS_TOOL_CC=gcc
  92. SRS_TOOL_CXX=g++
  93. SRS_TOOL_AR=ar
  94. SRS_TOOL_LD=ld
  95. SRS_TOOL_RANDLIB=randlib
  96. SRS_EXTRA_FLAGS=
  97. #
  98. #####################################################################################
  99. # Performance optimize.
  100. SRS_NASM=YES
  101. SRS_SRTP_ASM=YES
  102. SRS_DEBUG=NO
  103. SRS_DEBUG_STATS=NO
  104. #####################################################################################
  105. # menu
  106. #####################################################################################
  107. function show_help() {
  108. cat << END
  109. Presets:
  110. --x86-64, --x86-x64 For x86/x64 cpu, common pc and servers. Default: $(value2switch $SRS_X86_X64)
  111. --cross-build Enable cross-build, please set bellow Toolchain also. Default: $(value2switch $SRS_CROSS_BUILD)
  112. --osx Enable build for OSX/Darwin AppleOS. Default: $(value2switch $SRS_OSX)
  113. Features:
  114. -h, --help Print this message and exit 0.
  115. --https=on|off Whether enable HTTPS client and server. Default: $(value2switch $SRS_HTTPS)
  116. --hds=on|off Whether build the hds streaming, mux RTMP to F4M/F4V files. Default: $(value2switch $SRS_HDS)
  117. --cherrypy=on|off Whether install CherryPy for demo api-server. Default: $(value2switch $SRS_CHERRYPY)
  118. --utest=on|off Whether build the utest. Default: $(value2switch $SRS_UTEST)
  119. --srt=on|off Whether build the SRT. Default: $(value2switch $SRS_SRT)
  120. --rtc=on|off Whether build the WebRTC. Default: $(value2switch $SRS_RTC)
  121. --cxx11=on|off Whether enable the C++11. Default: $(value2switch $SRS_CXX11)
  122. --cxx14=on|off Whether enable the C++14. Default: $(value2switch $SRS_CXX14)
  123. --ffmpeg-fit=on|off Whether enable the FFmpeg fit(source code). Default: $(value2switch $SRS_FFMPEG_FIT)
  124. --prefix=<path> The absolute installation path. Default: $SRS_PREFIX
  125. --config=<path> The default config file for SRS. Default: $SRS_DEFAULT_CONFIG
  126. --gcov=on|off Whether enable the GCOV compiler options. Default: $(value2switch $SRS_GCOV)
  127. --debug=on|off Whether enable the debug code, may hurt performance. Default: $(value2switch $SRS_DEBUG)
  128. --debug-stats=on|off Whether enable the debug stats, may hurt performance. Default: $(value2switch $SRS_DEBUG_STATS)
  129. --jobs[=N] Allow N jobs at once; infinite jobs with no arg. Default: $SRS_JOBS
  130. --log-verbose=on|off Whether enable the log verbose level. Default: $(value2switch $SRS_LOG_VERBOSE)
  131. --log-info=on|off Whether enable the log info level. Default: $(value2switch $SRS_LOG_INFO)
  132. --log-trace=on|off Whether enable the log trace level. Default: $(value2switch $SRS_LOG_TRACE)
  133. Performance: @see https://blog.csdn.net/win_lin/article/details/53503869
  134. --valgrind=on|off Whether build valgrind for memory check. Default: $(value2switch $SRS_VALGRIND)
  135. --gperf=on|off Whether build SRS with gperf tools(no gmd/gmc/gmp/gcp, with tcmalloc only). Default: $(value2switch $SRS_GPERF)
  136. --gmc=on|off Whether build memory check with gperf tools. Default: $(value2switch $SRS_GPERF_MC)
  137. --gmd=on|off Whether build memory defense(corrupt memory) with gperf tools. Default: $(value2switch $SRS_GPERF_MD)
  138. --gmp=on|off Whether build memory profile with gperf tools. Default: $(value2switch $SRS_GPERF_MP)
  139. --gcp=on|off Whether build cpu profile with gperf tools. Default: $(value2switch $SRS_GPERF_CP)
  140. --gprof=on|off Whether build SRS with gprof(GNU profile tool). Default: $(value2switch $SRS_GPROF)
  141. --nasm=on|off Whether build FFMPEG for RTC with nasm. Default: $(value2switch $SRS_NASM)
  142. --srtp-nasm=on|off Whether build SRTP with ASM(openssl-asm), requires RTC and openssl-1.0.*. Default: $(value2switch $SRS_SRTP_ASM)
  143. Toolchain options: @see https://github.com/ossrs/srs/wiki/v4_CN_SrsLinuxArm#ubuntu-cross-build-srs
  144. --static=on|off Whether add '-static' to link options. Default: $(value2switch $SRS_STATIC)
  145. --cpu=<CPU> Toolchain: Select the minimum required CPU for cross-build.
  146. --arch=<ARCH> Toolchain: Select architecture for cross-build.
  147. --host=<BUILD> Toolchain: Cross-compile to build programs to run on HOST.
  148. --cross-prefix=<PREFIX> Toolchain: Use PREFIX for compilation tools.
  149. --cc=<CC> Toolchain: Use c compiler CC. Default: $SRS_TOOL_CC
  150. --cxx=<CXX> Toolchain: Use c++ compiler CXX. Default: $SRS_TOOL_CXX
  151. --ar=<AR> Toolchain: Use archive tool AR. Default: $SRS_TOOL_CXX
  152. --ld=<LD> Toolchain: Use linker tool LD. Default: $SRS_TOOL_CXX
  153. --randlib=<RANDLIB> Toolchain: Use randlib tool RANDLIB. Default: $SRS_TOOL_CXX
  154. --extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS.
  155. Experts:
  156. --sys-ssl=on|off Do not compile ssl, use system ssl(-lssl) if required. Default: $(value2switch $SRS_USE_SYS_SSL)
  157. --ssl-1-0=on|off Whether use openssl-1.0.*. Default: $(value2switch $SRS_SSL_1_0)
  158. --ssl-local=on|off Whether use local openssl, not system even exists. Default: $(value2switch $SRS_SSL_LOCAL)
  159. --shared-st=on|off Use shared libraries for ST which is MPL license. Default: $(value2switch $SRS_SHARED_ST)
  160. --shared-srt=on|off Use shared libraries for SRT which is MPL license. Default: $(value2switch $SRS_SHARED_SRT)
  161. --shared-ffmpeg=on|off Use shared libraries for FFmpeg which is LGPL license. Default: $(value2switch $SRS_SHARED_FFMPEG)
  162. --clean=on|off Whether do 'make clean' when configure. Default: $(value2switch $SRS_CLEAN)
  163. --simulator=on|off RTC: Whether enable network simulator. Default: $(value2switch $SRS_SIMULATOR)
  164. --build-tag=<TAG> Set the build object directory suffix.
  165. Workflow:
  166. 1. Apply "Presets". if not specified, use default preset.
  167. 2. Apply "Features", "Performance" and others. user specified option will override the preset.
  168. 3. Check configs and generate Makefile.
  169. Remark:
  170. 1. For performance, read https://blog.csdn.net/win_lin/article/details/53503869
  171. END
  172. }
  173. function parse_user_option() {
  174. # Ignore the options.
  175. if [[ $option == '--demo' || $option == '--dev' || $option == '--fast-dev' || $option == '--pi'
  176. || $option == '--cubie' || $option == '--fast' || $option == '--pure-rtmp' || $option == '--disable-all'
  177. || $option == '--full' || $option == '--with-http-callback' || $option == '--without-http-callback'
  178. || $option == '--http-callback' || $option == '--with-http-api' || $option == '--without-http-api'
  179. || $option == '--http-api' || $option == '--with-http-server' || $option == '--without-http-server'
  180. || $option == '--http-server' || $option == '--with-hls' || $option == '--without-hls'
  181. || $option == '--hls' || $option == '--with-dvr' || $option == '--without-dvr'
  182. || $option == '--dvr' || $option == '--without-transcode' || $option == '--without-ingest'
  183. || $option == '--without-stat' || $option == '--without-stream-caster' || $option == '--without-ssl'
  184. || $option == '--without-librtmp' || ($option == '--librtmp' && $(switch2value $value) == NO)
  185. || $option == '--without-research' || ($option == '--research' && $(switch2value $value) == NO)
  186. ]]; then
  187. echo "Ignore option $option $value"; return 0;
  188. fi
  189. # if specified export single file, export project first.
  190. if [[ $option == '--export-librtmp-single' || $option == '--export-librtmp-project' || $option == '--with-librtmp' || $option == '--librtmp' ]]; then
  191. echo "Error: The $option is not supported yet, please read https://github.com/ossrs/srs-librtmp/issues/32"; exit 1
  192. fi
  193. if [[ $option == '--with-research' || $option == '--research' ]]; then
  194. echo "Error: The $option is not supported yet"; exit 1
  195. fi
  196. if [[ $option == '--arm' || $option == '--mips' || $option == '--with-arm-ubuntu12' || $option == '--with-mips-ubuntu12' ]]; then
  197. echo "Error: Removed misleading option $option, please read https://github.com/ossrs/srs/wiki/v4_CN_SrsLinuxArm#ubuntu-cross-build-srs"
  198. exit -1
  199. fi
  200. # Parse options to variables.
  201. case "$option" in
  202. -h) help=yes ;;
  203. --help) help=yes ;;
  204. --jobs) SRS_JOBS=${value} ;;
  205. --prefix) SRS_PREFIX=${value} ;;
  206. --config) SRS_DEFAULT_CONFIG=${value} ;;
  207. --static) SRS_STATIC=$(switch2value $value) ;;
  208. --cpu) SRS_CROSS_BUILD_CPU=${value} ;;
  209. --arch) SRS_CROSS_BUILD_ARCH=${value} ;;
  210. --host) SRS_CROSS_BUILD_HOST=${value} ;;
  211. --cross-prefix) SRS_CROSS_BUILD_PREFIX=${value} ;;
  212. --cc) SRS_TOOL_CC=${value} ;;
  213. --cxx) SRS_TOOL_CXX=${value} ;;
  214. --ar) SRS_TOOL_AR=${value} ;;
  215. --ld) SRS_TOOL_LD=${value} ;;
  216. --randlib) SRS_TOOL_RANDLIB=${value} ;;
  217. --extra-flags) SRS_EXTRA_FLAGS=${value} ;;
  218. --build-tag) SRS_BUILD_TAG=${value} ;;
  219. --x86-x64) SRS_X86_X64=YES ;;
  220. --x86-64) SRS_X86_X64=YES ;;
  221. --osx) SRS_OSX=YES ;;
  222. --without-srtp-nasm) SRS_SRTP_ASM=NO ;;
  223. --with-srtp-nasm) SRS_SRTP_ASM=YES ;;
  224. --srtp-nasm) SRS_SRTP_ASM=$(switch2value $value) ;;
  225. --without-nasm) SRS_NASM=NO ;;
  226. --with-nasm) SRS_NASM=YES ;;
  227. --nasm) SRS_NASM=$(switch2value $value) ;;
  228. --with-ssl) SRS_SSL=YES ;;
  229. --ssl) SRS_SSL=$(switch2value $value) ;;
  230. --https) SRS_HTTPS=$(switch2value $value) ;;
  231. --ssl-1-0) SRS_SSL_1_0=$(switch2value $value) ;;
  232. --ssl-local) SRS_SSL_LOCAL=$(switch2value $value) ;;
  233. --with-hds) SRS_HDS=YES ;;
  234. --without-hds) SRS_HDS=NO ;;
  235. --hds) SRS_HDS=$(switch2value $value) ;;
  236. --with-transcode) SRS_TRANSCODE=YES ;;
  237. --transcode) SRS_TRANSCODE=$(switch2value $value) ;;
  238. --with-ingest) SRS_INGEST=YES ;;
  239. --ingest) SRS_INGEST=$(switch2value $value) ;;
  240. --with-stat) SRS_STAT=YES ;;
  241. --stat) SRS_STAT=$(switch2value $value) ;;
  242. --with-stream-caster) SRS_STREAM_CASTER=YES ;;
  243. --stream-caster) SRS_STREAM_CASTER=$(switch2value $value) ;;
  244. --with-utest) SRS_UTEST=YES ;;
  245. --without-utest) SRS_UTEST=NO ;;
  246. --utest) SRS_UTEST=$(switch2value $value) ;;
  247. --cherrypy) SRS_CHERRYPY=$(switch2value $value) ;;
  248. --gcov) SRS_GCOV=$(switch2value $value) ;;
  249. --with-srt) SRS_SRT=YES ;;
  250. --without-srt) SRS_SRT=NO ;;
  251. --srt) SRS_SRT=$(switch2value $value) ;;
  252. --with-rtc) SRS_RTC=YES ;;
  253. --without-rtc) SRS_RTC=NO ;;
  254. --rtc) SRS_RTC=$(switch2value $value) ;;
  255. --simulator) SRS_SIMULATOR=$(switch2value $value) ;;
  256. --ffmpeg-fit) SRS_FFMPEG_FIT=$(switch2value $value) ;;
  257. --cxx11) SRS_CXX11=$(switch2value $value) ;;
  258. --cxx14) SRS_CXX14=$(switch2value $value) ;;
  259. --with-clean) SRS_CLEAN=YES ;;
  260. --without-clean) SRS_CLEAN=NO ;;
  261. --clean) SRS_CLEAN=$(switch2value $value) ;;
  262. --with-gperf) SRS_GPERF=YES ;;
  263. --without-gperf) SRS_GPERF=NO ;;
  264. --gperf) SRS_GPERF=$(switch2value $value) ;;
  265. --with-gmc) SRS_GPERF_MC=YES ;;
  266. --without-gmc) SRS_GPERF_MC=NO ;;
  267. --gmc) SRS_GPERF_MC=$(switch2value $value) ;;
  268. --with-gmd) SRS_GPERF_MD=YES ;;
  269. --without-gmd) SRS_GPERF_MD=NO ;;
  270. --gmd) SRS_GPERF_MD=$(switch2value $value) ;;
  271. --with-gmp) SRS_GPERF_MP=YES ;;
  272. --without-gmp) SRS_GPERF_MP=NO ;;
  273. --gmp) SRS_GPERF_MP=$(switch2value $value) ;;
  274. --with-gcp) SRS_GPERF_CP=YES ;;
  275. --without-gcp) SRS_GPERF_CP=NO ;;
  276. --gcp) SRS_GPERF_CP=$(switch2value $value) ;;
  277. --with-gprof) SRS_GPROF=YES ;;
  278. --without-gprof) SRS_GPROF=NO ;;
  279. --gprof) SRS_GPROF=$(switch2value $value) ;;
  280. --use-sys-ssl) SRS_USE_SYS_SSL=YES ;;
  281. --sys-ssl) SRS_USE_SYS_SSL=$(switch2value $value) ;;
  282. --use-shared-st) SRS_SHARED_ST=YES ;;
  283. --use-shared-srt) SRS_SHARED_SRT=YES ;;
  284. --shared-st) SRS_SHARED_ST=$(switch2value $value) ;;
  285. --shared-srt) SRS_SHARED_SRT=$(switch2value $value) ;;
  286. --shared-ffmpeg) SRS_SHARED_FFMPEG=$(switch2value $value) ;;
  287. --with-valgrind) SRS_VALGRIND=YES ;;
  288. --without-valgrind) SRS_VALGRIND=NO ;;
  289. --valgrind) SRS_VALGRIND=$(switch2value $value) ;;
  290. --log-verbose) SRS_LOG_VERBOSE=$(switch2value $value) ;;
  291. --log-info) SRS_LOG_INFO=$(switch2value $value) ;;
  292. --log-trace) SRS_LOG_TRACE=$(switch2value $value) ;;
  293. --debug) SRS_DEBUG=$(switch2value $value) ;;
  294. --debug-stats) SRS_DEBUG_STATS=$(switch2value $value) ;;
  295. # Alias for --arm, cross build.
  296. --cross-build) SRS_CROSS_BUILD=YES ;;
  297. --enable-cross-compile) SRS_CROSS_BUILD=YES ;;
  298. # Deprecated, might be removed in future.
  299. --with-nginx) SRS_NGINX=YES ;;
  300. --without-nginx) SRS_NGINX=NO ;;
  301. --nginx) SRS_NGINX=$(switch2value $value) ;;
  302. --with-ffmpeg) SRS_FFMPEG_TOOL=YES ;;
  303. --without-ffmpeg) SRS_FFMPEG_TOOL=NO ;;
  304. --ffmpeg) SRS_FFMPEG_TOOL=$(switch2value $value) ;;
  305. --ffmpeg-tool) SRS_FFMPEG_TOOL=$(switch2value $value) ;;
  306. *)
  307. echo "$0: error: invalid option \"$option\""
  308. exit 1
  309. ;;
  310. esac
  311. }
  312. function parse_user_option_to_value_and_option() {
  313. case "$option" in
  314. -*=*)
  315. value=`echo "$option" | sed -e 's|[-_a-zA-Z0-9/]*=||'`
  316. option=`echo "$option" | sed -e 's|=[-_a-zA-Z0-9/. +]*||'`
  317. ;;
  318. *) value="" ;;
  319. esac
  320. }
  321. # For variable values, might be three values: YES, RESERVED, NO(by default).
  322. function value2switch() {
  323. if [[ $1 == YES ]]; then
  324. echo on;
  325. else
  326. echo off;
  327. fi
  328. }
  329. # For user options, only off or on(by default).
  330. function switch2value() {
  331. if [[ $1 == off ]]; then
  332. echo NO;
  333. else
  334. echo YES;
  335. fi
  336. }
  337. #####################################################################################
  338. # parse preset options
  339. #####################################################################################
  340. opt=
  341. for option
  342. do
  343. opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`"
  344. parse_user_option_to_value_and_option
  345. parse_user_option
  346. done
  347. function apply_auto_options() {
  348. # set default preset if not specifies
  349. if [[ $SRS_X86_X64 == NO && $SRS_OSX == NO && $SRS_CROSS_BUILD == NO ]]; then
  350. SRS_X86_X64=YES; opt="--x86-x64 $opt";
  351. fi
  352. if [[ $SRS_CROSS_BUILD == YES ]]; then
  353. if [[ $SRS_CROSS_BUILD_PREFIX != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then
  354. SRS_CROSS_BUILD_HOST=$(echo $SRS_CROSS_BUILD_PREFIX| sed 's/-$//g')
  355. fi
  356. if [[ $SRS_TOOL_CC != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then
  357. SRS_CROSS_BUILD_HOST=$(echo $SRS_TOOL_CC| sed 's/-gcc$//g')
  358. fi
  359. if [[ $SRS_CROSS_BUILD_PREFIX == "" ]]; then
  360. SRS_CROSS_BUILD_PREFIX="${SRS_CROSS_BUILD_HOST}-"
  361. fi
  362. SRS_TOOL_CC=${SRS_CROSS_BUILD_PREFIX}gcc
  363. SRS_TOOL_CXX=${SRS_CROSS_BUILD_PREFIX}g++
  364. SRS_TOOL_AR=${SRS_CROSS_BUILD_PREFIX}ar
  365. SRS_TOOL_LD=${SRS_CROSS_BUILD_PREFIX}ld
  366. SRS_TOOL_RANDLIB=${SRS_CROSS_BUILD_PREFIX}randlib
  367. if [[ $SRS_CROSS_BUILD_ARCH == "" ]]; then
  368. echo $SRS_TOOL_CC| grep arm >/dev/null 2>&1 && SRS_CROSS_BUILD_ARCH="arm"
  369. echo $SRS_TOOL_CC| grep aarch64 >/dev/null 2>&1 && SRS_CROSS_BUILD_ARCH="aarch64"
  370. fi
  371. echo "For cross build, host: $SRS_CROSS_BUILD_HOST, prefix: $SRS_CROSS_BUILD_PREFIX, arch: $SRS_CROSS_BUILD_ARCH, cpu: $SRS_CROSS_BUILD_CPU gcc: $SRS_TOOL_CC"
  372. fi
  373. if [[ $SRS_OSX == YES ]]; then
  374. SRS_TOOL_LD=$SRS_TOOL_CC
  375. fi
  376. # The SRT code in SRS requires c++11, although we build libsrt without c++11.
  377. # TODO: FIXME: Remove c++11 code in SRT of SRS.
  378. if [[ $SRS_SRT == YES ]]; then
  379. SRS_CXX11=YES
  380. fi
  381. # Enable FFmpeg fit for RTC to transcode audio from AAC to OPUS, if user enabled it.
  382. if [[ $SRS_RTC == YES && $SRS_FFMPEG_FIT == RESERVED ]]; then
  383. SRS_FFMPEG_FIT=YES
  384. fi
  385. # if transcode/ingest specified, requires the ffmpeg stub classes.
  386. SRS_FFMPEG_STUB=NO
  387. if [ $SRS_TRANSCODE = YES ]; then SRS_FFMPEG_STUB=YES; fi
  388. if [ $SRS_INGEST = YES ]; then SRS_FFMPEG_STUB=YES; fi
  389. if [[ $SRS_SRTP_ASM == YES && $SRS_RTC == NO ]]; then
  390. echo "Disable SRTP-ASM, because RTC is disabled."
  391. SRS_SRTP_ASM=NO
  392. fi
  393. if [[ $SRS_SRTP_ASM == YES && $SRS_NASM == NO ]]; then
  394. echo "Disable SRTP-ASM, because NASM is disabled."
  395. SRS_SRTP_ASM=NO
  396. fi
  397. }
  398. if [ $help = yes ]; then
  399. apply_auto_options
  400. show_help
  401. exit 0
  402. fi
  403. #####################################################################################
  404. # apply options
  405. #####################################################################################
  406. function apply_detail_options() {
  407. # Always enable HTTP utilies.
  408. if [ $SRS_HTTP_CORE = NO ]; then SRS_HTTP_CORE=YES; echo -e "${YELLOW}[WARN] Always enable HTTP utilies.${BLACK}"; fi
  409. if [ $SRS_STREAM_CASTER = NO ]; then SRS_STREAM_CASTER=YES; echo -e "${YELLOW}[WARN] Always enable StreamCaster.${BLACK}"; fi
  410. if [ $SRS_INGEST = NO ]; then SRS_INGEST=YES; echo -e "${YELLOW}[WARN] Always enable Ingest.${BLACK}"; fi
  411. if [ $SRS_SSL = NO ]; then SRS_SSL=YES; echo -e "${YELLOW}[WARN] Always enable SSL.${BLACK}"; fi
  412. if [ $SRS_STAT = NO ]; then SRS_STAT=YES; echo -e "${YELLOW}[WARN] Always enable Statistic.${BLACK}"; fi
  413. if [ $SRS_TRANSCODE = NO ]; then SRS_TRANSCODE=YES; echo -e "${YELLOW}[WARN] Always enable Transcode.${BLACK}"; fi
  414. if [ $SRS_HTTP_CALLBACK = NO ]; then SRS_HTTP_CALLBACK=YES; echo -e "${YELLOW}[WARN] Always enable HTTP callback.${BLACK}"; fi
  415. if [ $SRS_HTTP_SERVER = NO ]; then SRS_HTTP_SERVER=YES; echo -e "${YELLOW}[WARN] Always enable HTTP server.${BLACK}"; fi
  416. if [ $SRS_HTTP_API = NO ]; then SRS_HTTP_API=YES; echo -e "${YELLOW}[WARN] Always enable HTTP API.${BLACK}"; fi
  417. if [ $SRS_HLS = NO ]; then SRS_HLS=YES; echo -e "${YELLOW}[WARN] Always enable HLS.${BLACK}"; fi
  418. if [ $SRS_DVR = NO ]; then SRS_DVR=YES; echo -e "${YELLOW}[WARN] Always enable DVR.${BLACK}"; fi
  419. # parse the jobs for make
  420. if [[ "" -eq SRS_JOBS ]]; then
  421. export SRS_JOBS="--jobs=1"
  422. else
  423. export SRS_JOBS="--jobs=${SRS_JOBS}"
  424. fi
  425. }
  426. apply_auto_options
  427. apply_detail_options
  428. function regenerate_options() {
  429. # save all config options to macro to write to auto headers file
  430. SRS_AUTO_USER_CONFIGURE=`echo $opt`
  431. # regenerate the options for default values.
  432. SRS_AUTO_CONFIGURE="--prefix=${SRS_PREFIX}"
  433. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --config=$SRS_DEFAULT_CONFIG"
  434. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --hls=$(value2switch $SRS_HLS)"
  435. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --hds=$(value2switch $SRS_HDS)"
  436. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --dvr=$(value2switch $SRS_DVR)"
  437. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ssl=$(value2switch $SRS_SSL)"
  438. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --https=$(value2switch $SRS_HTTPS)"
  439. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ssl-1-0=$(value2switch $SRS_SSL_1_0)"
  440. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ssl-local=$(value2switch $SRS_SSL_LOCAL)"
  441. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sys-ssl=$(value2switch $SRS_USE_SYS_SSL)"
  442. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --transcode=$(value2switch $SRS_TRANSCODE)"
  443. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ingest=$(value2switch $SRS_INGEST)"
  444. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --stat=$(value2switch $SRS_STAT)"
  445. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --http-callback=$(value2switch $SRS_HTTP_CALLBACK)"
  446. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --http-server=$(value2switch $SRS_HTTP_SERVER)"
  447. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --stream-caster=$(value2switch $SRS_STREAM_CASTER)"
  448. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --http-api=$(value2switch $SRS_HTTP_API)"
  449. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --utest=$(value2switch $SRS_UTEST)"
  450. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cherrypy=$(value2switch $SRS_CHERRYPY)"
  451. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srt=$(value2switch $SRS_SRT)"
  452. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --rtc=$(value2switch $SRS_RTC)"
  453. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --simulator=$(value2switch $SRS_SIMULATOR)"
  454. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx11=$(value2switch $SRS_CXX11)"
  455. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx14=$(value2switch $SRS_CXX14)"
  456. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ffmpeg-fit=$(value2switch $SRS_FFMPEG_FIT)"
  457. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --nasm=$(value2switch $SRS_NASM)"
  458. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --srtp-nasm=$(value2switch $SRS_SRTP_ASM)"
  459. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --clean=$(value2switch $SRS_CLEAN)"
  460. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gperf=$(value2switch $SRS_GPERF)"
  461. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gmc=$(value2switch $SRS_GPERF_MC)"
  462. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gmd=$(value2switch $SRS_GPERF_MD)"
  463. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gmp=$(value2switch $SRS_GPERF_MP)"
  464. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gcp=$(value2switch $SRS_GPERF_CP)"
  465. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gprof=$(value2switch $SRS_GPROF)"
  466. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --static=$(value2switch $SRS_STATIC)"
  467. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --shared-st=$(value2switch $SRS_SHARED_ST)"
  468. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --shared-srt=$(value2switch $SRS_SHARED_SRT)"
  469. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --shared-ffmpeg=$(value2switch $SRS_SHARED_FFMPEG)"
  470. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-verbose=$(value2switch $SRS_LOG_VERBOSE)"
  471. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-info=$(value2switch $SRS_LOG_INFO)"
  472. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --log-trace=$(value2switch $SRS_LOG_TRACE)"
  473. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --gcov=$(value2switch $SRS_GCOV)"
  474. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug=$(value2switch $SRS_DEBUG)"
  475. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)"
  476. SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cross-build=$(value2switch $SRS_CROSS_BUILD)"
  477. if [[ $SRS_CROSS_BUILD_ARCH != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --arch=$SRS_CROSS_BUILD_ARCH"; fi
  478. if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cpu=$SRS_CROSS_BUILD_CPU"; fi
  479. if [[ $SRS_CROSS_BUILD_HOST != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --host=$SRS_CROSS_BUILD_HOST"; fi
  480. if [[ $SRS_CROSS_BUILD_PREFIX != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cross-prefix=$SRS_CROSS_BUILD_PREFIX"; fi
  481. if [[ $SRS_EXTRA_FLAGS != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --extra-flags=\\\"$SRS_EXTRA_FLAGS\\\""; fi
  482. if [[ $SRS_BUILD_TAG != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --build-tag=\\\"$SRS_BUILD_TAG\\\""; fi
  483. if [[ $SRS_TOOL_CC != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cc=$SRS_TOOL_CC"; fi
  484. if [[ $SRS_TOOL_CXX != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cxx=$SRS_TOOL_CXX"; fi
  485. if [[ $SRS_TOOL_AR != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ar=$SRS_TOOL_AR"; fi
  486. if [[ $SRS_TOOL_LD != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --ld=$SRS_TOOL_LD"; fi
  487. if [[ $SRS_TOOL_RANDLIB != '' ]]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --randlib=$SRS_TOOL_RANDLIB"; fi
  488. echo "User config: $SRS_AUTO_USER_CONFIGURE"
  489. echo "Detail config: ${SRS_AUTO_CONFIGURE}"
  490. }
  491. regenerate_options
  492. #####################################################################################
  493. # check user options
  494. #####################################################################################
  495. function check_option_conflicts() {
  496. if [[ $SRS_TOOL_CC == '' || $SRS_TOOL_CXX == '' || $SRS_TOOL_AR == '' || $SRS_TOOL_LD == '' || $SRS_TOOL_RANDLIB == '' ]]; then
  497. echo "Error: No build toolchain, cc: $SRS_TOOL_CC, cxx: $SRS_TOOL_CXX, ar: $SRS_TOOL_AR, ld: $SRS_TOOL_LD, randlib: $SRS_TOOL_RANDLIB"; exit -1
  498. fi
  499. if [[ $SRS_CROSS_BUILD == YES && ($SRS_TOOL_CC == 'gcc' || $SRS_TOOL_CXX == 'g++' || $SRS_TOOL_AR == 'ar') ]]; then
  500. echo "Error: For cross build, should setup the toolchain(./configure -h|grep -i toolchain), cc: $SRS_TOOL_CC, cxx: $SRS_TOOL_CXX, ar: $SRS_TOOL_AR"; exit 1
  501. fi
  502. if [[ $SRS_NGINX == YES ]]; then
  503. echo "Warning: Don't support building NGINX, please use docker https://github.com/ossrs/srs-docker"
  504. SRS_NGINX=NO
  505. fi
  506. # TODO: FIXME: check more os.
  507. __check_ok=YES
  508. # check conflict
  509. if [ $SRS_GPERF = NO ]; then
  510. if [ $SRS_GPERF_MC = YES ]; then echo "gperf-mc depends on gperf, see: ./configure --help"; __check_ok=NO; fi
  511. if [ $SRS_GPERF_MD = YES ]; then echo "gperf-md depends on gperf, see: ./configure --help"; __check_ok=NO; fi
  512. if [ $SRS_GPERF_MP = YES ]; then echo "gperf-mp depends on gperf, see: ./configure --help"; __check_ok=NO; fi
  513. if [ $SRS_GPERF_CP = YES ]; then echo "gperf-cp depends on gperf, see: ./configure --help"; __check_ok=NO; fi
  514. fi
  515. if [[ $SRS_GPERF_MC = YES && $SRS_GPERF_MP = YES ]]; then
  516. echo "gperf-mc not compatible with gperf-mp, see: ./configure --help";
  517. echo "@see: https://gperftools.github.io/gperftools/heap_checker.html";
  518. echo "Note that since the heap-checker uses the heap-profiling framework internally, it is not possible to run both the heap-checker and heap profiler at the same time";
  519. __check_ok=NO
  520. fi
  521. # generate the group option: SRS_GPERF
  522. __gperf_slow=NO
  523. if [ $SRS_GPERF_MC = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi
  524. if [ $SRS_GPERF_MD = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi
  525. if [ $SRS_GPERF_MP = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi
  526. if [ $SRS_GPERF_CP = YES ]; then SRS_GPERF=YES; __gperf_slow=YES; fi
  527. if [ $__gperf_slow = YES ]; then if [ $SRS_GPROF = YES ]; then
  528. echo "gmc/gmp/gcp not compatible with gprof, see: ./configure --help"; __check_ok=NO;
  529. fi fi
  530. # check variable neccessary
  531. if [ $SRS_HDS = RESERVED ]; then echo "you must specifies the hds, see: ./configure --help"; __check_ok=NO; fi
  532. if [ $SRS_SSL = RESERVED ]; then echo "you must specifies the ssl, see: ./configure --help"; __check_ok=NO; fi
  533. if [ $SRS_STREAM_CASTER = RESERVED ]; then echo "you must specifies the stream-caster, see: ./configure --help"; __check_ok=NO; fi
  534. if [ $SRS_UTEST = RESERVED ]; then echo "you must specifies the utest, see: ./configure --help"; __check_ok=NO; fi
  535. if [ $SRS_GPERF = RESERVED ]; then echo "you must specifies the gperf, see: ./configure --help"; __check_ok=NO; fi
  536. if [ $SRS_GPERF_MC = RESERVED ]; then echo "you must specifies the gperf-mc, see: ./configure --help"; __check_ok=NO; fi
  537. if [ $SRS_GPERF_MD = RESERVED ]; then echo "you must specifies the gperf-md, see: ./configure --help"; __check_ok=NO; fi
  538. if [ $SRS_GPERF_MP = RESERVED ]; then echo "you must specifies the gperf-mp, see: ./configure --help"; __check_ok=NO; fi
  539. if [ $SRS_GPERF_CP = RESERVED ]; then echo "you must specifies the gperf-cp, see: ./configure --help"; __check_ok=NO; fi
  540. if [ $SRS_GPROF = RESERVED ]; then echo "you must specifies the gprof, see: ./configure --help"; __check_ok=NO; fi
  541. if [[ -z $SRS_PREFIX ]]; then echo "you must specifies the prefix, see: ./configure --prefix"; __check_ok=NO; fi
  542. if [ $__check_ok = NO ]; then
  543. exit 1;
  544. fi
  545. }
  546. check_option_conflicts