apps.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "generate 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. # 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 ${item} ]; then
  36. ignored=1
  37. fi
  38. if [ ${ignored} == 1 ]; then
  39. continue;
  40. fi
  41. OBJ_FILE=${SRS_OBJS_DIR}/$item
  42. OBJ_FILE="${OBJ_FILE%.*}.o"
  43. echo -n "${OBJ_FILE} " >> ${FILE}
  44. done
  45. echo "" >> ${FILE}
  46. echo "generate app ${APP_NAME} link...";
  47. # genereate the actual link command, for example:
  48. # $(LINK) -o objs/srs objs/src/core/srs_core.o -ldl
  49. echo -n " \$(LINK) -o ${APP_TARGET} " >> ${FILE}
  50. for item in ${MODULE_OBJS[*]}; do
  51. FILE_NAME=`basename $item`
  52. FILE_NAME=${FILE_NAME%.*}
  53. ignored=0
  54. for disabled_item in ${MAIN_ENTRANCES[*]}; do
  55. if [[ ${FILE_NAME} == ${disabled_item} && ${FILE_NAME} != ${APP_MAIN} ]]; then
  56. ignored=1
  57. continue;
  58. fi
  59. done
  60. if [ ! -f ${item} ]; then
  61. ignored=1
  62. fi
  63. if [ ${ignored} == 1 ]; then
  64. continue;
  65. fi
  66. OBJ_FILE=${SRS_OBJS_DIR}/$item
  67. OBJ_FILE="${OBJ_FILE%.*}.o"
  68. echo -n "${OBJ_FILE} " >> ${FILE}
  69. done
  70. # 3rdpart library static link.
  71. for item in ${ModuleLibFiles[*]}; do
  72. echo -n "$item " >> ${FILE}
  73. done
  74. # link options.
  75. echo -n "${LINK_OPTIONS}" >> ${FILE}
  76. echo "" >> ${FILE}
  77. echo -n "generate app ${APP_NAME} ok"; echo '!';