2
0

apps.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # generate the binary
  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. # $MAIN_ENTRANCES array, disable all except the $APP_MAIN itself. ie. ["srs_main_server" "srs_main_bandcheck"]
  9. # $APP_MAIN the object file that contains main function. ie. srs_main_server
  10. # $BUILD_KEY a string indicates the build key for Makefile. ie. srs
  11. # $APP_NAME the app name to output. ie. srs
  12. # $MODULE_OBJS array, the objects to compile the app.
  13. # $ModuleLibFiles array, the 3rdpart library file to link with. ie. [objs/st-1.9/obj/libst.a objs/libx264/obj/libx264.a]
  14. # $LINK_OPTIONS the linker options. ie. -ldl
  15. FILE=${SRS_OBJS}/${SRS_MAKEFILE}
  16. APP_TARGET="${SRS_OBJS_DIR}/${APP_NAME}"
  17. echo "Generating app ${APP_NAME} depends.";
  18. echo "# build ${APP_TARGET}" >> ${FILE}
  19. # generate the binary depends, for example:
  20. # srs: objs/srs
  21. echo "${BUILD_KEY}: ${APP_TARGET}" >> ${FILE}
  22. echo "" >> ${FILE}
  23. # the link commands, for example:
  24. # objs/srs: objs/src/core/srs_core.o
  25. echo -n "${APP_TARGET}: " >> ${FILE}
  26. for item in ${MODULE_OBJS[*]}; do
  27. FILE_NAME=`basename $item`
  28. FILE_NAME=${FILE_NAME%.*}
  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. if [ ! -f ${item} ]; then
  37. ignored=1
  38. fi
  39. if [ ${ignored} == 1 ]; then
  40. continue;
  41. fi
  42. OBJ_FILE=${SRS_OBJS_DIR}/$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 ${item} ]; then
  62. ignored=1
  63. fi
  64. if [ ${ignored} == 1 ]; then
  65. continue;
  66. fi
  67. OBJ_FILE=${SRS_OBJS_DIR}/$item
  68. OBJ_FILE="${OBJ_FILE%.*}.o"
  69. echo -n "${OBJ_FILE} " >> ${FILE}
  70. done
  71. # 3rdpart library static link.
  72. for item in ${ModuleLibFiles[*]}; do
  73. echo -n "$item " >> ${FILE}
  74. done
  75. # link options.
  76. echo -n "${LINK_OPTIONS}" >> ${FILE}
  77. echo "" >> ${FILE}
  78. echo "" >> ${FILE}
  79. echo -n "Generate app ${APP_NAME} ok"; echo '!';