Steven Liu

Support porting srs on MacOS OSX system Platform

Add the OSX platform cross complie options into srs
@@ -214,6 +214,91 @@ function Centos_prepare() @@ -214,6 +214,91 @@ function Centos_prepare()
214 return 0 214 return 0
215 } 215 }
216 Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "CentOS prepare failed, ret=$ret"; exit $ret; fi 216 Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "CentOS prepare failed, ret=$ret"; exit $ret; fi
  217 +#####################################################################################
  218 +# for OSX, auto install tools by brew
  219 +#####################################################################################
  220 +OS_IS_OSX=NO
  221 +function OSX_prepare()
  222 +{
  223 + SYS_NAME=`uname -s`
  224 + if [ $SYS_NAME != Darwin ]; then
  225 + echo "This is not Darwin OSX"
  226 + return 0;
  227 + fi
  228 +
  229 + OS_IS_OSX=YES
  230 + echo "OSX detected, install tools if needed"
  231 +
  232 + gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  233 + echo "install gcc"
  234 + require_sudoer "sudo brew install gcc"
  235 + sudo brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  236 + echo "install gcc success"
  237 + fi
  238 +
  239 + g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  240 + echo "install gcc-c++"
  241 + require_sudoer "sudo brew install gcc-c++"
  242 + sudo brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  243 + echo "install gcc-c++ success"
  244 + fi
  245 +
  246 + make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  247 + echo "install make"
  248 + require_sudoer "sudo brew install make"
  249 + sudo brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  250 + echo "install make success"
  251 + fi
  252 +
  253 + patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  254 + echo "install patch"
  255 + require_sudoer "sudo brew install patch"
  256 + sudo brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  257 + echo "install patch success"
  258 + fi
  259 +
  260 + if [ $SRS_FFMPEG_TOOL = YES ]; then
  261 + automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  262 + echo "install automake"
  263 + require_sudoer "sudo brew install automake"
  264 + sudo brew install automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  265 + echo "install automake success"
  266 + fi
  267 +
  268 + autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  269 + echo "install autoconf"
  270 + require_sudoer "sudo brew install autoconf"
  271 + sudo brew install autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  272 + echo "install autoconf success"
  273 + fi
  274 +
  275 + libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  276 + echo "install libtool"
  277 + require_sudoer "sudo brew install libtool"
  278 + sudo brew install libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  279 + echo "install libtool success"
  280 + fi
  281 +
  282 + if [[ ! -f /usr/include/pcre.h ]]; then
  283 + echo "install pcre-devel"
  284 + require_sudoer "sudo brew install pcre-devel"
  285 + sudo brew install pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  286 + echo "install pcre-devel success"
  287 + fi
  288 +
  289 + if [[ ! -f /usr/include/zlib.h ]]; then
  290 + echo "install zlib-devel"
  291 + require_sudoer "sudo brew install zlib-devel"
  292 + sudo brew install zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  293 + echo "install zlib-devel success"
  294 + fi
  295 + fi
  296 +
  297 + echo "OSX install tools success"
  298 + return 0
  299 +}
  300 +OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi
  301 +
217 302
218 ##################################################################################### 303 #####################################################################################
219 # st-1.9 304 # st-1.9
@@ -237,6 +322,23 @@ if [ $SRS_EMBEDED_CPU = YES ]; then @@ -237,6 +322,23 @@ if [ $SRS_EMBEDED_CPU = YES ]; then
237 ) 322 )
238 fi 323 fi
239 else 324 else
  325 + if [ $OS_IS_OSX = YES ]; then
  326 + if [[ ! -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a && -f ${SRS_OBJS}/st/libst.so ]]; then
  327 + echo "st-1.9t is ok.";
  328 + else
  329 + echo "build st-1.9t";
  330 + (
  331 + rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} &&
  332 + unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 &&
  333 + echo "we alaways patch the st, for we may build srs under arm directly" &&
  334 + echo "the 1.st.arm.patch is ok for x86 because it's only modify code under macro linux arm" &&
  335 + patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
  336 + make darwin-debug &&
  337 + cd .. && rm -rf st && ln -sf st-1.9/obj st &&
  338 + cd .. && rm -f ${SRS_OBJS}/_flag.st.arm.tmp
  339 + )
  340 + fi
  341 + else
240 # arm not specified, if exists flag, need to rebuild for no-arm platform. 342 # arm not specified, if exists flag, need to rebuild for no-arm platform.
241 if [[ ! -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a && -f ${SRS_OBJS}/st/libst.so ]]; then 343 if [[ ! -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a && -f ${SRS_OBJS}/st/libst.so ]]; then
242 echo "st-1.9t is ok."; 344 echo "st-1.9t is ok.";
@@ -253,11 +355,16 @@ else @@ -253,11 +355,16 @@ else
253 cd .. && rm -f ${SRS_OBJS}/_flag.st.arm.tmp 355 cd .. && rm -f ${SRS_OBJS}/_flag.st.arm.tmp
254 ) 356 )
255 fi 357 fi
  358 + fi
256 fi 359 fi
257 # check status 360 # check status
258 ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi 361 ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
259 -if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi  
260 -if [ ! -f ${SRS_OBJS}/st/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi 362 +if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "build st-1.9 static lib failed."; exit -1; fi
  363 +if [ OS_IS_OSX = Darwin ] then
  364 + if [ ! -f ${SRS_OBJS}/st/libst.dylib ]; then echo "build st-1.9 shared lib failed."; exit -1; fi
  365 +else
  366 + if [ ! -f ${SRS_OBJS}/st/libst.so ]; then echo "build st-1.9 shared lib failed."; exit -1; fi
  367 +fi
261 368
262 ##################################################################################### 369 #####################################################################################
263 # http-parser-2.1 370 # http-parser-2.1
@@ -252,6 +252,7 @@ function parse_user_option() { @@ -252,6 +252,7 @@ function parse_user_option() {
252 --cubie) SRS_CUBIE=YES ;; 252 --cubie) SRS_CUBIE=YES ;;
253 --dev) SRS_DEV=YES ;; 253 --dev) SRS_DEV=YES ;;
254 --fast-dev) SRS_FAST_DEV=YES ;; 254 --fast-dev) SRS_FAST_DEV=YES ;;
  255 + --osx-dev) SRS_OSX_DEV=YES ;;
255 --demo) SRS_DEMO=YES ;; 256 --demo) SRS_DEMO=YES ;;
256 --fast) SRS_FAST=YES ;; 257 --fast) SRS_FAST=YES ;;
257 --disable-all) SRS_DISABLE_ALL=YES ;; 258 --disable-all) SRS_DISABLE_ALL=YES ;;
@@ -579,6 +580,32 @@ function apply_user_presets() { @@ -579,6 +580,32 @@ function apply_user_presets() {
579 SRS_STATIC=NO 580 SRS_STATIC=NO
580 fi 581 fi
581 582
  583 + # if osx dev specified, open main server features.
  584 + if [ $SRS_OSX_DEV = YES ]; then
  585 + SRS_HLS=YES
  586 + SRS_DVR=YES
  587 + SRS_NGINX=NO
  588 + SRS_SSL=NO
  589 + SRS_FFMPEG_TOOL=NO
  590 + SRS_TRANSCODE=YES
  591 + SRS_INGEST=NO
  592 + SRS_HTTP_PARSER=NO
  593 + SRS_HTTP_CALLBACK=NO
  594 + SRS_HTTP_SERVER=NO
  595 + SRS_HTTP_API=NO
  596 + SRS_LIBRTMP=NO
  597 + SRS_RESEARCH=NO
  598 + SRS_UTEST=NO
  599 + SRS_GPERF=NO
  600 + SRS_GPERF_MC=NO
  601 + SRS_GPERF_MP=NO
  602 + SRS_GPERF_CP=NO
  603 + SRS_GPROF=NO
  604 + SRS_STATIC=NO
  605 + fi
  606 +
  607 +
  608 +
582 # for srs demo 609 # for srs demo
583 if [ $SRS_DEMO = YES ]; then 610 if [ $SRS_DEMO = YES ]; then
584 SRS_HLS=YES 611 SRS_HLS=YES
@@ -526,7 +526,6 @@ extern "C" { @@ -526,7 +526,6 @@ extern "C" {
526 #include <stdlib.h> 526 #include <stdlib.h>
527 #include <stdio.h> 527 #include <stdio.h>
528 #include <string.h> 528 #include <string.h>
529 -#include <malloc.h>  
530 #include <assert.h> 529 #include <assert.h>
531 530
532 //#include "nxjson.h" 531 //#include "nxjson.h"
@@ -476,7 +476,7 @@ int SrsServer::acquire_pid_file() @@ -476,7 +476,7 @@ int SrsServer::acquire_pid_file()
476 } 476 }
477 477
478 // require write lock 478 // require write lock
479 - flock lock; 479 + struct flock lock;
480 480
481 lock.l_type = F_WRLCK; // F_RDLCK, F_WRLCK, F_UNLCK 481 lock.l_type = F_WRLCK; // F_RDLCK, F_WRLCK, F_UNLCK
482 lock.l_start = 0; // type offset, relative to l_whence 482 lock.l_start = 0; // type offset, relative to l_whence