jdk

Форк
0
/
Hsdis.gmk 
208 строк · 7.0 Кб
1
#
2
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
#
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.
10
#
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).
16
#
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.
20
#
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
23
# questions.
24
#
25

26
default: all
27

28
include $(SPEC)
29
include MakeBase.gmk
30
include JdkNativeCompilation.gmk
31

32
################################################################################
33
# This makefile compiles and installs the hsdis library
34
#
35
################################################################################
36

37
HSDIS_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/hsdis
38
REAL_HSDIS_NAME := hsdis-$(OPENJDK_TARGET_CPU_LEGACY_LIB)$(SHARED_LIBRARY_SUFFIX)
39
BUILT_HSDIS_LIB := $(HSDIS_OUTPUT_DIR)/$(REAL_HSDIS_NAME)
40

41
HSDIS_LINK_TYPE := C
42

43
ifeq ($(HSDIS_BACKEND), capstone)
44
  ifeq ($(call isTargetCpuArch, x86), true)
45
    CAPSTONE_ARCH := CS_ARCH_X86
46
    CAPSTONE_MODE := CS_MODE_$(OPENJDK_TARGET_CPU_BITS)
47
  else ifeq ($(call isTargetCpuArch, aarch64), true)
48
    CAPSTONE_ARCH := CS_ARCH_$(CAPSTONE_ARCH_AARCH64_NAME)
49
    CAPSTONE_MODE := CS_MODE_ARM
50
  else
51
    $(error No support for Capstone on this platform)
52
  endif
53

54
  HSDIS_CFLAGS += -DCAPSTONE_ARCH=$(CAPSTONE_ARCH) \
55
      -DCAPSTONE_MODE=$(CAPSTONE_MODE)
56
endif
57

58
ifeq ($(HSDIS_BACKEND), llvm)
59
  # Use C++ instead of C
60
  HSDIS_LINK_TYPE := C++
61

62
  ifeq ($(call isTargetOs, linux), true)
63
    LLVM_OS := pc-linux-gnu
64
  else ifeq ($(call isTargetOs, macosx), true)
65
    LLVM_OS := apple-darwin
66
  else ifeq ($(call isTargetOs, windows), true)
67
    LLVM_OS := pc-windows-msvc
68
  else
69
    $(error No support for LLVM on this platform)
70
  endif
71

72
  HSDIS_CFLAGS += -DLLVM_DEFAULT_TRIPLET='"$(OPENJDK_TARGET_CPU)-$(LLVM_OS)"'
73
endif
74

75
ifeq ($(HSDIS_BACKEND), binutils)
76
  ifeq ($(call isTargetOs, windows), true)
77
    # On windows, we need to "fake" a completely different toolchain using gcc
78
    # instead of the normal microsoft toolchain. This is quite hacky...
79

80
    MINGW_BASE := x86_64-w64-mingw32
81

82
    MINGW_SYSROOT = $(shell $(MINGW_BASE)-gcc -print-sysroot)
83
    ifeq ($(wildcard $(MINGW_SYSROOT)), )
84
      # Use fallback path
85
      MINGW_SYSROOT := /usr/$(MINGW_BASE)
86
      ifeq ($(wildcard $(MINGW_SYSROOT)), )
87
        $(error mingw sysroot not found)
88
      endif
89
    endif
90

91
    BUILD_HSDIS_CC := $(MINGW_BASE)-gcc
92
    BUILD_HSDIS_LD := $(MINGW_BASE)-ld
93
    BUILD_HSDIS_OBJCOPY := $(MINGW_BASE)-objcopy
94
    BUILD_HSDIS_SYSROOT_CFLAGS := --sysroot=$(MINGW_SYSROOT)
95
    BUILD_HSDIS_SYSROOT_LDFLAGS := --sysroot=$(MINGW_SYSROOT)
96

97
    MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/mingw/lib
98
    ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
99
      # Try without mingw
100
      MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/lib
101
      ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
102
        $(error mingw sysroot lib path not found)
103
      endif
104
    endif
105

106
    MINGW_VERSION = $(shell $(MINGW_BASE)-gcc -v 2>&1 | $(GREP) "gcc version" | $(CUT) -d " " -f 3)
107
    MINGW_GCC_LIB_PATH := /usr/lib/gcc/$(MINGW_BASE)/$(MINGW_VERSION)
108
    ifeq ($(wildcard $(MINGW_GCC_LIB_PATH)), )
109
      # Try using only major version number
110
      MINGW_VERSION_MAJOR := $(firstword $(subst ., , $(MINGW_VERSION)))
111
      MINGW_GCC_LIB_PATH := /usr/lib/gcc/$(MINGW_BASE)/$(MINGW_VERSION_MAJOR)
112
      ifeq ($(wildcard $(MINGW_GCC_LIB_PATH)), )
113
        $(error mingw gcc lib path not found)
114
      endif
115
    endif
116

117
    TOOLCHAIN_TYPE := gcc
118
    OPENJDK_TARGET_OS := linux
119
    OPENJDK_TARGET_OS_TYPE := unix
120
    CC_OUT_OPTION := -o$(SPACE)
121
    GENDEPS_FLAGS := -MMD -MF
122
    CFLAGS_DEBUG_SYMBOLS := -g
123
    DISABLED_WARNINGS :=
124
    DISABLE_WARNING_PREFIX := -Wno-
125
    CFLAGS_WARNINGS_ARE_ERRORS := -Werror
126
    SHARED_LIBRARY_FLAGS := -shared
127

128
    HSDIS_TOOLCHAIN_DEFAULT_CFLAGS := false
129
    HSDIS_TOOLCHAIN_DEFAULT_LDFLAGS := false
130
    HSDIS_LDFLAGS += -L$(MINGW_GCC_LIB_PATH) -L$(MINGW_SYSROOT_LIB_PATH)
131
    MINGW_DLLCRT := $(MINGW_SYSROOT_LIB_PATH)/dllcrt2.o
132
    HSDIS_TOOLCHAIN_LIBS := $(MINGW_DLLCRT) -lmingw32 -lgcc -lgcc_eh -lmoldname \
133
        -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32
134
  else
135
    HSDIS_TOOLCHAIN_LIBS := -ldl
136
  endif
137
endif
138

139
################################################################################
140
## Build libhsdis
141
################################################################################
142

143
$(eval $(call SetupJdkLibrary, BUILD_HSDIS, \
144
    NAME := hsdis, \
145
    LINK_TYPE := $(HSDIS_LINK_TYPE), \
146
    SRC := $(TOPDIR)/src/utils/hsdis/$(HSDIS_BACKEND), \
147
    EXTRA_HEADER_DIRS := \
148
          java.base:include \
149
          $(TOPDIR)/src/utils/hsdis, \
150
    OUTPUT_DIR := $(HSDIS_OUTPUT_DIR), \
151
    OBJECT_DIR := $(HSDIS_OUTPUT_DIR), \
152
    DISABLED_WARNINGS_gcc := undef format-nonliteral sign-compare, \
153
    DISABLED_WARNINGS_clang := undef format-nonliteral, \
154
    DEFAULT_CFLAGS := $(HSDIS_TOOLCHAIN_DEFAULT_CFLAGS), \
155
    CFLAGS := $(HSDIS_CFLAGS), \
156
    CXXFLAGS := $(HSDIS_CFLAGS), \
157
    LD_SET_ORIGIN := false, \
158
    DEFAULT_LDFLAGS := $(HSDIS_TOOLCHAIN_DEFAULT_LDFLAGS), \
159
    LDFLAGS := $(HSDIS_LDFLAGS) $(SHARED_LIBRARY_FLAGS), \
160
    LIBS := $(HSDIS_LIBS) $(HSDIS_TOOLCHAIN_LIBS), \
161
))
162

163
$(BUILT_HSDIS_LIB): $(BUILD_HSDIS_TARGET)
164
	$(install-file)
165

166
build: $(BUILD_HSDIS) $(BUILT_HSDIS_LIB)
167

168
TARGETS += build
169

170
ifeq ($(ENABLE_HSDIS_BUNDLING), false)
171

172
  ifeq ($(call isTargetOs, windows), true)
173
    JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/bin
174
    IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/bin
175
  else
176
    JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/lib
177
    IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/lib
178
  endif
179

180

181
  INSTALLED_HSDIS_JDK := $(JDK_HSDIS_DIR)/$(REAL_HSDIS_NAME)
182
  INSTALLED_HSDIS_IMAGE := $(IMAGE_HSDIS_DIR)/$(REAL_HSDIS_NAME)
183

184
  $(INSTALLED_HSDIS_JDK): $(BUILT_HSDIS_LIB)
185
          ifeq ($(HSDIS_BACKEND), binutils)
186
	    $(call LogWarn, NOTE: The resulting build might not be redistributable. Seek legal advice before distributing.)
187
          endif
188
	$(install-file)
189

190
  $(INSTALLED_HSDIS_IMAGE): $(BUILT_HSDIS_LIB)
191
	$(install-file)
192

193
  install: $(INSTALLED_HSDIS_JDK) $(INSTALLED_HSDIS_IMAGE)
194

195
else
196

197
  install:
198
	$(ECHO) NOTE: make install-hsdis is a no-op with --enable-hsdis-bundling
199

200
endif
201

202
TARGETS += install
203

204
################################################################################
205

206
all: $(TARGETS)
207

208
.PHONY: all default build install
209

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.