modules.sh 3.4 KB

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