modules.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #
  2. # Generate the module(in src, not modules) info to Makefile
  3. #
  4. # params:
  5. # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs
  6. # $SRS_OBJS_DIR the objs directory for Makefile. ie. objs
  7. # $SRS_MAKEFILE the makefile name. ie. Makefile
  8. #
  9. # $MODULE_DIR the module dir. ie. src/os/linux
  10. # $MODULE_ID the id of module. ie. CORE
  11. # $MODULE_DEPENDS array, the denpend MODULEs id. ie. (CORE OS)
  12. # $ModuleLibIncs array, the depend 3rdpart library includes. ie. (objs/st-1.9/obj objs/libx264/obj)
  13. # $MODULE_FILES array, the head/cpp files of modules. ie. (public log)
  14. # $DEFINES string, the build macro defines. ie. "-DMY_SRS"
  15. #
  16. # returns:
  17. # $MODULE_OBJS array, the objects of the modules, used for link the binary
  18. FILE=${SRS_OBJS}/${SRS_MAKEFILE}
  19. echo "#####################################################################################" >> ${FILE}
  20. echo "# The module ${MODULE_ID}." >> ${FILE}
  21. echo "#####################################################################################" >> ${FILE}
  22. echo >> ${FILE}
  23. # INCS
  24. echo "# INCS for ${MODULE_ID}, headers of module and its depends to compile" >> ${FILE}
  25. #
  26. # the public include files, for example:
  27. # CORE_MODULE_INCS = -Isrc/core
  28. echo "${MODULE_ID}_MODULE_INCS = -I${MODULE_DIR} " >> ${FILE}
  29. #
  30. # the private include files, for example:
  31. # CORE_INCS = -Isrc/core -Iobjs
  32. # CORE_LIBS_INCS = -Iobjs/st -Iobjs/ffmpeg/include
  33. # where the public will be used for other modules which depends on it.
  34. INCS_NAME="${MODULE_ID}_INCS"
  35. #
  36. # current module header files
  37. echo -n "${INCS_NAME} = -I${MODULE_DIR} " >> ${FILE}
  38. #
  39. # depends module header files
  40. for item in ${MODULE_DEPENDS[*]}; do
  41. DEP_INCS_NAME="${item}_MODULE_INCS"
  42. echo -n "\$(${DEP_INCS_NAME})" >> ${FILE}
  43. done
  44. echo "" >> ${FILE}
  45. #
  46. # depends library header files
  47. INCS_LIBS_NAME="${MODULE_ID}_LIBS_INCS"
  48. echo -n "${INCS_LIBS_NAME} = " >> ${FILE}
  49. for item in ${ModuleLibIncs[*]}; do
  50. echo -n "-I${item} " >> ${FILE}
  51. done
  52. echo "" >> ${FILE}; echo "" >> ${FILE}
  53. # DEPS
  54. echo "# DEPS for ${MODULE_ID}, the depends of make schema" >> ${FILE}
  55. # depends on headers of self module, for example:
  56. # CORE_DEPS = src/core/srs_core.hpp
  57. DEPS_NAME="${MODULE_ID}_DEPS"
  58. echo -n "${DEPS_NAME} = " >> ${FILE}
  59. for item in ${MODULE_FILES[*]}; do
  60. HEADER_FILE="${MODULE_DIR}/${item}.hpp"
  61. if [[ ! -f ${HEADER_FILE} ]]; then HEADER_FILE="${MODULE_DIR}/${item}.h"; fi
  62. if [ -f ${HEADER_FILE} ]; then
  63. echo -n " ${HEADER_FILE}" >> ${FILE}
  64. fi
  65. done
  66. # depends on other modules, for example:
  67. # MAIN_DEPS = $(CORE_DEPS)
  68. for item in ${MODULE_DEPENDS[*]}; do
  69. DEP_DEPS_NAME="${item}_DEPS"
  70. echo -n " \$(${DEP_DEPS_NAME}) " >> ${FILE}
  71. done
  72. echo "" >> ${FILE}; echo "" >> ${FILE}
  73. # OBJ
  74. echo "# OBJ for ${MODULE_ID}, each object file" >> ${FILE}
  75. MODULE_OBJS=()
  76. for item in ${MODULE_FILES[*]}; do
  77. CPP_FILE="${MODULE_DIR}/${item}.cpp"
  78. if [[ ! -f ${CPP_FILE} ]]; then CPP_FILE="${MODULE_DIR}/${item}.cc"; fi
  79. OBJ_FILE="${SRS_OBJS_DIR}/${MODULE_DIR}/${item}.o"
  80. MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}"
  81. if [ -f ${CPP_FILE} ]; then
  82. echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE}
  83. echo " \$(CXX) -c \$(CXXFLAGS) ${DEFINES}\\" >> ${FILE}
  84. echo " \$(${INCS_NAME})\\" >> ${FILE}
  85. echo " \$(${INCS_LIBS_NAME})\\" >> ${FILE}
  86. echo " -o ${OBJ_FILE} \\" >> ${FILE}
  87. echo " ${CPP_FILE}" >> ${FILE}
  88. fi
  89. done
  90. echo "" >> ${FILE}
  91. # parent Makefile, to create module output dir before compile it.
  92. echo " @mkdir -p ${SRS_OBJS_DIR}/${MODULE_DIR}" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  93. echo -n "Generate modules ${MODULE_ID} ok"; echo '!';