2
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
# This code is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation. Oracle designates this
8
# particular file as subject to the "Classpath" exception as provided
9
# by Oracle in the LICENSE file that accompanied this code.
11
# This code is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
# version 2 for more details (a copy is included in the LICENSE file that
15
# accompanied this code).
17
# You should have received a copy of the GNU General Public License version
18
# 2 along with this work; if not, write to the Free Software Foundation,
19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
# or visit www.oracle.com if you need additional information or have any
26
################################################################################
27
# This file contains functionality related to linking a native binary;
28
# creating either a dynamic library, a static library or an executable.
30
################################################################################
31
define CreateLinkedResultMicrosoft
32
ifeq ($$($1_TYPE), STATIC_LIBRARY)
33
$$(eval $$(call CreateStaticLibraryMicrosoft,$1))
35
$$(eval $$(call CreateDynamicLibraryOrExecutableMicrosoft,$1))
39
################################################################################
40
define CreateStaticLibraryMicrosoft
41
$1_VARDEPS := $$($1_LIB) $$(LIBFLAGS) $$($1_LIBS) \
43
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
44
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
46
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_EXTRA_LINK_DEPS) \
49
$$($1_TARGET): $$($1_TARGET_DEPS)
50
ifneq ($$($1_OBJ_FILE_LIST), )
51
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
53
$$(call LogInfo, Building static library $$($1_BASENAME))
54
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
55
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_run_lib, \
56
$$($1_LIB) -nologo $$(LIBFLAGS) -out:$$($1_TARGET) \
57
$$($1_LD_OBJ_ARG) $$($1_RES))
60
################################################################################
61
define CreateDynamicLibraryOrExecutableMicrosoft
62
ifeq ($$($1_EMBED_MANIFEST), true)
63
$1_EXTRA_LDFLAGS += -manifest:embed
66
$1_IMPORT_LIBRARY := $$($1_OBJECT_DIR)/$$($1_NAME).lib
67
$1_EXTRA_LDFLAGS += "-implib:$$($1_IMPORT_LIBRARY)"
69
ifeq ($$($1_TYPE), LIBRARY)
70
# To properly trigger downstream dependants of the import library, just as
71
# for debug files, we must have a recipe in the rule. To avoid rerunning
72
# the recipe every time have it touch the target. If an import library
73
# file is deleted by something external, explicitly delete the target to
74
# trigger a rebuild of both.
75
ifneq ($$(wildcard $$($1_IMPORT_LIBRARY)), $$($1_IMPORT_LIBRARY))
76
$$(call LogDebug, Deleting $$($1_BASENAME) because import library is missing)
77
$$(shell $(RM) $$($1_TARGET))
79
$$($1_IMPORT_LIBRARY): $$($1_TARGET)
82
$1 += $$($1_IMPORT_LIBRARY)
85
$1_VARDEPS := $$($1_LD) $$($1_SYSROOT_LDFLAGS) $$($1_LDFLAGS) \
86
$$($1_EXTRA_LDFLAGS) $$($1_LIBS) $$($1_EXTRA_LIBS) $$($1_MT) \
87
$$($1_MANIFEST_VERSION)
89
$1_VARDEPS_FILE := $$(call DependOnVariable, $1_VARDEPS, \
90
$$($1_OBJECT_DIR)/$$($1_NOSUFFIX).vardeps)
92
$1_TARGET_DEPS := $$($1_ALL_OBJS) $$($1_RES) $$($1_MANIFEST) \
93
$$($1_EXTRA_LINK_DEPS) $$($1_VARDEPS_FILE)
95
$$($1_TARGET): $$($1_TARGET_DEPS)
96
ifneq ($$($1_OBJ_FILE_LIST), )
97
$$(eval $$(call ListPathsSafely, $1_ALL_OBJS, $$($1_OBJ_FILE_LIST)))
99
$$(call LogInfo, Linking $$($1_BASENAME))
100
$$(call MakeDir, $$($1_OUTPUT_DIR) $$($1_SYMBOLS_DIR))
101
$$(call ExecuteWithLog, $$($1_OBJECT_DIR)/$$($1_SAFE_NAME)_run_ld, \
102
$$($1_LD) -nologo $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) \
103
$$($1_SYSROOT_LDFLAGS) -out:$$($1_TARGET) $$($1_LD_OBJ_ARG) \
104
$$($1_RES) $$($1_LIBS) $$($1_EXTRA_LIBS)) \
105
| $(GREP) -v "^ Creating library .*\.lib and object .*\.exp" || \
107
ifeq ($(call isBuildOsEnv, windows.wsl2), true)
108
$$(CHMOD) +x $$($1_TARGET)
110
ifneq ($$($1_MANIFEST), )
111
$$($1_MT) -nologo -manifest $$($1_MANIFEST) \
112
-identity:"$$($1_NAME).exe, version=$$($1_MANIFEST_VERSION)" \
113
-outputresource:$$@;#1