configure 10.7 KB
#!/bin/bash

#####################################################################################
# the main output dir, all configure and make output are in this dir.
#####################################################################################
# create the main objs
SRS_OBJS="objs"
mkdir -p ${SRS_OBJS}

#####################################################################################
# parse user options, set the variables like SRS_SSL/SRS_HLS/SRS_FFMPEG/SRS_HTTP
#####################################################################################
# parse options, exit with error when parse options invalid.
. auto/options.sh

# clean the exists
# do this only when the options is ok.
if [[ -f Makefile ]]; then
    make clean
fi

#####################################################################################
# generate auto headers file, depends on the finished of options.sh
#####################################################################################
# write user options to headers
SRS_AUTO_HEADERS_H="${SRS_OBJS}/srs_auto_headers.hpp"
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"
SRS_MAKEFILE="Makefile"
cat << END > ${SRS_MAKEFILE}
.PHONY: default help clean server bandwidth librtmp librtmp-sample _prepare_dir

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

default: server bandwidth librtmp librtmp-sample
	@echo -e "\$(GREEN)"
	@echo -e "build success:"
	@echo -e "     server:          ./objs/srs, the srs server"
	@echo -e "     bandwidth:       ./objs/bandwidth, the bandwidth test client"
	@echo -e "     librtmp:         ./objs/include, ./objs/lib, the srs-librtmp library"
	@echo -e "     librtmp-sample:  ./research/librtmp, the srs-librtmp client sample"
	@echo -e "\$(BLACK)"

help:
	@echo "Usage: make <help>|<clean>|<server>|<bandwidth>|<librtmp>|<librtmp-sample>"
	@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."
	@echo "  librtmp            build the client publish/play library."
	@echo "  librtmp-sample     build the srs-librtmp sample"

clean: 
	(rm -f Makefile; cd ${SRS_OBJS}; rm -rf srs bandwidth Makefile *.hpp src st_*_load research include lib)
	(cd research/librtmp; make clean)

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

librtmp: _prepare_dir
	@echo "build the client publish/play library."
	\$(MAKE) -f ${SRS_OBJS}/${SRS_MAKEFILE} librtmp

librtmp-sample:
	@echo "build the srs-librtmp sample"
	(cd research/librtmp; make)
	@echo "srs-librtmp sample build success"

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

#####################################################################################
# build tools or compiler args.
# 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"
# for library compile
LibraryCompile="-fPIC"
# the cxx flag generated.
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${LibraryCompile}"
#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
CC ?= gcc
GCC ?= gcc
CXX ?= g++
AR ?= ar
CXXFLAGS = ${CXXFLAGS}
LINK = g++

.PHONY: default srs bandwidth 

default:

END

#####################################################################################
# Libraries, external library to build in srs,
# header(.h): add to ModuleLibIncs if need the specified library. for example, LibSTRoot
# library(.a): add to ModuleLibFiles if binary need the specifeid library. for example, LibSTfile
#
# st(state-threads) the basic network library for SRS.
LibSTRoot="${SRS_OBJS}/st"
LibSTfile="${LibSTRoot}/libst.a"
# hp(http-parser) the http request/url parser, for SRS to support HTTP callback.
LibHttpParserRoot=""
LibHttpParserfile=""
if [ $SRS_HTTP = YES ]; then
    LibHttpParserRoot="${SRS_OBJS}/hp"
    LibHttpParserfile="${LibHttpParserRoot}/libhttp_parser.a"
fi
# openssl-1.0.1f, for the RTMP complex handshake.
LibSSLRoot=""
LibSSLfile=""
if [ $SRS_SSL = YES ]; then
    LibSSLRoot="${SRS_OBJS}/openssl/include"
    LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"
fi

#####################################################################################
# Modules, compile each module, then link to binary
#
#Core, depends only on system apis.
MODULE_ID="CORE" 
MODULE_DEPENDS=() 
ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_core" "srs_core_autofree")
MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"
#
#Kernel, depends on core, provides error/log/config, nothing about stream information.
MODULE_ID="KERNEL" 
MODULE_DEPENDS=("CORE") 
ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_stream" "srs_kernel_buffer")
MODULE_DIR="src/kernel" . auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}"
#
#RTMP Protocol, depends on core/kernel, provides rtmp/htttp protocol features.
MODULE_ID="RTMP" 
MODULE_DEPENDS=("CORE" "KERNEL") 
ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot})
MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_rtmp_stack" "srs_protocol_rtmp"
        "srs_protocol_handshake" "srs_protocol_utility")
MODULE_DIR="src/rtmp" . auto/modules.sh
RTMP_OBJS="${MODULE_OBJS[@]}"
#
#App Module
MODULE_ID="APP" 
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 
ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
MODULE_FILES=("srs_core_server" "srs_core_conn" "srs_core_client" "srs_core_socket" "srs_core_source" 
        "srs_core_codec" "srs_core_refer" "srs_core_hls" "srs_core_forward" "srs_core_encoder"
        "srs_core_http" "srs_core_thread" "srs_core_bandwidth" "srs_core_st" "srs_core_log"
        "srs_core_config" "srs_core_pithy_print" "srs_core_reload")
MODULE_DIR="src/app" . auto/modules.sh
APP_OBJS="${MODULE_OBJS[@]}"
#
#LIBS Module, build libsrs.a for static link.
MODULE_ID="LIBS" 
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 
ModuleLibIncs=(${SRS_OBJS})
MODULE_FILES=("srs_librtmp" "srs_lib_simple_socket")
MODULE_DIR="src/libs" . auto/modules.sh
LIBS_OBJS="${MODULE_OBJS[@]}"
#
#Main Module
MODULE_ID="MAIN" 
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
MODULE_FILES=("srs_main_server" "srs_main_bandcheck")
MODULE_DIR="src/main" . auto/modules.sh
MAIN_OBJS="${MODULE_OBJS[@].o}"

#####################################################################################
# Binaries, main entrances, link the module and its depends modules,
# then link to a binary, for example, objs/srs
#
# all main entrances
MAIN_ENTRANCES=("srs_main_server" "srs_main_bandcheck")
# 
# all depends libraries
ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
# all depends objects
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
LINK_OPTIONS="-ldl"
#
# srs:
# srs(simple rtmp server) over st(state-threads)
BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh
#
# bandwidth
# bandwidth test tool, to test the bandwidth to server
BUILD_KEY="bandwidth" APP_MAIN="srs_main_bandcheck" APP_NAME="bandwidth" . auto/apps.sh
#
# srs librtmp
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${LIBS_OBJS[@]}"
BUILD_KEY="librtmp" LIB_NAME="lib/srs_librtmp" . auto/libs.sh

echo 'configure ok! '

#####################################################################################
# when configure success, prepare build
#####################################################################################
# create objs/logs for ffmpeg to write log.
mkdir -p ${SRS_OBJS}/logs
# lib and include for library
mkdir -p ${SRS_OBJS}/lib
mkdir -p ${SRS_OBJS}/include

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

# 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
if [ $SRS_RESEARCH = YES ]; then
    echo -e "${GREEN}research tools are builded${BLACK}"
else
    echo -e "${BLACK}note: research tools are not builded${BLACK}"
fi

#####################################################################################
# next step
#####################################################################################
ip=`ifconfig|grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'|awk -F ':' 'NR==1 {print $2}'`
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"