TestFilesCompilation.gmk revision 1538:7aaab92958c4
174462Salfred#
274462Salfred# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
374462Salfred# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
492990Sobrien#
592990Sobrien# This code is free software; you can redistribute it and/or modify it
692990Sobrien# under the terms of the GNU General Public License version 2 only, as
775094Siedowse# published by the Free Software Foundation.  Oracle designates this
874462Salfred# particular file as subject to the "Classpath" exception as provided
974462Salfred# by Oracle in the LICENSE file that accompanied this code.
1074462Salfred#
1174462Salfred# This code is distributed in the hope that it will be useful, but WITHOUT
12111010Snectar# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1374462Salfred# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14156090Sdeischen# version 2 for more details (a copy is included in the LICENSE file that
1574462Salfred# accompanied this code).
16156090Sdeischen#
17156090Sdeischen# You should have received a copy of the GNU General Public License version
18156090Sdeischen# 2 along with this work; if not, write to the Free Software Foundation,
19156090Sdeischen# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20156090Sdeischen#
21156090Sdeischen# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22156090Sdeischen# or visit www.oracle.com if you need additional information or have any
23156090Sdeischen# questions.
24156090Sdeischen#
25156090Sdeischen
26156090Sdeischenifndef _TEST_FILES_COMPILATION_GMK
27156090Sdeischen_TEST_FILES_COMPILATION_GMK := 1
28156090Sdeischen
29156090Sdeischenifeq (,$(_MAKEBASE_GMK))
30156090Sdeischen  $(error You must include MakeBase.gmk prior to including TestFilesCompilation.gmk)
31156090Sdeischenendif
32156090Sdeischen
3374462Salfred
3474462Salfredinclude NativeCompilation.gmk
3574462Salfred# FIXME: This is a bad fix currently needed due to JDK-8064808 not being resolved.
3674462Salfredinclude $(JDK_TOPDIR)/make/Tools.gmk
3774462Salfred
3874462Salfred# Setup make rules for creating a set of native test files (libraries or
3974462Salfred# executables). This will locate native files matching a certain pattern,
4074462Salfred# and compile these into libraries or executables.
4174462Salfred#
4274462Salfred# Parameter 1 is the name of the rule. This name is used as variable prefix,
4374462Salfred# and the targets generated are listed in a variable by that name.
4474462Salfred#
4574462Salfred# Remaining parameters are named arguments. These include:
4674462Salfred#   TYPE Must be either PROGRAM or LIBRARY.
4774462Salfred#   SOURCE_DIRS A list of source directories to search
4874462Salfred#   OUTPUT_DIR Where to put the resulting files
4974462SalfredSetupTestFilesCompilation = $(NamedParamsMacroTemplate)
5074462Salfreddefine SetupTestFilesCompilationBody
5174462Salfred
5274462Salfred  # Check for duplicate base file names. That would have failed later anyhow, but
5374462Salfred  # this gives a better error message.
5474462Salfred  $1_DUPLICATED_NAMES := $$(call dups, $$(notdir $$($1_FILE_LIST)))
5574462Salfred  ifneq ($$($1_DUPLICATED_NAMES), )
5674462Salfred    $$(error There are duplicate test file names for $1: $$($1_DUPLICATED_NAMES))
5774462Salfred  endif
5874462Salfred
5974462Salfred  # The list to depend on starts out empty
6074462Salfred  $1 :=
6174462Salfred  ifeq ($$($1_TYPE), LIBRARY)
6274462Salfred    $1_PREFIX = lib
6374462Salfred    $1_OUTPUT_SUBDIR := lib
6474462Salfred    $1_CFLAGS := $(CFLAGS_TESTLIB) $(CFLAGS_WARNINGS_ARE_ERRORS)
6574462Salfred    $1_LDFLAGS := $(LDFLAGS_TESTLIB) $(call SET_SHARED_LIBRARY_ORIGIN)
6674462Salfred  else ifeq ($$($1_TYPE), PROGRAM)
6774462Salfred    $1_PREFIX = exe
6874462Salfred    $1_OUTPUT_SUBDIR := bin
6974462Salfred    $1_CFLAGS := $(CFLAGS_TESTEXE) $(CFLAGS_WARNINGS_ARE_ERRORS)
7074462Salfred    $1_LDFLAGS := $(LDFLAGS_TESTEXE)
7174462Salfred  else
7274462Salfred    $$(error Unknown type: $$($1_TYPE))
7374462Salfred  endif
7474462Salfred
7574462Salfred  # Locate all files with the matching prefix
7674462Salfred  $1_FILE_LIST := \
7774462Salfred      $$(shell $$(FIND) $$($1_SOURCE_DIRS) -type f -name "$$($1_PREFIX)*.c")
7874462Salfred
7974462Salfred  # Setup a compilation for each and every one of them
8074462Salfred  $$(foreach file, $$($1_FILE_LIST),\
8174462Salfred    $$(eval name := $$(strip $$(patsubst $$($1_PREFIX)%, %, $$(basename $$(notdir $$(file)))))) \
8274462Salfred    $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \
8374462Salfred        $$($1_TYPE) := $$(name), \
84204950Sjhb        SRC := $$(patsubst %/,%,$$(dir $$(file))), \
85204950Sjhb        INCLUDE_FILES := $$(notdir $$(file)), \
86204950Sjhb        OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$($1_PREFIX)$$(name), \
8774462Salfred        OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \
88204950Sjhb        LANG := C, \
89204950Sjhb        CFLAGS := $$($1_CFLAGS) $$($1_CFLAGS_$$($1_PREFIX)$$(name)), \
90204950Sjhb        LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$($1_PREFIX)$$(name)), \
91204950Sjhb        OPTIMIZATION := LOW, \
92204950Sjhb        DEBUG_SYMBOLS := true)) \
93204950Sjhb    $$(eval $1 += $$(BUILD_TEST_$$(name)) )  \
94204950Sjhb  )
9574462Salfred
9674462Salfredendef
9774462Salfred
9874462Salfredendif # _TEST_FILES_COMPILATION_GMK
9974462Salfred