view make/lib/Awt2dLibraries.gmk @ 53579:b7192ab3fdf5

8214007: Fix sun.awt.nativedebug on X11 platforms Reviewed-by: erikj, ihse
author simonis
date Mon, 19 Nov 2018 19:25:57 +0100
parents 804792ce736f
children 6902fefe90aa
line wrap: on
line source
#
# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
# 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.
#

$(eval $(call IncludeCustomExtension, lib/Awt2dLibraries-pre.gmk))

WIN_AWT_LIB := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libawt/awt.lib

LIBAWT_DEFAULT_HEADER_DIRS := \
    libawt/awt/image \
    libawt/awt/image/cvutils \
    libawt/java2d \
    libawt/java2d/loops \
    libawt/java2d/pipe \
    #

################################################################################

# We must not include java.desktop/unix/native/libmlib_image, which is only
# for usage by solaris-sparc in libmlib_image_v.
BUILD_LIBMLIB_EXCLUDE_SRC_PATTERNS := unix

BUILD_LIBMLIB_CFLAGS := -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES -DMLIB_NO_LIBSUNMATH

ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
  BUILD_LIBMLIB_CFLAGS += -DMLIB_OS64BIT
endif

$(eval $(call SetupJdkLibrary, BUILD_LIBMLIB_IMAGE, \
    NAME := mlib_image, \
    EXTRA_SRC := common/awt/medialib, \
    EXCLUDE_FILES := mlib_c_ImageBlendTable.c, \
    EXCLUDE_SRC_PATTERNS := $(BUILD_LIBMLIB_EXCLUDE_SRC_PATTERNS), \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(BUILD_LIBMLIB_CFLAGS), \
    DISABLED_WARNINGS_gcc := unused-function, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LIBS := $(JDKLIB_LIBS), \
    LIBS_unix := $(LIBM) $(LIBDL), \
))

$(BUILD_LIBMLIB_IMAGE): $(call FindLib, java.base, java)

TARGETS += $(BUILD_LIBMLIB_IMAGE)

################################################################################

ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)

  # libmlib_image_v is basically built from mlib_image sources, with some additions
  # and some exclusions.
  LIBMLIB_IMAGE_V_SRC := \
     libmlib_image \
     common/awt/medialib \
     #

  LIBMLIB_IMAGE_V_CFLAGS := -xarch=sparcvis -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES \
      $(TOPDIR)/src/$(MODULE)/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il

  ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
    LIBMLIB_IMAGE_V_CFLAGS += -DMLIB_OS64BIT
  endif

  BUILD_LIBMLIB_IMAGE_V_EXFILES := \
      awt_ImagingLib.c \
      mlib_c_ImageAffine_BC.c \
      mlib_c_ImageAffine_BC_S16.c \
      mlib_c_ImageAffine_BC_U16.c \
      mlib_c_ImageAffine_BL.c \
      mlib_c_ImageAffine_BL_S16.c \
      mlib_c_ImageAffine_BL_U16.c \
      mlib_c_ImageAffine_NN.c \
      mlib_c_ImageConvClearEdge.c \
      mlib_c_ImageConvCopyEdge.c \
      mlib_c_ImageConv_f.c \
      mlib_c_ImageConvVersion.c \
      mlib_c_ImageCopy.c \
      mlib_c_ImageLookUp.c \
      mlib_c_ImageLookUp_f.c \
      #

  $(eval $(call SetupJdkLibrary, BUILD_LIBMLIB_IMAGE_V, \
      NAME := mlib_image_v, \
      SRC := $(LIBMLIB_IMAGE_V_SRC), \
      EXCLUDE_FILES := $(BUILD_LIBMLIB_IMAGE_V_EXFILES), \
      OPTIMIZATION := HIGHEST, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(LIBMLIB_IMAGE_V_CFLAGS), \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LIBS := -ljava -ljvm $(LIBM) $(LIBDL), \
  ))

  $(BUILD_LIBMLIB_IMAGE_V): $(call FindLib, java.base, java)

  TARGETS += $(BUILD_LIBMLIB_IMAGE_V)

endif

################################################################################

LIBAWT_EXTRA_SRC := \
    common/awt/debug \
    $(TOPDIR)/src/$(MODULE)/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
    #

ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)
  LIBAWT_EXTRA_SRC += $(TOPDIR)/src/$(MODULE)/share/native/common/awt/medialib
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBAWT_EXTRA_SRC += \
      $(TOPDIR)/src/$(MODULE)/share/native/common/awt/utility \
      $(TOPDIR)/src/$(MODULE)/share/native/common/font \
      $(TOPDIR)/src/$(MODULE)/share/native/common/java2d/opengl \
      $(TOPDIR)/src/$(MODULE)/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt/systemscale \
      #
endif

ifneq ($(filter $(OPENJDK_TARGET_OS), solaris linux macosx aix), )
  LIBAWT_EXFILES += awt_Font.c CUPSfuncs.c fontpath.c X11Color.c
endif

ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBAWT_EXFILES += initIDs.c awt/image/cvutils/img_colors.c
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBAWT_EXFILES += \
      java2d/d3d/D3DShaderGen.c \
      awt/image/cvutils/img_colors.c \
      #
endif

ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), solaris-sparcv9)
  LIBAWT_EXFILES += java2d/loops/MapAccelFunc.c
else
  LIBAWT_EXCLUDES += \
      $(TOPDIR)/src/$(MODULE)/unix/native/libawt/awt/medialib \
      $(TOPDIR)/src/$(MODULE)/unix/native/libawt/java2d/loops \
      $(TOPDIR)/src/$(MODULE)/unix/native/common/awt/medialib \
      #
endif

LIBAWT_EXTRA_HEADER_DIRS := \
    $(LIBAWT_DEFAULT_HEADER_DIRS) \
    $(call GetJavaHeaderDir, java.base) \
    libawt/awt/medialib \
    libawt/java2d/d3d \
    libawt/java2d/opengl \
    libawt/java2d/windows \
    libawt/windows \
    common/awt/medialib \
    libmlib_image \
    include \
    java.base:libjava \
    java.base:include \
    #

LIBAWT_CFLAGS += -D__MEDIALIB_OLD_NAMES -D__USE_J2D_NAMES $(X_CFLAGS)

ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), solaris-sparcv9)
  LIBAWT_CFLAGS += -xarch=sparcvis -DMLIB_ADD_SUFF \
      $(TOPDIR)/src/$(MODULE)/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il

  LIBAWT_ASFLAGS = -P -xarch=v9a
endif

ifneq ($(OPENJDK_TARGET_OS), solaris)
  LIBAWT_CFLAGS += -DMLIB_NO_LIBSUNMATH
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBAWT_CFLAGS += -EHsc -DUNICODE -D_UNICODE
  ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
    LIBAWT_CFLAGS += -DMLIB_OS64BIT
  endif

  LIBAWT_RC_FLAGS ?= -I $(TOPDIR)/src/java.base/windows/native/launcher/icons
  LIBAWT_VERSIONINFO_RESOURCE := $(TOPDIR)/src/$(MODULE)/windows/native/libawt/windows/awt.rc
endif

ifeq ($(OPENJDK_TARGET_OS), linux)
  # FIXME: This is probably not what we want to do, but keep it now for compatibility.
  LIBAWT_CFLAGS += $(EXPORT_ALL_SYMBOLS)
endif

# Turn off all warnings for debug_mem.c This is needed because the specific warning
# about initializing a declared 'extern' cannot be turned off individually. Only
# applies to debug builds.
ifeq ($(TOOLCHAIN_TYPE), gcc)
  BUILD_LIBAWT_debug_mem.c_CFLAGS := -w
  # This option improves performance of MaskFill in Java2D by 20% for some gcc
  LIBAWT_CFLAGS += -fgcse-after-reload
endif

$(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
    NAME := awt, \
    EXTRA_SRC := $(LIBAWT_EXTRA_SRC), \
    EXCLUDES := $(LIBAWT_EXCLUDES), \
    EXCLUDE_FILES := $(LIBAWT_EXFILES), \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_CFLAGS), \
    EXTRA_HEADER_DIRS := $(LIBAWT_EXTRA_HEADER_DIRS), \
    DISABLED_WARNINGS_gcc := sign-compare unused-result maybe-uninitialized \
        format-nonliteral parentheses unused-value unused-function, \
    DISABLED_WARNINGS_clang := logical-op-parentheses extern-initializer \
        sign-compare format-nonliteral, \
    DISABLED_WARNINGS_solstudio := E_DECLARATION_IN_CODE, \
    DISABLED_WARNINGS_microsoft := 4244 4267 4996, \
    ASFLAGS := $(LIBAWT_ASFLAGS), \
    LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_macosx := -L$(INSTALL_LIBRARIES_HERE), \
    LDFLAGS_windows := -delayload:user32.dll -delayload:gdi32.dll \
        -delayload:shell32.dll -delayload:winmm.dll \
        -delayload:winspool.drv -delayload:imm32.dll \
        -delayload:ole32.dll -delayload:comdlg32.dll \
        -delayload:comctl32.dll -delayload:shlwapi.dll, \
    LIBS_unix := -ljvm -ljava $(LIBM), \
    LIBS_linux :=  $(LIBDL), \
    LIBS_solaris := $(LIBDL), \
    LIBS_aix := $(LIBDL),\
    LIBS_macosx := -lmlib_image \
        -framework Cocoa \
        -framework OpenGL \
        -framework JavaNativeFoundation \
        -framework JavaRuntimeSupport \
        -framework ApplicationServices \
        -framework AudioToolbox, \
    LIBS_windows := kernel32.lib user32.lib gdi32.lib winspool.lib \
        imm32.lib ole32.lib uuid.lib shell32.lib \
        comdlg32.lib winmm.lib comctl32.lib shlwapi.lib \
        delayimp.lib jvm.lib $(WIN_JAVA_LIB) advapi32.lib, \
    VERSIONINFO_RESOURCE := $(LIBAWT_VERSIONINFO_RESOURCE), \
    RC_FLAGS := $(RC_FLAGS) $(LIBAWT_RC_FLAGS) \
        -D "JDK_FNAME=awt.dll" \
        -D "JDK_INTERNAL_NAME=awt" \
        -D "JDK_FTYPE=0x2L", \
))

$(BUILD_LIBAWT): $(call FindLib, java.base, java)

ifeq ($(OPENJDK_TARGET_OS), macosx)
  $(BUILD_LIBAWT): $(BUILD_LIBMLIB_IMAGE)
endif

TARGETS += $(BUILD_LIBAWT)

################################################################################

ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx), )
  ifeq ($(ENABLE_HEADLESS_ONLY), false)

    LIBAWT_XAWT_EXTRA_SRC := \
        common/awt \
        common/java2d \
        common/font \
        #

    LIBAWT_XAWT_EXCLUDES := medialib debug

    LIBAWT_XAWT_EXTRA_HEADER_DIRS := \
        $(LIBAWT_DEFAULT_HEADER_DIRS) \
        libawt_xawt/awt \
        include \
        common/awt/debug \
        common/awt/systemscale \
        common/font \
        common/java2d/opengl \
        common/java2d/x11 \
        #

    LIBAWT_XAWT_CFLAGS += -DXAWT -DXAWT_HACK \
        $(FONTCONFIG_CFLAGS) \
        $(CUPS_CFLAGS)

    ifeq ($(OPENJDK_TARGET_OS), solaris)
      LIBAWT_XAWT_CFLAGS += -DFUNCPROTO=15
    endif

    ifeq ($(OPENJDK_TARGET_OS), linux)
      ifeq ($(DISABLE_XRENDER), true)
        LIBAWT_XAWT_CFLAGS += -DDISABLE_XRENDER_BY_DEFAULT=true
      endif
    endif

    LIBAWT_XAWT_LIBS := $(LIBM) -lawt -lXext -lX11 -lXrender $(LIBDL) -lXtst -lXi -ljava -ljvm

    ifeq ($(OPENJDK_TARGET_OS), linux)
      LIBAWT_XAWT_LIBS += -lpthread
    endif

    ifeq ($(TOOLCHAIN_TYPE), gcc)
      # Turn off all warnings for the following files since they contain warnings
      # that cannot be turned of individually.
      # redefining a macro
      BUILD_LIBAWT_XAWT_gtk2_interface.c_CFLAGS := -w
      # comparison between pointer and integer
      BUILD_LIBAWT_XAWT_awt_Font.c_CFLAGS := -w
      # initializing a declared 'extern'
      BUILD_LIBAWT_XAWT_debug_mem.c_CFLAGS := -w
    endif

    $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_XAWT, \
        NAME := awt_xawt, \
        EXTRA_SRC := $(LIBAWT_XAWT_EXTRA_SRC), \
        EXTRA_HEADER_DIRS := $(LIBAWT_XAWT_EXTRA_HEADER_DIRS), \
        EXCLUDES := $(LIBAWT_XAWT_EXCLUDES), \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_XAWT_CFLAGS) \
            $(X_CFLAGS), \
        WARNINGS_AS_ERRORS_xlc := false, \
        DISABLED_WARNINGS_gcc := type-limits pointer-to-int-cast \
            unused-result maybe-uninitialized format \
            format-security int-to-pointer-cast parentheses \
            implicit-fallthrough undef unused-function, \
        DISABLED_WARNINGS_clang := parentheses format undef \
            logical-op-parentheses format-nonliteral int-conversion, \
        DISABLED_WARNINGS_solstudio := E_DECLARATION_IN_CODE \
            E_ASSIGNMENT_TYPE_MISMATCH E_NON_CONST_INIT, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(call SET_SHARED_LIBRARY_ORIGIN) \
            -L$(INSTALL_LIBRARIES_HERE), \
        LIBS :=  $(X_LIBS) $(LIBAWT_XAWT_LIBS), \
    ))

    $(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java)

    $(BUILD_LIBAWT_XAWT): $(BUILD_LIBAWT)

    TARGETS += $(BUILD_LIBAWT_XAWT)

  endif
endif

################################################################################

# The fast floor code loses precision.
LCMS_CFLAGS=-DCMS_DONT_USE_FAST_FLOOR

ifeq ($(USE_EXTERNAL_LCMS), true)
  # If we're using an external library, we'll just need the wrapper part.
  # By including it explicitly, all other files will be excluded.
  BUILD_LIBLCMS_INCLUDE_FILES := LCMS.c
  # If we're using an external library, we can't include our own SRC path
  # as includes, instead the system headers should be used.
  LIBLCMS_HEADERS_FROM_SRC := false
else
  BUILD_LIBLCMS_INCLUDE_FILES :=
endif

$(eval $(call SetupJdkLibrary, BUILD_LIBLCMS, \
    NAME := lcms, \
    INCLUDE_FILES := $(BUILD_LIBLCMS_INCLUDE_FILES), \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(LCMS_CFLAGS), \
    CFLAGS_solaris := -xc99=no_lib, \
    CFLAGS_windows := -DCMS_IS_WINDOWS_, \
    EXTRA_HEADER_DIRS := \
        common/awt/debug \
        libawt/java2d, \
    HEADERS_FROM_SRC := $(LIBLCMS_HEADERS_FROM_SRC), \
    DISABLED_WARNINGS_gcc := format-nonliteral type-limits \
        misleading-indentation undef unused-function, \
    DISABLED_WARNINGS_clang := tautological-compare format-nonliteral undef, \
    DISABLED_WARNINGS_solstudio := E_STATEMENT_NOT_REACHED, \
    DISABLED_WARNINGS_microsoft := 4819, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
    LIBS_unix := -lawt -ljvm -ljava $(LCMS_LIBS) $(LIBM), \
    LIBS_windows := $(WIN_AWT_LIB) $(WIN_JAVA_LIB), \
))

TARGETS += $(BUILD_LIBLCMS)

$(BUILD_LIBLCMS): $(BUILD_LIBAWT)

################################################################################

# "DISABLED_WARNINGS_gcc := clobbered" rationale:
# Suppress gcc warnings like "variable might be clobbered by 'longjmp'
# or 'vfork'": this warning indicates that some variable is placed to
# a register by optimized compiler and it's value might be lost on longjmp().
# Recommended way to avoid such warning is to declare the variable as
# volatile to prevent the optimization. However, this approach does not
# work because we have to declare all variables as volatile in result.

ifeq ($(USE_EXTERNAL_LIBJPEG), true)
  LIBJPEG_LIBS := -ljpeg
  BUILD_LIBJAVAJPEG_INCLUDE_FILES := \
      imageioJPEG.c \
      jpegdecoder.c
  # If we're using an external library, we can't include our own SRC path
  # as includes, instead the system headers should be used.
  LIBJPEG_HEADERS_FROM_SRC := false
else
  LIBJPEG_LIBS :=
  BUILD_LIBJAVAJPEG_INCLUDE_FILES :=
endif

$(eval $(call SetupJdkLibrary, BUILD_LIBJAVAJPEG, \
    NAME := javajpeg, \
    INCLUDE_FILES := $(BUILD_LIBJAVAJPEG_INCLUDE_FILES), \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(CFLAGS_JDKLIB), \
    HEADERS_FROM_SRC := $(LIBJPEG_HEADERS_FROM_SRC), \
    DISABLED_WARNINGS_gcc := clobbered implicit-fallthrough shift-negative-value, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LIBS := $(LIBJPEG_LIBS) $(JDKLIB_LIBS), \
    LIBS_windows := $(WIN_JAVA_LIB) jvm.lib, \
))

$(BUILD_LIBJAVAJPEG): $(call FindLib, java.base, java)

TARGETS += $(BUILD_LIBJAVAJPEG)

################################################################################

# Mac and Windows only use the native AWT lib, do not build libawt_headless
ifeq ($(findstring $(OPENJDK_TARGET_OS), windows macosx),)

  LIBAWT_HEADLESS_EXTRA_SRC := \
      common/font \
      common/java2d \
      $(TOPDIR)/src/$(MODULE)/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
      #

  LIBAWT_HEADLESS_EXCLUDES := medialib

  LIBAWT_HEADLESS_EXTRA_HEADER_DIRS := \
      $(LIBAWT_DEFAULT_HEADER_DIRS) \
      common/awt/debug \
      common/font \
      common/java2d/opengl \
      #

  LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \
      -DHEADLESS=true

  $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
      NAME := awt_headless, \
      EXTRA_SRC := $(LIBAWT_HEADLESS_EXTRA_SRC), \
      EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(LIBAWT_HEADLESS_CFLAGS), \
      EXTRA_HEADER_DIRS := $(LIBAWT_HEADLESS_EXTRA_HEADER_DIRS), \
      DISABLED_WARNINGS_gcc := unused-function, \
      DISABLED_WARNINGS_xlc := 1506-356, \
      DISABLED_WARNINGS_solstudio := E_EMPTY_TRANSLATION_UNIT, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
      LIBS_unix := -lawt -ljvm -ljava, \
      LIBS_linux := $(LIBM) $(LIBDL), \
      LIBS_solaris := $(LIBM) $(LIBDL) $(LIBCXX), \
  ))

  # AIX warning explanation:
  # 1506-356 : (W) Compilation unit is empty.
  #            This happens during the headless build

  $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)

  TARGETS += $(BUILD_LIBAWT_HEADLESS)

endif

################################################################################

ifeq ($(FREETYPE_TO_USE), system)
  # For use by libfontmanager:
  LIBFREETYPE_CFLAGS := $(FREETYPE_CFLAGS)
  LIBFREETYPE_LIBS := $(FREETYPE_LIBS)
else
  BUILD_LIBFREETYPE_HEADER_DIRS := $(TOPDIR)/src/$(MODULE)/share/native/libfreetype/include
  BUILD_LIBFREETYPE_CFLAGS := -DFT2_BUILD_LIBRARY $(EXPORT_ALL_SYMBOLS)

  # For use by libfontmanager:
  LIBFREETYPE_CFLAGS := -I$(BUILD_LIBFREETYPE_HEADER_DIRS)
  ifeq ($(OPENJDK_TARGET_OS), windows)
    LIBFREETYPE_LIBS := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libfreetype/freetype.lib
  else
    LIBFREETYPE_LIBS := -lfreetype
  endif

  $(eval $(call SetupJdkLibrary, BUILD_LIBFREETYPE, \
      NAME := freetype, \
      OPTIMIZATION := HIGHEST, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(BUILD_LIBFREETYPE_CFLAGS), \
      EXTRA_HEADER_DIRS := $(BUILD_LIBFREETYPE_HEADER_DIRS), \
      DISABLED_WARNINGS_solstudio := \
         E_STATEMENT_NOT_REACHED \
         E_END_OF_LOOP_CODE_NOT_REACHED, \
      DISABLED_WARNINGS_microsoft := 4267 4244 4312, \
      DISABLED_WARNINGS_gcc := implicit-fallthrough, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
  ))

  TARGETS += $(BUILD_LIBFREETYPE)
endif

###########################################################################

#### Begin harfbuzz configuration

HARFBUZZ_CFLAGS := -DHAVE_OT -DHAVE_FALLBACK -DHAVE_UCDN -DHAVE_ROUND

ifneq ($(OPENJDK_TARGET_OS), windows)
  HARFBUZZ_CFLAGS += -DGETPAGESIZE -DHAVE_MPROTECT -DHAVE_PTHREAD \
                      -DHAVE_SYSCONF -DHAVE_SYS_MMAN_H -DHAVE_UNISTD_H
endif
ifneq (, $(findstring $(OPENJDK_TARGET_OS), linux macosx))
  HARFBUZZ_CFLAGS += -DHAVE_INTEL_ATOMIC_PRIMITIVES
endif
ifeq ($(OPENJDK_TARGET_OS), solaris)
  HARFBUZZ_CFLAGS += -DHAVE_SOLARIS_ATOMIC_OPS
endif
ifeq ($(OPENJDK_TARGET_OS), macosx)
  HARFBUZZ_CFLAGS += -DHAVE_CORETEXT
endif
ifneq ($(OPENJDK_TARGET_OS), macosx)
  LIBFONTMANAGER_EXCLUDE_FILES += harfbuzz/hb-coretext.cc
endif
# hb-ft.cc is not presently needed, and requires freetype 2.4.2 or later.
LIBFONTMANAGER_EXCLUDE_FILES += harfbuzz/hb-ft.cc

LIBFONTMANAGER_CFLAGS += $(HARFBUZZ_CFLAGS)

#### End harfbuzz configuration

LIBFONTMANAGER_EXTRA_HEADER_DIRS := \
    libfontmanager/harfbuzz \
    libfontmanager/harfbuzz/hb-ucdn \
    common/awt \
    common/font \
    libawt/java2d \
    libawt/java2d/pipe \
    libawt/java2d/loops \
    #

LIBFONTMANAGER_CFLAGS += $(LIBFREETYPE_CFLAGS)
BUILD_LIBFONTMANAGER_FONTLIB += $(LIBFREETYPE_LIBS)

LIBFONTMANAGER_OPTIMIZATION := HIGH

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBFONTMANAGER_EXCLUDE_FILES += X11FontScaler.c \
      X11TextRenderer.c
  LIBFONTMANAGER_OPTIMIZATION := HIGHEST
else ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBFONTMANAGER_EXCLUDE_FILES += X11FontScaler.c \
      X11TextRenderer.c \
      fontpath.c \
      lcdglyph.c
else
  LIBFONTMANAGER_EXCLUDE_FILES += fontpath.c \
      lcdglyph.c
endif

LIBFONTMANAGER_CFLAGS += $(X_CFLAGS) -DLE_STANDALONE -DHEADLESS

ifeq ($(TOOLCHAIN_TYPE), gcc)
  # Turn off all warnings for sunFont.c. This is needed because the specific warning
  # about discarding 'const' qualifier cannot be turned off individually.
  BUILD_LIBFONTMANAGER_sunFont.c_CFLAGS := -w
endif

# LDFLAGS clarification:
#   Filter relevant linker flags disallowing unresolved symbols as we cannot
#   build-time decide to which library to link against (libawt_headless or
#   libawt_xawt). See JDK-8196516 for details.
$(eval $(call SetupJdkLibrary, BUILD_LIBFONTMANAGER, \
    NAME := fontmanager, \
    EXCLUDE_FILES := $(LIBFONTMANAGER_EXCLUDE_FILES) \
        AccelGlyphCache.c, \
    TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
    CFLAGS := $(CFLAGS_JDKLIB) $(LIBFONTMANAGER_CFLAGS), \
    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(LIBFONTMANAGER_CFLAGS), \
    OPTIMIZATION := $(LIBFONTMANAGER_OPTIMIZATION), \
    CFLAGS_windows = -DCC_NOEX, \
    EXTRA_HEADER_DIRS := $(LIBFONTMANAGER_EXTRA_HEADER_DIRS), \
    WARNINGS_AS_ERRORS_xlc := false, \
    DISABLED_WARNINGS_gcc := sign-compare int-to-pointer-cast \
        type-limits missing-field-initializers implicit-fallthrough \
        strict-aliasing undef unused-function, \
    DISABLED_WARNINGS_CXX_gcc := reorder delete-non-virtual-dtor strict-overflow \
        maybe-uninitialized, \
    DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
        tautological-constant-out-of-range-compare int-to-pointer-cast \
        sign-compare undef missing-field-initializers, \
    DISABLED_WARNINGS_C_solstudio = \
        E_INTEGER_OVERFLOW_DETECTED \
        E_ARG_INCOMPATIBLE_WITH_ARG_L \
        E_ENUM_VAL_OVERFLOWS_INT_MAX, \
    DISABLED_WARNINGS_CXX_solstudio := \
        truncwarn wvarhidenmem wvarhidemem wbadlkginit identexpected \
        hidevf w_novirtualdescr arrowrtn2, \
    DISABLED_WARNINGS_microsoft := 4267 4244 4018 4090 4996 4146 4334 4819 4101, \
    LDFLAGS := $(subst -Xlinker -z -Xlinker defs,, \
        $(subst -Wl$(COMMA)-z$(COMMA)defs,,$(LDFLAGS_JDKLIB))) $(LDFLAGS_CXX_JDK) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
    LDFLAGS_aix := -Wl$(COMMA)-berok, \
    LIBS := $(BUILD_LIBFONTMANAGER_FONTLIB), \
    LIBS_unix := -lawt -ljava -ljvm $(LIBM) $(LIBCXX), \
    LIBS_macosx := -lawt_lwawt -framework CoreText -framework CoreFoundation \
        -framework CoreGraphics, \
    LIBS_windows := $(WIN_JAVA_LIB) advapi32.lib user32.lib gdi32.lib \
        $(WIN_AWT_LIB), \
))

$(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT)

ifeq ($(OPENJDK_TARGET_OS), macosx)
  $(BUILD_LIBFONTMANAGER): $(call FindLib, $(MODULE), awt_lwawt)
endif

ifeq ($(FREETYPE_TO_USE), bundled)
  $(BUILD_LIBFONTMANAGER): $(BUILD_LIBFREETYPE)
endif

TARGETS += $(BUILD_LIBFONTMANAGER)

################################################################################

ifeq ($(OPENJDK_TARGET_OS), windows)

  LIBJAWT_CFLAGS := -EHsc -DUNICODE -D_UNICODE

  LIBJAWT_EXTRA_HEADER_DIRS := \
      include \
      common/awt/debug \
      libawt/awt/image/cvutils \
      libawt/java2d \
      libawt/java2d/windows \
      libawt/windows \
      java.base:include \
      java.base:libjava \
      #

  ifeq ($(OPENJDK_TARGET_CPU), x86)
    KERNEL32_LIB := kernel32.lib
  endif

  $(eval $(call SetupJdkLibrary, BUILD_LIBJAWT, \
      NAME := jawt, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CXXFLAGS_JDKLIB) \
          $(LIBJAWT_CFLAGS), \
      EXTRA_HEADER_DIRS := $(LIBJAWT_EXTRA_HEADER_DIRS), \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK), \
      LIBS := $(JDKLIB_LIBS) $(KERNEL32_LIB) advapi32.lib $(WIN_AWT_LIB), \
  ))

  $(BUILD_LIBJAWT): $(BUILD_LIBAWT)

  $(eval $(call SetupCopyFiles, COPY_JAWT_LIB, \
      FILES := $(BUILD_LIBJAWT_IMPORT_LIBRARY), \
      DEST := $(SUPPORT_OUTPUTDIR)/modules_libs/$(MODULE), \
  ))

  $(COPY_JAWT_LIB): $(BUILD_LIBJAWT)

  TARGETS += $(COPY_JAWT_LIB)

else # OPENJDK_TARGET_OS not windows

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    # libjawt on macosx do not use the unix code
    LIBJAWT_EXCLUDE_SRC_PATTERNS := unix
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    JAWT_LIBS := -lawt_lwawt
  else
    JAWT_LIBS :=
    ifneq ($(OPENJDK_TARGET_OS), solaris)
      JAWT_LIBS += -lawt
    endif
    ifeq ($(ENABLE_HEADLESS_ONLY), false)
      JAWT_LIBS += -lawt_xawt
    else
      JAWT_LIBS += -lawt_headless
      ifeq ($(OPENJDK_TARGET_OS), linux)
        JAWT_CFLAGS += -DHEADLESS
      endif
    endif
  endif

  $(eval $(call SetupJdkLibrary, BUILD_LIBJAWT, \
      NAME := jawt, \
      EXCLUDE_SRC_PATTERNS := $(LIBJAWT_EXCLUDE_SRC_PATTERNS), \
      INCLUDE_FILES := $(JAWT_FILES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(JAWT_CFLAGS), \
      DISABLED_WARNINGS_clang := sign-compare, \
      EXTRA_HEADER_DIRS := \
          include \
          common/awt, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
      LDFLAGS_macosx := -Wl$(COMMA)-rpath$(COMMA)@loader_path, \
      LIBS_unix := $(JAWT_LIBS) $(JDKLIB_LIBS), \
      LIBS_solaris := $(X_LIBS) -lXrender, \
      LIBS_macosx := -framework Cocoa, \
  ))

  ifeq ($(ENABLE_HEADLESS_ONLY), false)
    $(BUILD_LIBJAWT): $(BUILD_LIBAWT_XAWT)
  else
    $(BUILD_LIBJAWT): $(call FindLib, $(MODULE), awt_headless)
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
   $(BUILD_LIBJAWT): $(call FindLib, $(MODULE), awt_lwawt)
  endif

endif # OPENJDK_TARGET_OS

TARGETS += $(BUILD_LIBJAWT)

################################################################################

ifeq ($(ENABLE_HEADLESS_ONLY), false)

  LIBSPLASHSCREEN_EXTRA_SRC := \
      common/awt/systemscale \
      #

  ifeq ($(USE_EXTERNAL_LIBGIF), false)
    LIBSPLASHSCREEN_HEADER_DIRS += libsplashscreen/giflib
  else
    LIBSPLASHSCREEN_EXCLUDES := giflib
    GIFLIB_LIBS := -lgif
  endif

  ifeq ($(USE_EXTERNAL_LIBJPEG), false)
    # While the following ought to work, it will currently pull in the closed
    # additions to this library, and this was not done previously in the build.
    # LIBSPLASHSCREEN_EXTRA_SRC += libjavajpeg
    LIBSPLASHSCREEN_EXTRA_SRC += $(TOPDIR)/src/java.desktop/share/native/libjavajpeg
  else
    LIBJPEG_LIBS := -ljpeg
  endif

  ifeq ($(USE_EXTERNAL_LIBPNG), false)
    LIBSPLASHSCREEN_HEADER_DIRS += libsplashscreen/libpng

    ifeq ($(OPENJDK_TARGET_OS), macosx)
      ifeq ($(USE_EXTERNAL_LIBZ), true)
        # When building our own libpng and using an external libz, we need to
        # inject our own libz.h to tweak the exported ZLIB_VERNUM macro. See
        # $(TOPDIR)/src/java.desktop/macosx/native/libsplashscreen/libpng/zlibwrapper/zlib.h
        # for details. This must be specified with -iquote, not -I to avoid a
        # circular include.
        LIBSPLASHSCREEN_CFLAGS += -iquote $(TOPDIR)/src/$(MODULE)/macosx/native/libsplashscreen/libpng/zlibwrapper
      endif
    endif
  else
    LIBSPLASHSCREEN_EXCLUDES += libpng
  endif

  ifeq ($(USE_EXTERNAL_LIBZ), false)
    LIBSPLASHSCREEN_EXTRA_SRC += java.base:libzip/zlib
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    # libsplashscreen on macosx do not use the unix code
    LIBSPLASHSCREEN_EXCLUDE_SRC_PATTERNS := unix
  endif

  LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE -DPNG_ARM_NEON_OPT=0

  ifeq ($(OPENJDK_TARGET_OS), linux)
    ifeq ($(OPENJDK_TARGET_CPU_ARCH), ppc)
      LIBSPLASHSCREEN_CFLAGS += -DPNG_POWERPC_VSX_OPT=0
    endif
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    LIBSPLASHSCREEN_CFLAGS += -DWITH_MACOSX

    BUILD_LIBSPLASHSCREEN_java_awt_SplashScreen.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_gfx_impl.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_gif.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_impl.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_jpeg.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_png.c_CFLAGS := -x objective-c -O0
    BUILD_LIBSPLASHSCREEN_splashscreen_sys.m_CFLAGS := -O0

  else ifeq ($(OPENJDK_TARGET_OS), windows)
    LIBSPLASHSCREEN_CFLAGS += -DWITH_WIN32
  else
    LIBSPLASHSCREEN_CFLAGS += -DWITH_X11 $(X_CFLAGS)
  endif

  LIBSPLASHSCREEN_LIBS :=

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    LIBSPLASHSCREEN_LIBS += \
        $(LIBM) -lpthread -liconv -losxapp \
        -framework ApplicationServices \
        -framework Foundation \
        -framework Cocoa \
        -framework JavaNativeFoundation
  else ifeq ($(OPENJDK_TARGET_OS), windows)
    LIBSPLASHSCREEN_LIBS += kernel32.lib user32.lib gdi32.lib delayimp.lib $(WIN_JAVA_LIB) jvm.lib
  else
    LIBSPLASHSCREEN_LIBS += $(X_LIBS) -lX11 -lXext $(LIBM) -lpthread -ldl
  endif

  LIBSPLASHSCREEN_HEADER_DIRS += \
      libosxapp \
      java.base:include \
      java.base:libjava \
      #

  $(eval $(call SetupJdkLibrary, BUILD_LIBSPLASHSCREEN, \
      NAME := splashscreen, \
      EXTRA_SRC := $(LIBSPLASHSCREEN_EXTRA_SRC), \
      EXCLUDE_SRC_PATTERNS := $(LIBSPLASHSCREEN_EXCLUDE_SRC_PATTERNS), \
      EXCLUDE_FILES := imageioJPEG.c jpegdecoder.c pngtest.c, \
      EXCLUDES := $(LIBSPLASHSCREEN_EXCLUDES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) $(LIBSPLASHSCREEN_CFLAGS) \
          $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
      EXTRA_HEADER_DIRS := $(LIBSPLASHSCREEN_HEADER_DIRS), \
      DISABLED_WARNINGS_gcc := sign-compare type-limits unused-result \
          maybe-uninitialized shift-negative-value implicit-fallthrough \
          unused-function, \
      DISABLED_WARNINGS_clang := incompatible-pointer-types sign-compare, \
      DISABLED_WARNINGS_solstudio := E_NEWLINE_NOT_LAST E_DECLARATION_IN_CODE \
          E_STATEMENT_NOT_REACHED, \
      DISABLED_WARNINGS_microsoft := 4018 4244 4267, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_macosx := -L$(INSTALL_LIBRARIES_HERE), \
      LDFLAGS_windows := -delayload:user32.dll, \
      LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ_LIBS) \
          $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \
      LIBS_aix := -liconv, \
  ))

  TARGETS += $(BUILD_LIBSPLASHSCREEN)

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    $(BUILD_LIBSPLASHSCREEN): $(call FindLib, $(MODULE), osxapp)
  endif

endif

################################################################################

ifeq ($(OPENJDK_TARGET_OS), macosx)

  LIBAWT_LWAWT_EXTRA_SRC := \
      $(TOPDIR)/src/$(MODULE)/unix/native/common/awt \
      $(TOPDIR)/src/$(MODULE)/share/native/common/font \
      $(TOPDIR)/src/$(MODULE)/share/native/common/java2d \
      #

  LIBAWT_LWAWT_EXTRA_HEADER_DIRS := \
      $(LIBAWT_DEFAULT_HEADER_DIRS) \
      libawt_lwawt/awt \
      libawt_lwawt/font \
      libawt_lwawt/java2d/opengl \
      include \
      common/awt/debug \
      common/java2d/opengl \
      libosxapp \
      #

  LIBAWT_LWAWT_CFLAGS := $(X_CFLAGS) $(X_LIBS)

  LIBAWT_LWAWT_EXFILES := fontpath.c awt_Font.c X11Color.c
  LIBAWT_LWAWT_EXCLUDES := $(TOPDIR)/src/$(MODULE)/unix/native/common/awt/medialib

  $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_LWAWT, \
      NAME := awt_lwawt, \
      EXTRA_SRC := $(LIBAWT_LWAWT_EXTRA_SRC), \
      INCLUDE_FILES := $(LIBAWT_LWAWT_FILES), \
      EXCLUDE_FILES := $(LIBAWT_LWAWT_EXFILES), \
      EXCLUDES := $(LIBAWT_LWAWT_EXCLUDES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(LIBAWT_LWAWT_CFLAGS), \
      EXTRA_HEADER_DIRS := $(LIBAWT_LWAWT_EXTRA_HEADER_DIRS), \
      DISABLED_WARNINGS_clang := incomplete-implementation enum-conversion \
          deprecated-declarations objc-method-access bitwise-op-parentheses \
          incompatible-pointer-types parentheses-equality extra-tokens \
          sign-compare semicolon-before-method-body format-nonliteral undef \
          pointer-arith, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN) \
          -L$(INSTALL_LIBRARIES_HERE), \
      LIBS := -lawt -lmlib_image -losxapp -ljvm $(LIBM) \
          -framework Accelerate \
          -framework ApplicationServices \
          -framework AudioToolbox \
          -framework Carbon \
          -framework Cocoa \
          -framework Security \
          -framework ExceptionHandling \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -framework OpenGL \
          -framework QuartzCore -ljava, \
  ))

  TARGETS += $(BUILD_LIBAWT_LWAWT)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBAWT)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBMLIB_IMAGE)

  $(BUILD_LIBAWT_LWAWT): $(call FindLib, $(MODULE), osxapp)

  $(BUILD_LIBAWT_LWAWT): $(call FindLib, java.base, java)

endif

################################################################################

ifeq ($(OPENJDK_TARGET_OS), macosx)

  $(eval $(call SetupJdkLibrary, BUILD_LIBOSXUI, \
      NAME := osxui, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB), \
      EXTRA_HEADER_DIRS := \
          libawt_lwawt/awt \
          libosxapp, \
      DISABLED_WARNINGS_clang := deprecated-declarations sign-compare, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN) \
          -Wl$(COMMA)-rpath$(COMMA)@loader_path \
          -L$(INSTALL_LIBRARIES_HERE), \
      LIBS := -lawt -losxapp -lawt_lwawt \
          -framework Cocoa \
          -framework Carbon \
          -framework ApplicationServices \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -ljava -ljvm, \
  ))

  TARGETS += $(BUILD_LIBOSXUI)

  $(BUILD_LIBOSXUI): $(BUILD_LIBAWT)

  $(BUILD_LIBOSXUI): $(call FindLib, $(MODULE), osxapp)

  $(BUILD_LIBOSXUI): $(BUILD_LIBAWT_LWAWT)

endif

################################################################################

# Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, lib/Awt2dLibraries.gmk))