TestFilesCompilation.gmk revision 2264:278f9a9e9329
1174891Sedwin# 2174891Sedwin# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 3174891Sedwin# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4174891Sedwin# 5174891Sedwin# This code is free software; you can redistribute it and/or modify it 6174891Sedwin# under the terms of the GNU General Public License version 2 only, as 7174891Sedwin# published by the Free Software Foundation. Oracle designates this 8174891Sedwin# particular file as subject to the "Classpath" exception as provided 9174891Sedwin# by Oracle in the LICENSE file that accompanied this code. 10174891Sedwin# 11174891Sedwin# This code is distributed in the hope that it will be useful, but WITHOUT 12174891Sedwin# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13174891Sedwin# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14174891Sedwin# version 2 for more details (a copy is included in the LICENSE file that 15174891Sedwin# accompanied this code). 16174891Sedwin# 17174891Sedwin# You should have received a copy of the GNU General Public License version 18174891Sedwin# 2 along with this work; if not, write to the Free Software Foundation, 19174891Sedwin# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20174891Sedwin# 21174891Sedwin# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22174891Sedwin# or visit www.oracle.com if you need additional information or have any 23174891Sedwin# questions. 24174891Sedwin# 25174891Sedwin 26174891Sedwinifndef _TEST_FILES_COMPILATION_GMK 27228992Suqs_TEST_FILES_COMPILATION_GMK := 1 28174891Sedwin 29174891Sedwinifeq (,$(_MAKEBASE_GMK)) 30174891Sedwin $(error You must include MakeBase.gmk prior to including TestFilesCompilation.gmk) 31174891Sedwinendif 32174891Sedwin 33174891Sedwin 34174891Sedwininclude NativeCompilation.gmk 35174891Sedwin 36174891Sedwin# Setup make rules for creating a set of native test files (libraries or 37174891Sedwin# executables). This will locate native files matching a certain pattern, 38174891Sedwin# and compile these into libraries or executables. 39174891Sedwin# 40174891Sedwin# Parameter 1 is the name of the rule. This name is used as variable prefix, 41174891Sedwin# and the targets generated are listed in a variable by that name. 42174891Sedwin# 43174891Sedwin# Remaining parameters are named arguments. These include: 44174891Sedwin# TYPE Must be either PROGRAM or LIBRARY. 45174891Sedwin# SOURCE_DIRS A list of source directories to search 46174891Sedwin# OUTPUT_DIR Where to put the resulting files 47174891SedwinSetupTestFilesCompilation = $(NamedParamsMacroTemplate) 48174891Sedwindefine SetupTestFilesCompilationBody 49174891Sedwin 50174891Sedwin # Check for duplicate base file names. That would have failed later anyhow, but 51174891Sedwin # this gives a better error message. 52174891Sedwin $1_DUPLICATED_NAMES := $$(call dups, $$(notdir $$($1_FILE_LIST))) 53174891Sedwin ifneq ($$($1_DUPLICATED_NAMES), ) 54174891Sedwin $$(error There are duplicate test file names for $1: $$($1_DUPLICATED_NAMES)) 55174891Sedwin endif 56174891Sedwin 57174891Sedwin # The list to depend on starts out empty 58174891Sedwin $1 := 59174891Sedwin ifeq ($$($1_TYPE), LIBRARY) 60174891Sedwin $1_PREFIX = lib 61174891Sedwin $1_OUTPUT_SUBDIR := lib 62174891Sedwin $1_CFLAGS := $(CFLAGS_TESTLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) 63174891Sedwin $1_LDFLAGS := $(LDFLAGS_TESTLIB) $(call SET_SHARED_LIBRARY_ORIGIN) 64174891Sedwin else ifeq ($$($1_TYPE), PROGRAM) 65174891Sedwin $1_PREFIX = exe 66174891Sedwin $1_OUTPUT_SUBDIR := bin 67174891Sedwin $1_CFLAGS := $(CFLAGS_TESTEXE) $(CFLAGS_WARNINGS_ARE_ERRORS) 68174891Sedwin $1_LDFLAGS := $(LDFLAGS_TESTEXE) 69174891Sedwin else 70174891Sedwin $$(error Unknown type: $$($1_TYPE)) 71174891Sedwin endif 72174891Sedwin 73174891Sedwin # Locate all files with the matching prefix 74174891Sedwin $1_FILE_LIST := \ 75174891Sedwin $$(shell $$(FIND) $$($1_SOURCE_DIRS) -type f -name "$$($1_PREFIX)*.c") 76224016Sbz 77174891Sedwin # Setup a compilation for each and every one of them 78174891Sedwin $$(foreach file, $$($1_FILE_LIST),\ 79174891Sedwin $$(eval name := $$(strip $$(patsubst $$($1_PREFIX)%, %, $$(basename $$(notdir $$(file)))))) \ 80174891Sedwin $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \ 81174891Sedwin $$($1_TYPE) := $$(name), \ 82174891Sedwin SRC := $$(patsubst %/,%,$$(dir $$(file))), \ 83174891Sedwin INCLUDE_FILES := $$(notdir $$(file)), \ 84174891Sedwin OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$($1_PREFIX)$$(name), \ 85174891Sedwin OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \ 86174891Sedwin LANG := C, \ 87174891Sedwin CFLAGS := $$($1_CFLAGS) $$($1_CFLAGS_$$($1_PREFIX)$$(name)), \ 88174891Sedwin LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$($1_PREFIX)$$(name)), \ 89174891Sedwin LIBS := $$($1_LIBS_$$($1_PREFIX)$$(name)), \ 90174891Sedwin OPTIMIZATION := LOW, \ 91174891Sedwin COPY_DEBUG_SYMBOLS := false, \ 92174891Sedwin STRIP_SYMBOLS := false, \ 93174891Sedwin )) \ 94174891Sedwin $$(eval $1 += $$(BUILD_TEST_$$(name)) ) \ 95174891Sedwin ) 96174891Sedwin 97174891Sedwinendef 98174891Sedwin 99174891Sedwinendif # _TEST_FILES_COMPILATION_GMK 100174891Sedwin