2
0

utest.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # generate utest 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. # $APP_NAME the app name to output. ie. srs_utest
  9. # $MODULE_DIR the src dir of utest code. ie. src/utest
  10. # $LINK_OPTIONS the link options for utest. ie. -lpthread -ldl
  11. FILE=${SRS_OBJS}/utest/${SRS_MAKEFILE}
  12. # create dir for Makefile
  13. mkdir -p ${SRS_OBJS}/utest
  14. # the prefix to generate the objs/utest/Makefile
  15. # dirs relative to current dir(objs/utest), it's trunk/objs/utest
  16. # trunk of srs, which contains the src dir, relative to objs/utest, it's trunk
  17. SRS_TRUNK_PREFIX=../../..
  18. # gest dir, relative to objs/utest, it's trunk/objs/gtest
  19. GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/gtest
  20. cat << END > ${FILE}
  21. # user must run make the ${SRS_OBJS_DIR}/utest dir
  22. # at the same dir of Makefile.
  23. # A sample Makefile for building Google Test and using it in user
  24. # tests. Please tweak it to suit your environment and project. You
  25. # may want to move it to your project's root directory.
  26. #
  27. # SYNOPSIS:
  28. #
  29. # make [all] - makes everything.
  30. # make TARGET - makes the given target.
  31. # make clean - removes all files generated by make.
  32. # Please tweak the following variable definitions as needed by your
  33. # project, except GTEST_HEADERS, which you can use in your own targets
  34. # but shouldn't modify.
  35. # Points to the root of Google Test, relative to where this file is.
  36. # Remember to tweak this if you move this file.
  37. GTEST_DIR = ${GTEST_DIR}
  38. # Where to find user code.
  39. USER_DIR = .
  40. # Flags passed to the preprocessor.
  41. CPPFLAGS += -I\$(GTEST_DIR)/include
  42. # Flags passed to the C++ compiler.
  43. CXXFLAGS += -g -Wall -Wextra -O0 ${EXTRA_DEFINES}
  44. # All tests produced by this Makefile. Remember to add new tests you
  45. # created to the list.
  46. TESTS = ${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME}
  47. # All Google Test headers. Usually you shouldn't change this
  48. # definition.
  49. GTEST_HEADERS = \$(GTEST_DIR)/include/gtest/*.h \\
  50. \$(GTEST_DIR)/include/gtest/internal/*.h
  51. # House-keeping build targets.
  52. all : \$(TESTS)
  53. clean :
  54. rm -f \$(TESTS) gtest.a gtest_main.a *.o
  55. # Builds gtest.a and gtest_main.a.
  56. # Usually you shouldn't tweak such internal variables, indicated by a
  57. # trailing _.
  58. GTEST_SRCS_ = \$(GTEST_DIR)/src/*.cc \$(GTEST_DIR)/src/*.h \$(GTEST_HEADERS)
  59. # For simplicity and to avoid depending on Google Test's
  60. # implementation details, the dependencies specified below are
  61. # conservative and not optimized. This is fine as Google Test
  62. # compiles fast and for ordinary users its source rarely changes.
  63. gtest-all.o : \$(GTEST_SRCS_)
  64. \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  65. \$(GTEST_DIR)/src/gtest-all.cc
  66. gtest_main.o : \$(GTEST_SRCS_)
  67. \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  68. \$(GTEST_DIR)/src/gtest_main.cc
  69. gtest.a : gtest-all.o
  70. \$(AR) \$(ARFLAGS) \$@ \$^
  71. gtest_main.a : gtest-all.o gtest_main.o
  72. \$(AR) \$(ARFLAGS) \$@ \$^
  73. # Builds a sample test. A test should link with either gtest.a or
  74. # gtest_main.a, depending on whether it defines its own main()
  75. # function.
  76. #####################################################################################
  77. #####################################################################################
  78. # SRS(Simple RTMP Server) utest section
  79. #####################################################################################
  80. #####################################################################################
  81. END
  82. #####################################################################################
  83. # Includes, the include dir.
  84. echo "# Includes, the include dir." >> ${FILE}
  85. #
  86. # current module header files
  87. echo -n "SRS_UTEST_INC = -I${SRS_TRUNK_PREFIX}/${MODULE_DIR} " >> ${FILE}
  88. #
  89. # depends module header files
  90. for item in ${MODULE_DEPENDS[*]}; do
  91. DEP_INCS_NAME="${item}_INCS"
  92. echo -n "-I${SRS_TRUNK_PREFIX}/${!DEP_INCS_NAME} " >> ${FILE}
  93. done
  94. #
  95. # depends library header files
  96. for item in ${ModuleLibIncs[*]}; do
  97. echo -n "-I${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  98. done
  99. echo "" >> ${FILE}; echo "" >> ${FILE}
  100. #####################################################################################
  101. # Depends, the depends objects
  102. echo "# Depends, the depends objects" >> ${FILE}
  103. #
  104. # current module header files
  105. echo -n "SRS_UTEST_DEPS = " >> ${FILE}
  106. for item in ${MODULE_OBJS[*]}; do
  107. FILE_NAME=${item%.*}
  108. echo -n "${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${FILE_NAME}.o " >> ${FILE}
  109. done
  110. echo "" >> ${FILE}; echo "" >> ${FILE}
  111. #
  112. echo "# Depends, utest header files" >> ${FILE}
  113. DEPS_NAME="UTEST_DEPS"
  114. echo -n "${DEPS_NAME} = " >> ${FILE}
  115. for item in ${MODULE_FILES[*]}; do
  116. HEADER_FILE="${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.hpp"
  117. echo -n " ${HEADER_FILE}" >> ${FILE}
  118. done
  119. echo "" >> ${FILE}; echo "" >> ${FILE}
  120. #####################################################################################
  121. # Objects, build each object of utest
  122. echo "# Objects, build each object of utest" >> ${FILE}
  123. #
  124. MODULE_OBJS=()
  125. for item in ${MODULE_FILES[*]}; do
  126. MODULE_OBJS="${MODULE_OBJS[@]} ${item}.o"
  127. cat << END >> ${FILE}
  128. ${item}.o : \$(${DEPS_NAME}) ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp \$(SRS_UTEST_DEPS)
  129. \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SRS_UTEST_INC) -c ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp -o \$@
  130. END
  131. done
  132. echo "" >> ${FILE}
  133. #####################################################################################
  134. # App for utest
  135. #
  136. # link all depends libraries
  137. echo "# link all depends libraries" >> ${FILE}
  138. echo -n "DEPS_LIBRARIES_FILES = " >> ${FILE}
  139. for item in ${ModuleLibFiles[*]}; do
  140. if [[ -f ${item} ]]; then
  141. echo -n "${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  142. else
  143. echo -n "${item} " >> ${FILE}
  144. fi
  145. done
  146. echo "" >> ${FILE}; echo "" >> ${FILE}
  147. #
  148. echo "# generate the utest binary" >> ${FILE}
  149. cat << END >> ${FILE}
  150. ${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME} : \$(SRS_UTEST_DEPS) ${MODULE_OBJS} gtest.a
  151. \$(CXX) -o \$@ \$(CPPFLAGS) \$(CXXFLAGS) \$^ \$(DEPS_LIBRARIES_FILES) ${LINK_OPTIONS}
  152. END
  153. #####################################################################################
  154. # parent Makefile, to create module output dir before compile it.
  155. echo " @mkdir -p ${SRS_OBJS_DIR}/utest" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  156. echo -n "Generate utest ok"; echo '!';