1# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5fortify-test-src := clang-fortify-tests.cpp
6# -U_FORTIFY_SOURCE: Clang gets unhappy being passed `-D_FORTIFY_SOURCE=2
7#  -D_FORTIFY_SOURCE=1` (the first of which comes from our wrapper).
8fortify-cxx := $(CXX) $(fortify-test-src) $(CPPFLAGS) $(CXXFLAGS) -std=c++11 \
9	-D_GNU_SOURCE -fno-exceptions -O2 -U_FORTIFY_SOURCE
10fortify-diag-flags := -o /dev/null -Xclang -verify -DCOMPILATION_TESTS -c \
11	-Wformat-nonliteral
12fortify-runtime-flags := -Wno-user-defined-warnings -Wno-unused-result
13
14all: fortify-runtime-tests
15
16fortify-runtime-tests: clang-fortify-driver.o clang-fortify-tests-1.o \
17                       clang-fortify-tests-2.o
18	$(CXX) $(LDFLAGS) -o $@ $+
19
20# Test FORTIFY diagnostics in the same target as generating the .o file for
21# convenience. Testing diagnostics takes <1sec, and these tests silently fell
22# off the radar before (crbug.com/1159199).
23clang-fortify-tests-1.o: $(fortify-test-src)
24	# FIXME(crbug.com/1159199): Reenable this once the glibc fix is live.
25	# $(fortify-cxx) $(fortify-diag-flags) -D_FORTIFY_SOURCE=1
26	$(fortify-cxx) $(fortify-runtime-flags) -c -D_FORTIFY_SOURCE=1 -o $@
27
28clang-fortify-tests-2.o: $(fortify-test-src)
29	# FIXME(crbug.com/1159199): Reenable this once the glibc fix is live.
30	# $(fortify-cxx) $(fortify-diag-flags) -D_FORTIFY_SOURCE=2
31	$(fortify-cxx) $(fortify-runtime-flags) -c -D_FORTIFY_SOURCE=2 -o $@
32
33clean:
34	rm -f clang-fortify-*.o fortify-runtime-tests
35
36install:
37	install -m 0755 -d $(DESTDIR)/usr/local/bin
38	install -m 0755 toolchain-tests $(DESTDIR)/usr/local/bin
39	install -m 0755 fortify-runtime-tests $(DESTDIR)/usr/local/bin
40
41