configure 28 KB

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