2
0

apps.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # generate the binary
  2. #
  3. # params:
  4. # $SRS_OBJS the objs directory to store the Makefile. ie. ./objs
  5. # $SRS_OBJS the objs directory for Makefile. ie. objs
  6. #
  7. # $MAIN_ENTRANCES array, disable all except the $APP_MAIN itself. ie. ["srs_main_server"]
  8. # $APP_MAIN the object file that contains main function. ie. srs_main_server
  9. # $BUILD_KEY a string indicates the build key for Makefile. ie. srs
  10. # $APP_NAME the app name to output. ie. srs
  11. # $MODULE_OBJS array, the objects to compile the app.
  12. # $ModuleLibFiles array, the 3rdpart library file to link with. ie. [objs/st-1.9/obj/libst.a objs/libx264/obj/libx264.a]
  13. # $LINK_OPTIONS the linker options. ie. -ldl
  14. FILE=${SRS_OBJS}/Makefile
  15. APP_TARGET="${SRS_OBJS}/${APP_NAME}"
  16. echo "Generating app ${APP_NAME} depends.";
  17. echo "# build ${APP_TARGET}" >> ${FILE}
  18. # generate the binary depends, for example:
  19. # srs: objs/srs
  20. echo "${BUILD_KEY}: ${APP_TARGET}" >> ${FILE}
  21. echo "" >> ${FILE}
  22. # the link commands, for example:
  23. # objs/srs: objs/src/core/srs_core.o
  24. echo -n "${APP_TARGET}: " >> ${FILE}
  25. for item in ${MODULE_OBJS[*]}; do
  26. FILE_NAME=`basename $item`
  27. FILE_NAME=${FILE_NAME%.*}
  28. ignored=0
  29. for disabled_item in ${MAIN_ENTRANCES[*]}; do
  30. if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
  31. ignored=1
  32. continue;
  33. fi
  34. done
  35. if [ ! -f ${SRS_WORKDIR}/${item} ]; then
  36. ignored=1
  37. fi
  38. if [ ${ignored} == 1 ]; then
  39. echo "Ignore file ${FILE_NAME}"
  40. continue;
  41. fi
  42. OBJ_FILE=${SRS_OBJS}/$item
  43. OBJ_FILE="${OBJ_FILE%.*}.o"
  44. echo -n "${OBJ_FILE} " >> ${FILE}
  45. done
  46. echo "" >> ${FILE}
  47. echo "Generating app ${APP_NAME} link.";
  48. # genereate the actual link command, for example:
  49. # $(LINK) -o objs/srs objs/src/core/srs_core.o -ldl
  50. echo -n " \$(LINK) -o ${APP_TARGET} " >> ${FILE}
  51. for item in ${MODULE_OBJS[*]}; do
  52. FILE_NAME=`basename $item`
  53. FILE_NAME=${FILE_NAME%.*}
  54. ignored=0
  55. for disabled_item in ${MAIN_ENTRANCES[*]}; do
  56. if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
  57. ignored=1
  58. continue;
  59. fi
  60. done
  61. if [ ! -f ${SRS_WORKDIR}/${item} ]; then
  62. ignored=1
  63. fi
  64. if [ ${ignored} == 1 ]; then
  65. echo "Ignore file ${FILE_NAME}"
  66. continue;
  67. fi
  68. OBJ_FILE=${SRS_OBJS}/$item
  69. OBJ_FILE="${OBJ_FILE%.*}.o"
  70. echo -n "${OBJ_FILE} " >> ${FILE}
  71. done
  72. # 3rdpart library static link.
  73. for item in ${ModuleLibFiles[*]}; do
  74. echo -n "$item " >> ${FILE}
  75. done
  76. # link options.
  77. echo -n "${LINK_OPTIONS}" >> ${FILE}
  78. echo "" >> ${FILE}
  79. echo "" >> ${FILE}
  80. echo -n "Generate app ${APP_NAME} ok"; echo '!';