#!/bin/bash # variables, parent script must set it: # SRS_JOBS: the build jobs. # SrsArmMakeOptions: the arm make options for ubuntu12(armhf, v7cpu) ##################################################################################### ##################################################################################### # prepare the depends tools and libraries # DEPENDS: options.sh, only when user options parsed, the depends tools are known. ##################################################################################### ##################################################################################### ##################################################################################### # utilities ##################################################################################### function require_sudoer() { sudo echo "" >/dev/null 2>&1 ret=$?; if [[ 0 -ne $ret ]]; then echo "\"$1\" require sudoer failed. ret=$ret"; exit $ret; fi } # TODO: check gcc/g++ echo "Checking gcc/g++/gdb/make." echo "Required tools are ok." ##################################################################################### # for Ubuntu, auto install tools by apt-get ##################################################################################### OS_IS_UBUNTU=NO function Ubuntu_prepare() { uname -v|grep Ubuntu >/dev/null 2>&1 ret=$?; if [[ 0 -ne $ret ]]; then # for debian, we think it's ubuntu also. # for example, the wheezy/sid which is debian armv7 linux, can not identified by uname -v. if [[ ! -f /etc/debian_version ]]; then return 0; fi fi OS_IS_UBUNTU=YES echo "Installing tools for Ubuntu." gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing gcc." require_sudoer "sudo apt-get install -y --force-yes gcc" sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The gcc is installed." fi g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing g++." require_sudoer "sudo apt-get install -y --force-yes g++" sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The g++ is installed." fi make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing make." require_sudoer "sudo apt-get install -y --force-yes make" sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The make is installed." fi patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing patch." require_sudoer "sudo apt-get install -y --force-yes patch" sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The patch is installed." fi unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing unzip." require_sudoer "sudo apt-get install -y --force-yes unzip" sudo apt-get install -y --force-yes unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The unzip is installed." fi if [[ $SRS_VALGRIND == YES ]]; then valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing valgrind." require_sudoer "sudo apt-get install -y --force-yes valgrind" sudo apt-get install -y --force-yes valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The valgrind is installed." fi fi if [[ $SRS_VALGRIND == YES ]]; then if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then echo "Installing valgrind-dev." require_sudoer "sudo apt-get install -y --force-yes valgrind-dbg" sudo apt-get install -y --force-yes valgrind-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The valgrind-dev is installed." fi fi if [[ $SRS_SRT == YES ]]; then echo "SRT enable, install depend tools" tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing tcl." require_sudoer "sudo apt-get install -y --force-yes tcl" sudo apt-get install -y --force-yes tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The tcl is installed." fi cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing cmake." require_sudoer "sudo apt-get install -y --force-yes cmake" sudo apt-get install -y --force-yes cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The cmake is installed." fi fi pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing pkg-config." require_sudoer "sudo apt-get install -y --force-yes pkg-config" sudo apt-get install -y --force-yes pkg-config; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The pkg-config is installed." fi echo "Tools for Ubuntu are installed." return 0 } # donot prepare tools, for srs-librtmp depends only gcc and g++. Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for ubuntu failed, ret=$ret"; exit $ret; fi ##################################################################################### # for Centos, auto install tools by yum ##################################################################################### OS_IS_CENTOS=NO function Centos_prepare() { if [[ ! -f /etc/redhat-release ]]; then return 0; fi OS_IS_CENTOS=YES echo "Installing tools for Centos." gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing gcc." require_sudoer "sudo yum install -y gcc" sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The gcc is installed." fi g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing gcc-c++." require_sudoer "sudo yum install -y gcc-c++" sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The gcc-c++ is installed." fi make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing make." require_sudoer "sudo yum install -y make" sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The make is installed." fi patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing patch." require_sudoer "sudo yum install -y patch" sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The patch is installed." fi unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing unzip." require_sudoer "sudo yum install -y unzip" sudo yum install -y unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The unzip is installed." fi if [[ $SRS_VALGRIND == YES ]]; then valgrind --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing valgrind." require_sudoer "sudo yum install -y valgrind" sudo yum install -y valgrind; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The valgrind is installed." fi fi if [[ $SRS_VALGRIND == YES ]]; then if [[ ! -f /usr/include/valgrind/valgrind.h ]]; then echo "Installing valgrind-devel." require_sudoer "sudo yum install -y valgrind-devel" sudo yum install -y valgrind-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The valgrind-devel is installed." fi fi if [[ $SRS_SRT == YES ]]; then echo "SRT enable, install depend tools" tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing tcl." require_sudoer "sudo yum install -y tcl" sudo yum install -y tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The tcl is installed." fi cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing cmake." require_sudoer "sudo yum install -y cmake" sudo yum install -y cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "The cmake is installed." fi fi pkg-config --version --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Please install pkg-config"; exit -1; fi echo "Tools for Centos are installed." return 0 } # donot prepare tools, for srs-librtmp depends only gcc and g++. Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Install tools for CentOS failed, ret=$ret"; exit $ret; fi ##################################################################################### # For OSX, auto install tools by brew ##################################################################################### OS_IS_OSX=NO function OSX_prepare() { uname -s|grep Darwin >/dev/null 2>&1 ret=$?; if [[ 0 -ne $ret ]]; then if [ $SRS_OSX = YES ]; then echo "OSX check failed, actual is `uname -s`" exit 1; fi return 0; fi # cross build for arm, install the cross build tool chain. if [ $SRS_CROSS_BUILD = YES ]; then echo "The embeded(arm/mips) is invalid for OSX" return 1 fi OS_IS_OSX=YES # requires the osx when os if [ $OS_IS_OSX = YES ]; then if [ $SRS_OSX = NO ]; then echo "OSX detected, please use: ./configure --osx" exit 1 fi fi echo "OSX detected, install tools if needed" brew --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Please install brew at https://brew.sh/" exit $ret fi gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "install gcc" echo "brew install gcc" brew install gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install gcc success" fi g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "install gcc-c++" echo "brew install gcc-c++" brew install gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install gcc-c++ success" fi make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "install make" echo "brew install make" brew install make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install make success" fi patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "install patch" echo "brew install patch" brew install patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install patch success" fi unzip --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "install unzip" echo "brew install unzip" brew install unzip; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install unzip success" fi pkg-config --version >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Please install pkg-config"; exit -1; fi if [[ $SRS_SRT == YES ]]; then echo "SRT enable, install depend tools" tclsh <<< "exit" >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing tcl." echo "brew install tcl." brew install tcl; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install tcl success" fi cmake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then echo "Installing cmake." echo "brew install cmake." brew install cmake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi echo "install cmake success" fi fi echo "OSX install tools success" return 0 } # donot prepare tools, for srs-librtmp depends only gcc and g++. OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$ret"; exit $ret; fi ##################################################################################### # Whether CPU is loongarch ##################################################################################### OS_IS_LOONGARCH=$(uname -p|grep -q loongarch && echo YES) ##################################################################################### # for Centos, auto install tools by yum ##################################################################################### # We must use a bash function instead of variable. function sed_utility() { if [ $OS_IS_OSX = YES ]; then sed -i '' "$@" else sed -i "$@" fi ret=$?; if [[ $ret -ne 0 ]]; then if [ $OS_IS_OSX = YES ]; then echo "sed -i '' \"$@\"" else echo "sed -i \"$@\"" fi return $ret fi } SED="sed_utility" && echo "SED is $SED" function _srs_link_file() { tmp_dir=$1; if [[ $tmp_dir != *'/' ]]; then tmp_dir+='/'; fi tmp_dest=$2; if [[ $tmp_dest != *'/' ]]; then tmp_dest+='/'; fi tmp_prefix=$3; if [[ $tmp_prefix != *'/' ]]; then tmp_prefix+='/'; fi echo "LINK files at dir: $tmp_dir, dest: $tmp_dest, prefix: $tmp_prefix, pwd: `pwd`" for file in `(cd $tmp_dir && find . -maxdepth 1 -type f ! -name '*.o' ! -name '*.d' ! -name '*.log')`; do basefile=`basename $file` && #echo "ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile" && ln -sf ${tmp_prefix}${tmp_dir}$basefile ${tmp_dest}$basefile; done } ##################################################################################### # check the os. ##################################################################################### # Only supports: # linux, centos/ubuntu as such, # cross build for embeded system, for example, mips or arm, # directly build on arm/mips, for example, pi or cubie, # export srs-librtmp # others is invalid. if [[ $OS_IS_UBUNTU = NO && $OS_IS_CENTOS = NO && $OS_IS_OSX = NO && $SRS_CROSS_BUILD = NO ]]; then echo "Your OS `uname -s` is not supported." exit 1 fi ##################################################################################### # state-threads ##################################################################################### # check the cross build flag file, if flag changed, need to rebuild the st. _ST_MAKE=linux-debug && _ST_OBJ="LINUX_`uname -r`_DBG" # Always alloc on heap, @see https://github.com/ossrs/srs/issues/509#issuecomment-719931676 _ST_EXTRA_CFLAGS="-DMALLOC_STACK" # For valgrind to detect memory issues. if [[ $SRS_VALGRIND == YES ]]; then _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_VALGRIND" fi # for osx, use darwin for st, donot use epoll. if [[ $SRS_OSX == YES ]]; then _ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG" fi # For Ubuntu, the epoll detection might be fail. if [[ $OS_IS_UBUNTU == YES ]]; then _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL" fi # Whether enable debug stats. if [[ $SRS_DEBUG_STATS == YES ]]; then _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DDEBUG_STATS" fi # Pass the global extra flags. if [[ $SRS_EXTRA_FLAGS != '' ]]; then _ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS $SRS_EXTRA_FLAGS" fi # Whether link as .so if [[ $SRS_SHARED_ST == YES ]]; then _ST_STATIC_ONLY=no; else _ST_STATIC_ONLY=yes; fi # The final args to make st. _ST_MAKE_ARGS="${_ST_MAKE} STATIC_ONLY=${_ST_STATIC_ONLY}" _ST_MAKE_ARGS="${_ST_MAKE_ARGS} CC=${SRS_TOOL_CC} AR=${SRS_TOOL_AR} LD=${SRS_TOOL_LD} RANDLIB=${SRS_TOOL_RANDLIB}" # Patched ST from https://github.com/ossrs/state-threads/tree/srs if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ]]; then echo "The state-threads is ok."; else echo "Building state-threads."; ( rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && # Create a hidden directory .src cd ${SRS_OBJS}/${SRS_PLATFORM}/st-srs && ln -sf ../../../3rdparty/st-srs .src && # Link source files under .src _srs_link_file .src/ ./ ./ && # Build source code. env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make ${_ST_MAKE_ARGS} && cd .. && rm -rf st && ln -sf st-srs/${_ST_OBJ} st ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "Build state-threads failed, ret=$ret"; exit $ret; fi # Always update the links. (cd ${SRS_OBJS}/${SRS_PLATFORM} && rm -rf st && ln -sf st-srs/${_ST_OBJ} st) (cd ${SRS_OBJS} && rm -rf st && ln -sf ${SRS_PLATFORM}/st-srs/${_ST_OBJ} st) if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "Build state-threads static lib failed."; exit -1; fi ##################################################################################### # nginx for HLS, nginx-1.5.0 ##################################################################################### function write_nginx_html5() { cat< ${html_file} END } # create the nginx dir, for http-server if not build nginx mkdir -p ${SRS_OBJS}/nginx # the demo dir. # create forward dir mkdir -p ${SRS_OBJS}/nginx/html/live && html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5 # copy players to nginx html dir. rm -rf ${SRS_OBJS}/nginx/html/players && ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players # for favicon.ico rm -rf ${SRS_OBJS}/nginx/html/favicon.ico && ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico # For srs-console. rm -rf ${SRS_OBJS}/nginx/html/console && ln -sf `pwd`/research/console ${SRS_OBJS}/nginx/html/console # For SRS signaling. rm -rf ${SRS_OBJS}/nginx/html/demos && ln -sf `pwd`/3rdparty/signaling/www/demos ${SRS_OBJS}/nginx/html/demos # For home page index.html rm -rf ${SRS_OBJS}/nginx/html/index.html && ln -sf `pwd`/research/api-server/static-dir/index.html ${SRS_OBJS}/nginx/html/index.html # nginx.html to detect whether nginx is alive echo "Nginx is ok." > ${SRS_OBJS}/nginx/html/nginx.html ##################################################################################### # Generate default self-sign certificate for HTTPS server, test only. ##################################################################################### if [[ ! -f conf/server.key || ! -f conf/server.crt ]]; then openssl genrsa -out conf/server.key 2048 openssl req -new -x509 -key conf/server.key -out conf/server.crt -days 3650 -subj "/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=ossrs.net" echo "Generate test-only self-sign certificate files" fi ##################################################################################### # cherrypy for http hooks callback, CherryPy-3.2.4 ##################################################################################### if [[ $SRS_CHERRYPY == YES ]]; then # Detect python or python2 python --version >/dev/null 2>&1 && SYS_PYTHON=python; python2 --version >/dev/null 2>&1 && SYS_PYTHON=python2; # Install cherrypy for api server. if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]]; then echo "CherryPy-3.2.4 is ok."; else echo "Installing CherryPy-3.2.4"; ( rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS}/${SRS_PLATFORM} && unzip -q ../../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 && $SYS_PYTHON setup.py install --user --prefix='' ) fi # check status ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi if [ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi echo "Link players to cherrypy static-dir" rm -rf research/api-server/static-dir/players && ln -sf `pwd`/research/players research/api-server/static-dir/players && rm -rf research/api-server/static-dir/live && mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live && ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live && rm -rf research/api-server/static-dir/forward && mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward && ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward ret=$?; if [[ $ret -ne 0 ]]; then echo "Warning: Ignore error to link players to cherrypy static-dir."; fi fi ##################################################################################### # openssl, for rtmp complex handshake and HLS encryption. ##################################################################################### if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then echo "Warning: Use system libssl, without compiling openssl." fi # @see http://www.openssl.org/news/secadv/20140407.txt # Affected users should upgrade to OpenSSL 1.1.0e. Users unable to immediately # upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS. if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL != YES ]]; then OPENSSL_OPTIONS="-no-shared -no-threads -DOPENSSL_NO_HEARTBEATS" OPENSSL_CONFIG="./config" # https://stackoverflow.com/questions/15539062/cross-compiling-of-openssl-for-linux-arm-v5te-linux-gnueabi-toolchain if [[ $SRS_CROSS_BUILD == YES ]]; then OPENSSL_CONFIG="./Configure linux-generic32" if [[ $SRS_CROSS_BUILD_ARCH == "arm" ]]; then OPENSSL_CONFIG="./Configure linux-armv4"; fi if [[ $SRS_CROSS_BUILD_ARCH == "aarch64" ]]; then OPENSSL_CONFIG="./Configure linux-aarch64"; fi if [[ $SRS_CROSS_BUILD_ARCH == "mipsel" ]]; then OPENSSL_CONFIG="./Configure linux-mips32"; fi elif [[ ! -f ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib/libssl.a ]]; then # Try to use exists libraries. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == NO ]]; then (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/lib && ln -sf /usr/local/ssl/lib/libssl.a && ln -sf /usr/local/ssl/lib/libcrypto.a && mkdir -p /usr/local/ssl/lib/pkgconfig && ln -sf /usr/local/ssl/lib/pkgconfig) (mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && cd ${SRS_OBJS}/${SRS_PLATFORM}/openssl/include && ln -sf /usr/local/ssl/include/openssl) fi # Warning if not use the system ssl. if [[ -f /usr/local/ssl/lib/libssl.a && $SRS_SSL_LOCAL == YES ]]; then echo "Warning: Local openssl is on, ignore system openssl" fi fi # Patch for loongarch mips64, disable ASM for build failed message as bellow: # Error: opcode not supported on this processor: mips3 (mips3) g++ -dM -E -