TestFilesCompilation.gmk revision 2223:dcce309ab6a6
1169689Skan# 2169689Skan# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3169689Skan# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4169689Skan# 5169689Skan# This code is free software; you can redistribute it and/or modify it 6169689Skan# under the terms of the GNU General Public License version 2 only, as 7169689Skan# published by the Free Software Foundation. Oracle designates this 8169689Skan# particular file as subject to the "Classpath" exception as provided 9169689Skan# by Oracle in the LICENSE file that accompanied this code. 10169689Skan# 11169689Skan# This code is distributed in the hope that it will be useful, but WITHOUT 12169689Skan# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13169689Skan# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14169689Skan# version 2 for more details (a copy is included in the LICENSE file that 15169689Skan# accompanied this code). 16169689Skan# 17169689Skan# You should have received a copy of the GNU General Public License version 18169689Skan# 2 along with this work; if not, write to the Free Software Foundation, 19169689Skan# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20169689Skan# 21169689Skan# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22169689Skan# or visit www.oracle.com if you need additional information or have any 23169689Skan# questions. 24169689Skan# 25169689Skan 26169689Skanifndef _TEST_FILES_COMPILATION_GMK 27169689Skan_TEST_FILES_COMPILATION_GMK := 1 28169689Skan 29169689Skanifeq (,$(_MAKEBASE_GMK)) 30169689Skan $(error You must include MakeBase.gmk prior to including TestFilesCompilation.gmk) 31169689Skanendif 32169689Skan 33169689Skan 34169689Skaninclude NativeCompilation.gmk 35169689Skan 36169689Skan# Setup make rules for creating a set of native test files (libraries or 37169689Skan# executables). This will locate native files matching a certain pattern, 38169689Skan# and compile these into libraries or executables. 39169689Skan# 40169689Skan# Parameter 1 is the name of the rule. This name is used as variable prefix, 41169689Skan# and the targets generated are listed in a variable by that name. 42169689Skan# 43169689Skan# Remaining parameters are named arguments. These include: 44169689Skan# TYPE Must be either PROGRAM or LIBRARY. 45169689Skan# SOURCE_DIRS A list of source directories to search 46169689Skan# OUTPUT_DIR Where to put the resulting files 47169689SkanSetupTestFilesCompilation = $(NamedParamsMacroTemplate) 48169689Skandefine SetupTestFilesCompilationBody 49169689Skan 50169689Skan # Check for duplicate base file names. That would have failed later anyhow, but 51169689Skan # this gives a better error message. 52169689Skan $1_DUPLICATED_NAMES := $$(call dups, $$(notdir $$($1_FILE_LIST))) 53169689Skan ifneq ($$($1_DUPLICATED_NAMES), ) 54169689Skan $$(error There are duplicate test file names for $1: $$($1_DUPLICATED_NAMES)) 55169689Skan endif 56169689Skan 57169689Skan # The list to depend on starts out empty 58169689Skan $1 := 59169689Skan ifeq ($$($1_TYPE), LIBRARY) 60169689Skan $1_PREFIX = lib 61169689Skan $1_OUTPUT_SUBDIR := lib 62169689Skan $1_CFLAGS := $(CFLAGS_TESTLIB) $(CFLAGS_WARNINGS_ARE_ERRORS) 63169689Skan $1_LDFLAGS := $(LDFLAGS_TESTLIB) $(call SET_SHARED_LIBRARY_ORIGIN) 64169689Skan else ifeq ($$($1_TYPE), PROGRAM) 65169689Skan $1_PREFIX = exe 66169689Skan $1_OUTPUT_SUBDIR := bin 67169689Skan $1_CFLAGS := $(CFLAGS_TESTEXE) $(CFLAGS_WARNINGS_ARE_ERRORS) 68169689Skan $1_LDFLAGS := $(LDFLAGS_TESTEXE) 69169689Skan else 70169689Skan $$(error Unknown type: $$($1_TYPE)) 71169689Skan endif 72169689Skan 73169689Skan # Locate all files with the matching prefix 74169689Skan $1_FILE_LIST := \ 75169689Skan $$(shell $$(FIND) $$($1_SOURCE_DIRS) -type f -name "$$($1_PREFIX)*.c") 76169689Skan 77169689Skan # Setup a compilation for each and every one of them 78169689Skan $$(foreach file, $$($1_FILE_LIST),\ 79169689Skan $$(eval name := $$(strip $$(patsubst $$($1_PREFIX)%, %, $$(basename $$(notdir $$(file)))))) \ 80169689Skan $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \ 81169689Skan $$($1_TYPE) := $$(name), \ 82169689Skan SRC := $$(patsubst %/,%,$$(dir $$(file))), \ 83169689Skan INCLUDE_FILES := $$(notdir $$(file)), \ 84169689Skan OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$($1_PREFIX)$$(name), \ 85169689Skan OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \ 86169689Skan LANG := C, \ 87169689Skan CFLAGS := $$($1_CFLAGS) $$($1_CFLAGS_$$($1_PREFIX)$$(name)), \ 88169689Skan LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$($1_PREFIX)$$(name)), \ 89169689Skan LIBS := $$($1_LIBS_$$($1_PREFIX)$$(name)), \ 90169689Skan OPTIMIZATION := LOW, \ 91169689Skan )) \ 92169689Skan $$(eval $1 += $$(BUILD_TEST_$$(name)) ) \ 93169689Skan ) 94169689Skan 95169689Skanendef 96169689Skan 97169689Skanendif # _TEST_FILES_COMPILATION_GMK 98169689Skan