2
0

modules.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # generate the module info to Makefile
  2. #
  3. # params:
  4. # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs
  5. # $SRS_OBJS_DIR the objs directory for Makefile. ie. objs
  6. # $SRS_MAKEFILE the makefile name. ie. Makefile
  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}/${SRS_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${MODULE_DIR} " >> ${FILE}
  28. #
  29. # the private include files, for example:
  30. # CORE_INCS = -Isrc/core -Iobjs/st -Iobjs -Iobjs/hp -Iobjs
  31. # MAIN_INCS = -Isrc/main $(CORE_MODULE_INCS) -Iobjs/st -Iobjs
  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${MODULE_DIR} " >> ${FILE}
  37. #
  38. # depends module header files
  39. for item in ${MODULE_DEPENDS[*]}; do
  40. DEP_INCS_NAME="${item}_INCS"do
  41. DEP_INCS_NAME="${item}_MODULE_INCS"
  42. echo -n "\$(${DEP_INCS_NAME})" >> ${FILE}
  43. done
  44. #
  45. # depends library header files
  46. for item in ${ModuleLibIncs[*]}; do
  47. echo -n "-I${item} " >> ${FILE}
  48. done
  49. echo "" >> ${FILE}; echo "" >> ${FILE}
  50. # DEPS
  51. echo "# DEPS for ${MODULE_ID}, the depends of make schema" >> ${FILE}
  52. # depends on headers of self module, for example:
  53. # CORE_DEPS = src/core/srs_core.hpp
  54. DEPS_NAME="${MODULE_ID}_DEPS"
  55. echo -n "${DEPS_NAME} = " >> ${FILE}
  56. for item in ${MODULE_FILES[*]}; do
  57. HEADER_FILE="${MODULE_DIR}/${item}.hpp"
  58. if [ -f ${HEADER_FILE} ]; then
  59. echo -n " ${HEADER_FILE}" >> ${FILE}
  60. fi
  61. done
  62. # depends on other modules, for example:
  63. # MAIN_DEPS = $(CORE_DEPS)
  64. for item in ${MODULE_DEPENDS[*]}; do
  65. DEP_DEPS_NAME="${item}_DEPS"
  66. echo -n " \$(${DEP_DEPS_NAME}) " >> ${FILE}
  67. done
  68. echo "" >> ${FILE}; echo "" >> ${FILE}
  69. # OBJ
  70. echo "# OBJ for ${MODULE_ID}, each object file" >> ${FILE}
  71. MODULE_OBJS=()
  72. for item in ${MODULE_FILES[*]}; do
  73. CPP_FILE="${MODULE_DIR}/${item}.cpp"
  74. OBJ_FILE="${SRS_OBJS_DIR}/${MODULE_DIR}/${item}.o"
  75. MODULE_OBJS="${MODULE_OBJS[@]} ${CPP_FILE}"
  76. if [ -f ${CPP_FILE} ]; then
  77. echo "${OBJ_FILE}: \$(${DEPS_NAME}) ${CPP_FILE} " >> ${FILE}
  78. echo " \$(CXX) -c \$(CXXFLAGS) ${DEFINES}\\" >> ${FILE}
  79. echo " \$(${INCS_NAME})\\" >> ${FILE}
  80. echo " -o ${OBJ_FILE} ${CPP_FILE}" >> ${FILE}
  81. fi
  82. done
  83. echo "" >> ${FILE}
  84. # parent Makefile, to create module output dir before compile it.
  85. echo " @mkdir -p ${SRS_OBJS_DIR}/${MODULE_DIR}" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  86. echo -n "Generate modules ${MODULE_ID} ok"; echo '!';