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