makefile 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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) -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. # All Google Test headers. Usually you shouldn't change this definition.
  36. GTEST_HEADERS = /usr/include/gtest/*.h \
  37. /usr/include/gtest/internal/*.h
  38. # House-keeping build targets.
  39. .PHONY: clean/gtest veryclean/gtest
  40. clean: clean/gtest
  41. clean/gtest:
  42. rm -f $(gtest-OBJS)
  43. veryclean: veryclean/gtest
  44. veryclean/gtest: clean/gtest
  45. rm -f $(LIB)/gtest.a
  46. # Usually you shouldn't tweak such internal variables, indicated by a
  47. # trailing _.
  48. GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
  49. # Builds gtest.a
  50. # For simplicity and to avoid depending on Google Test's
  51. # implementation details, the dependencies specified below are
  52. # conservative and not optimized. This is fine as Google Test
  53. # compiles fast and for ordinary users its source rarely changes.
  54. $(gtest-OBJS): $(GTEST_SRCS_)
  55. echo Compiling $@
  56. $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
  57. $(LIB)/gtest.a: $(OBJ)/gtest-all.o
  58. echo Building static library $@
  59. -rm -f $@
  60. $(AR) $(ARFLAGS) $@ $^
  61. else
  62. test:
  63. @echo "APT uses Googles C++ testing framework for its unit tests"
  64. @echo "On Debian systems this is available in the 'libgtest-dev' package."
  65. @echo "Please install it before attempting to run the unit tests."
  66. exit 100
  67. endif