configure 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. #!/bin/bash
  2. #####################################################################################
  3. # the main output dir, all configure and make output are in this dir.
  4. #####################################################################################
  5. # create the main objs
  6. SRS_WORKDIR="."
  7. SRS_OBJS_DIR="objs"
  8. SRS_OBJS="${SRS_WORKDIR}/${SRS_OBJS_DIR}"
  9. SRS_MAKEFILE="Makefile"
  10. # linux shell color support.
  11. RED="\\033[31m"
  12. GREEN="\\033[32m"
  13. YELLOW="\\033[33m"
  14. BLACK="\\033[0m"
  15. #####################################################################################
  16. # parse user options, set the variables like:
  17. # srs features: SRS_SSL/SRS_HLS/SRS_HTTP_CALLBACK/......
  18. # build options: SRS_JOBS
  19. #####################################################################################
  20. # parse options, exit with error when parse options invalid.
  21. . auto/options.sh
  22. # setup variables when options parsed.
  23. . auto/setup_variables.sh
  24. # We don't need to cleanup the exists files.
  25. rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}
  26. # create objs
  27. mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}
  28. # apply user options.
  29. . auto/depends.sh
  30. # the auto generated variables.
  31. . auto/auto_headers.sh
  32. #####################################################################################
  33. # generate Makefile.
  34. #####################################################################################
  35. # ubuntu echo in Makefile cannot display color, use bash instead
  36. SRS_BUILD_SUMMARY="_srs_build_summary.sh"
  37. # utest make entry, (cd utest; make)
  38. SrsUtestMakeEntry="@echo -e \"ignore utest for it's disabled\""
  39. if [ $SRS_UTEST = YES ]; then SrsUtestMakeEntry="(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/utest && \$(MAKE))"; fi
  40. #####################################################################################
  41. # finger out modules to install.
  42. # where srs module is a dir which contains a config file.
  43. SRS_MODULES=()
  44. __mfiles=`find modules -name "config"` && for __mfile in $__mfiles; do
  45. SRS_MODULES+=("`dirname $__mfile`")
  46. done
  47. # variables for makefile for all modules.
  48. __mphonys="" && __mdefaults="" && __mcleanups="" && __makefiles=""
  49. # add each modules for application
  50. for SRS_MODULE in ${SRS_MODULES[*]}; do
  51. echo "install module at: $SRS_MODULE"
  52. . $SRS_MODULE/config
  53. if [[ $SRS_MODULE_MAKEFILE != "" ]]; then
  54. __makefiles="$__makefiles $SRS_MODULE_MAKEFILE"
  55. fi
  56. if [[ 0 -ne ${#SRS_MODULE_MAIN[@]} ]]; then
  57. __mphonys="$__mphonys $SRS_MODULE_NAME"
  58. __mdefaults="$__mdefaults $SRS_MODULE_NAME"
  59. __mcleanups="$__mcleanups $SRS_MODULE_NAME"
  60. fi
  61. done
  62. # generate extra phony for each modules.
  63. cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
  64. .PHONY: $__mphonys
  65. END
  66. #####################################################################################
  67. # build tools or compiler args.
  68. # enable gdb debug
  69. GDBDebug=" -g -O0"
  70. # the warning level.
  71. WarnLevel=" -Wall -Wno-deprecated-declarations"
  72. # the compile standard.
  73. CppStd="-ansi"
  74. if [[ $SRS_CXX11 == YES ]]; then
  75. CppStd="-std=c++11"
  76. fi
  77. if [[ $SRS_CXX14 == YES ]]; then
  78. CppStd="-std=c++14"
  79. fi
  80. # performance of gprof
  81. SrsGprof=""; SrsGprofLink=""; if [ $SRS_GPROF = YES ]; then SrsGprof=" -pg -lc_p"; SrsGprofLink=" -pg"; fi
  82. # performance of gperf
  83. SrsGperf=""; SrsGperfLink=""; if [ $SRS_GPERF = YES ]; then SrsGperfLink=" -lpthread"; fi
  84. # the cxx flag generated.
  85. CXXFLAGS="${CXXFLAGS} ${CppStd}${WarnLevel}${GDBDebug}${LibraryCompile}${SrsGprof}"
  86. if [ $SRS_GPERF = YES ]; then
  87. CXXFLAGS="${CXXFLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free";
  88. fi
  89. # For coverage.
  90. if [[ $SRS_GCOV == YES ]]; then
  91. SrsGcov="-fprofile-arcs -ftest-coverage"
  92. fi
  93. if [[ $SRS_GCOV == YES ]]; then
  94. CXXFLAGS="${CXXFLAGS} ${SrsGcov}";
  95. fi
  96. # User configed options.
  97. if [[ $SRS_EXTRA_FLAGS != '' ]]; then
  98. CXXFLAGS="${CXXFLAGS} $SRS_EXTRA_FLAGS";
  99. fi
  100. # Start to generate the Makefile.
  101. cat << END >> ${SRS_OBJS}/${SRS_MAKEFILE}
  102. GCC = ${SRS_TOOL_CC}
  103. CXX = ${SRS_TOOL_CXX}
  104. AR = ${SRS_TOOL_AR}
  105. LINK = ${SRS_TOOL_CXX}
  106. CXXFLAGS = ${CXXFLAGS}
  107. .PHONY: default srs srs_ingest_hls
  108. default:
  109. END
  110. #####################################################################################
  111. # Libraries, external library to build in srs,
  112. # header(.h): add to ModuleLibIncs if need the specified library. for example, LibSTRoot
  113. # library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile
  114. #
  115. # st(state-threads) the basic network library for SRS.
  116. LibSTRoot="${SRS_OBJS_DIR}/st"; LibSTfile="${LibSTRoot}/libst.a"
  117. if [[ $SRS_SHARED_ST == YES ]]; then LibSTfile="-L${LibSTRoot} -lst"; fi
  118. # srtp
  119. if [[ $SRS_RTC == YES ]]; then
  120. LibSrtpRoot="${SRS_OBJS_DIR}/srtp2/include"; LibSrtpFile="${SRS_OBJS_DIR}/srtp2/lib/libsrtp2.a"
  121. fi
  122. # FFMPEG for WebRTC transcoding, such as aac to opus.
  123. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  124. LibFfmpegRoot="${SRS_OBJS_DIR}/ffmpeg/include"; LibFfmpegFile="${SRS_OBJS_DIR}/ffmpeg/lib/libavcodec.a ${SRS_OBJS_DIR}/ffmpeg/lib/libswresample.a ${SRS_OBJS_DIR}/ffmpeg/lib/libavutil.a"
  125. if [[ $SRS_CROSS_BUILD == NO ]]; then
  126. LibFfmpegRoot="${LibFfmpegRoot} ${SRS_OBJS_DIR}/opus/include"; LibFfmpegFile="${LibFfmpegFile} ${SRS_OBJS_DIR}/opus/lib/libopus.a"
  127. fi
  128. if [[ $SRS_SHARED_FFMPEG == YES ]]; then LibFfmpegFile="-L${SRS_OBJS_DIR}/ffmpeg/lib -lavcodec -lswresample -lavutil -L${SRS_OBJS_DIR}/opus/lib -lopus"; fi
  129. fi
  130. # openssl-1.1.0e, for the RTMP complex handshake.
  131. LibSSLRoot="";LibSSLfile=""
  132. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == NO ]]; then
  133. LibSSLRoot="${SRS_OBJS_DIR}/openssl/include"; LibSSLfile="${SRS_OBJS_DIR}/openssl/lib/libssl.a ${SRS_OBJS_DIR}/openssl/lib/libcrypto.a";
  134. fi
  135. # gperftools-2.1, for mem check and mem/cpu profile
  136. LibGperfRoot=""; LibGperfFile=""
  137. if [ $SRS_GPERF = YES ]; then
  138. LibGperfRoot="${SRS_OBJS_DIR}/gperf/include"; LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_and_profiler.a";
  139. fi
  140. if [ $SRS_GPERF_MD = YES ]; then
  141. LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_debug.a";
  142. fi
  143. # srt code path
  144. if [[ $SRS_SRT == YES ]]; then
  145. SrsSRTRoot="${SRS_WORKDIR}/src/srt"
  146. LibSRTRoot="${SRS_OBJS_DIR}/srt/include"; LibSRTfile="${SRS_OBJS_DIR}/srt/lib/libsrt.a"
  147. if [[ $SRS_SHARED_SRT == YES ]]; then LibSRTfile="-L${SRS_OBJS_DIR}/srt/lib -lsrt"; fi
  148. fi
  149. # the link options, always use static link
  150. SrsLinkOptions="-ldl -lpthread";
  151. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
  152. SrsLinkOptions="${SrsLinkOptions} -lssl -lcrypto";
  153. fi
  154. # Static link the c++ libraries, for user who build SRS by a new version of gcc,
  155. # so we need to link the c++ libraries staticly but not all.
  156. # @see https://stackoverflow.com/a/26107550
  157. if [ $SRS_STATIC = YES ]; then
  158. SrsLinkOptions="${SrsLinkOptions} -static-libstdc++";
  159. fi
  160. # For coverage.
  161. if [[ $SRS_GCOV == YES ]]; then
  162. SrsLinkOptions="${SrsLinkOptions} ${SrsGcov}";
  163. fi
  164. # For FFMPEG/RTC on Linux.
  165. if [[ $SRS_OSX != YES && $SRS_RTC == YES && $SRS_FFMPEG_FIT == YES ]]; then
  166. SrsLinkOptions="${SrsLinkOptions} -lrt";
  167. fi
  168. #####################################################################################
  169. # Modules, compile each module, then link to binary
  170. #
  171. #Core, depends only on system apis.
  172. MODULE_ID="CORE"
  173. MODULE_DEPENDS=()
  174. ModuleLibIncs=(${SRS_OBJS_DIR})
  175. MODULE_FILES=("srs_core" "srs_core_version4" "srs_core_autofree" "srs_core_performance"
  176. "srs_core_time")
  177. CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh
  178. CORE_OBJS="${MODULE_OBJS[@]}"
  179. #
  180. #Kernel, depends on core, provides error/log/config, nothing about stream information.
  181. MODULE_ID="KERNEL"
  182. MODULE_DEPENDS=("CORE")
  183. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot})
  184. MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_buffer"
  185. "srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_io"
  186. "srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts"
  187. "srs_kernel_stream" "srs_kernel_balance" "srs_kernel_mp4" "srs_kernel_file"
  188. "srs_kernel_kbps")
  189. if [[ $SRS_RTC == YES ]]; then
  190. MODULE_FILES+=("srs_kernel_rtc_rtp" "srs_kernel_rtc_rtcp")
  191. fi
  192. KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . auto/modules.sh
  193. KERNEL_OBJS="${MODULE_OBJS[@]}"
  194. #
  195. #RTMP/HTTP/Raw Protocol, depends on core/kernel, provides rtmp/htttp protocol features.
  196. MODULE_ID="PROTOCOL"
  197. MODULE_DEPENDS=("CORE" "KERNEL")
  198. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot})
  199. MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
  200. "srs_rtmp_handshake" "srs_protocol_utility" "srs_rtmp_msg_array" "srs_protocol_stream"
  201. "srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json"
  202. "srs_protocol_format" "srs_service_log" "srs_service_st" "srs_service_http_client" "srs_service_http_conn"
  203. "srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn")
  204. if [[ $SRS_RTC == YES ]]; then
  205. MODULE_FILES+=("srs_rtc_stun_stack")
  206. ModuleLibIncs+=(${LibSrtpRoot})
  207. fi
  208. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  209. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  210. fi
  211. PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
  212. PROTOCOL_OBJS="${MODULE_OBJS[@]}"
  213. #
  214. #srt protocol features.
  215. if [[ $SRS_SRT == YES ]]; then
  216. MODULE_ID="SRT"
  217. MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
  218. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot} ${LibSRTRoot})
  219. MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data" "srt_log")
  220. SRT_INCS=(${LibSRTRoot} ${SrsSRTRoot}); MODULE_DIR=${SrsSRTRoot} . auto/modules.sh
  221. SRT_OBJS="${MODULE_OBJS[@]}"
  222. fi
  223. #
  224. #App Module, for SRS server only.
  225. MODULE_ID="APP"
  226. MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
  227. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot})
  228. if [ $SRS_GPERF = YES ]; then
  229. ModuleLibIncs+=(${LibGperfRoot})
  230. fi
  231. if [[ $SRS_RTC == YES ]]; then
  232. ModuleLibIncs+=(${LibSrtpRoot})
  233. fi
  234. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  235. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  236. fi
  237. MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source"
  238. "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream"
  239. "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
  240. "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
  241. "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_edge"
  242. "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_http_static"
  243. "srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_hds"
  244. "srs_app_mpegts_udp" "srs_app_listener" "srs_app_async_call"
  245. "srs_app_caster_flv" "srs_app_latest_version" "srs_app_uuid" "srs_app_process" "srs_app_ng_exec"
  246. "srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
  247. "srs_app_coworkers" "srs_app_hybrid" "srs_app_threads")
  248. if [[ $SRS_RTC == YES ]]; then
  249. MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp"
  250. "srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
  251. fi
  252. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  253. MODULE_FILES+=("srs_app_rtc_codec")
  254. fi
  255. DEFINES=""
  256. # add each modules for app
  257. for SRS_MODULE in ${SRS_MODULES[*]}; do
  258. . $SRS_MODULE/config
  259. MODULE_FILES+=("${SRS_MODULE_APP[*]}")
  260. DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}"
  261. done
  262. APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
  263. APP_OBJS="${MODULE_OBJS[@]}"
  264. #
  265. #Server Module, for SRS only.
  266. MODULE_ID="SERVER"
  267. MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
  268. if [[ $SRS_SRT == YES ]]; then
  269. MODULE_DEPENDS+=("SRT")
  270. fi
  271. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot})
  272. if [[ $SRS_RTC == YES ]]; then
  273. ModuleLibIncs+=(${LibSrtpRoot})
  274. fi
  275. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  276. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  277. fi
  278. if [[ $SRS_SRT == YES ]]; then
  279. ModuleLibIncs+=(${LibSRTRoot})
  280. ModuleLibIncs+=("${SrsSRTRoot[*]}")
  281. fi
  282. MODULE_FILES=("srs_main_server")
  283. SERVER_INCS="src/main"; MODULE_DIR=${SERVER_INCS} . auto/modules.sh
  284. SERVER_OBJS="${MODULE_OBJS[@]}"
  285. #
  286. #Main Module, for app from modules.
  287. MODULE_ID="MAIN"
  288. MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
  289. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot})
  290. if [[ $SRS_RTC == YES ]]; then
  291. ModuleLibIncs+=(${LibSrtpRoot})
  292. fi
  293. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  294. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  295. fi
  296. if [[ $SRS_SRT == YES ]]; then
  297. ModuleLibIncs+=(${LibSRTRoot})
  298. ModuleLibIncs+=("${SrsSRTRoot[*]}")
  299. fi
  300. MODULE_FILES=()
  301. DEFINES=""
  302. # add each modules for main
  303. for SRS_MODULE in ${SRS_MODULES[*]}; do
  304. . $SRS_MODULE/config
  305. MODULE_FILES+=("${SRS_MODULE_MAIN[*]}")
  306. DEFINES="${DEFINES} ${SRS_MODULE_DEFINES}"
  307. done
  308. MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
  309. MAIN_OBJS="${MODULE_OBJS[@]}"
  310. #####################################################################################
  311. # Binaries, main entrances, link the module and its depends modules,
  312. # then link to a binary, for example, objs/srs
  313. #
  314. # all main entrances
  315. MAIN_ENTRANCES=("srs_main_server")
  316. for SRS_MODULE in ${SRS_MODULES[*]}; do
  317. . $SRS_MODULE/config
  318. MAIN_ENTRANCES+=("${SRS_MODULE_MAIN[*]}")
  319. done
  320. #
  321. # all depends libraries
  322. ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile})
  323. if [[ $SRS_RTC == YES ]]; then
  324. ModuleLibFiles+=(${LibSrtpFile})
  325. fi
  326. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  327. ModuleLibFiles+=("${LibFfmpegFile[*]}")
  328. fi
  329. if [[ $SRS_SRT == YES ]]; then
  330. ModuleLibFiles+=("${LibSRTfile[*]}")
  331. fi
  332. # all depends objects
  333. MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}"
  334. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibGperfRoot} ${LibSSLRoot})
  335. if [[ $SRS_RTC == YES ]]; then
  336. ModuleLibIncs+=(${LibSrtpRoot})
  337. fi
  338. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  339. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  340. fi
  341. if [[ $SRS_SRT == YES ]]; then
  342. ModuleLibIncs+=(${LibSRTRoot})
  343. ModuleLibIncs+=("${SrsSRTRoot[*]}")
  344. MODULE_OBJS="${MODULE_OBJS} ${SRT_OBJS[@]}"
  345. fi
  346. LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}"
  347. #
  348. # srs: srs(simple rtmp server) over st(state-threads)
  349. BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh
  350. #
  351. # For modules, without the app module.
  352. MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}"
  353. ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile})
  354. if [[ $SRS_RTC == YES ]]; then
  355. ModuleLibFiles+=(${LibSrtpFile})
  356. fi
  357. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  358. ModuleLibFiles+=("${LibFfmpegFile[*]}")
  359. fi
  360. #
  361. for SRS_MODULE in ${SRS_MODULES[*]}; do
  362. . $SRS_MODULE/config
  363. # no SRS_MODULE_MAIN
  364. if [[ 0 -eq ${#SRS_MODULE_MAIN[@]} ]]; then continue; fi
  365. BUILD_KEY="$SRS_MODULE_NAME" APP_MAIN="${SRS_MODULE_MAIN[0]}" APP_NAME="$SRS_MODULE_NAME" . auto/apps.sh
  366. done
  367. # For utest on mac.
  368. # @see https://github.com/protocolbuffers/protobuf/issues/51#issuecomment-111044468
  369. if [[ $SRS_OSX == YES ]]; then
  370. UTEST_EXTRA_DEFINES="-DGTEST_USE_OWN_TR1_TUPLE=1"
  371. fi
  372. #
  373. # utest, the unit-test cases of srs, base on gtest1.6
  374. if [ $SRS_UTEST = YES ]; then
  375. MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_protocol" "srs_utest_kernel" "srs_utest_core"
  376. "srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
  377. "srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_srt")
  378. ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot})
  379. if [[ $SRS_RTC == YES ]]; then
  380. ModuleLibIncs+=(${LibSrtpRoot})
  381. fi
  382. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  383. ModuleLibIncs+=("${LibFfmpegRoot[*]}")
  384. fi
  385. if [[ $SRS_SRT == YES ]]; then
  386. ModuleLibIncs+=("${SrsSRTRoot[*]}")
  387. fi
  388. ModuleLibFiles=(${LibSTfile} ${LibSSLfile})
  389. if [[ $SRS_RTC == YES ]]; then
  390. ModuleLibFiles+=(${LibSrtpFile})
  391. fi
  392. if [[ $SRS_FFMPEG_FIT == YES ]]; then
  393. ModuleLibFiles+=("${LibFfmpegFile[*]}")
  394. fi
  395. if [[ $SRS_SRT == YES ]]; then
  396. ModuleLibFiles+=("${LibSRTfile[*]}")
  397. fi
  398. MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
  399. if [[ $SRS_SRT == YES ]]; then
  400. MODULE_DEPENDS+=("SRT")
  401. fi
  402. MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${APP_OBJS[@]} ${SRT_OBJS[@]}"
  403. LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh
  404. fi
  405. #####################################################################################
  406. # generate colorful summary script
  407. . auto/summary.sh
  408. #####################################################################################
  409. # makefile
  410. echo "Generate Makefile"
  411. # backup old makefile.
  412. rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk &&
  413. mv ${SRS_WORKDIR}/${SRS_MAKEFILE} ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk
  414. # generate phony header
  415. cat << END > ${SRS_WORKDIR}/${SRS_MAKEFILE}
  416. .PHONY: default all _default install help clean destroy server srs_ingest_hls utest _prepare_dir $__mphonys
  417. .PHONY: clean_srs clean_modules clean_openssl clean_nginx clean_cherrypy clean_srtp2 clean_opus clean_ffmpeg clean_st
  418. .PHONY: st ffmpeg
  419. GCC = ${SRS_TOOL_CC}
  420. CXX = ${SRS_TOOL_CXX}
  421. AR = ${SRS_TOOL_AR}
  422. LINK = ${SRS_TOOL_LD}
  423. RANDLIB = ${SRS_TOOL_RANDLIB}
  424. CXXFLAGS = ${CXXFLAGS}
  425. # install prefix.
  426. SRS_PREFIX=${SRS_PREFIX}
  427. SRS_DEFAULT_CONFIG=${SRS_DEFAULT_CONFIG}
  428. __REAL_INSTALL=\$(DESTDIR)\$(SRS_PREFIX)
  429. default: server
  430. all: _default
  431. END
  432. # the real entry for all platform:
  433. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  434. _default: server srs_ingest_hls utest __modules $__mdefaults
  435. @bash objs/_srs_build_summary.sh
  436. help:
  437. @echo "Usage: make <help>|<clean>|<destroy>|<server>|<utest>|<install>|<uninstall>"
  438. @echo " help Display this help menu"
  439. @echo " clean Cleanup project and all depends"
  440. @echo " destroy Cleanup all files for this platform in ${SRS_OBJS_DIR}/${SRS_PLATFORM}"
  441. @echo " server Build the srs and other modules in main"
  442. @echo " utest Build the utest for srs"
  443. @echo " install Install srs to the prefix path"
  444. @echo " uninstall Uninstall srs from prefix path"
  445. @echo "To rebuild special module:"
  446. @echo " st Rebuild st-srs in ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs"
  447. @echo " ffmpeg Rebuild ffmpeg in ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit"
  448. @echo "To reconfigure special depends:"
  449. @echo " clean_openssl Remove the openssl cache."
  450. @echo " clean_srtp2 Remove the libsrtp2 cache."
  451. @echo " clean_opus Remove the opus cache."
  452. @echo " clean_ffmpeg Remove the FFmpeg cache."
  453. @echo " clean_st Remove the ST cache."
  454. @echo "For example:"
  455. @echo " make"
  456. @echo " make help"
  457. doclean:
  458. (cd ${SRS_OBJS_DIR} && rm -rf srs srs_utest $__mcleanups)
  459. (cd ${SRS_OBJS_DIR} && rm -rf src/* include lib)
  460. (mkdir -p ${SRS_OBJS_DIR}/utest && cd ${SRS_OBJS_DIR}/utest && rm -rf *.o *.a)
  461. (cd research/api-server/static-dir && rm -rf crossdomain.xml forward live players)
  462. clean: clean_srs clean_modules
  463. destroy:
  464. (cd ${SRS_OBJS_DIR} && rm -rf ${SRS_PLATFORM})
  465. clean_srs:
  466. @(cd ${SRS_OBJS_DIR} && rm -rf srs srs_utest)
  467. @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf include/* lib/*)
  468. @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && find src -name "*.o" -delete)
  469. @(cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && find utest -name "*.o" -delete)
  470. clean_modules:
  471. @(cd ${SRS_OBJS_DIR} && rm -rf $__mdefaults)
  472. clean_openssl:
  473. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf openssl*)
  474. @echo "Please rebuild openssl by: ./configure"
  475. clean_srtp2:
  476. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf libsrtp-2.0.0)
  477. @echo "Please rebuild libsrtp2 by: ./configure"
  478. clean_opus:
  479. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf opus-1.3.1)
  480. @echo "Please rebuild opus by: ./configure"
  481. clean_ffmpeg:
  482. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf ffmpeg-4.2-fit)
  483. @echo "Please rebuild FFmpeg by: ./configure"
  484. clean_st:
  485. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM} && rm -rf st-srs)
  486. @echo "Please rebuild ST by: ./configure"
  487. clean_nginx:
  488. (cd ${SRS_OBJS_DIR} && rm -rf nginx)
  489. clean_cherrypy:
  490. (cd research/api-server/static-dir && rm -rf crossdomain.xml forward live players)
  491. st:
  492. (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest)
  493. (cd ${SRS_OBJS_DIR}/${SRS_PLATFORM}/st-srs && \$(MAKE) clean && \$(MAKE) ${_ST_MAKE} EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" CC=\$(GCC) AR=\$(AR) LD=\$(LINK) RANDLIB=\$(RANDLIB))
  494. @echo "Please rebuild srs by: rm -f objs/srs && make"
  495. ffmpeg:
  496. (cd ${SRS_OBJS_DIR} && rm -f srs srs_utest)
  497. (cd ${SRS_OBJS}/${SRS_PLATFORM}/ffmpeg-4.2-fit && \$(MAKE) && \$(MAKE) install-libs)
  498. @echo "Please rebuild srs by: rm -f objs/srs && make"
  499. END
  500. # for Makefile of all modules.
  501. # depends on server, for some modules maybe use srs files.
  502. echo "__modules: server" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  503. for MMF in ${__makefiles[*]}; do
  504. echo " \$(MAKE) -f $MMF" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  505. done
  506. echo "" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  507. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  508. server: _prepare_dir
  509. @echo "Build the SRS server"
  510. \$(MAKE) -f ${SRS_OBJS_DIR}/${SRS_MAKEFILE} srs
  511. END
  512. # generate all modules entry
  513. for SRS_MODULE in ${SRS_MODULES[*]}; do
  514. . $SRS_MODULE/config
  515. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  516. $SRS_MODULE_NAME: _prepare_dir server
  517. @echo "Build the $SRS_MODULE_NAME over SRS"
  518. \$(MAKE) -f ${SRS_OBJS_DIR}/${SRS_MAKEFILE} $SRS_MODULE_NAME
  519. END
  520. done
  521. # install entry
  522. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  523. uninstall:
  524. @echo "rmdir \$(SRS_PREFIX)"
  525. @rm -rf \$(SRS_PREFIX)
  526. install:
  527. @echo "Now mkdir \$(__REAL_INSTALL)"
  528. @mkdir -p \$(__REAL_INSTALL)
  529. @echo "Now make the http root dir"
  530. @mkdir -p \$(__REAL_INSTALL)/objs/nginx/html
  531. @cp -f research/api-server/static-dir/index.html \$(__REAL_INSTALL)/objs/nginx/html
  532. @cp -f research/players/crossdomain.xml \$(__REAL_INSTALL)/objs/nginx/html
  533. @cp -f research/api-server/static-dir/favicon.ico \$(__REAL_INSTALL)/objs/nginx/html
  534. @cp -Rf research/players \$(__REAL_INSTALL)/objs/nginx/html/
  535. @cp -Rf research/console \$(__REAL_INSTALL)/objs/nginx/html/
  536. @cp -Rf 3rdparty/signaling/www/demos \$(__REAL_INSTALL)/objs/nginx/html/
  537. @echo "Now copy binary files"
  538. @mkdir -p \$(__REAL_INSTALL)/objs
  539. @cp -f objs/srs \$(__REAL_INSTALL)/objs
  540. @echo "Now copy srs conf files"
  541. @mkdir -p \$(__REAL_INSTALL)/conf
  542. @cp -f conf/*.conf \$(__REAL_INSTALL)/conf
  543. @cp -f conf/server.key conf/server.crt \$(__REAL_INSTALL)/conf
  544. @echo "Now copy init.d script files"
  545. @mkdir -p \$(__REAL_INSTALL)/etc/init.d
  546. @cp -f etc/init.d/srs \$(__REAL_INSTALL)/etc/init.d
  547. @sed -i "s|^ROOT=.*|ROOT=\"\$(SRS_PREFIX)\"|g" \$(__REAL_INSTALL)/etc/init.d/srs
  548. @sed -i "s|^CONFIG=.*|CONFIG=\"\$(SRS_DEFAULT_CONFIG)\"|g" \$(__REAL_INSTALL)/etc/init.d/srs
  549. @echo "Now copy systemctl service files"
  550. @mkdir -p \$(__REAL_INSTALL)/usr/lib/systemd/system
  551. @cp -f usr/lib/systemd/system/srs.service \$(__REAL_INSTALL)/usr/lib/systemd/system/srs.service
  552. @echo ""
  553. @echo "@see: https://github.com/ossrs/srs/wiki/v4_CN_LinuxService"
  554. END
  555. if [ $SRS_UTEST = YES ]; then
  556. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  557. utest: server
  558. @echo "Building the utest for srs"
  559. ${SrsUtestMakeEntry}
  560. @echo "The utest is built ok."
  561. END
  562. else
  563. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  564. utest: server
  565. @echo "Ignore utest for it's disabled."
  566. END
  567. fi
  568. cat << END >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  569. # the ./configure will generate it.
  570. _prepare_dir:
  571. @mkdir -p ${SRS_OBJS_DIR}
  572. END
  573. # generate makefile ok, append the tails.
  574. cat ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk >> ${SRS_WORKDIR}/${SRS_MAKEFILE} &&
  575. rm -f ${SRS_WORKDIR}/${SRS_MAKEFILE}.bk
  576. echo 'Configure ok! '
  577. #####################################################################################
  578. # when configure success, prepare build
  579. #####################################################################################
  580. # create objs/logs for ffmpeg to write log.
  581. mkdir -p ${SRS_OBJS}/logs
  582. #####################################################################################
  583. # configure summary
  584. #####################################################################################
  585. # summary
  586. echo ""
  587. echo "Configure summary:"
  588. echo " ${SRS_AUTO_USER_CONFIGURE}"
  589. echo " ${SRS_AUTO_CONFIGURE}"
  590. if [ $SRS_HLS = YES ]; then
  591. echo -e "${GREEN}HLS is enabled.${BLACK}"
  592. else
  593. echo -e "${YELLOW}Warning: HLS is disabled.${BLACK}"
  594. fi
  595. if [ $SRS_STREAM_CASTER = YES ]; then
  596. echo -e "${YELLOW}Experiment: StreamCaster is enabled.${BLACK}"
  597. else
  598. echo -e "${GREEN}Note: StreamCaster is disabled.${BLACK}"
  599. fi
  600. if [ $SRS_HDS = YES ]; then
  601. echo -e "${YELLOW}Experiment: HDS is enabled.${BLACK}"
  602. else
  603. echo -e "${GREEN}Warning: HDS is disabled.${BLACK}"
  604. fi
  605. if [ $SRS_SRT = YES ]; then
  606. echo -e "${YELLOW}Experiment: SRT is enabled. https://github.com/ossrs/srs/issues/1147${BLACK}"
  607. else
  608. echo -e "${GREEN}Warning: SRT is disabled.${BLACK}"
  609. fi
  610. if [ $SRS_RTC = YES ]; then
  611. echo -e "${YELLOW}Experiment: RTC is enabled. https://github.com/ossrs/srs/issues/307${BLACK}"
  612. else
  613. echo -e "${GREEN}Warning: RTC is disabled.${BLACK}"
  614. fi
  615. if [ $SRS_HTTPS = YES ]; then
  616. echo -e "${YELLOW}Experiment: HTTPS is enabled. https://github.com/ossrs/srs/issues/1657${BLACK}"
  617. else
  618. echo -e "${GREEN}Warning: HTTPS is disabled.${BLACK}"
  619. fi
  620. if [ $SRS_DVR = YES ]; then
  621. echo -e "${GREEN}DVR is enabled.${BLACK}"
  622. else
  623. echo -e "${YELLOW}Warning: DVR is disabled.${BLACK}"
  624. fi
  625. if [ $SRS_SSL = YES ]; then
  626. echo -e "${GREEN}RTMP complex handshake is enabled${BLACK}"
  627. else
  628. echo -e "${YELLOW}Warning: RTMP complex handshake is disabled, flash cann't play h264/aac.${BLACK}"
  629. fi
  630. if [[ $SRS_NASM == YES ]]; then
  631. echo -e "${GREEN}NASM for HTTPS(openssl) and FFmepg is enabled${BLACK}"
  632. else
  633. echo -e "${YELLOW}Warning: NASM for HTTPS(openssl) and FFmepg is disabled${BLACK}"
  634. fi
  635. if [[ $SRS_SRTP_ASM == YES ]]; then
  636. echo -e "${GREEN}SRTP-NASM for WebRTC(openssl) is enabled${BLACK}"
  637. else
  638. echo -e "${YELLOW}Warning: SRTP-NASM for WebRTC(openssl) is disabled${BLACK}"
  639. fi
  640. if [ $SRS_TRANSCODE = YES ]; then
  641. echo -e "${GREEN}The transcoding is enabled${BLACK}"
  642. else
  643. echo -e "${YELLOW}Warning: The transcoding is disabled.${BLACK}"
  644. fi
  645. if [ $SRS_INGEST = YES ]; then
  646. echo -e "${GREEN}The ingesting is enabled.${BLACK}"
  647. else
  648. echo -e "${YELLOW}Warning: The ingesting is disabled.${BLACK}"
  649. fi
  650. if [ $SRS_HTTP_CALLBACK = YES ]; then
  651. echo -e "${GREEN}The http-callback is enabled${BLACK}"
  652. else
  653. echo -e "${YELLOW}Warning: The http-callback is disabled.${BLACK}"
  654. fi
  655. if [ $SRS_HTTP_SERVER = YES ]; then
  656. echo -e "${GREEN}Embeded HTTP server for HTTP-FLV/HLS is enabled.${BLACK}"
  657. else
  658. echo -e "${YELLOW}Warning: Embeded HTTP server is disabled, HTTP-FLV is disabled, please use nginx to delivery HLS.${BLACK}"
  659. fi
  660. if [ $SRS_HTTP_API = YES ]; then
  661. echo -e "${GREEN}The HTTP API is enabled${BLACK}"
  662. else
  663. echo -e "${YELLOW}Warning: The HTTP API is disabled.${BLACK}"
  664. fi
  665. if [ $SRS_UTEST = YES ]; then
  666. echo -e "${GREEN}The utests are enabled.${BLACK}"
  667. else
  668. echo -e "${YELLOW}Note: The utests are disabled.${BLACK}"
  669. fi
  670. if [ $SRS_GPERF = YES ]; then
  671. echo -e "${GREEN}The gperf(tcmalloc) is enabled.${BLACK}"
  672. else
  673. echo -e "${GREEN}Note: The gperf(tcmalloc) is disabled.${BLACK}"
  674. fi
  675. if [ $SRS_GPERF_MC = YES ]; then
  676. echo -e "${YELLOW}The gmc(gperf memory check) is enabled, performance may suffer.${BLACK}"
  677. else
  678. echo -e "${GREEN}Note: The gmc(gperf memory check) is disabled.${BLACK}"
  679. fi
  680. if [ $SRS_GPERF_MD = YES ]; then
  681. echo -e "${YELLOW}The gmd(gperf memory defense) is enabled, performance may suffer.${BLACK}"
  682. else
  683. echo -e "${GREEN}Note: The gmd(gperf memory defense) is disabled.${BLACK}"
  684. fi
  685. if [ $SRS_GPERF_MP = YES ]; then
  686. echo -e "${YELLOW}The gmp(gperf memory profile) is enabled, performance may suffer.${BLACK}"
  687. else
  688. echo -e "${GREEN}Note: The gmp(gperf memory profile) is disabled.${BLACK}"
  689. fi
  690. if [ $SRS_GPERF_CP = YES ]; then
  691. echo -e "${YELLOW}The gcp(gperf cpu profile) is enabled, performance may suffer.${BLACK}"
  692. else
  693. echo -e "${GREEN}Note: The gcp(gperf cpu profile) is disabled.${BLACK}"
  694. fi
  695. if [ $SRS_GPROF = YES ]; then
  696. echo -e "${YELLOW}The gprof(GNU profile tool) is enabled, performance may suffer.${BLACK}"
  697. else
  698. echo -e "${GREEN}Note: The gprof(GNU profile tool) is disabled.${BLACK}"
  699. fi
  700. if [ $SRS_CROSS_BUILD = YES ]; then
  701. echo -e "${YELLOW}The cross-build is enabled.${BLACK}"
  702. else
  703. echo -e "${GREEN}Note: The cross-build is disabled.${BLACK}"
  704. fi
  705. if [ $SRS_VALGRIND = YES ]; then
  706. echo -e "${GREEN}The valgrind is enabled.${BLACK}"
  707. else
  708. echo -e "${GREEN}Note: The valgrind is disabled.${BLACK}"
  709. fi
  710. # add each modules for application
  711. for SRS_MODULE in ${SRS_MODULES[*]}; do
  712. echo -e "${GREEN}Enable module: $SRS_MODULE${BLACK}"
  713. done
  714. #####################################################################################
  715. # Do cleanup when configure done.
  716. #####################################################################################
  717. if [[ $SRS_CLEAN == YES && -f Makefile ]]; then
  718. #echo "Do full cleanup, you can disable it by: --clean=off"
  719. make clean
  720. fi
  721. #####################################################################################
  722. # next step
  723. #####################################################################################
  724. if [[ $SRS_CHERRYPY == YES ]]; then
  725. echo ""
  726. echo "You can run 3rdparty applications:"
  727. if [ $SRS_HTTP_CALLBACK = YES ]; then
  728. echo -e "\" python ./research/api-server/server.py 8085 \" to start the api-server"
  729. fi
  730. fi
  731. echo ""
  732. echo "You can build SRS:"
  733. echo "\" make \" to build the SRS server"
  734. echo "\" make help \" to get some help"