winlin

add build framework

不能预览此文件类型
  1 +#!/bin/bash
  2 +
  3 +# params:
  4 +# $GLOBAL_DIR_OBJS the objs directory. ie. objs
  5 +# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile
  6 +# $MAIN_ENTRANCES array, all main entrance, disable all except the $APP_MAIN itself
  7 +# $MODULE_OBJS array, the objects to compile the app.
  8 +# $BUILD_KEY a string indicates the build key for Makefile. ie. dump
  9 +# $APP_MAIN the object file that contains main function. ie. your_app_main
  10 +# $APP_NAME the app name to output. ie. your_app
  11 +# $ModuleLibFiles array, the 3rdpart library file to link with. ie. (objs/st-1.9/obj/libst.a objs/libx264/obj/libx264.a)
  12 +# $LINK_OPTIONS the linker options.
  13 +# $SO_PATH the libssl.so.10 and other so file path.
  14 +
  15 +FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
  16 +
  17 +APP_TARGET="${GLOBAL_DIR_OBJS}/${APP_NAME}"
  18 +
  19 +echo "generate app ${APP_NAME} depends...";
  20 +
  21 +echo "# build ${APP_TARGET}" >> ${FILE}
  22 +echo "${BUILD_KEY}: ${APP_TARGET}" >> ${FILE}
  23 +
  24 +echo -n "${APP_TARGET}: " >> ${FILE}
  25 +for item in ${MODULE_OBJS[*]}; do
  26 + FILE_NAME=`basename $item`
  27 + FILE_NAME=${FILE_NAME%.*}
  28 +
  29 + ignored=0
  30 + for disabled_item in ${MAIN_ENTRANCES[*]}; do
  31 + if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
  32 + ignored=1
  33 + continue;
  34 + fi
  35 + done
  36 +
  37 + if [ ! -f ${item} ]; then
  38 + ignored=1
  39 + fi
  40 +
  41 + if [ ${ignored} == 1 ]; then
  42 + continue;
  43 + fi
  44 +
  45 + OBJ_FILE=${GLOBAL_DIR_OBJS}/$item
  46 + OBJ_FILE="${OBJ_FILE%.*}.o"
  47 + echo -n "${OBJ_FILE} " >> ${FILE}
  48 +done
  49 +echo "" >> ${FILE}
  50 +
  51 +echo "generate app ${APP_NAME} link...";
  52 +
  53 +echo -n " \$(LINK) ${PerformanceLink} -o ${APP_TARGET} " >> ${FILE}
  54 +for item in ${MODULE_OBJS[*]}; do
  55 + FILE_NAME=`basename $item`
  56 + FILE_NAME=${FILE_NAME%.*}
  57 +
  58 + ignored=0
  59 + for disabled_item in ${MAIN_ENTRANCES[*]}; do
  60 + if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
  61 + ignored=1
  62 + continue;
  63 + fi
  64 + done
  65 +
  66 + if [ ! -f ${item} ]; then
  67 + ignored=1
  68 + fi
  69 +
  70 + if [ ${ignored} == 1 ]; then
  71 + continue;
  72 + fi
  73 +
  74 + OBJ_FILE=${GLOBAL_DIR_OBJS}/$item
  75 + OBJ_FILE="${OBJ_FILE%.*}.o"
  76 + echo -n "${OBJ_FILE} " >> ${FILE}
  77 +done
  78 +# 3rdpart library static link.
  79 +for item in ${ModuleLibFiles[*]}; do
  80 + echo -n "$item " >> ${FILE}
  81 +done
  82 +# link options.
  83 +echo -n "${LINK_OPTIONS}" >> ${FILE}
  84 +echo "" >> ${FILE}
  85 +
  86 +# set the so reference path.
  87 +if [[ ! -z ${SO_PATH} ]]; then
  88 + echo -n " @bash auto/set_so_rpath.sh ${SOPathTool} ${APP_TARGET} ${SO_PATH}" >> ${FILE}
  89 + echo "" >> ${FILE}
  90 +fi
  91 +
  92 +echo -n "generate app ${APP_NAME} ok"; echo '!';
  1 +# params:
  2 +# $GLOBAL_DIR_OBJS the objs directory. ie. objs
  3 +# $GLOBAL_FILE_MAKEFILE the makefile name. ie. Makefile
  4 +# $MODULE_DIR the module dir. ie. src/os/linux
  5 +# $MODULE_ID the id of module. ie. CORE
  6 +# $MODULE_DEPENDS array, the denpend MODULEs id. ie. (CORE OS)
  7 +# $ModuleLibIncs array, the depend 3rdpart library includes. ie. (objs/st-1.9/obj objs/libx264/obj)
  8 +# $MODULE_FILES array, the head/cpp files of modules. ie. (public log)
  9 +#
  10 +# returns:
  11 +# $MODULE_OBJS array, the objects of the modules.
  12 +
  13 +FILE=${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
  14 +
  15 +# INCS
  16 +INCS_NAME="${MODULE_ID}_INCS"
  17 +echo "# the ${MODULE_ID} module." >> ${FILE}
  18 +echo "${MODULE_ID}_MODULE_INCS = -I ${MODULE_DIR} " >> ${FILE}
  19 +echo -n "${INCS_NAME} = -I ${MODULE_DIR} " >> ${FILE}
  20 +for item in ${MODULE_DEPENDS[*]}; do
  21 + DEP_INCS_NAME="${item}_INCS"do
  22 + DEP_INCS_NAME="${item}_MODULE_INCS"
  23 + echo -n "\$(${DEP_INCS_NAME}) " >> ${FILE}
  24 +done
  25 +for item in ${ModuleLibIncs[*]}; do
  26 + echo -n "-I ${item} " >> ${FILE}
  27 +done
  28 +echo "" >> ${FILE}
  29 +
  30 +# DEPS
  31 +DEPS_NAME="${MODULE_ID}_DEPS"
  32 +echo -n "${DEPS_NAME} = " >> ${FILE}
  33 +for item in ${MODULE_FILES[*]}; do
  34 + HEADER_FILE="${MODULE_DIR}/${item}.hpp"
  35 + if [ -f ${HEADER_FILE} ]; then
  36 + echo -n " ${HEADER_FILE}" >> ${FILE}
  37 + fi
  38 +done
  39 +for item in ${MODULE_DEPENDS[*]}; do
  40 + DEP_DEPS_NAME="${item}_DEPS"
  41 + echo -n " \$(${DEP_DEPS_NAME}) " >> ${FILE}
  42 +done
  43 +echo "" >> ${FILE}; echo "" >> ${FILE}
  44 +
  45 +# OBJ
  46 +MODULE_OBJS=()
  47 +for item in ${MODULE_FILES[*]}; do
  48 + CPP_FILE="${MODULE_DIR}/${item}.cpp"
  49 + OBJ_FILE="${GLOBAL_DIR_OBJS}/${MODULE_DIR}/${item}.o"
  50 + MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}"
  51 + if [ -f ${CPP_FILE} ]; then
  52 + echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE}
  53 + echo " \$(GCC) -c \$(CXXFLAGS) \$(${INCS_NAME}) -o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE}
  54 + fi
  55 +done
  56 +echo "" >> ${FILE}
  57 +
  58 +# Makefile
  59 +echo " mkdir -p ${GLOBAL_DIR_OBJS}/${MODULE_DIR}" >> ${GLOBAL_FILE_MAKEFILE}
  60 +
  61 +echo -n "generate module ${MODULE_ID} ok"; echo '!';
  1 +#!/bin/bash
  2 +
  3 +GLOBAL_FILE_MAKEFILE="Makefile"
  4 +GLOBAL_DIR_OBJS="objs"
  5 +
  6 +mkdir -p ${GLOBAL_DIR_OBJS}
  7 +
  8 +#####################################################################################
  9 +# prepare the depends tools
  10 +#####################################################################################
  11 +# st-1.9
  12 +if [[ -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a && -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]]; then
  13 + echo "st-1.9t is ok.";
  14 +else
  15 + echo "build st-1.9t";
  16 + (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)
  17 +fi
  18 +# check status
  19 +ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
  20 +if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi
  21 +if [ ! -f ${GLOBAL_DIR_OBJS}/st-1.9/obj/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi
  22 +
  23 +#####################################################################################
  24 +# generate Makefile.
  25 +#####################################################################################
  26 +echo "generate Makefile"
  27 +
  28 +cat << END > ${GLOBAL_FILE_MAKEFILE}
  29 +.PHONY: default help clean server _prepare_dir
  30 +default: server
  31 +
  32 +help:
  33 + @echo "Usage: make <help>|<clean>|<server>"
  34 + @echo " help display this help menu"
  35 + @echo " clean cleanup project"
  36 + @echo " server build the srs(simple rtmp server) over st(state-threads)"
  37 +
  38 +clean:
  39 + (cd ${GLOBAL_DIR_OBJS}; rm -rf src st_*_load)
  40 +
  41 +server: _prepare_dir
  42 + @echo "build the srs(simple rtmp server) over st(state-threads)"
  43 + \$(MAKE) -f ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE} server
  44 +
  45 +# the ./configure will generate it.
  46 +_prepare_dir:
  47 + @mkdir -p ${GLOBAL_DIR_OBJS}
  48 +END
  49 +
  50 +echo 'generate Makefile ok!'
  51 +
  52 +# the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt
  53 +#Performance="-pg"
  54 +#PerformanceLink="-pg"
  55 +# enable gdb debug
  56 +GDBDebug="-g -O0"
  57 +# the warning level.
  58 +WarnLevel="-Wall -Wextra"
  59 +# the compile standard.
  60 +CppStd="-std=c++98"
  61 +# other macros defined
  62 +UserMacros=""
  63 +# the cxx flag generated.
  64 +CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance} ${UserMacros}"
  65 +cat << END > ${GLOBAL_DIR_OBJS}/${GLOBAL_FILE_MAKEFILE}
  66 +CXXFLAGS = ${CXXFLAGS}
  67 +GCC = g++
  68 +LINK = \$(GCC)
  69 +AR = ar
  70 +
  71 +.PHONY: default server
  72 +
  73 +default:
  74 +
  75 +END
  76 +
  77 +# Libraries
  78 +LibSTRoot="${GLOBAL_DIR_OBJS}/st-1.9/obj"
  79 +LibSTfile="${LibSTRoot}/libst.a"
  80 +
  81 +#Core Module
  82 +MODULE_ID="CORE"
  83 +MODULE_DEPENDS=()
  84 +ModuleLibIncs=()
  85 +MODULE_FILES=("srs_core_log")
  86 +MODULE_DIR="src/core" . auto/modules.sh
  87 +CORE_OBJS="${MODULE_OBJS[@]}"
  88 +
  89 +#Main Module
  90 +MODULE_ID="MAIN"
  91 +MODULE_DEPENDS=("CORE")
  92 +ModuleLibIncs=(${LibSTRoot})
  93 +MODULE_FILES=("srs_main_server")
  94 +MODULE_DIR="src/main" . auto/modules.sh
  95 +MAIN_OBJS="${MODULE_OBJS[@].o}"
  96 +
  97 +# all main entrances
  98 +MAIN_ENTRANCES=("srs_main_server")
  99 +
  100 +# srs(simple rtmp server) over st(state-threads)
  101 +ModuleLibFiles=(${LibSTfile})
  102 +MODULE_OBJS="${CORE_OBJS[@]} ${CONFIG_OBJS[@]} ${PROTOCOL_OBJS[@]} ${MAIN_OBJS[@]}"
  103 +BUILD_KEY="server" APP_MAIN="srs_main_server" APP_NAME="server" LINK_OPTIONS="-ldl" SO_PATH="" . auto/apps.sh
  104 +
  105 +echo 'configure ok! '
  106 +
  107 +# next step.
  108 +echo "you can:"
  109 +echo "\" make \" to build the srs(simple rtmp server)."
  110 +echo "\" make help \" to get the usage of make"
  1 +#include <srs_core_log.hpp>
  1 +#ifndef SRS_CORE_LOG_HPP
  2 +#define SRS_CORE_LOG_HPP
  3 +
  4 +#endif
  1 +#include <unistd.h>
  2 +
  3 +int main(int /*argc*/, char** /*argv*/){
  4 + return 0;
  5 +}
  1 +#ifndef _upp_icpp_init_stub
  2 +#define _upp_icpp_init_stub
  3 +#endif
  1 +file
  2 + main readonly separator,
  3 + ..\main\srs_main_server.cpp,
  4 + core readonly separator,
  5 + ..\core\srs_core_log.hpp,
  6 + ..\core\srs_core_log.cpp;
  7 +mainconfig
  8 + "" = "MAIN";
  9 +