2
0

Makefile 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # The main dir of st.
  2. ST_DIR = ..
  3. # The main dir of st utest.
  4. ST_UTEST = .
  5. # The main dir of gtest.
  6. GTEST_DIR = $(ST_UTEST)/gtest-fit/googletest
  7. # Flags passed to the C++ compiler.
  8. CXXFLAGS += -g -O0 -std=c++11
  9. CXXFLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
  10. # Flags for warnings.
  11. WARNFLAGS += -Wall -Wno-deprecated-declarations -Wno-unused-private-field -Wno-unused-command-line-argument
  12. # House-keeping build targets.
  13. all : $(ST_DIR)/obj/st_utest
  14. clean :
  15. rm -f $(ST_DIR)/obj/st_utest* $(ST_DIR)/obj/gtest*
  16. # Usually you shouldn't tweak such internal variables, indicated by a
  17. # trailing _.
  18. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_DIR)/include/gtest/*.h $(GTEST_DIR)/include/gtest/internal/*.h
  19. # For simplicity and to avoid depending on Google Test's
  20. # implementation details, the dependencies specified below are
  21. # conservative and not optimized. This is fine as Google Test
  22. # compiles fast and for ordinary users its source rarely changes.
  23. $(ST_DIR)/obj/gtest-all.o : $(GTEST_SRCS_)
  24. $(CXX) -c $(GTEST_DIR)/src/gtest-all.cc -o $@ \
  25. $(CXXFLAGS) $(UTEST_FLAGS) \
  26. $(WARNFLAGS) \
  27. -I$(GTEST_DIR)/include -I$(GTEST_DIR)
  28. $(ST_DIR)/obj/gtest.a : $(ST_DIR)/obj/gtest-all.o
  29. $(AR) $(ARFLAGS) $@ $^
  30. #####################################################################################
  31. #####################################################################################
  32. # ST(state-threads) utest section
  33. #####################################################################################
  34. #####################################################################################
  35. # Depends, the depends objects
  36. ST_UTEST_DEPS = $(ST_DIR)/obj/libst.a
  37. # Depends, utest header files
  38. UTEST_DEPS = $(ST_UTEST)/st_utest.hpp Makefile
  39. # Compile all sources files at current directory. For example:
  40. # (st_utest.cpp st_utest_coroutines.cpp st_utest_tcp.cpp)
  41. SOURCE_FILES = $(shell ls *.cpp)
  42. #
  43. # Convert all source files to object files. For example:
  44. # (st_utest.o st_utest_coroutines.o st_utest_tcp.o)
  45. # https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_8.html
  46. OBJECTS_FILES = $(patsubst %.cpp,%.o,$(SOURCE_FILES))
  47. #
  48. # Prefix object files to objects. For example:
  49. # ($(ST_DIR)/obj/st_utest.o $(ST_DIR)/obj/st_utest_coroutines.o $(ST_DIR)/obj/st_utest_tcp.o)
  50. OBJECTS = $(addprefix $(ST_DIR)/obj/,$(OBJECTS_FILES))
  51. # Objects, build each object of utest
  52. $(ST_DIR)/obj/%.o : %.cpp $(ST_UTEST_DEPS) $(UTEST_DEPS)
  53. $(CXX) -c $< -o $@ \
  54. $(CXXFLAGS) $(UTEST_FLAGS) \
  55. $(WARNFLAGS) \
  56. -I$(GTEST_DIR)/include -I$(ST_UTEST) -I$(ST_DIR) -I$(ST_DIR)/obj
  57. # Generate the utest binary
  58. $(ST_DIR)/obj/st_utest : $(OBJECTS) $(ST_DIR)/obj/gtest.a $(ST_UTEST_DEPS)
  59. $(CXX) -o $@ $(CXXFLAGS) $(UTEST_FLAGS) \
  60. -lpthread -ldl $^