winlin

add build framework

不能预览此文件类型
#!/bin/bash
# params:
# $GLOBAL_DIR_OBJS the objs directory. ie. objs
# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile
# $MAIN_ENTRANCES array, all main entrance, disable all except the $APP_MAIN itself
# $MODULE_OBJS array, the objects to compile the app.
# $BUILD_KEY a string indicates the build key for Makefile. ie. dump
# $APP_MAIN the object file that contains main function. ie. your_app_main
# $APP_NAME the app name to output. ie. your_app
# $ModuleLibFiles array, the 3rdpart library file to link with. ie. (objs/st-1.9/obj/libst.a objs/libx264/obj/libx264.a)
# $LINK_OPTIONS the linker options.
# $SO_PATH the libssl.so.10 and other so file path.
FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
APP_TARGET="${GLOBAL_DIR_OBJS}/${APP_NAME}"
echo "generate app ${APP_NAME} depends...";
echo "# build ${APP_TARGET}" >> ${FILE}
echo "${BUILD_KEY}: ${APP_TARGET}" >> ${FILE}
echo -n "${APP_TARGET}: " >> ${FILE}
for item in ${MODULE_OBJS[*]}; do
FILE_NAME=`basename $item`
FILE_NAME=${FILE_NAME%.*}
ignored=0
for disabled_item in ${MAIN_ENTRANCES[*]}; do
if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
ignored=1
continue;
fi
done
if [ ! -f ${item} ]; then
ignored=1
fi
if [ ${ignored} == 1 ]; then
continue;
fi
OBJ_FILE=${GLOBAL_DIR_OBJS}/$item
OBJ_FILE="${OBJ_FILE%.*}.o"
echo -n "${OBJ_FILE} " >> ${FILE}
done
echo "" >> ${FILE}
echo "generate app ${APP_NAME} link...";
echo -n " \$(LINK) ${PerformanceLink} -o ${APP_TARGET} " >> ${FILE}
for item in ${MODULE_OBJS[*]}; do
FILE_NAME=`basename $item`
FILE_NAME=${FILE_NAME%.*}
ignored=0
for disabled_item in ${MAIN_ENTRANCES[*]}; do
if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
ignored=1
continue;
fi
done
if [ ! -f ${item} ]; then
ignored=1
fi
if [ ${ignored} == 1 ]; then
continue;
fi
OBJ_FILE=${GLOBAL_DIR_OBJS}/$item
OBJ_FILE="${OBJ_FILE%.*}.o"
echo -n "${OBJ_FILE} " >> ${FILE}
done
# 3rdpart library static link.
for item in ${ModuleLibFiles[*]}; do
echo -n "$item " >> ${FILE}
done
# link options.
echo -n "${LINK_OPTIONS}" >> ${FILE}
echo "" >> ${FILE}
# set the so reference path.
if [[ ! -z ${SO_PATH} ]]; then
echo -n " @bash auto/set_so_rpath.sh ${SOPathTool} ${APP_TARGET} ${SO_PATH}" >> ${FILE}
echo "" >> ${FILE}
fi
echo -n "generate app ${APP_NAME} ok"; echo '!';
... ...
# params:
# $GLOBAL_DIR_OBJS the objs directory. ie. objs
# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile
# $MODULE_DIR the module dir. ie. src/os/linux
# $MODULE_ID the id of module. ie. CORE
# $MODULE_DEPENDS array, the denpend MODULEs id. ie. (CORE OS)
# $ModuleLibIncs array, the depend 3rdpart library includes. ie. (objs/st-1.9/obj objs/libx264/obj)
# $MODULE_FILES array, the head/cpp files of modules. ie. (public log)
#
# returns:
# $MODULE_OBJS array, the objects of the modules.
FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
# INCS
INCS_NAME="${MODULE_ID}_INCS"
echo "# the ${MODULE_ID} module." >> ${FILE}
echo "${MODULE_ID}_MODULE_INCS = -I ${MODULE_DIR} " >> ${FILE}
echo -n "${INCS_NAME} = -I ${MODULE_DIR} " >> ${FILE}
for item in ${MODULE_DEPENDS[*]}; do
DEP_INCS_NAME="${item}_INCS"do
DEP_INCS_NAME="${item}_MODULE_INCS"
echo -n "\$(${DEP_INCS_NAME}) " >> ${FILE}
done
for item in ${ModuleLibIncs[*]}; do
echo -n "-I ${item} " >> ${FILE}
done
echo "" >> ${FILE}
# DEPS
DEPS_NAME="${MODULE_ID}_DEPS"
echo -n "${DEPS_NAME} = " >> ${FILE}
for item in ${MODULE_FILES[*]}; do
HEADER_FILE="${MODULE_DIR}/${item}.hpp"
if [ -f ${HEADER_FILE} ]; then
echo -n " ${HEADER_FILE}" >> ${FILE}
fi
done
for item in ${MODULE_DEPENDS[*]}; do
DEP_DEPS_NAME="${item}_DEPS"
echo -n " \$(${DEP_DEPS_NAME}) " >> ${FILE}
done
echo "" >> ${FILE}; echo "" >> ${FILE}
# OBJ
MODULE_OBJS=()
for item in ${MODULE_FILES[*]}; do
CPP_FILE="${MODULE_DIR}/${item}.cpp"
OBJ_FILE="${GLOBAL_DIR_OBJS}/${MODULE_DIR}/${item}.o"
MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}"
if [ -f ${CPP_FILE} ]; then
echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE}
echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME}) -o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE}
fi
done
echo "" >> ${FILE}
# Makefile
echo " mkdir -p ${GLOBAL_DIR_OBJS}/${MODULE_DIR}" >> ${GLOBAL_FILE_MAKEFILE}
echo -n "generate module ${MODULE_ID} ok"; echo '!';
... ...
#!/bin/bash
GLOBAL_FILE_MAKEFILE="Makefile"
GLOBAL_DIR_OBJS="objs"
mkdir -p ${GLOBAL_DIR_OBJS}
#####################################################################################
# prepare the depends tools
#####################################################################################
# st-1.9
if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]]; then
echo "st-1.9t is ok.";
else
echo "build st-1.9t";
(rm -rf ${GLOBAL_DIR_OBJS}/st-1.9 && cd ${GLOBAL_DIR_OBJS} && unzip ../3rdparty/st-1.9.zip && cd st-1.9 && make linux-debug)
fi
# check status
ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi
if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi
#####################################################################################
# generate Makefile.
#####################################################################################
echo "generate Makefile"
cat << END > ${GLOBAL_FILE_MAKEFILE}
.PHONY: default help clean server _prepare_dir
default: server
help:
@echo "Usage: make <help>|<clean>|<server>"
@echo " help display this help menu"
@echo " clean cleanup project"
@echo " server build the srs(simple rtmp server) over st(state-threads)"
clean:
(cd ${GLOBAL_DIR_OBJS}; rm -rf src st_*_load)
server: _prepare_dir
@echo "build the srs(simple rtmp server) over st(state-threads)"
\$(MAKE) -f ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} server
# the ./configure will generate it.
_prepare_dir:
@mkdir -p ${GLOBAL_DIR_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"
#PerformanceLink="-pg"
# enable gdb debug
GDBDebug="-g -O0"
# the warning level.
WarnLevel="-Wall -Wextra"
# the compile standard.
CppStd="-std=c++98"
# other macros defined
UserMacros=""
# the cxx flag generated.
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance} ${UserMacros}"
cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
CXXFLAGS = ${CXXFLAGS}
GCC = g++
LINK = \$(GCC)
AR = ar
.PHONY: default server
default:
END
# Libraries
LibSTRoot="${GLOBAL_DIR_OBJS}/st-1.9/obj"
LibSTfile="${LibSTRoot}/libst.a"
#Core Module
MODULE_ID="CORE"
MODULE_DEPENDS=()
ModuleLibIncs=()
MODULE_FILES=("srs_core_log")
MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"
#Main Module
MODULE_ID="MAIN"
MODULE_DEPENDS=("CORE")
ModuleLibIncs=(${LibSTRoot})
MODULE_FILES=("srs_main_server")
MODULE_DIR="src/main" . auto/modules.sh
MAIN_OBJS="${MODULE_OBJS[@].o}"
# all main entrances
MAIN_ENTRANCES=("srs_main_server")
# srs(simple rtmp server) over st(state-threads)
ModuleLibFiles=(${LibSTfile})
MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}"
BUILD_KEY="server" APP_MAIN="srs_main_server" APP_NAME="server" LINK_OPTIONS="-ldl" SO_PATH="" . auto/apps.sh
echo 'configure ok! '
# next step.
echo "you can:"
echo "\" make \" to build the srs(simple rtmp server)."
echo "\" make help \" to get the usage of make"
... ...
#include <srs_core_log.hpp>
... ...
#ifndef SRS_CORE_LOG_HPP
#define SRS_CORE_LOG_HPP
#endif
... ...
#include <unistd.h>
int main(int /*argc*/, char** /*argv*/){
return 0;
}
... ...
#ifndef _upp_icpp_init_stub
#define _upp_icpp_init_stub
#endif
... ...
file
main readonly separator,
..\main\srs_main_server.cpp,
core readonly separator,
..\core\srs_core_log.hpp,
..\core\srs_core_log.cpp;
mainconfig
"" = "MAIN";
... ...