makefile 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- make -*-
  2. BASE=../..
  3. SUBDIR=test/libapt
  4. BASENAME=_libapt_test
  5. APT_DOMAIN=none
  6. # Bring in the default rules
  7. include ../../buildlib/defaults.mak
  8. .PHONY: test
  9. ifeq (file-okay,$(shell $(CC) -I $(BASE)/build/include -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay'))
  10. test: $(BIN)/gtest$(BASENAME)
  11. MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME)
  12. $(BIN)/gtest$(BASENAME): $(LIB)/gtest.a
  13. PROGRAM = gtest${BASENAME}
  14. SLIBS = -lapt-pkg -lapt-private -pthread $(LIB)/gtest.a
  15. LIB_MAKES = apt-pkg/makefile apt-private/makefile
  16. SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc)
  17. include $(PROGRAM_H)
  18. MKDIRS += $(OBJ) $(LIB)
  19. LOCAL=gtest
  20. SOURCE=gtest-all
  21. gtest-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(SOURCE)))
  22. # The rest of the file is based on the example found in
  23. # /usr/share/doc/libgtest-dev/examples/make/Makefile
  24. GTEST_DIR = /usr/src/gtest
  25. # Flags passed to the preprocessor.
  26. # Set Google Test's header directory as a system directory, such that
  27. # the compiler doesn't generate warnings in Google Test headers.
  28. #CPPFLAGS += -isystem $(GTEST_DIR)/include
  29. # Flags passed to the C++ compiler.
  30. CXXFLAGS += -pthread
  31. # disable some flags for gtest again
  32. CXXFLAGS+= -Wno-missing-declarations
  33. CXXFLAGS+= -Wno-missing-field-initializers
  34. CXXFLAGS+= -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn
  35. CXXFLAGS+= -Wno-undef
  36. # All Google Test headers. Usually you shouldn't change this definition.
  37. GTEST_HEADERS = /usr/include/gtest/*.h \
  38. /usr/include/gtest/internal/*.h
  39. # House-keeping build targets.
  40. .PHONY: clean/gtest veryclean/gtest
  41. clean: clean/gtest
  42. clean/gtest:
  43. rm -f $(gtest-OBJS)
  44. veryclean: veryclean/gtest
  45. veryclean/gtest: clean/gtest
  46. rm -f $(LIB)/gtest.a
  47. # Usually you shouldn't tweak such internal variables, indicated by a
  48. # trailing _.
  49. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
  50. # Builds gtest.a
  51. # For simplicity and to avoid depending on Google Test's
  52. # implementation details, the dependencies specified below are
  53. # conservative and not optimized. This is fine as Google Test
  54. # compiles fast and for ordinary users its source rarely changes.
  55. $(gtest-OBJS): $(GTEST_SRCS_)
  56. echo Compiling $@
  57. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
  58. $(LIB)/gtest.a: $(OBJ)/gtest-all.o
  59. echo Building static library $@
  60. -rm -f $@
  61. $(AR) $(ARFLAGS) $@ $^
  62. else
  63. test:
  64. @echo "APT uses Googles C++ testing framework for its unit tests"
  65. @echo "On Debian systems this is available in the 'libgtest-dev' package."
  66. @echo "Please install it before attempting to run the unit tests."
  67. $(CC) -I $(BASE)/build/include -M gtest_runner.cc
  68. exit 100
  69. endif