Makefile 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. CXX = g++
  2. CXXFLAGS ?= -g -Wall -W -Winline -ansi
  3. LDFLAGS ?=
  4. SED = sed
  5. MV = mv
  6. RM = rm
  7. .SUFFIXES: .o .cpp
  8. lib = libUnitTest++.a
  9. test = TestUnitTest++
  10. src = src/AssertException.cpp \
  11. src/Test.cpp \
  12. src/Checks.cpp \
  13. src/TestRunner.cpp \
  14. src/TestResults.cpp \
  15. src/TestReporter.cpp \
  16. src/TestReporterStdout.cpp \
  17. src/ReportAssert.cpp \
  18. src/TestList.cpp \
  19. src/TimeConstraint.cpp \
  20. src/TestDetails.cpp \
  21. src/MemoryOutStream.cpp \
  22. src/DeferredTestReporter.cpp \
  23. src/DeferredTestResult.cpp \
  24. src/XmlTestReporter.cpp \
  25. src/CurrentTest.cpp
  26. ifeq ($(MSYSTEM), MINGW32)
  27. src += src/Win32/TimeHelpers.cpp
  28. else
  29. src += src/Posix/SignalTranslator.cpp \
  30. src/Posix/TimeHelpers.cpp
  31. endif
  32. test_src = src/tests/Main.cpp \
  33. src/tests/TestAssertHandler.cpp \
  34. src/tests/TestChecks.cpp \
  35. src/tests/TestUnitTest++.cpp \
  36. src/tests/TestTest.cpp \
  37. src/tests/TestTestResults.cpp \
  38. src/tests/TestTestRunner.cpp \
  39. src/tests/TestCheckMacros.cpp \
  40. src/tests/TestTestList.cpp \
  41. src/tests/TestTestMacros.cpp \
  42. src/tests/TestTimeConstraint.cpp \
  43. src/tests/TestTimeConstraintMacro.cpp \
  44. src/tests/TestMemoryOutStream.cpp \
  45. src/tests/TestDeferredTestReporter.cpp \
  46. src/tests/TestXmlTestReporter.cpp \
  47. src/tests/TestCurrentTest.cpp
  48. objects = $(patsubst %.cpp, %.o, $(src))
  49. test_objects = $(patsubst %.cpp, %.o, $(test_src))
  50. dependencies = $(subst .o,.d,$(objects))
  51. test_dependencies = $(subst .o,.d,$(test_objects))
  52. define make-depend
  53. $(CXX) $(CXXFLAGS) -M $1 | \
  54. $(SED) -e 's,\($(notdir $2)\) *:,$(dir $2)\1: ,' > $3.tmp
  55. $(SED) -e 's/#.*//' \
  56. -e 's/^[^:]*: *//' \
  57. -e 's/ *\\$$//' \
  58. -e '/^$$/ d' \
  59. -e 's/$$/ :/' $3.tmp >> $3.tmp
  60. $(MV) $3.tmp $3
  61. endef
  62. all: $(test)
  63. $(lib): $(objects)
  64. @echo Creating $(lib) library...
  65. @ar cr $(lib) $(objects)
  66. $(test): $(lib) $(test_objects)
  67. @echo Linking $(test)...
  68. @$(CXX) $(LDFLAGS) -o $(test) $(test_objects) $(lib)
  69. @echo Running unit tests...
  70. @./$(test)
  71. clean:
  72. -@$(RM) $(objects) $(test_objects) $(dependencies) $(test_dependencies) $(test) $(lib) 2> /dev/null
  73. %.o : %.cpp
  74. @echo $<
  75. @$(call make-depend,$<,$@,$(subst .o,.d,$@))
  76. @$(CXX) $(CXXFLAGS) -c $< -o $(patsubst %.cpp, %.o, $<)
  77. ifneq "$(MAKECMDGOALS)" "clean"
  78. -include $(dependencies)
  79. -include $(test_dependencies)
  80. endif