utest.sh 6.4 KB

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