1DEBUG=0 2LDFLAGS=-ldl -lrt -lpthread -pie 3CXXFLAGS = -std=c++11 -fPIE -fno-rtti -g -Wall -Werror \ 4 -DGTEST_HAS_RTTI=0 -DSANITIZER_DEBUG=$(DEBUG) 5CLANG=clang 6FILECHECK=FileCheck 7# Silence warnings that Clang produces for gtest code. 8# Use -Wno-attributes so that gcc doesn't complain about unknown warning types. 9CXXFLAGS += -Wno-attributes 10ifeq ($(DEBUG), 0) 11 CXXFLAGS += -O3 12endif 13ifeq ($(CXX), $(CLANG)++) 14 CXXFLAGS += -Wno-unused-private-field -Wno-static-in-inline -Wgnu 15else 16 CXXFLAGS += -Wno-maybe-uninitialized 17endif 18 19LIBTSAN=rtl/libtsan.a 20GTEST_ROOT=third_party/googletest 21GTEST_INCLUDE=-I$(GTEST_ROOT)/include 22GTEST_BUILD_DIR=$(GTEST_ROOT)/build 23GTEST_LIB_NAME=gtest-all.o 24GTEST_LIB=$(GTEST_BUILD_DIR)/$(GTEST_LIB_NAME) 25 26SANITIZER_TESTS_PATH=../sanitizer_common/tests 27SANITIZER_COMMON_TESTS_SRC=$(wildcard $(SANITIZER_TESTS_PATH)/*_test.cc) 28SANITIZER_COMMON_EXCLUDED_TESTS=$(SANITIZER_TESTS_PATH)/sanitizer_nolibc_test.cc 29SANITIZER_COMMON_GOOD_TESTS=$(filter-out $(SANITIZER_COMMON_EXCLUDED_TESTS), $(SANITIZER_COMMON_TESTS_SRC)) 30SANITIZER_COMMON_TESTS_OBJ=$(patsubst %.cc,%.o,$(SANITIZER_COMMON_GOOD_TESTS)) 31RTL_TEST_SRC=$(wildcard tests/rtl/*.cc) 32RTL_TEST_OBJ=$(patsubst %.cc,%.o,$(RTL_TEST_SRC)) 33UNIT_TEST_SRC=$(wildcard tests/unit/*_test.cc) 34UNIT_TEST_OBJ=$(patsubst %.cc,%.o,$(UNIT_TEST_SRC)) 35UNIT_TEST_HDR=$(wildcard rtl/*.h) $(wildcard ../sanitizer_common/*.h) 36LIT_TESTS_PATH=../../test/tsan 37 38INCLUDES=-Irtl -I.. -I../../include $(GTEST_INCLUDE) 39 40all: libtsan test 41 42help: 43 @ echo "A little help is always welcome!" 44 @ echo "The most useful targets are:" 45 @ echo " make install_deps # Install third-party dependencies required for building" 46 @ echo " make presubmit # Run it every time before committing" 47 @ echo 48 @ echo "For more info, see http://code.google.com/p/thread-sanitizer/wiki/Development" 49 50$(LIBTSAN): libtsan 51 52libtsan: 53 $(MAKE) -C rtl -f Makefile.old DEBUG=$(DEBUG) 54 55%.o: %.cc $(UNIT_TEST_HDR) $(LIBTSAN) 56 $(CXX) $(CXXFLAGS) $(CFLAGS) $(INCLUDES) -o $@ -c $< 57 58tsan_test: $(UNIT_TEST_OBJ) $(RTL_TEST_OBJ) \ 59 $(SANITIZER_COMMON_TESTS_OBJ) $(LIBTSAN) $(GTEST_LIB) 60 $(CXX) -Wl,--whole-archive $^ -Wl,--no-whole-archive -o $@ $(LDFLAGS) 61 62test: libtsan tsan_test 63 64run: all 65 (ulimit -s 8192; ./tsan_test) 66 CC=$(CLANG) CXX=$(CLANG)++ FILECHECK=$(FILECHECK) $(LIT_TESTS_PATH)/test_output.sh 67 68presubmit: 69 ../sanitizer_common/scripts/check_lint.sh 70 # Debug build with clang. 71 $(MAKE) -f Makefile.old clean 72 $(MAKE) -f Makefile.old run DEBUG=1 -j 16 CC=$(CLANG) CXX=$(CLANG)++ 73 # Release build with clang. 74 $(MAKE) -f Makefile.old clean 75 $(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=$(CLANG) CXX=$(CLANG)++ 76 ./check_memcpy.sh 77 # Debug build with gcc 78 $(MAKE) -f Makefile.old clean 79 $(MAKE) -f Makefile.old run DEBUG=1 -j 16 CC=gcc CXX=g++ 80 # Release build with gcc 81 $(MAKE) -f Makefile.old clean 82 $(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=gcc CXX=g++ 83 ./check_memcpy.sh 84 ./check_analyze.sh 85 # Sanity check for Go runtime 86 (cd go && ./buildgo.sh) 87 # Check cmake build 88 ./check_cmake.sh 89 @ echo PRESUBMIT PASSED 90 91install_deps: 92 rm -rf third_party 93 mkdir third_party 94 (cd third_party && \ 95 svn co -r613 http://googletest.googlecode.com/svn/trunk googletest \ 96 ) 97 98$(GTEST_LIB): 99 mkdir -p $(GTEST_BUILD_DIR) && \ 100 cd $(GTEST_BUILD_DIR) && \ 101 $(MAKE) -f ../make/Makefile CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" CC=$(CC) CXX=$(CXX) $(GTEST_LIB_NAME) 102 103clean: 104 rm -f asm_*.s libtsan.nm libtsan.objdump */*.o tsan_test 105 rm -rf $(GTEST_BUILD_DIR) 106 $(MAKE) clean -C rtl -f Makefile.old 107 rm -f go/*.s 108 rm -rf build 109