TestFilesCompilation.gmk revision 1629:f105fbc01fd7
152419Sjulian#
252419Sjulian# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
352419Sjulian# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
452419Sjulian#
552419Sjulian# This code is free software; you can redistribute it and/or modify it
652419Sjulian# under the terms of the GNU General Public License version 2 only, as
752419Sjulian# published by the Free Software Foundation.  Oracle designates this
852419Sjulian# particular file as subject to the "Classpath" exception as provided
952419Sjulian# by Oracle in the LICENSE file that accompanied this code.
1052419Sjulian#
1152419Sjulian# This code is distributed in the hope that it will be useful, but WITHOUT
1252419Sjulian# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1352419Sjulian# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1452419Sjulian# version 2 for more details (a copy is included in the LICENSE file that
1552419Sjulian# accompanied this code).
1652419Sjulian#
1752419Sjulian# You should have received a copy of the GNU General Public License version
1852419Sjulian# 2 along with this work; if not, write to the Free Software Foundation,
1952419Sjulian# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2052419Sjulian#
2152419Sjulian# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2252419Sjulian# or visit www.oracle.com if you need additional information or have any
2352419Sjulian# questions.
2452419Sjulian#
2552419Sjulian
2652419Sjulianifndef _TEST_FILES_COMPILATION_GMK
2752419Sjulian_TEST_FILES_COMPILATION_GMK := 1
2852419Sjulian
2952419Sjulianifeq (,$(_MAKEBASE_GMK))
3052419Sjulian  $(error You must include MakeBase.gmk prior to including TestFilesCompilation.gmk)
3152419Sjulianendif
3252419Sjulian
3352419Sjulian
3452419Sjulianinclude NativeCompilation.gmk
3552419Sjulian
3652419Sjulian# Setup make rules for creating a set of native test files (libraries or
3752419Sjulian# executables). This will locate native files matching a certain pattern,
3852419Sjulian# and compile these into libraries or executables.
3952419Sjulian#
40158882Sglebius# Parameter 1 is the name of the rule. This name is used as variable prefix,
41158882Sglebius# and the targets generated are listed in a variable by that name.
42158882Sglebius#
43158882Sglebius# Remaining parameters are named arguments. These include:
44158882Sglebius#   TYPE Must be either PROGRAM or LIBRARY.
45158882Sglebius#   SOURCE_DIRS A list of source directories to search
4652419Sjulian#   OUTPUT_DIR Where to put the resulting files
4752419SjulianSetupTestFilesCompilation = $(NamedParamsMacroTemplate)
4852419Sjuliandefine SetupTestFilesCompilationBody
4952419Sjulian
5052419Sjulian  # Check for duplicate base file names. That would have failed later anyhow, but
5152419Sjulian  # this gives a better error message.
5252419Sjulian  $1_DUPLICATED_NAMES := $$(call dups, $$(notdir $$($1_FILE_LIST)))
5352419Sjulian  ifneq ($$($1_DUPLICATED_NAMES), )
54125011Sru    $$(error There are duplicate test file names for $1: $$($1_DUPLICATED_NAMES))
55125011Sru  endif
5652419Sjulian
5752419Sjulian  # The list to depend on starts out empty
5852419Sjulian  $1 :=
59125011Sru  ifeq ($$($1_TYPE), LIBRARY)
6052419Sjulian    $1_PREFIX = lib
61125115Sru    $1_OUTPUT_SUBDIR := lib
62125115Sru    $1_CFLAGS := $(CFLAGS_TESTLIB) $(CFLAGS_WARNINGS_ARE_ERRORS)
63125011Sru    $1_LDFLAGS := $(LDFLAGS_TESTLIB) $(call SET_SHARED_LIBRARY_ORIGIN)
64125011Sru  else ifeq ($$($1_TYPE), PROGRAM)
6552419Sjulian    $1_PREFIX = exe
6652419Sjulian    $1_OUTPUT_SUBDIR := bin
6752419Sjulian    $1_CFLAGS := $(CFLAGS_TESTEXE) $(CFLAGS_WARNINGS_ARE_ERRORS)
6852419Sjulian    $1_LDFLAGS := $(LDFLAGS_TESTEXE)
6952419Sjulian  else
7052419Sjulian    $$(error Unknown type: $$($1_TYPE))
71160002Sglebius  endif
7252419Sjulian
7352419Sjulian  # Locate all files with the matching prefix
7452419Sjulian  $1_FILE_LIST := \
7552419Sjulian      $$(shell $$(FIND) $$($1_SOURCE_DIRS) -type f -name "$$($1_PREFIX)*.c")
7652419Sjulian
7752419Sjulian  # Setup a compilation for each and every one of them
78160002Sglebius  $$(foreach file, $$($1_FILE_LIST),\
7952419Sjulian    $$(eval name := $$(strip $$(patsubst $$($1_PREFIX)%, %, $$(basename $$(notdir $$(file)))))) \
80125115Sru    $$(eval $$(call SetupNativeCompilation, BUILD_TEST_$$(name), \
8152419Sjulian        $$($1_TYPE) := $$(name), \
82160002Sglebius        SRC := $$(patsubst %/,%,$$(dir $$(file))), \
8352419Sjulian        INCLUDE_FILES := $$(notdir $$(file)), \
8452419Sjulian        OBJECT_DIR := $$($1_OUTPUT_DIR)/support/$$($1_PREFIX)$$(name), \
8552419Sjulian        OUTPUT_DIR := $$($1_OUTPUT_DIR)/$$($1_OUTPUT_SUBDIR), \
86125115Sru        LANG := C, \
8752419Sjulian        CFLAGS := $$($1_CFLAGS) $$($1_CFLAGS_$$($1_PREFIX)$$(name)), \
8852419Sjulian        LDFLAGS := $$($1_LDFLAGS) $$($1_LDFLAGS_$$($1_PREFIX)$$(name)), \
8952419Sjulian        OPTIMIZATION := LOW, \
9052419Sjulian        DEBUG_SYMBOLS := true)) \
9152419Sjulian    $$(eval $1 += $$(BUILD_TEST_$$(name)) )  \
9252419Sjulian  )
9352419Sjulian
9459880Sarchieendef
9552419Sjulian
9652419Sjulianendif # _TEST_FILES_COMPILATION_GMK
9752419Sjulian