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.
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
30
include JdkNativeCompilation.gmk
32
################################################################################
33
# This makefile compiles and installs the hsdis library
35
################################################################################
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)
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
51
$(error No support for Capstone on this platform)
54
HSDIS_CFLAGS += -DCAPSTONE_ARCH=$(CAPSTONE_ARCH) \
55
-DCAPSTONE_MODE=$(CAPSTONE_MODE)
58
ifeq ($(HSDIS_BACKEND), llvm)
59
# Use C++ instead of C
60
HSDIS_LINK_TYPE := C++
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
69
$(error No support for LLVM on this platform)
72
HSDIS_CFLAGS += -DLLVM_DEFAULT_TRIPLET='"$(OPENJDK_TARGET_CPU)-$(LLVM_OS)"'
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...
80
MINGW_BASE := x86_64-w64-mingw32
82
MINGW_SYSROOT = $(shell $(MINGW_BASE)-gcc -print-sysroot)
83
ifeq ($(wildcard $(MINGW_SYSROOT)), )
85
MINGW_SYSROOT := /usr/$(MINGW_BASE)
86
ifeq ($(wildcard $(MINGW_SYSROOT)), )
87
$(error mingw sysroot not found)
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)
97
MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/mingw/lib
98
ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
100
MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/lib
101
ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
102
$(error mingw sysroot lib path not found)
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)
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
124
DISABLE_WARNING_PREFIX := -Wno-
125
CFLAGS_WARNINGS_ARE_ERRORS := -Werror
126
SHARED_LIBRARY_FLAGS := -shared
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
135
HSDIS_TOOLCHAIN_LIBS := -ldl
139
################################################################################
141
################################################################################
143
$(eval $(call SetupJdkLibrary, BUILD_HSDIS, \
145
LINK_TYPE := $(HSDIS_LINK_TYPE), \
146
SRC := $(TOPDIR)/src/utils/hsdis/$(HSDIS_BACKEND), \
147
EXTRA_HEADER_DIRS := \
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), \
163
$(BUILT_HSDIS_LIB): $(BUILD_HSDIS_TARGET)
166
build: $(BUILD_HSDIS) $(BUILT_HSDIS_LIB)
170
ifeq ($(ENABLE_HSDIS_BUNDLING), false)
172
ifeq ($(call isTargetOs, windows), true)
173
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/bin
174
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/bin
176
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/lib
177
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/lib
181
INSTALLED_HSDIS_JDK := $(JDK_HSDIS_DIR)/$(REAL_HSDIS_NAME)
182
INSTALLED_HSDIS_IMAGE := $(IMAGE_HSDIS_DIR)/$(REAL_HSDIS_NAME)
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.)
190
$(INSTALLED_HSDIS_IMAGE): $(BUILT_HSDIS_LIB)
193
install: $(INSTALLED_HSDIS_JDK) $(INSTALLED_HSDIS_IMAGE)
198
$(ECHO) NOTE: make install-hsdis is a no-op with --enable-hsdis-bundling
204
################################################################################
208
.PHONY: all default build install