2021-10-13 02:28:53 +03:00
|
|
|
#
|
2024-02-26 18:43:47 +03:00
|
|
|
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
2021-10-13 02:28:53 +03:00
|
|
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
#
|
|
|
|
# This code is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License version 2 only, as
|
|
|
|
# published by the Free Software Foundation. Oracle designates this
|
|
|
|
# particular file as subject to the "Classpath" exception as provided
|
|
|
|
# by Oracle in the LICENSE file that accompanied this code.
|
|
|
|
#
|
|
|
|
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
# version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
# accompanied this code).
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version
|
|
|
|
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
# or visit www.oracle.com if you need additional information or have any
|
|
|
|
# questions.
|
|
|
|
#
|
|
|
|
|
|
|
|
default: all
|
|
|
|
|
|
|
|
include $(SPEC)
|
|
|
|
include MakeBase.gmk
|
|
|
|
include JdkNativeCompilation.gmk
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# This makefile compiles and installs the hsdis library
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
HSDIS_OUTPUT_DIR := $(SUPPORT_OUTPUTDIR)/hsdis
|
2022-03-02 21:17:47 +03:00
|
|
|
REAL_HSDIS_NAME := hsdis-$(OPENJDK_TARGET_CPU_LEGACY_LIB)$(SHARED_LIBRARY_SUFFIX)
|
|
|
|
BUILT_HSDIS_LIB := $(HSDIS_OUTPUT_DIR)/$(REAL_HSDIS_NAME)
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2024-02-27 14:14:11 +03:00
|
|
|
HSDIS_LINK_TYPE := C
|
2022-02-18 00:18:15 +03:00
|
|
|
|
|
|
|
ifeq ($(HSDIS_BACKEND), capstone)
|
|
|
|
ifeq ($(call isTargetCpuArch, x86), true)
|
|
|
|
CAPSTONE_ARCH := CS_ARCH_X86
|
|
|
|
CAPSTONE_MODE := CS_MODE_$(OPENJDK_TARGET_CPU_BITS)
|
|
|
|
else ifeq ($(call isTargetCpuArch, aarch64), true)
|
2023-11-28 11:33:23 +03:00
|
|
|
CAPSTONE_ARCH := CS_ARCH_$(CAPSTONE_ARCH_AARCH64_NAME)
|
2022-02-18 00:18:15 +03:00
|
|
|
CAPSTONE_MODE := CS_MODE_ARM
|
|
|
|
else
|
|
|
|
$(error No support for Capstone on this platform)
|
|
|
|
endif
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2022-02-18 00:18:15 +03:00
|
|
|
HSDIS_CFLAGS += -DCAPSTONE_ARCH=$(CAPSTONE_ARCH) \
|
|
|
|
-DCAPSTONE_MODE=$(CAPSTONE_MODE)
|
|
|
|
endif
|
|
|
|
|
2022-02-21 13:37:44 +03:00
|
|
|
ifeq ($(HSDIS_BACKEND), llvm)
|
|
|
|
# Use C++ instead of C
|
2024-02-27 14:14:11 +03:00
|
|
|
HSDIS_LINK_TYPE := C++
|
2022-02-21 13:37:44 +03:00
|
|
|
|
|
|
|
ifeq ($(call isTargetOs, linux), true)
|
|
|
|
LLVM_OS := pc-linux-gnu
|
|
|
|
else ifeq ($(call isTargetOs, macosx), true)
|
|
|
|
LLVM_OS := apple-darwin
|
|
|
|
else ifeq ($(call isTargetOs, windows), true)
|
|
|
|
LLVM_OS := pc-windows-msvc
|
|
|
|
else
|
|
|
|
$(error No support for LLVM on this platform)
|
|
|
|
endif
|
|
|
|
|
|
|
|
HSDIS_CFLAGS += -DLLVM_DEFAULT_TRIPLET='"$(OPENJDK_TARGET_CPU)-$(LLVM_OS)"'
|
|
|
|
endif
|
|
|
|
|
2022-02-18 00:18:15 +03:00
|
|
|
ifeq ($(HSDIS_BACKEND), binutils)
|
|
|
|
ifeq ($(call isTargetOs, windows), true)
|
|
|
|
# On windows, we need to "fake" a completely different toolchain using gcc
|
|
|
|
# instead of the normal microsoft toolchain. This is quite hacky...
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2022-02-18 00:18:15 +03:00
|
|
|
MINGW_BASE := x86_64-w64-mingw32
|
|
|
|
|
|
|
|
MINGW_SYSROOT = $(shell $(MINGW_BASE)-gcc -print-sysroot)
|
2021-11-10 17:33:02 +03:00
|
|
|
ifeq ($(wildcard $(MINGW_SYSROOT)), )
|
2022-02-18 00:18:15 +03:00
|
|
|
# Use fallback path
|
|
|
|
MINGW_SYSROOT := /usr/$(MINGW_BASE)
|
|
|
|
ifeq ($(wildcard $(MINGW_SYSROOT)), )
|
|
|
|
$(error mingw sysroot not found)
|
|
|
|
endif
|
2021-11-10 17:33:02 +03:00
|
|
|
endif
|
|
|
|
|
2024-02-27 14:14:11 +03:00
|
|
|
BUILD_HSDIS_CC := $(MINGW_BASE)-gcc
|
|
|
|
BUILD_HSDIS_LD := $(MINGW_BASE)-ld
|
|
|
|
BUILD_HSDIS_OBJCOPY := $(MINGW_BASE)-objcopy
|
|
|
|
BUILD_HSDIS_SYSROOT_CFLAGS := --sysroot=$(MINGW_SYSROOT)
|
|
|
|
BUILD_HSDIS_SYSROOT_LDFLAGS := --sysroot=$(MINGW_SYSROOT)
|
2022-02-18 00:18:15 +03:00
|
|
|
|
|
|
|
MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/mingw/lib
|
2021-11-10 17:33:02 +03:00
|
|
|
ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
|
2022-02-18 00:18:15 +03:00
|
|
|
# Try without mingw
|
|
|
|
MINGW_SYSROOT_LIB_PATH := $(MINGW_SYSROOT)/lib
|
|
|
|
ifeq ($(wildcard $(MINGW_SYSROOT_LIB_PATH)), )
|
|
|
|
$(error mingw sysroot lib path not found)
|
|
|
|
endif
|
2021-11-10 17:33:02 +03:00
|
|
|
endif
|
|
|
|
|
2022-02-18 00:18:15 +03:00
|
|
|
MINGW_VERSION = $(shell $(MINGW_BASE)-gcc -v 2>&1 | $(GREP) "gcc version" | $(CUT) -d " " -f 3)
|
|
|
|
MINGW_GCC_LIB_PATH := /usr/lib/gcc/$(MINGW_BASE)/$(MINGW_VERSION)
|
2021-11-10 17:33:02 +03:00
|
|
|
ifeq ($(wildcard $(MINGW_GCC_LIB_PATH)), )
|
2022-02-18 00:18:15 +03:00
|
|
|
# Try using only major version number
|
|
|
|
MINGW_VERSION_MAJOR := $(firstword $(subst ., , $(MINGW_VERSION)))
|
|
|
|
MINGW_GCC_LIB_PATH := /usr/lib/gcc/$(MINGW_BASE)/$(MINGW_VERSION_MAJOR)
|
|
|
|
ifeq ($(wildcard $(MINGW_GCC_LIB_PATH)), )
|
|
|
|
$(error mingw gcc lib path not found)
|
|
|
|
endif
|
2021-11-10 17:33:02 +03:00
|
|
|
endif
|
|
|
|
|
2022-02-18 00:18:15 +03:00
|
|
|
TOOLCHAIN_TYPE := gcc
|
|
|
|
OPENJDK_TARGET_OS := linux
|
2024-02-26 18:43:47 +03:00
|
|
|
OPENJDK_TARGET_OS_TYPE := unix
|
2022-02-18 00:18:15 +03:00
|
|
|
CC_OUT_OPTION := -o$(SPACE)
|
|
|
|
GENDEPS_FLAGS := -MMD -MF
|
|
|
|
CFLAGS_DEBUG_SYMBOLS := -g
|
|
|
|
DISABLED_WARNINGS :=
|
|
|
|
DISABLE_WARNING_PREFIX := -Wno-
|
|
|
|
CFLAGS_WARNINGS_ARE_ERRORS := -Werror
|
|
|
|
SHARED_LIBRARY_FLAGS := -shared
|
|
|
|
|
2024-03-15 17:36:57 +03:00
|
|
|
HSDIS_TOOLCHAIN_DEFAULT_CFLAGS := false
|
2024-03-18 17:41:51 +03:00
|
|
|
HSDIS_TOOLCHAIN_DEFAULT_LDFLAGS := false
|
|
|
|
HSDIS_LDFLAGS += -L$(MINGW_GCC_LIB_PATH) -L$(MINGW_SYSROOT_LIB_PATH)
|
2022-02-18 00:18:15 +03:00
|
|
|
MINGW_DLLCRT := $(MINGW_SYSROOT_LIB_PATH)/dllcrt2.o
|
|
|
|
HSDIS_TOOLCHAIN_LIBS := $(MINGW_DLLCRT) -lmingw32 -lgcc -lgcc_eh -lmoldname \
|
|
|
|
-lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32
|
|
|
|
else
|
|
|
|
HSDIS_TOOLCHAIN_LIBS := -ldl
|
|
|
|
endif
|
2021-10-13 02:28:53 +03:00
|
|
|
endif
|
|
|
|
|
2024-04-05 11:37:41 +03:00
|
|
|
################################################################################
|
|
|
|
## Build libhsdis
|
|
|
|
################################################################################
|
|
|
|
|
2021-10-13 02:28:53 +03:00
|
|
|
$(eval $(call SetupJdkLibrary, BUILD_HSDIS, \
|
|
|
|
NAME := hsdis, \
|
2024-02-27 14:14:11 +03:00
|
|
|
LINK_TYPE := $(HSDIS_LINK_TYPE), \
|
2022-02-18 00:18:15 +03:00
|
|
|
SRC := $(TOPDIR)/src/utils/hsdis/$(HSDIS_BACKEND), \
|
2024-04-09 18:01:02 +03:00
|
|
|
EXTRA_HEADER_DIRS := \
|
|
|
|
java.base:include \
|
|
|
|
$(TOPDIR)/src/utils/hsdis, \
|
2021-10-13 02:28:53 +03:00
|
|
|
OUTPUT_DIR := $(HSDIS_OUTPUT_DIR), \
|
|
|
|
OBJECT_DIR := $(HSDIS_OUTPUT_DIR), \
|
|
|
|
DISABLED_WARNINGS_gcc := undef format-nonliteral sign-compare, \
|
|
|
|
DISABLED_WARNINGS_clang := undef format-nonliteral, \
|
2024-03-15 17:36:57 +03:00
|
|
|
DEFAULT_CFLAGS := $(HSDIS_TOOLCHAIN_DEFAULT_CFLAGS), \
|
|
|
|
CFLAGS := $(HSDIS_CFLAGS), \
|
|
|
|
CXXFLAGS := $(HSDIS_CFLAGS), \
|
2024-03-18 17:41:51 +03:00
|
|
|
LD_SET_ORIGIN := false, \
|
|
|
|
DEFAULT_LDFLAGS := $(HSDIS_TOOLCHAIN_DEFAULT_LDFLAGS), \
|
|
|
|
LDFLAGS := $(HSDIS_LDFLAGS) $(SHARED_LIBRARY_FLAGS), \
|
2021-10-13 02:28:53 +03:00
|
|
|
LIBS := $(HSDIS_LIBS) $(HSDIS_TOOLCHAIN_LIBS), \
|
|
|
|
))
|
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
$(BUILT_HSDIS_LIB): $(BUILD_HSDIS_TARGET)
|
|
|
|
$(install-file)
|
|
|
|
|
|
|
|
build: $(BUILD_HSDIS) $(BUILT_HSDIS_LIB)
|
2021-10-13 02:28:53 +03:00
|
|
|
|
|
|
|
TARGETS += build
|
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
ifeq ($(ENABLE_HSDIS_BUNDLING), false)
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
ifeq ($(call isTargetOs, windows), true)
|
|
|
|
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/bin
|
|
|
|
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/bin
|
|
|
|
else
|
|
|
|
JDK_HSDIS_DIR := $(JDK_OUTPUTDIR)/lib
|
|
|
|
IMAGE_HSDIS_DIR := $(JDK_IMAGE_DIR)/lib
|
|
|
|
endif
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
|
|
|
|
INSTALLED_HSDIS_JDK := $(JDK_HSDIS_DIR)/$(REAL_HSDIS_NAME)
|
|
|
|
INSTALLED_HSDIS_IMAGE := $(IMAGE_HSDIS_DIR)/$(REAL_HSDIS_NAME)
|
|
|
|
|
|
|
|
$(INSTALLED_HSDIS_JDK): $(BUILT_HSDIS_LIB)
|
|
|
|
ifeq ($(HSDIS_BACKEND), binutils)
|
|
|
|
$(call LogWarn, NOTE: The resulting build might not be redistributable. Seek legal advice before distributing.)
|
|
|
|
endif
|
2021-10-13 02:28:53 +03:00
|
|
|
$(install-file)
|
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
$(INSTALLED_HSDIS_IMAGE): $(BUILT_HSDIS_LIB)
|
2022-02-18 00:18:15 +03:00
|
|
|
$(install-file)
|
2021-10-13 02:28:53 +03:00
|
|
|
|
2022-03-02 21:17:47 +03:00
|
|
|
install: $(INSTALLED_HSDIS_JDK) $(INSTALLED_HSDIS_IMAGE)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
install:
|
|
|
|
$(ECHO) NOTE: make install-hsdis is a no-op with --enable-hsdis-bundling
|
|
|
|
|
|
|
|
endif
|
2021-10-13 02:28:53 +03:00
|
|
|
|
|
|
|
TARGETS += install
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
all: $(TARGETS)
|
|
|
|
|
|
|
|
.PHONY: all default build install
|