2
0

utest.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. # C++ compiler
  41. CXX = ${SRS_TOOL_CXX}
  42. # Flags passed to the preprocessor.
  43. CPPFLAGS += -I\$(GTEST_DIR)/include
  44. # Flags passed to the C++ compiler.
  45. CXXFLAGS += ${CXXFLAGS} ${UTEST_EXTRA_DEFINES} -Wno-unused-private-field -Wno-unused-command-line-argument
  46. # Always use C++11 for gtest required, see https://github.com/google/googletest
  47. CXXFLAGS += -std=c++11
  48. # All tests produced by this Makefile. Remember to add new tests you
  49. # created to the list.
  50. TESTS = ${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME}
  51. # All Google Test headers. Usually you shouldn't change this
  52. # definition.
  53. GTEST_HEADERS = \$(GTEST_DIR)/include/gtest/*.h \\
  54. \$(GTEST_DIR)/include/gtest/internal/*.h
  55. # House-keeping build targets.
  56. all : \$(TESTS)
  57. clean :
  58. rm -f \$(TESTS) gtest.a gtest_main.a *.o
  59. # Builds gtest.a and gtest_main.a.
  60. # Usually you shouldn't tweak such internal variables, indicated by a
  61. # trailing _.
  62. GTEST_SRCS_ = \$(GTEST_DIR)/src/*.cc \$(GTEST_DIR)/src/*.h \$(GTEST_HEADERS)
  63. # For simplicity and to avoid depending on Google Test's
  64. # implementation details, the dependencies specified below are
  65. # conservative and not optimized. This is fine as Google Test
  66. # compiles fast and for ordinary users its source rarely changes.
  67. gtest-all.o : \$(GTEST_SRCS_)
  68. \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  69. \$(GTEST_DIR)/src/gtest-all.cc
  70. gtest_main.o : \$(GTEST_SRCS_)
  71. \$(CXX) \$(CPPFLAGS) -I\$(GTEST_DIR) \$(CXXFLAGS) -c \\
  72. \$(GTEST_DIR)/src/gtest_main.cc
  73. gtest.a : gtest-all.o
  74. \$(AR) \$(ARFLAGS) \$@ \$^
  75. gtest_main.a : gtest-all.o gtest_main.o
  76. \$(AR) \$(ARFLAGS) \$@ \$^
  77. # Builds a sample test. A test should link with either gtest.a or
  78. # gtest_main.a, depending on whether it defines its own main()
  79. # function.
  80. #####################################################################################
  81. #####################################################################################
  82. # SRS(Simple RTMP Server) utest section
  83. #####################################################################################
  84. #####################################################################################
  85. END
  86. #####################################################################################
  87. # Includes, the include dir.
  88. echo "# Includes, the include dir." >> ${FILE}
  89. #
  90. # current module header files
  91. echo -n "SRS_UTEST_INC = -I${SRS_TRUNK_PREFIX}/${MODULE_DIR} " >> ${FILE}
  92. #
  93. # depends module header files
  94. for item in ${MODULE_DEPENDS[*]}; do
  95. DEP_INCS_NAME="${item}_INCS"
  96. echo -n "-I${SRS_TRUNK_PREFIX}/${!DEP_INCS_NAME} " >> ${FILE}
  97. done
  98. #
  99. # depends library header files
  100. for item in ${ModuleLibIncs[*]}; do
  101. if [[ "${item:0:1}" == "/" ]]; then
  102. echo -n "-I${item} " >> ${FILE}
  103. else
  104. echo -n "-I${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  105. fi
  106. done
  107. echo "" >> ${FILE}; echo "" >> ${FILE}
  108. #####################################################################################
  109. # Depends, the depends objects
  110. echo "# Depends, the depends objects" >> ${FILE}
  111. #
  112. # current module header files
  113. echo -n "SRS_UTEST_DEPS = " >> ${FILE}
  114. for item in ${MODULE_OBJS[*]}; do
  115. FILE_NAME=${item%.*}
  116. echo -n "${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${FILE_NAME}.o " >> ${FILE}
  117. done
  118. echo "" >> ${FILE}; echo "" >> ${FILE}
  119. #
  120. echo "# Depends, utest header files" >> ${FILE}
  121. DEPS_NAME="UTEST_DEPS"
  122. echo -n "${DEPS_NAME} = " >> ${FILE}
  123. for item in ${MODULE_FILES[*]}; do
  124. HEADER_FILE="${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.hpp"
  125. echo -n " ${HEADER_FILE}" >> ${FILE}
  126. done
  127. echo "" >> ${FILE}; echo "" >> ${FILE}
  128. #####################################################################################
  129. # Objects, build each object of utest
  130. echo "# Objects, build each object of utest" >> ${FILE}
  131. #
  132. MODULE_OBJS=()
  133. for item in ${MODULE_FILES[*]}; do
  134. MODULE_OBJS="${MODULE_OBJS[@]} ${item}.o"
  135. cat << END >> ${FILE}
  136. ${item}.o : \$(${DEPS_NAME}) ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp \$(SRS_UTEST_DEPS)
  137. \$(CXX) \$(CPPFLAGS) \$(CXXFLAGS) \$(SRS_UTEST_INC) -c ${SRS_TRUNK_PREFIX}/${MODULE_DIR}/${item}.cpp -o \$@
  138. END
  139. done
  140. echo "" >> ${FILE}
  141. #####################################################################################
  142. # App for utest
  143. #
  144. # link all depends libraries
  145. echo "# link all depends libraries" >> ${FILE}
  146. echo -n "DEPS_LIBRARIES_FILES = " >> ${FILE}
  147. for item in ${ModuleLibFiles[*]}; do
  148. if [[ "${item:0:1}" == "/" ]]; then
  149. echo -n "${item} " >> ${FILE}
  150. else
  151. echo -n "${SRS_TRUNK_PREFIX}/${item} " >> ${FILE}
  152. fi
  153. done
  154. echo "" >> ${FILE}; echo "" >> ${FILE}
  155. #
  156. echo "# generate the utest binary" >> ${FILE}
  157. cat << END >> ${FILE}
  158. ${SRS_TRUNK_PREFIX}/${SRS_OBJS_DIR}/${APP_NAME} : \$(SRS_UTEST_DEPS) ${MODULE_OBJS} gtest.a
  159. \$(CXX) -o \$@ \$(CPPFLAGS) \$(CXXFLAGS) \$^ \$(DEPS_LIBRARIES_FILES) ${LINK_OPTIONS}
  160. END
  161. #####################################################################################
  162. # parent Makefile, to create module output dir before compile it.
  163. echo " @mkdir -p ${SRS_OBJS_DIR}/utest" >> ${SRS_WORKDIR}/${SRS_MAKEFILE}
  164. echo -n "Generate utest ok"; echo '!';