configure 5.8 KB
#!/bin/bash

SRS_MAKEFILE="Makefile"
SRS_OBJS="objs"
SRS_AUTO_HEADERS_H="${SRS_OBJS}/srs_auto_headers.hpp"

mkdir -p ${SRS_OBJS}

# linux shell color support.
RED="\\e[31m"
GREEN="\\e[32m"
YELLOW="\\e[33m"
BLACK="\\e[0m"

# parse user options.
. auto/options.sh

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
}

# clean the exists
if [[ -f Makefile ]]; then
    make clean
fi

# generate the audo headers file.
echo "#define SRS_CONFIGURE \"${SRS_CONFIGURE}\"" > $SRS_AUTO_HEADERS_H
echo "#define SRS_BUILD_DATE \"`date \"+%Y-%m-%d %H:%M:%S\"`\"" >> $SRS_AUTO_HEADERS_H
echo "#define SRS_BUILD_TS \"`date +%s`\"" >> $SRS_AUTO_HEADERS_H

# apply user options.
. auto/depends.sh

# new empty line to auto headers file.
echo "" >> $SRS_AUTO_HEADERS_H

#####################################################################################
# generate Makefile.
#####################################################################################
echo "generate Makefile"

cat << END > ${SRS_MAKEFILE}
.PHONY: default help clean server bandwidth _prepare_dir
default: server bandwidth

help:
	@echo "Usage: make <help>|<clean>|<server>|<bandwidth>"
	@echo "  help       display this help menu"
	@echo "  clean      cleanup project"
	@echo "  server     build the srs(simple rtmp server) over st(state-threads)"
	@echo "  bandwidth  build the bandwidth test client tool."

clean: 
	(rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load)

server: _prepare_dir
	@echo "build the srs(simple rtmp server) over st(state-threads)"
	\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} srs

bandwidth: _prepare_dir
	@echo "build the bandwidth test client tool"
	\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} bandwidth

# the ./configure will generate it.
_prepare_dir:
	@mkdir -p ${SRS_OBJS}
END

echo 'generate Makefile ok!'

# the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt
Performance="-pg"
# enable gdb debug
GDBDebug="-g -O0"
# the warning level.
WarnLevel="-Wall"
# the compile standard.
CppStd="-ansi"
# the cxx flag generated.
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug}"
#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
CXXFLAGS = ${CXXFLAGS}
GCC = g++
LINK = \$(GCC)
AR = ar

.PHONY: default srs bandwidth 

default:

END

# Libraries
LibSTRoot="${SRS_OBJS}/st"
LibSTfile="${LibSTRoot}/libst.a"
if [ $SRS_HTTP = YES ]; then
    LibHttpParserRoot="${SRS_OBJS}/hp"
    LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"
fi

#Core Module
MODULE_ID="CORE" 
MODULE_DEPENDS=() 
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
if [ $SRS_HTTP = YES ]; then
    ModuleLibIncs="${ModuleLibIncs[@]} ${LibHttpParserRoot}"
fi
MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" 
        "srs_core_error" "srs_core_conn" "srs_core_client" 
        "srs_core_rtmp" "srs_core_socket" "srs_core_buffer"
        "srs_core_autofree" "srs_core_protocol" "srs_core_amf0"
        "srs_core_stream" "srs_core_source" "srs_core_codec"
        "srs_core_handshake" "srs_core_pithy_print"
        "srs_core_config" "srs_core_refer" "srs_core_reload"
        "srs_core_hls" "srs_core_forward" "srs_core_encoder"
        "srs_core_http" "srs_core_thread" "srs_core_bandwidth")
MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"

#Main Module
MODULE_ID="MAIN" 
MODULE_DEPENDS=("CORE")
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
MODULE_FILES=("srs_main_server" "srs_main_bandcheck")
MODULE_DIR="src/main" . auto/modules.sh
MAIN_OBJS="${MODULE_OBJS[@].o}"

# all main entrances
MAIN_ENTRANCES=("srs_main_server" "srs_main_bandcheck")

# srs(simple rtmp server) over st(state-threads)
ModuleLibFiles=(${LibSTfile})
if [ $SRS_HTTP = YES ]; then
    ModuleLibFiles="${ModuleLibFiles[@]} ${LibHttpParserfile}"
fi
MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}"
if [ $SRS_SSL = YES ]; then
    LINK_OPTIONS="-ldl -lssl -lcrypto"
else
    LINK_OPTIONS="-ldl"
fi
BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" SO_PATH="" . auto/apps.sh
BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" SO_PATH="" . auto/apps.sh

echo 'configure ok! '

# summary
echo ""
echo "configure summary:"
if [ $SRS_HLS = YES ]; then
    echo -e "${GREEN}HLS over nginx is enabled${BLACK}"
else
    echo -e "${YELLOW}warning: without HLS support${BLACK}"
fi
if [ $SRS_SSL = YES ]; then
    echo -e "${GREEN}rtmp complex handshake is enabled${BLACK}"
else
    echo -e "${YELLOW}warning: without rtmp complex handshake support, donot support h264/aac to adobe flash player${BLACK}"
fi
if [ $SRS_FFMPEG = YES ]; then
    echo -e "${GREEN}live stream transcoding over FFMPEG is enabled${BLACK}"
else
    echo -e "${YELLOW}warning: without live stream transcoding over FFMPEG support${BLACK}"
fi
if [ $SRS_HTTP = YES ]; then
    echo -e "${GREEN}http hooks callback over CherryPy is enabled${BLACK}"
else
    echo -e "${YELLOW}warning: without http hooks callback over CherryPy support${BLACK}"
fi

# mkdir dirs
mkdir -p ${SRS_OBJS}/logs

ip=`ifconfig|grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'|awk -F ':' 'NR==1 {print $2}'`
# next step.
echo ""
echo "you can:"
echo "\" make \" to build the srs(simple rtmp server)."
echo "\" make help \" to get the usage of make"
if [ $SRS_HLS = YES ]; then
    echo "\" sudo ./objs/nginx/sbin/nginx  \" to start the nginx http server for hls"
    echo "\" http://$ip \" rtmp players(OSMF/JWPlayer)"
fi
if [ $SRS_FFMPEG = YES ]; then
    echo -e "\" ./objs/ffmpeg/bin/ffmpeg  \" is used for live stream transcoding"
fi
if [ $SRS_HTTP = YES ]; then
    echo -e "\" python ./research/api-server/server.py 8085  \" to start the api-server"
fi
echo "\" ./objs/srs -c conf/srs.conf \" to start the srs live server"