jdk/makefiles/CompileNativeLibraries.gmk
author chegar
Mon, 21 Oct 2013 15:00:56 +0100
changeset 22332 fba4c66089bb
parent 22317 b420ef26d238
parent 20884 66f924cdfeb9
permissions -rw-r--r--
Merge

#
# Copyright (c) 2011, 2013, 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.
#

default: all

include $(SPEC)
include MakeBase.gmk
include NativeCompilation.gmk

# Setup the java compilers for the JDK build.
include Setup.gmk

# Copy files (can now depend on $(COPY_FILES))
include CopyFiles.gmk

# Prepare the find cache. Only used if running on windows.
$(eval $(call FillCacheFind, $(JDK_TOPDIR)/src))

# Build tools
include Tools.gmk

# Include the javah generated headers.
CFLAGS_JDKLIB += -I$(JDK_OUTPUTDIR)/gensrc_headers
CXXFLAGS_JDKLIB += -I$(JDK_OUTPUTDIR)/gensrc_headers

# Put the libraries here. Different locations for different target apis.
ifeq ($(OPENJDK_TARGET_OS_API), posix)
  INSTALL_LIBRARIES_HERE := $(JDK_OUTPUTDIR)/lib$(OPENJDK_TARGET_CPU_LIBDIR)
else
  INSTALL_LIBRARIES_HERE := $(JDK_OUTPUTDIR)/bin
endif

BUILD_LIBRARIES =

# Absolute paths to lib files on windows for use in LDFLAGS. Should figure out a more
# elegant solution to this.
WIN_VERIFY_LIB := $(JDK_OUTPUTDIR)/objs/libverify/verify.lib
WIN_JAVA_LIB := $(JDK_OUTPUTDIR)/objs/libjava/java.lib
WIN_AWT_LIB := $(JDK_OUTPUTDIR)/objs/libawt/awt.lib

# Use this variable to set DEBUG_SYMBOLS true on windows for all libraries, but
# not on other platforms.
ifeq ($(OPENJDK_TARGET_OS), windows)
  DEBUG_ALL_BINARIES := true
endif

# Build everything with debugging on OpenJDK
ifdef OPENJDK
  DEBUG_ALL_BINARIES := true
endif

#
# TODO replace with X_FLAGS / X_LIBS
# and add them to configure
#
OPENWIN_LIB := $(OPENWIN_HOME)/lib

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

BUILD_LIBFDLIBM_OPTIMIZATION := HIGH

ifneq ($(OPENJDK_TARGET_OS), solaris)
  BUILD_LIBFDLIBM_OPTIMIZATION := NONE
endif

ifneq ($(OPENJDK_TARGET_OS), macosx)
  $(eval $(call SetupNativeCompilation,BUILD_LIBFDLIBM, \
      STATIC_LIBRARY := fdlibm, \
      OUTPUT_DIR := $(JDK_OUTPUTDIR)/objs, \
      SRC := $(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/src, \
      LANG := C, \
      OPTIMIZATION := $(BUILD_LIBFDLIBM_OPTIMIZATION), \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/include, \
      CFLAGS_windows_debug := -DLOGGING, \
      ARFLAGS := $(ARFLAGS), \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libfdlibm, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

else

# On macosx the old build does partial (incremental) linking of fdlibm instead of
# a plain static library.
  $(eval $(call SetupNativeCompilation,BUILD_LIBFDLIBM_MAC, \
      LIBRARY := fdlibm, \
      OUTPUT_DIR := $(JDK_OUTPUTDIR)/objs/libfdlibm, \
      SRC := $(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/src, \
      LANG := C, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/include, \
      LDFLAGS := -nostdlib -r -arch x86_64, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libfdlibm, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBFDLIBM := $(JDK_OUTPUTDIR)/objs/$(LIBRARY_PREFIX)fdlibm$(STATIC_LIBRARY_SUFFIX)
  $(BUILD_LIBFDLIBM): $(BUILD_LIBFDLIBM_MAC)
	$(call install-file)

endif
BUILD_LIBRARIES += $(BUILD_LIBFDLIBM)

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

BUILD_LIBVERIFY_SRC := check_code.c check_format.c

ifeq ($(OPENJDK_TARGET_OS), solaris)
  ifneq ($(OPENJDK_TARGET_CPU), x86_64)
    BUILD_LIBVERIFY_REORDER := $(JDK_TOPDIR)/makefiles/mapfiles/libverify/reorder-$(OPENJDK_TARGET_CPU)
  endif
endif

LIBVERIFY_OPTIMIZATION := HIGH
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
  ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
    LIBVERIFY_OPTIMIZATION := LOW
  endif
endif


$(eval $(call SetupNativeCompilation,BUILD_LIBVERIFY, \
    LIBRARY := verify, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/common, \
    INCLUDE_FILES := $(BUILD_LIBVERIFY_SRC), \
    LANG := C, \
    OPTIMIZATION := $(LIBVERIFY_OPTIMIZATION), \
    CFLAGS := $(CFLAGS_JDKLIB), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libverify/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_posix := -ljvm -lc, \
    LDFLAGS_SUFFIX_windows := jvm.lib, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=verify.dll" \
        -D "JDK_INTERNAL_NAME=verify" \
        -D "JDK_FTYPE=0x2L", \
    REORDER := $(BUILD_LIBVERIFY_REORDER), \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libverify, \
    DEBUG_SYMBOLS := true))

BUILD_LIBRARIES += $(BUILD_LIBVERIFY)

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

LIBJAVA_SRC_DIRS := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/lang \
  $(JDK_TOPDIR)/src/share/native/java/lang \
  $(JDK_TOPDIR)/src/share/native/java/lang/ref \
  $(JDK_TOPDIR)/src/share/native/java/lang/reflect \
  $(JDK_TOPDIR)/src/share/native/java/io \
  $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/io \
  $(JDK_TOPDIR)/src/share/native/java/nio \
  $(JDK_TOPDIR)/src/share/native/java/security \
  $(JDK_TOPDIR)/src/share/native/common \
  $(JDK_TOPDIR)/src/share/native/sun/misc \
  $(JDK_TOPDIR)/src/share/native/sun/reflect \
  $(JDK_TOPDIR)/src/share/native/java/util \
  $(JDK_TOPDIR)/src/share/native/java/util/concurrent/atomic \
  $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/common \
  $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/util

ifneq ($(OPENJDK_TARGET_OS), macosx)
  LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/util/locale/provider
else
  LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/macosx/native/sun/util/locale/provider
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/provider \
      $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/io
endif

LIBJAVA_CFLAGS := $(foreach dir, $(LIBJAVA_SRC_DIRS), -I$(dir)) \
    -I$(JDK_TOPDIR)/src/share/native/java/lang/fdlibm/include \
    -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"'

LIBJAVA_CFLAGS += -DJDK_MAJOR_VERSION='"$(JDK_MAJOR_VERSION)"' \
    -DJDK_MINOR_VERSION='"$(JDK_MINOR_VERSION)"' \
    -DJDK_MICRO_VERSION='"$(JDK_MICRO_VERSION)"' \
     -DJDK_BUILD_NUMBER='"$(JDK_BUILD_NUMBER)"'

ifneq (, $(JDK_UPDATE_VERSION))
  LIBJAVA_CFLAGS += -DJDK_UPDATE_VERSION='"$(JDK_UPDATE_VERSION)"'
endif

LIBJAVA_EXCLUDE_FILES := check_code.c check_format.c jspawnhelper.c

ifneq ($(OPENJDK_TARGET_OS), macosx)
  LIBJAVA_EXCLUDE_FILES += java_props_macosx.c
else
  BUILD_LIBJAVA_java_props_md.c_CFLAGS := -x objective-c
  BUILD_LIBJAVA_java_props_macosx.c_CFLAGS := -x objective-c
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBJAVA_EXCLUDE_FILES += \
      UNIXProcess_md.c \
      UnixFileSystem_md.c \
      FileSystemPreferences.c
else
  LIBJAVA_EXCLUDE_FILES += \
      ProcessImpl_md.c \
      WinNTFileSystem_md.c \
      dirent_md.c \
      WindowsPreferences.c \
      sun/security/provider/WinCAPISeedGenerator.c \
      sun/io/Win32ErrorMode.c
endif

ifeq ($(OPENJDK_TARGET_OS), solaris)
  ifneq ($(OPENJDK_TARGET_CPU), x86_64)
    LIBJAVA_REORDER := $(JDK_TOPDIR)/makefiles/mapfiles/libjava/reorder-$(OPENJDK_TARGET_CPU)
  endif
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \
    LIBRARY := java, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(LIBJAVA_SRC_DIRS), \
    EXCLUDES := fdlibm/src zip, \
    EXCLUDE_FILES := $(LIBJAVA_EXCLUDE_FILES), \
    LANG := C, \
    OPTIMIZATION := HIGH, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(LIBJAVA_CFLAGS), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjava/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_posix := -ljvm -lverify, \
    LDFLAGS_SUFFIX_solaris := -lsocket -lnsl -lscf $(LIBDL) $(BUILD_LIBFDLIBM) -lc, \
    LDFLAGS_SUFFIX_linux := $(LIBDL) $(BUILD_LIBFDLIBM), \
    LDFLAGS_SUFFIX_macosx := -L$(JDK_OUTPUTDIR)/objs/ -lfdlibm \
        -framework CoreFoundation \
        -framework Foundation \
        -framework Security -framework SystemConfiguration, \
    LDFLAGS_SUFFIX_windows := -export:winFileHandleOpen -export:handleLseek \
        jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \
        shell32.lib delayimp.lib -DELAYLOAD:shell32.dll \
        advapi32.lib, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=java.dll" \
        -D "JDK_INTERNAL_NAME=java" \
        -D "JDK_FTYPE=0x2L", \
    REORDER := $(LIBJAVA_REORDER), \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjava, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBJAVA)

$(BUILD_LIBJAVA): $(LIBJLI_BINARY)

$(BUILD_LIBJAVA): $(BUILD_LIBVERIFY)

$(BUILD_LIBJAVA): $(BUILD_LIBFDLIBM)

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

BUILD_LIBMLIB_SRC := $(JDK_TOPDIR)/src/share/native/sun/awt/medialib
BUILD_LIBMLIB_CFLAGS := -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES \
    -I$(BUILD_LIBMLIB_SRC) \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt/medialib

BUILD_LIBMLIB_LDLIBS :=
BUILD_LIBMLIB_IMAGE_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libmlib_image/mapfile-vers

BUILD_LIBMLIB_CFLAGS += -DMLIB_NO_LIBSUNMATH

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

ifneq ($(OPENJDK_TARGET_OS), windows)
  BUILD_LIBMLIB_LDLIBS += $(LIBM) $(LIBDL)
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBMLIB_IMAGE, \
    LIBRARY := mlib_image, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(BUILD_LIBMLIB_SRC), \
    EXCLUDE_FILES := awt_ImagingLib.c mlib_c_ImageBlendTable.c, \
    LANG := C, \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(BUILD_LIBMLIB_CFLAGS), \
    MAPFILE := $(BUILD_LIBMLIB_IMAGE_MAPFILE), \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX := $(BUILD_LIBMLIB_LDLIBS) \
        $(LDFLAGS_JDKLIB_SUFFIX), \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=mlib_image.dll" \
        -D "JDK_INTERNAL_NAME=mlib_image" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libmlib_image, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBMLIB_IMAGE): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBMLIB_IMAGE)

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

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

  BUILD_LIBMLIB_IMAGE_V_FILES := \
      mlib_v_ImageLookUp.c \
      mlib_ImageCreate.c \
      mlib_ImageAffine.c \
      mlib_ImageConvMxN.c \
      mlib_ImageConvKernelConvert.c \
      mlib_sys.c \
      mlib_ImageLookUp_64.c \
      mlib_ImageLookUp_Bit.c \
      mlib_ImageColorTrue2Index.c \
      mlib_c_ImageThresh1_U8.c \
      mlib_v_ImageLookUpS16S16Func.c \
      mlib_v_ImageLookUpS16S32Func.c \
      mlib_v_ImageLookUpS16U16Func.c \
      mlib_v_ImageLookUpS16U8Func.c \
      mlib_v_ImageLookUpS32S16Func.c \
      mlib_v_ImageLookUpS32S32Func.c \
      mlib_v_ImageLookUpS32U16Func.c \
      mlib_v_ImageLookUpS32U8Func.c \
      mlib_v_ImageLookUpSIS16S16Func.c \
      mlib_v_ImageLookUpSIS16S32Func.c \
      mlib_v_ImageLookUpSIS16U16Func.c \
      mlib_v_ImageLookUpSIS16U8Func.c \
      mlib_v_ImageLookUpSIS32S16Func.c \
      mlib_v_ImageLookUpSIS32S32Func.c \
      mlib_v_ImageLookUpSIS32U16Func.c \
      mlib_v_ImageLookUpSIS32U8Func.c \
      mlib_v_ImageLookUpSIU16S16Func.c \
      mlib_v_ImageLookUpSIU16S32Func.c \
      mlib_v_ImageLookUpSIU16U16Func.c \
      mlib_v_ImageLookUpSIU16U8Func.c \
      mlib_v_ImageLookUpSIU8S16Func.c \
      mlib_v_ImageLookUpSIU8S32Func.c \
      mlib_v_ImageLookUpSIU8U16Func.c \
      mlib_v_ImageLookUpSIU8U8Func.c \
      mlib_v_ImageLookUpU16S16Func.c \
      mlib_v_ImageLookUpU16S32Func.c \
      mlib_v_ImageLookUpU16U16Func.c \
      mlib_v_ImageLookUpU16U8Func.c \
      mlib_v_ImageLookUpU8S16Func.c \
      mlib_v_ImageLookUpU8S32Func.c \
      mlib_v_ImageLookUpU8U16Func.c \
      mlib_v_ImageLookUpU8U8Func.c \
      mlib_v_ImageAffineIndex_BC.c \
      mlib_v_ImageAffine_BC.c \
      mlib_v_ImageAffine_BC_S16.c \
      mlib_v_ImageAffine_BC_U16.c \
      mlib_v_ImageAffine_BL.c \
      mlib_v_ImageAffine_BL_S16.c \
      mlib_v_ImageAffine_BL_U16.c \
      mlib_v_ImageAffine_NN.c \
      mlib_v_ImageFilters.c \
      mlib_ImageAffineEdge.c \
      mlib_ImageAffine_BC_D64.c \
      mlib_ImageAffine_BC_F32.c \
      mlib_ImageAffine_BC_S32.c \
      mlib_ImageAffine_BL_D64.c \
      mlib_ImageAffine_BL_F32.c \
      mlib_ImageAffine_BL_S32.c \
      mlib_ImageAffine_NN.c \
      mlib_ImageAffine_NN_Bit.c \
      mlib_ImageFilters.c \
      mlib_ImageScanPoly.c \
      mlib_ImageConv_8nw.c \
      mlib_ImageConv_8ext.c \
      mlib_ImageConv_16nw.c \
      mlib_ImageConv_16ext.c \
      mlib_ImageConv_u16nw.c \
      mlib_ImageConv_u16ext.c \
      mlib_ImageConv_32nw.c \
      mlib_ImageConv_F32nw.c \
      mlib_ImageConvMxN_Fp.c \
      mlib_ImageConvMxN_ext.c \
      mlib_ImageConv_D64nw.c \
      mlib_ImageClipping.c \
      mlib_ImageConvCopyEdge_Bit.c \
      mlib_ImageConvClearEdge_Bit.c \
      mlib_ImageConv2x2_f.c \
      mlib_ImageConvClearEdge_Fp.c \
      mlib_v_ImageConvMxN_8.c \
      mlib_v_ImageConvClearEdge.c \
      mlib_v_ImageConvCopyEdge.c \
      mlib_v_ImageConvMxN_8ext.c \
      mlib_v_ImageConvVersion.c \
      mlib_v_ImageConv_8nw.c \
      mlib_ImageConvCopyEdge_Fp.c \
      mlib_v_ImageChannelInsert_1.c \
      mlib_v_ImageChannelExtract_43.c \
      mlib_v_ImageChannelExtract_1.c \
      mlib_ImageCopy_Bit.c \
      mlib_v_ImageCopy_f.c \
      mlib_ImageUtils.c \
      mlib_ImageDivTables.c

  BUILD_LIBMLIB_V_CFLAGS := $(filter-out -DMLIB_NO_LIBSUNMATH, $(BUILD_LIBMLIB_CFLAGS))

  $(eval $(call SetupNativeCompilation,BUILD_LIBMLIB_IMAGE_V, \
      LIBRARY := mlib_image_v, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/share/native/sun/awt/medialib \
          $(JDK_TOPDIR)/src/solaris/native/sun/awt/medialib, \
      LANG := C, \
      INCLUDE_FILES := $(BUILD_LIBMLIB_IMAGE_V_FILES), \
      OPTIMIZATION := HIGHEST, \
      CFLAGS := -xarch=sparcvis \
          $(JDK_TOPDIR)/src/solaris/native/sun/awt/medialib/vis_$(OPENJDK_TARGET_CPU_BITS).il \
          $(BUILD_LIBMLIB_V_CFLAGS) \
          $(CFLAGS_JDKLIB), \
      MAPFILE := $(BUILD_LIBMLIB_IMAGE_MAPFILE), \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(BUILD_LIBMLIB_LDLIBS) -ljava -ljvm \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX_solaris := -lc, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libmlib_image_v, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBMLIB_IMAGE_V): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBMLIB_IMAGE_V)

endif

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

LIBAWT_DIRS := \
    $(JDK_TOPDIR)/src/share/native/sun/awt \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt \
    $(JDK_TOPDIR)/src/share/native/sun/awt/image \
    $(JDK_TOPDIR)/src/share/native/sun/awt/image/gif \
    $(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
    $(JDK_TOPDIR)/src/share/native/sun/awt/medialib \
    $(JDK_TOPDIR)/src/share/native/sun/awt/debug \
    $(JDK_TOPDIR)/src/share/native/sun/awt/utility \
    $(JDK_TOPDIR)/src/share/native/sun/java2d \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d \
    $(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
    $(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
    $(JDK_TOPDIR)/src/share/native/sun/awt/image \
    $(JDK_TOPDIR)/src/share/native/sun/java2d/opengl \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/opengl \
    $(JDK_TOPDIR)/src/share/native/sun/font

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBAWT_DIRS += \
      $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/windows \
      $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/windows \
      $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/d3d
else
  LIBAWT_DIRS += \
      $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/x11
endif

LIBAWT_CFLAGS += -D__MEDIALIB_OLD_NAMES -D__USE_J2D_NAMES \
    $(X_CFLAGS) \
    $(foreach dir, $(LIBAWT_DIRS), -I$(dir))

LIBAWT_FILES := \
    gifdecoder.c \
    imageInitIDs.c \
    img_globals.c \
    SurfaceData.c \
    Region.c \
    BufImgSurfaceData.c \
    Disposer.c \
    Trace.c \
    GraphicsPrimitiveMgr.c \
    Blit.c \
    BlitBg.c \
    ScaledBlit.c \
    FillRect.c \
    FillSpans.c \
    FillParallelogram.c \
    DrawParallelogram.c \
    DrawLine.c \
    DrawRect.c \
    DrawPolygons.c \
    DrawPath.c \
    FillPath.c \
    ProcessPath.c \
    MaskBlit.c \
    MaskFill.c \
    TransformHelper.c \
    AlphaMath.c \
    AlphaMacros.c \
    AnyByte.c \
    ByteBinary1Bit.c \
    ByteBinary2Bit.c \
    ByteBinary4Bit.c \
    ByteIndexed.c \
    ByteGray.c \
    Index8Gray.c \
    Index12Gray.c \
    AnyShort.c \
    Ushort555Rgb.c \
    Ushort565Rgb.c \
    Ushort4444Argb.c \
    Ushort555Rgbx.c \
    UshortGray.c \
    UshortIndexed.c \
    Any3Byte.c \
    ThreeByteBgr.c \
    AnyInt.c \
    IntArgb.c \
    IntArgbPre.c \
    IntArgbBm.c \
    IntRgb.c \
    IntBgr.c \
    IntRgbx.c \
    Any4Byte.c \
    FourByteAbgr.c \
    FourByteAbgrPre.c \
    BufferedMaskBlit.c \
    BufferedRenderPipe.c \
    ShapeSpanIterator.c \
    SpanClipRenderer.c \
    awt_ImageRep.c \
    awt_ImagingLib.c \
    awt_Mlib.c \
    awt_parseImage.c \
    DataBufferNative.c \
    dither.c \
    debug_assert.c \
    debug_mem.c \
    debug_trace.c \
    debug_util.c

ifneq (, $(filter $(OPENJDK_TARGET_OS), solaris linux))
  LIBAWT_FILES += awt_LoadLibrary.c initIDs.c img_colors.c
endif

ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBAWT_FILES += awt_LoadLibrary.c img_colors.c
  LIBAWT_CFLAGS += -F/System/Library/Frameworks/JavaVM.framework/Frameworks
endif

ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)
  LIBAWT_CFLAGS += -DMLIB_ADD_SUFF
  LIBAWT_CFLAGS += -xarch=sparcvis
  LIBAWT_CFLAGS += $(JDK_TOPDIR)/src/solaris/native/sun/awt/medialib/vis_$(OPENJDK_TARGET_CPU_BITS).il
  LIBAWT_CFLAGS += \
      -I$(JDK_TOPDIR)/src/solaris/native/sun/awt/medialib \
      -I$(JDK_TOPDIR)/src/solaris/native/sun/java2d/medialib \
      -I$(JDK_TOPDIR)/src/solaris/native/sun/java2d/loops

  LIBAWT_DIRS += $(JDK_TOPDIR)/src/solaris/native/sun/awt/medialib \
      $(JDK_TOPDIR)/src/solaris/native/sun/java2d/loops

  LIBAWT_FILES += \
      vis_FuncArray.c \
      java2d_Mlib.c \
      mlib_ImageCreate.c \
      mlib_ImageZoom_NN.c \
      mlib_ImageCopy_Bit.c \
      mlib_sys.c \
      mlib_v_ImageClear.c \
      mlib_v_ImageClear_f.c \
      mlib_v_ImageConstXor.c \
      mlib_v_ImageCopy.c \
      mlib_v_ImageCopy_f.c \
      mlib_v_ImageXor.c \
      mlib_v_ImageZoom_NN_f.c \
      vis_Interp.c \
      vis_AlphaMacros.c \
      vis_AlphaMaskBlit.c \
      vis_AlphaMaskFill.c \
      vis_ByteGray.c \
      vis_ByteGray_FromRgb.c \
      vis_ByteGray_Mask.c \
      vis_ByteIndexed.c \
      vis_DrawLine.c \
      vis_FourByteAbgr.c \
      vis_IntArgb.c \
      vis_IntArgbPre.c \
      vis_IntArgbPre_Mask.c \
      vis_IntBgr.c \
      vis_IntRgb.c \
      vis_IntRgbx.c \
      vis_SrcMaskFill.c \
      vis_SrcOverMaskBlit.c \
      vis_SrcOverMaskFill.c \
      vis_FourByteAbgrPre.c \
      vis_GlyphList.c \
      vis_GlyphListXor.c \
      vis_IntArgbBm.c \
      vis_ThreeByteBgr.c \
      vis_UshortGray.c \
      vis_UshortGray_FromRgb.c \
      vis_XorBlit.c \
      mlib_v_ImageCopy_blk.s

  ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
    LIBAWT_ASFLAGS = -P -xarch=v9a
  else
    LIBAWT_ASFLAGS = -P -xarch=v8plusa
  endif
else
  LIBAWT_FILES += MapAccelFunc.c
endif

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

LIBAWT_LANG := C

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBAWT_FILES += AccelGlyphCache.c \
      ShaderList.c \
      CmdIDList.cpp \
      Hashtable.cpp \
      GDIHashtable.cpp \
      Devices.cpp \
      ObjectList.cpp \
      GDIBlitLoops.cpp \
      GDIRenderer.cpp \
      GDIWindowSurfaceData.cpp \
      WindowsFlags.cpp \
      WPrinterJob.cpp \
      awt_%.cpp \
      D3DBlitLoops.cpp \
      D3DBufImgOps.cpp \
      D3DContext.cpp \
      D3DGlyphCache.cpp \
      D3DGraphicsDevice.cpp \
      D3DMaskBlit.cpp \
      D3DMaskCache.cpp \
      D3DMaskFill.cpp \
      D3DPipelineManager.cpp \
      D3DPaints.cpp \
      D3DRenderer.cpp \
      D3DRenderQueue.cpp \
      D3DResourceManager.cpp \
      D3DSurfaceData.cpp \
      D3DTextRenderer.cpp \
      D3DVertexCacher.cpp \
      ShellFolder2.cpp \
      ThemeReader.cpp \
      ComCtl32Util.cpp \
      DllUtil.cpp \
      initIDs.cpp \
      MouseInfo.cpp \
      rect.c \
      OGLBlitLoops.c \
      OGLBufImgOps.c \
      OGLContext.c \
      OGLFuncs.c \
      OGLMaskBlit.c \
      OGLMaskFill.c \
      OGLPaints.c \
      OGLRenderQueue.c \
      OGLRenderer.c \
      OGLSurfaceData.c \
      OGLTextRenderer.c \
      OGLVertexCache.c \
      WGLGraphicsConfig.c \
      WGLSurfaceData.c

  LIBAWT_LANG := C++
  LIBAWT_CFLAGS += -EHsc -DUNICODE -D_UNICODE
  ifeq ($(OPENJDK_TARGET_CPU_BITS), 64)
    LIBAWT_CFLAGS += -DMLIB_OS64BIT
  endif

  ifdef OPENJDK
    LIBAWT_RC_FLAGS := -i "$(JDK_TOPDIR)/src/windows/resource/icons"
  else
    LIBAWT_RC_FLAGS := -i "$(JDK_TOPDIR)/src/closed/windows/native/sun/windows"
  endif
  LIBAWT_VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/native/sun/windows/awt.rc
endif

ifeq ($(MILESTONE), internal)
  LIBAWT_CFLAGS += -DINTERNAL_BUILD
endif

LIBAWT_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libawt/mapfile-vers
ifeq ($(OPENJDK_TARGET_OS), linux)
  LIBAWT_MAPFILE :=
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBAWT, \
    LIBRARY := awt, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(LIBAWT_DIRS), \
    INCLUDE_FILES := $(LIBAWT_FILES), \
    LANG := $(LIBAWT_LANG), \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_CFLAGS), \
    ASFLAGS := $(LIBAWT_ASFLAGS), \
    MAPFILE := $(LIBAWT_MAPFILE), \
    LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_solaris := -R/usr/dt/lib$(OPENJDK_TARGET_CPU_ISADIR) -R$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR), \
    LDFLAGS_SUFFIX_linux := -ljvm $(LIBM) $(LIBDL) -ljava, \
    LDFLAGS_SUFFIX_solaris := -ljvm $(LIBM) $(LIBDL) -ljava -lc, \
    LDFLAGS_SUFFIX_macosx := -lmlib_image -ljvm $(LIBM) \
        -framework Cocoa \
        -framework OpenGL \
        -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
        -framework JavaNativeFoundation \
        -framework JavaRuntimeSupport \
        -framework ApplicationServices \
        -framework AudioToolbox \
        -ljava, \
    LDFLAGS_SUFFIX_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 \
        -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, \
    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", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libawt, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBAWT): $(BUILD_LIBJAVA)

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

BUILD_LIBRARIES += $(BUILD_LIBAWT)

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

# TODO!!
# Even though this variable as a general name, it is
# only used on macos, in fontpath.c, as prefix for where to find fonts.
#
# It's used for libawt_headless _and_ libawt_xawt
#
X11_PATH := /usr/X11R6

ifneq ($(OPENJDK_TARGET_OS), windows)
  ifndef BUILD_HEADLESS_ONLY

    LIBAWT_XAWT_DIRS := \
        $(JDK_TOPDIR)/src/share/native/sun/awt/debug \
        $(JDK_TOPDIR)/src/share/native/sun/awt/utility \
        $(JDK_TOPDIR)/src/share/native/sun/font \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/font \
        $(JDK_TOPDIR)/src/share/native/sun/java2d/opengl \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/opengl \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/x11 \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/xawt \

    LIBAWT_XAWT_CFLAGS := -DXAWT -DXAWT_HACK \
        -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
        $(CUPS_CFLAGS) \
        $(foreach dir, $(LIBAWT_XAWT_DIRS), -I$(dir)) \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/jdga

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

    ifeq ($(OPENJDK_TARGET_OS), linux)
      ifndef OPENJDK
        include $(JDK_TOPDIR)/make/closed/xawt.gmk
      endif

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

    ifeq ($(MILESTONE), internal)
      LIBAWT_XAWT_CFLAGS += -DINTERNAL_BUILD
    endif

    LIBAWT_XAWT_FILES := \
        XlibWrapper.c \
        XWindow.c \
        XToolkit.c \
        X11Color.c \
        X11SurfaceData.c \
        awt_GraphicsEnv.c \
        awt_InputMethod.c \
        robot_common.c \
        awt_Robot.c \
        list.c \
        multiVis.c \
        initIDs.c \
        awt_util.c \
        awt_Desktop.c \
        awt_UNIXToolkit.c \
        X11FontScaler_md.c \
        X11TextRenderer_md.c \
        fontpath.c \
        awt_Insets.c \
        awt_Event.c \
        X11Renderer.c \
        X11PMBlitLoops.c \
        OGLBlitLoops.c \
        OGLBufImgOps.c \
        OGLContext.c \
        OGLFuncs.c \
        OGLMaskBlit.c \
        OGLMaskFill.c \
        OGLPaints.c \
        OGLRenderQueue.c \
        OGLRenderer.c \
        OGLSurfaceData.c \
        OGLTextRenderer.c \
        OGLVertexCache.c \
        GLXGraphicsConfig.c \
        GLXSurfaceData.c \
        AccelGlyphCache.c \
        awt_Font.c \
        multi_font.c \
        awt_AWTEvent.c \
        awt_DrawingSurface.c \
        jawt.c \
        CUPSfuncs.c \
        debug_assert.c \
        debug_mem.c \
        debug_trace.c \
        debug_util.c \
        awt_Plugin.c \
        gnome_interface.c \
        gtk2_interface.c \
        swing_GTKEngine.c \
        swing_GTKStyle.c \
        rect.c \
        sun_awt_X11_GtkFileDialogPeer.c \
        XRSurfaceData.c \
        XRBackendNative.c

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

    ifeq ($(OPENJDK_TARGET_OS), linux)
      # To match old build, add this to LDFLAGS instead of suffix.
      LIBAWT_XAWT_LDFLAGS += -lpthread
    endif

    ifeq ($(OPENJDK_TARGET_OS), macosx)
      LIBAWT_XAWT_LDFLAGS_SUFFIX += -lpthread
    endif

    # On macosx, the shared library origin is set twice for this lib.
    $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_XAWT, \
        LIBRARY := awt_xawt, \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(LIBAWT_XAWT_DIRS), \
        INCLUDE_FILES := $(LIBAWT_XAWT_FILES), \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_XAWT_CFLAGS) \
            $(X_CFLAGS), \
        MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libawt_xawt/mapfile-vers, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(X_LIBS) $(LIBAWT_XAWT_LDFLAGS), \
        LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN) \
            $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
        LDFLAGS_solaris := -L$(OPENWIN_HOME)/sfw/lib$(OPENJDK_TARGET_CPU_ISADIR) \
            -L$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR) \
            -R$(OPENWIN_HOME)/sfw/lib$(OPENJDK_TARGET_CPU_ISADIR) \
            -R$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR) \
            -R/usr/dt/lib$(OPENJDK_TARGET_CPU_ISADIR) \
            $(call SET_SHARED_LIBRARY_ORIGIN) \
            $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
        LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN) \
            $(call SET_SHARED_LIBRARY_ORIGIN). \
            $(call SET_SHARED_LIBRARY_ORIGIN) \
            $(call SET_SHARED_LIBRARY_ORIGIN)., \
        LDFLAGS_SUFFIX := $(LIBAWT_XAWT_LDFLAGS_SUFFIX), \
        VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
        RC_FLAGS := $(RC_FLAGS) \
            -D "JDK_FNAME=xawt.dll" \
            -D "JDK_INTERNAL_NAME=xawt" \
            -D "JDK_FTYPE=0x2L", \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libawt_xawt, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    $(BUILD_LIBAWT_XAWT): $(BUILD_LIBJAVA)

    $(BUILD_LIBAWT_XAWT): $(BUILD_LIBAWT)

    BUILD_LIBRARIES += $(BUILD_LIBAWT_XAWT)

  endif
endif

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

BUILD_LIBZIP_EXCLUDES :=
ifeq ($(USE_EXTERNAL_LIBZ), true)
  LIBZ := -lz
  LIBZIP_EXCLUDES += zlib-1.2.5
else
  ZLIB_CPPFLAGS := -I$(JDK_TOPDIR)/src/share/native/java/util/zip/zlib-1.2.5
endif

BUILD_LIBZIP_REORDER :=
ifeq ($(OPENJDK_TARGET_OS), solaris)
  ifneq ($(OPENJDK_TARGET_CPU), x86_64)
    BUILD_LIBZIP_REORDER := $(JDK_TOPDIR)/makefiles/mapfiles/libzip/reorder-$(OPENJDK_TARGET_CPU)
  endif
endif

ifeq ($(LIBZIP_CAN_USE_MMAP), true)
  BUILD_LIBZIP_MMAP := -DUSE_MMAP
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBZIP, \
    LIBRARY := zip, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    LANG := C, \
    OPTIMIZATION := LOW, \
    SRC := $(JDK_TOPDIR)/src/share/native/java/util/zip, \
    EXCLUDES := $(LIBZIP_EXCLUDES), \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(ZLIB_CPPFLAGS) \
        -I$(JDK_TOPDIR)/src/share/native/java/io \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/io, \
    CFLAGS_posix := $(BUILD_LIBZIP_MMAP) -UDEBUG, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libzip/mapfile-vers, \
    REORDER := $(BUILD_LIBZIP_REORDER), \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN) \
        $(EXPORT_ZIP_FUNCS), \
    LDFLAGS_windows := -export:ZIP_Open -export:ZIP_Close -export:ZIP_FindEntry \
        -export:ZIP_ReadEntry -export:ZIP_GetNextEntry jvm.lib \
        $(WIN_JAVA_LIB), \
    LDFLAGS_SUFFIX_linux := -ljvm -ljava $(LIBZ), \
    LDFLAGS_SUFFIX_solaris := -ljvm -ljava $(LIBZ) -lc, \
    LDFLAGS_SUFFIX_macosx := $(LIBZ) -ljava -ljvm, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=zip.dll" \
        -D "JDK_INTERNAL_NAME=zip" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libzip, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))


$(BUILD_LIBZIP): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBZIP)

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

$(eval $(call SetupNativeCompilation,BUILD_LIBUNPACK, \
    LIBRARY := unpack, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/com/sun/java/util/jar/pack, \
    EXCLUDE_FILES := main.cpp, \
    LANG := C++, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CXXFLAGS_JDKLIB) \
        -DNO_ZLIB -DUNPACK_JNI -DFULL, \
    CFLAGS_release := -DPRODUCT, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libunpack/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_windows := -map:$(JDK_OUTPUTDIR)/objs/unpack.map -debug \
        jvm.lib $(WIN_JAVA_LIB), \
    LDFLAGS_SUFFIX_posix := -ljvm $(LIBCXX) -ljava -lc, \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libunpack, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=unpack.dll" \
        -D "JDK_INTERNAL_NAME=unpack" \
        -D "JDK_FTYPE=0x2L", \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBUNPACK): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBUNPACK)

ifeq ($(OPENJDK_TARGET_OS), windows)
  $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)unpack.map: $(BUILD_LIBUNPACK)
	$(ECHO) Copying $(@F)
	$(CP) $(patsubst %$(SHARED_LIBRARY_SUFFIX), %.map, $<) $@

  $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)unpack.pdb: $(BUILD_LIBUNPACK)
	$(ECHO) Copying $(@F)
	$(CP) $(patsubst %$(SHARED_LIBRARY_SUFFIX), %.pdb, $<) $@
endif

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

LIBATTACH_EXCLUDE_FILES :=
ifneq ($(OPENJDK_TARGET_OS), solaris)
  LIBATTACH_EXCLUDE_FILES += SolarisVirtualMachine.c
endif
ifneq ($(OPENJDK_TARGET_OS), linux)
  LIBATTACH_EXCLUDE_FILES += LinuxVirtualMachine.c
endif
ifneq ($(OPENJDK_TARGET_OS), macosx)
  LIBATTACH_EXCLUDE_FILES += BsdVirtualMachine.c
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBATTACH, \
    LIBRARY := attach, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/tools/attach, \
    EXCLUDE_FILES := $(LIBATTACH_EXCLUDE_FILES), \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB), \
    CFLAGS_windows := /Gy, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libattach/mapfile-$(OPENJDK_TARGET_OS), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=attach.dll" \
        -D "JDK_INTERNAL_NAME=attach" \
        -D "JDK_FTYPE=0x2L", \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_solaris := -ldoor, \
    LDFLAGS_windows := /ORDER:@$(JDK_TOPDIR)/makefiles/mapfiles/libattach/reorder-windows-$(OPENJDK_TARGET_CPU), \
    LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
    LDFLAGS_SUFFIX_windows := $(WIN_JAVA_LIB) advapi32.lib psapi.lib, \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libattach, \
    DEBUG_SYMBOLS := true))

$(BUILD_LIBATTACH): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBATTACH)

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

$(eval $(call SetupNativeCompilation,BUILD_LIBDT_SOCKET, \
    LIBRARY := dt_socket, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/transport/socket \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/socket, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
        -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
        -I$(JDK_TOPDIR)/src/share/transport/socket \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/socket \
        -I$(JDK_TOPDIR)/src/share/back/export \
        -I$(JDK_TOPDIR)/src/share/back, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libdt_socket/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_linux := -lpthread, \
    LDFLAGS_SUFFIX_solaris := -lnsl -lsocket -lc, \
    LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX) -export:jdwpTransport_OnLoad ws2_32.lib, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=dt_socket.dll" \
        -D "JDK_INTERNAL_NAME=dt_socket" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libdt_socket, \
    DEBUG_SYMBOLS := true))

$(BUILD_LIBDT_SOCKET): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBDT_SOCKET)

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

ifeq ($(OPENJDK_TARGET_OS), windows)

  $(eval $(call SetupNativeCompilation,BUILD_LIBDT_SHMEM, \
      LIBRARY := dt_shmem, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/share/native/com/sun/tools/jdi \
          $(JDK_TOPDIR)/src/share/transport/shmem \
          $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/shmem, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
          -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
          -I$(JDK_TOPDIR)/src/share/transport/shmem \
          -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/transport/shmem \
          -I$(JDK_TOPDIR)/src/share/back/export, \
      LDFLAGS := $(LDFLAGS_JDKLIB), \
      LDFLAGS_windows := -export:jdwpTransport_OnLoad, \
      LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=dt_shmem.dll" \
          -D "JDK_INTERNAL_NAME=dt_shmem" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libdt_shmem, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBDT_SHMEM)

endif # OPENJDK_TARGET_OS

##########################################################################################
# JDWP_LOGGING causes log messages to be compiled into the library.
$(eval $(call SetupNativeCompilation,BUILD_LIBJDWP, \
    LIBRARY := jdwp, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/back $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/back, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) -DJDWP_LOGGING \
        -I$(JDK_TOPDIR)/src/share/transport/export \
        -I$(JDK_TOPDIR)/src/share/back/export \
        -I$(JDK_TOPDIR)/src/share/npt \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt \
        -I$(JDK_TOPDIR)/src/share/back \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/back \
        -I$(JDK_OUTPUTDIR)/gensrc_jdwp_headers, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjdwp/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_linux := $(LIBDL), \
    LDFLAGS_SUFFIX_solaris := $(LIBDL) -lc, \
    LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=jdwp.dll" \
        -D "JDK_INTERNAL_NAME=jdwp" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjdwp, \
    DEBUG_SYMBOLS := true))

$(BUILD_LIBJDWP): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBJDWP)

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

LIBJAAS_MAPFILE :=
ifneq ($(OPENJDK_TARGET_OS), solaris)
  LIBJAAS_EXCLUDE_FILES := Solaris.c
else
  # only on solaris...wonder why
  LIBJAAS_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjaas/mapfile-vers
endif

LIBJAAS_NAME := jaas_unix
ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBJAAS_NAME := jaas_nt
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBJAAS, \
    LIBRARY := $(LIBJAAS_NAME), \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/com/sun/security/auth/module, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB), \
    MAPFILE := $(LIBJAAS_MAPFILE), \
    LDFLAGS := $(filter-out -ljava, $(LDFLAGS_JDKLIB)) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_windows := netapi32.lib user32.lib mpr.lib advapi32.lib, \
    LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX), \
    LDFLAGS_SUFFIX_solaris := -lc, \
    EXCLUDE_FILES := $(LIBJAAS_EXCLUDE_FILES), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=$(LIBJAAS_NAME).dll" \
        -D "JDK_INTERNAL_NAME=$(LIBJAAS_NAME)" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjaas, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBJAAS): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBJAAS)

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

$(eval $(call SetupNativeCompilation,BUILD_LIBJSDT, \
    LIBRARY := jsdt, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/sun/tracing/dtrace \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/tracing/dtrace, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        -I$(JDK_TOPDIR)/src/share/native/sun/tracing/dtrace, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjsdt/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_linux := $(LIBDL), \
    LDFLAGS_SUFFIX_windows := $(LDFLAGS_JDKLIB_SUFFIX) $(LIBDL), \
    LDFLAGS_SUFFIX_macosx := $(LIBDL), \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=jsdt.dll" \
        -D "JDK_INTERNAL_NAME=jsdt" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjsdt, \
    DEBUG_SYMBOLS := true))

$(BUILD_LIBJSDT): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBJSDT)

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

# TODO: Update awt lib path when awt is converted
$(eval $(call SetupNativeCompilation,BUILD_LIBLCMS, \
    LIBRARY := lcms, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/sun/java2d/cmm/lcms, \
    LANG := C, \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(filter-out -xc99=%none, $(CFLAGS_JDKLIB)) \
        $(SHARED_LIBRARY_FLAGS) \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug, \
    CFLAGS_solaris := -xc99=no_lib, \
    CFLAGS_windows := -DCMS_IS_WINDOWS_, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/liblcms/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_solaris := /usr/lib$(OPENJDK_TARGET_CPU_ISADIR)/libm.so.2, \
    LDFLAGS_windows := $(WIN_AWT_LIB) $(WIN_JAVA_LIB), \
    LDFLAGS_SUFFIX_solaris := -lawt -ljava -ljvm -lc, \
    LDFLAGS_SUFFIX_macosx := $(LIBM) -lawt -ljava -ljvm, \
    LDFLAGS_SUFFIX_linux := -lm -lawt -ljava -ljvm, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=lcms.dll" \
        -D "JDK_INTERNAL_NAME=lcms" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/liblcms, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBLCMS)

$(BUILD_LIBLCMS): $(BUILD_LIBAWT)

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

ifdef OPENJDK
  BUILD_LIBJPEG_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjpeg/mapfile-vers
else
  BUILD_LIBJPEG_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjpeg/mapfile-vers-closed
  BUILD_LIBJPEG_CLOSED_SRC := $(JDK_TOPDIR)/src/closed/share/native/sun/awt/image/jpeg
  BUILD_LIBJPEG_CLOSED_INCLUDES := -I$(BUILD_LIBJPEG_CLOSED_SRC)
endif

BUILD_LIBJPEG_REORDER :=
ifeq ($(OPENJDK_TARGET_OS), solaris)
  ifneq ($(OPENJDK_TARGET_CPU), x86_64)
    BUILD_LIBJPEG_REORDER := $(JDK_TOPDIR)/makefiles/mapfiles/libjpeg/reorder-$(OPENJDK_TARGET_CPU)
  endif
endif

# 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.
#ifndef CROSS_COMPILE_ARCH
#  CC_43_OR_NEWER := \
#      $(shell $(EXPR) $(CC_MAJORVER) \> 4 \| \
#          \( $(CC_MAJORVER) = 4 \& $(CC_MINORVER) \>= 3 \) )
#  ifeq ($(CC_43_OR_NEWER), 1)
#    BUILD_LIBJPEG_CFLAGS_linux += -Wno-clobbered
#  endif
#endif

$(eval $(call SetupNativeCompilation,BUILD_LIBJPEG, \
    LIBRARY := jpeg, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(BUILD_LIBJPEG_CLOSED_SRC) \
        $(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg, \
    LANG := C, \
    OPTIMIZATION := HIGHEST, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(BUILD_LIBJPEG_CLOSED_INCLUDES) \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg, \
    MAPFILE := $(BUILD_LIBJPEG_MAPFILE), \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_windows := $(WIN_JAVA_LIB) jvm.lib, \
    LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=jpeg.dll" \
        -D "JDK_INTERNAL_NAME=jpeg" \
        -D "JDK_FTYPE=0x2L", \
    REORDER := $(BUILD_LIBJPEG_REORDER), \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjpeg, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBJPEG): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBJPEG)

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

ifndef OPENJDK
  FONT_HEADERS := -I$(JDK_TOPDIR)/src/closed/share/native/sun/font/t2k
  BUILD_LIBFONTMANAGER_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libfontmanager/mapfile-vers
  LIBFONTMANAGER_EXCLUDE_FILES += freetypeScaler.c
else
  FONT_HEADERS := $(FREETYPE2_CFLAGS)
  BUILD_LIBFONTMANAGER_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libfontmanager/mapfile-vers.openjdk
  BUILD_LIBFONTMANAGER_FONTLIB := $(FREETYPE2_LIBS)
endif

LIBFONTMANAGER_OPTIMIZATION := HIGH

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

BUILD_LIBFONTMANAGER_CFLAGS_COMMON := \
    $(X_CFLAGS) \
    -DLE_STANDALONE -DHEADLESS \
    $(FONT_HEADERS) \
    -I$(JDK_TOPDIR)/src/share/native/sun/font \
    -I$(JDK_TOPDIR)/src/share/native/sun/font/layout \
    -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt \
    -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \
    -I$(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
    -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d \
    -I$(JDK_TOPDIR)/src/share/native/sun/java2d

# Turn off aliasing with GCC for ExtensionSubtables.cpp
ifeq ($(OPENJDK_TARGET_OS), linux)
  BUILD_LIBFONTMANAGER_ExtensionSubtables.cpp_CXXFLAGS := -fno-strict-aliasing
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBFONTMANAGER, \
    LIBRARY := fontmanager, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/sun/font \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/font, \
    EXCLUDE_FILES := $(LIBFONTMANAGER_EXCLUDE_FILES) \
        AccelGlyphCache.c, \
    LANG := C++, \
    CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBFONTMANAGER_CFLAGS_COMMON), \
    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(BUILD_LIBFONTMANAGER_CFLAGS_COMMON), \
    OPTIMIZATION := $(LIBFONTMANAGER_OPTIMIZATION), \
    CFLAGS_windows = -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/windows \
        -DCC_NOEX, \
    MAPFILE := $(BUILD_LIBFONTMANAGER_MAPFILE), \
    LDFLAGS := $(subst -Xlinker -z -Xlinker defs,,$(LDFLAGS_JDKLIB)) $(LDFLAGS_CXX_JDK) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX := $(BUILD_LIBFONTMANAGER_FONTLIB), \
    LDFLAGS_SUFFIX_linux := -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \
    LDFLAGS_SUFFIX_solaris := -lawt -lawt_xawt -lc $(LIBM) $(LIBCXX) -ljava -ljvm, \
    LDFLAGS_SUFFIX_macosx := -lawt $(LIBM) $(LIBCXX) -undefined dynamic_lookup \
        -ljava -ljvm, \
    LDFLAGS_SUFFIX_windows := $(WIN_JAVA_LIB) advapi32.lib user32.lib gdi32.lib \
        $(WIN_AWT_LIB), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=fontmanager.dll" \
        -D "JDK_INTERNAL_NAME=fontmanager" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libfontmanager, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT)

ifneq (, $(findstring $(OPENJDK_TARGET_OS), solaris macosx))
  $(BUILD_LIBFONTMANAGER): $(BUILD_LIBAWT_XAWT)
endif

BUILD_LIBRARIES += $(BUILD_LIBFONTMANAGER)

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

ifndef OPENJDK

  #ifeq ($(OPENJDK_TARGET_OS), linux)
  #  ifeq ("$(CC_VER_MAJOR)", "3")
  #    OTHER_LDLIBS += -Wl,-Bstatic -lgcc_eh -Wl,-Bdynamic
  #  endif
  #endif
  #
  # The resulting size of the t2k lib file is (at least on linux) dependant on the order of
  # the input .o files. Because of this the new build will differ in size to the old build.
  BUILD_LIBT2K_CFLAGS_COMMON := -I$(JDK_TOPDIR)/src/share/native/sun/font \
      -I$(JDK_TOPDIR)/src/closed/share/native/sun/font/t2k \
      -I$(JDK_TOPDIR)/src/closed/share/native/sun/font \
      -I$(JDK_TOPDIR)/src/share/share/native/sun/font \
      -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/font \
      -I$(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
      -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
      -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d \
      -I$(JDK_TOPDIR)/src/share/native/sun/java2d

  $(eval $(call SetupNativeCompilation,BUILD_LIBT2K, \
      LIBRARY := t2k, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/closed/share/native/sun/font \
          $(JDK_TOPDIR)/src/closed/share/native/sun/font/t2k \
          $(JDK_TOPDIR)/src/closed/share/native/sun/font/t2k/ttHints, \
      EXCLUDE_FILES := orion.c, \
      LANG := C++, \
      OPTIMIZATION := HIGH, \
      CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBT2K_CFLAGS_COMMON), \
      CXXFLAGS := $(CXXFLAGS_JDKLIB) $(BUILD_LIBT2K_CFLAGS_COMMON), \
      CFLAGS_windows = -DCC_NOEX, \
      CXXFLAGS_windows = -DCC_NOEX, \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libt2k/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_windows := user32.lib $(JDK_OUTPUTDIR)/objs/libfontmanager/fontmanager.lib, \
      LDFLAGS_SUFFIX_posix := $(LIBM) $(LIBCXX) -lfontmanager -ljava -ljvm -lc, \
      LDFLAGS_SUFFIX_solaris := -lawt -lawt_xawt, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=t2k.dll" \
          -D "JDK_INTERNAL_NAME=t2k" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libt2k, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  # t2k is linked against fontmanager
  $(BUILD_LIBT2K): $(BUILD_LIBFONTMANAGER)

  BUILD_LIBRARIES += $(BUILD_LIBT2K)
endif

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

ifeq ($(OPENJDK_TARGET_OS), windows)
  ifeq ($(OPENJDK_TARGET_CPU), x86)
    KERNEL32_LIB := kernel32.lib
  endif
  $(eval $(call SetupNativeCompilation,BUILD_LIBJAWT, \
      LIBRARY := jawt, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/windows, \
      INCLUDE_FILES := jawt.cpp, \
      LANG := C++, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CXXFLAGS_JDKLIB) \
          -EHsc -DUNICODE -D_UNICODE \
          -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/windows \
          -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \
          -I$(JDK_TOPDIR)/src/share/native/sun/java2d \
          -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
          -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d/windows, \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(KERNEL32_LIB) $(LDFLAGS_CXX_JDK) \
          advapi32.lib $(WIN_AWT_LIB), \
      LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=jawt.dll" \
          -D "JDK_INTERNAL_NAME=jawt" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjawt, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBJAWT): $(BUILD_LIBAWT)

  $(JDK_OUTPUTDIR)/lib/$(LIBRARY_PREFIX)jawt$(STATIC_LIBRARY_SUFFIX): $(BUILD_LIBJAWT)
	$(ECHO) Copying $(@F)
	$(CP) $(JDK_OUTPUTDIR)/objs/libjawt/$(LIBRARY_PREFIX)jawt$(STATIC_LIBRARY_SUFFIX) $@

  BUILD_LIBRARIES += $(JDK_OUTPUTDIR)/lib/$(LIBRARY_PREFIX)jawt$(STATIC_LIBRARY_SUFFIX)

else # OPENJDK_TARGET_OS not windows

  JAWT_LIBS :=
  ifneq ($(OPENJDK_TARGET_OS), solaris)
    JAWT_LIBS += -lawt
  endif

  ifndef BUILD_HEADLESS_ONLY
    JAWT_LIBS += -lawt_xawt
  else
    JAWT_LIBS += -lawt_headless
    HEADLESS_CFLAG += -DHEADLESS
  endif

  JAWT_FILES := jawt.c
  ifeq ($(OPENJDK_TARGET_OS), macosx)
    JAWT_FILES := jawt.m
    JAWT_LIBS := -lawt_lwawt
  endif

  $(eval $(call SetupNativeCompilation,BUILD_LIBJAWT, \
      LIBRARY := jawt, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt \
          $(JDK_TOPDIR)/src/macosx/native/sun/awt, \
      INCLUDE_FILES := $(JAWT_FILES), \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB), \
      CFLAGS_linux := $(HEADLESS_CFLAG), \
      CFLAGS_macosx := -I$(JDK_TOPDIR)/src/solaris/native/sun/awt, \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjawt/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_solaris := -L$(OPENWIN_HOME)/sfw/lib$(OPENJDK_TARGET_CPU_ISADIR) -L$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR), \
      LDFLAGS_SUFFIX_linux := $(JAWT_LIBS) $(LDFLAGS_JDKLIB_SUFFIX), \
      LDFLAGS_SUFFIX_solaris := $(JAWT_LIBS) $(LDFLAGS_JDKLIB_SUFFIX) -lXrender, \
      LDFLAGS_SUFFIX_macosx := -Xlinker -rpath -Xlinker @loader_path $(JAWT_LIBS) \
          -framework Cocoa $(LDFLAGS_JDKLIB_SUFFIX), \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjawt, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  ifndef BUILD_HEADLESS_ONLY
    $(BUILD_LIBJAWT): $(BUILD_LIBAWT_XAWT)
  else
    $(BUILD_LIBJAWT): $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)awt_headless$(SHARED_LIBRARY_SUFFIX)
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    $(BUILD_LIBJAWT): $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)awt_lwawt$(SHARED_LIBRARY_SUFFIX)
  endif

endif # OPENJDK_TARGET_OS

BUILD_LIBRARIES += $(BUILD_LIBJAWT)

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

LIBINSTRUMENT_SRC := $(JDK_TOPDIR)/src/share/instrument \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/io \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/instrument

LIBINSTRUMENT_FILES := \
    EncodingSupport.c \
    EncodingSupport_md.c \
    FileSystemSupport_md.c \
    InstrumentationImplNativeMethods.c \
    InvocationAdapter.c \
    JarFacade.c \
    JPLISAgent.c \
    JPLISAssert.c \
    JavaExceptions.c \
    PathCharsValidator.c \
    Reentrancy.c \
    Utilities.c \
    canonicalize_md.c

LIBINSTRUMENT_DIR := $(JDK_OUTPUTDIR)/objs/libinstrument
LIBINSTRUMENT_CFLAGS := $(CFLAGS_JDKLIB) \
    -I$(JDK_TOPDIR)/src/share/instrument \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/instrument \
    -I$(JDK_TOPDIR)/src/share/bin

LIBINSTRUMENT_LDFLAGS :=
LIBINSTRUMENT_LDFLAGS_SUFFIX :=

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBINSTRUMENT_LDFLAGS += $(JDK_OUTPUTDIR)/objs/jli_static.lib $(WIN_JAVA_LIB) \
      -export:Agent_OnAttach advapi32.lib
  # Statically link the C runtime so that there are not dependencies on modules
  # not on the search patch when invoked from the Windows system directory
  # (or elsewhere).
  LIBINSTRUMENT_CFLAGS := $(filter-out -MD, $(LIBINSTRUMENT_CFLAGS))
  # equivalent of strcasecmp is stricmp on Windows
  LIBINSTRUMENT_CFLAGS += -Dstrcasecmp=stricmp
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBINSTRUMENT, \
    LIBRARY := instrument, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(LIBINSTRUMENT_SRC), \
    INCLUDE_FILES := $(LIBINSTRUMENT_FILES), \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(LIBINSTRUMENT_CFLAGS), \
    CFLAGS_debug := -DJPLIS_LOGGING, \
    CFLAGS_release := -DNO_JPLIS_LOGGING, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libinstrument/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN) \
        $(LIBINSTRUMENT_LDFLAGS), \
    LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/jli), \
    LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/jli), \
    LDFLAGS_macosx := -Xlinker -all_load $(JDK_OUTPUTDIR)/objs/libjli_static.a \
        -framework Cocoa -framework Security -framework ApplicationServices, \
    LDFLAGS_SUFFIX := $(LIBINSTRUMENT_LDFLAGS_SUFFIX), \
    LDFLAGS_SUFFIX_macosx := -liconv $(LIBZ), \
    LDFLAGS_SUFFIX_solaris := $(LIBZ) -L $(INSTALL_LIBRARIES_HERE)/jli -ljli $(LIBDL) -lc, \
    LDFLAGS_SUFFIX_linux := $(LIBZ) -L $(INSTALL_LIBRARIES_HERE)/jli -ljli $(LIBDL), \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=instrument.dll" \
        -D "JDK_INTERNAL_NAME=instrument" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(LIBINSTRUMENT_DIR), \
    DEBUG_SYMBOLS := true))

ifneq (, $(findstring $(OPENJDK_TARGET_OS), macosx windows))
  $(BUILD_LIBINSTRUMENT): $(JDK_OUTPUTDIR)/objs/$(LIBRARY_PREFIX)jli_static$(STATIC_LIBRARY_SUFFIX)
else
  $(BUILD_LIBINSTRUMENT): $(INSTALL_LIBRARIES_HERE)/jli/$(LIBRARY_PREFIX)jli$(SHARED_LIBRARY_SUFFIX)
endif
$(BUILD_LIBINSTRUMENT): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBINSTRUMENT)

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

BUILD_LIBMANAGEMENT_SRC := $(JDK_TOPDIR)/src/share/native/sun/management \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/management \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/com/sun/management

BUILD_LIBMANAGEMENT_EXCLUDES :=

BUILD_LIBMANAGEMENT_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/management

ifneq ($(OPENJDK_TARGET_OS), windows)
  BUILD_LIBMANAGEMENT_EXCLUDES += OperatingSystem_md.c
else
  BUILD_LIBMANAGEMENT_EXCLUDES += UnixOperatingSystem_md.c
endif

ifneq ($(OPENJDK_TARGET_OS), solaris)
  BUILD_LIBMANAGEMENT_EXCLUDES += SolarisOperatingSystem.c
endif

ifneq ($(OPENJDK_TARGET_OS), linux)
  BUILD_LIBMANAGEMENT_EXCLUDES += LinuxOperatingSystem.c
endif

ifneq ($(OPENJDK_TARGET_OS), macosx)
  BUILD_LIBMANAGEMENT_EXCLUDES += MacosxOperatingSystem.c
endif

LIBMANAGEMENT_OPTIMIZATION := HIGH
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
  ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
    LIBMANAGEMENT_OPTIMIZATION := LOW
  endif
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBMANAGEMENT, \
    LIBRARY := management, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(BUILD_LIBMANAGEMENT_SRC), \
    EXCLUDE_FILES := $(BUILD_LIBMANAGEMENT_EXCLUDES), \
    LANG := C, \
    OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \
    CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBMANAGEMENT_CFLAGS), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libmanagement/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_solaris := -lkstat, \
    LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX), \
    LDFLAGS_SUFFIX_windows := jvm.lib psapi.lib $(WIN_JAVA_LIB) advapi32.lib, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=management.dll" \
        -D "JDK_INTERNAL_NAME=management" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libmanagement, \
    DEBUG_SYMBOLS := true))

$(BUILD_LIBMANAGEMENT): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBMANAGEMENT)

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

BUILD_LIBHPROF_SRC := $(JDK_TOPDIR)/src/share/demo/jvmti/hprof $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/demo/jvmti/hprof
BUILD_LIBHPROF_CFLAGS := -I$(JDK_TOPDIR)/src/share/demo/jvmti/hprof \
    -I$(JDK_TOPDIR)/src/share/npt \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt \
    -I$(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo

BUILD_LIBHPROF_LDFLAGS :=

LIBHPROF_OPTIMIZATION := HIGHEST
ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
  ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
    LIBHPROF_OPTIMIZATION := LOW
  endif
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBHPROF, \
    LIBRARY := hprof, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(BUILD_LIBHPROF_SRC), \
    LANG := C, \
    OPTIMIZATION := $(LIBHPROF_OPTIMIZATION), \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(BUILD_LIBHPROF_CFLAGS), \
    CFLAGS_debug := -DHPROF_LOGGING, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libhprof/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_windows := wsock32.lib winmm.lib advapi32.lib, \
    LDFLAGS_SUFFIX_linux := $(LIBDL), \
    LDFLAGS_SUFFIX_macosx := $(LIBDL), \
    LDFLAGS_SUFFIX_solaris := -lsocket -lnsl $(LIBDL) -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=hprof.dll" \
        -D "JDK_INTERNAL_NAME=hprof" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libhprof_jvmti, \
    DEBUG_SYMBOLS := true))

BUILD_LIBRARIES += $(BUILD_LIBHPROF)

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

$(eval $(call SetupNativeCompilation,BUILD_LIBJAVA_CRW_DEMO, \
    LIBRARY := java_crw_demo, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        -I$(JDK_TOPDIR)/src/share/demo/jvmti/java_crw_demo, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjava_crw_demo/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=java_crw_demo.dll" \
        -D "JDK_INTERNAL_NAME=java_crw_demo" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjava_crw_demo, \
    DEBUG_SYMBOLS := true))

BUILD_LIBRARIES += $(BUILD_LIBJAVA_CRW_DEMO)

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

$(eval $(call SetupNativeCompilation,BUILD_LIBNPT, \
    LIBRARY := npt, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/npt $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        -I$(JDK_TOPDIR)/src/share/npt \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/npt, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libnpt/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_macosx := -liconv, \
    LDFLAGS_SUFFIX_windows := -export:nptInitialize -export:nptTerminate, \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=npt.dll" \
        -D "JDK_INTERNAL_NAME=npt" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libnpt, \
    DEBUG_SYMBOLS := true))

BUILD_LIBRARIES += $(BUILD_LIBNPT)

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

LIBNET_SRC_DIRS := $(JDK_TOPDIR)/src/share/native/java/net \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/dns \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/spi

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBNET_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/www/protocol/http/ntlm
else
  LIBNET_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/sdp
endif

LIBNET_CFLAGS := $(foreach dir, $(LIBNET_SRC_DIRS), -I$(dir))

LIBNET_EXCLUDE_FILES :=
ifneq ($(OPENJDK_TARGET_OS), linux)
  LIBNET_EXCLUDE_FILES += linux_close.c
endif

ifneq ($(OPENJDK_TARGET_OS), macosx)
  LIBNET_EXCLUDE_FILES += bsd_close.c
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBNET_EXCLUDE_FILES += PlainSocketImpl.c PlainDatagramSocketImpl.c SdpSupport.c
else
  LIBNET_EXCLUDE_FILES += TwoStacksPlainSocketImpl.c DualStackPlainSocketImpl.c \
      TwoStacksPlainDatagramSocketImpl.c DualStackPlainDatagramSocketImpl.c \
      NTLMAuthSequence.c NetworkInterface_winXP.c
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBNET, \
    LIBRARY := net, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(LIBNET_SRC_DIRS), \
    EXCLUDE_FILES := $(LIBNET_EXCLUDE_FILES), \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(LIBNET_CFLAGS), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libnet/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_macosx := -ljvm -ljava, \
    LDFLAGS_SUFFIX_solaris := -ljvm -ljava -lnsl -lsocket $(LIBDL) -lc, \
    LDFLAGS_SUFFIX_linux := $(LIBDL) -ljvm -lpthread -ljava, \
    LDFLAGS_SUFFIX_windows := ws2_32.lib jvm.lib secur32.lib iphlpapi.lib \
        delayimp.lib $(WIN_JAVA_LIB) advapi32.lib \
        -DELAYLOAD:secur32.dll -DELAYLOAD:iphlpapi.dll, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=net.dll" \
        -D "JDK_INTERNAL_NAME=net" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libnet, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBNET): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBNET)

$(JDK_OUTPUTDIR)/lib/net.properties: $(JDK_TOPDIR)/src/share/lib/net.properties
	$(ECHO) $(LOG_INFO) Copying $(@F)
	$(call install-file)

COPY_FILES += $(JDK_OUTPUTDIR)/lib/net.properties

ifeq ($(OPENJDK_TARGET_OS), solaris)
  $(JDK_OUTPUTDIR)/lib/sdp/sdp.conf.template: $(JDK_TOPDIR)/src/${OPENJDK_TARGET_OS_API_DIR}/lib/sdp/sdp.conf.template
	$(ECHO) $(LOG_INFO) Copying $(@F)
	$(call install-file)

  COPY_FILES += $(JDK_OUTPUTDIR)/lib/sdp/sdp.conf.template
endif

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

BUILD_LIBNIO_SRC := \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/nio \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/ch \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/fs

BUILD_LIBNIO_CFLAGS := \
    -I$(JDK_TOPDIR)/src/share/native/sun/nio/ch \
    -I$(JDK_TOPDIR)/src/share/native/java/io \
    -I$(JDK_TOPDIR)/src/share/native/java/net \
    -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net

BUILD_LIBNIO_FILES := \
    DatagramChannelImpl.c \
    DatagramDispatcher.c \
    FileChannelImpl.c \
    FileDispatcherImpl.c \
    FileKey.c \
    IOUtil.c \
    MappedByteBuffer.c \
    Net.c \
    ServerSocketChannelImpl.c \
    SocketChannelImpl.c \
    SocketDispatcher.c

ifeq ($(OPENJDK_TARGET_OS), windows)
  BUILD_LIBNIO_FILES += \
      Iocp.c \
      RegistryFileTypeDetector.c \
      WindowsAsynchronousFileChannelImpl.c \
      WindowsAsynchronousServerSocketChannelImpl.c \
      WindowsAsynchronousSocketChannelImpl.c \
      WindowsNativeDispatcher.c \
      WindowsSelectorImpl.c
endif

ifeq ($(OPENJDK_TARGET_OS), linux)
  BUILD_LIBNIO_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
  BUILD_LIBNIO_FILES += \
      EPoll.c \
      EPollArrayWrapper.c \
      EPollPort.c \
      InheritedChannel.c \
      NativeThread.c \
      PollArrayWrapper.c \
      UnixAsynchronousServerSocketChannelImpl.c \
      UnixAsynchronousSocketChannelImpl.c \
      GnomeFileTypeDetector.c \
      MagicFileTypeDetector.c \
      LinuxNativeDispatcher.c \
      LinuxWatchService.c \
      UnixCopyFile.c \
      UnixNativeDispatcher.c
endif

ifeq ($(OPENJDK_TARGET_OS), macosx)
  BUILD_LIBNIO_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
  BUILD_LIBNIO_SRC += $(JDK_TOPDIR)/src/macosx/native/sun/nio/ch
  BUILD_LIBNIO_FILES += \
      InheritedChannel.c \
      NativeThread.c \
      PollArrayWrapper.c \
      UnixAsynchronousServerSocketChannelImpl.c \
      UnixAsynchronousSocketChannelImpl.c \
      BsdNativeDispatcher.c \
      MacOSXNativeDispatcher.c \
      UnixCopyFile.c \
      UnixNativeDispatcher.c \
      KQueue.c \
      KQueuePort.c \
      KQueueArrayWrapper.c
endif

ifeq ($(OPENJDK_TARGET_OS), solaris)
  BUILD_LIBNIO_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libnio/mapfile-$(OPENJDK_TARGET_OS)
  BUILD_LIBNIO_FILES += \
      DevPollArrayWrapper.c \
      InheritedChannel.c \
      NativeThread.c \
      PollArrayWrapper.c \
      SolarisEventPort.c \
      UnixAsynchronousServerSocketChannelImpl.c \
      UnixAsynchronousSocketChannelImpl.c \
      GnomeFileTypeDetector.c \
      SolarisNativeDispatcher.c \
      SolarisWatchService.c \
      UnixCopyFile.c \
      UnixNativeDispatcher.c
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBNIO, \
    LIBRARY := nio, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(BUILD_LIBNIO_SRC), \
    INCLUDE_FILES := $(BUILD_LIBNIO_FILES), \
    LANG := C, \
    OPTIMIZATION := HIGH, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(BUILD_LIBNIO_CFLAGS), \
    MAPFILE := $(BUILD_LIBNIO_MAPFILE), \
    LDFLAGS := $(LDFLAGS_JDKLIB) $(BUILD_LIBNIO_LDFLAGS) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_linux := -ljava -lnet -lpthread $(LIBDL), \
    LDFLAGS_SUFFIX_solaris := -ljvm -lsocket -lposix4 $(LIBDL) \
        -lsendfile -ljava -lnet -lc, \
    LDFLAGS_SUFFIX_windows := jvm.lib ws2_32.lib $(WIN_JAVA_LIB) \
        $(JDK_OUTPUTDIR)/objs/libnet/net.lib \
        advapi32.lib, \
    LDFLAGS_SUFFIX_macosx := -ljava -lnet -pthread -framework CoreFoundation, \
    LDFLAGS_SUFFIX :=, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=nio.dll" \
        -D "JDK_INTERNAL_NAME=nio" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libnio, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBNIO)

$(BUILD_LIBNIO): $(BUILD_LIBNET)

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

ifeq ($(OPENJDK_TARGET_OS_API), posix)

  ifneq ($(OPENJDK_TARGET_OS), macosx)

    SCTP_WERROR := -Werror
    ifeq ($(OPENJDK_TARGET_CPU_ARCH), ppc)
      SCTP_WERROR :=
    endif

    $(eval $(call SetupNativeCompilation,BUILD_LIBSCTP, \
        LIBRARY := sctp, \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/ch/sctp, \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) \
            -I$(JDK_TOPDIR)/src/share/native/sun/nio/ch \
            -I$(JDK_TOPDIR)/src/share/native/sun/nio/ch/sctp \
            -I$(JDK_TOPDIR)/src/share/native/java/net \
            -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/ch \
            -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net, \
        CFLAGS_linux := $(SCTP_WERROR), \
        MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libsctp/mapfile-vers, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(call SET_SHARED_LIBRARY_ORIGIN), \
        LDFLAGS_SUFFIX_linux := -lpthread $(LIBDL) -ljava -ljvm, \
        LDFLAGS_SUFFIX_posix := -lnio -lnet, \
        LDFLAGS_SUFFIX_solaris := -lsocket -ljava -ljvm -lc, \
        LDFLAGS_SUFFIX_macosx := -ljava -ljvm, \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libsctp, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    BUILD_LIBRARIES += $(BUILD_LIBSCTP)

    $(BUILD_LIBSCTP): $(BUILD_LIBNIO)
  endif
endif

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

BUILD_LIBJLI_SRC_DIRS := $(JDK_TOPDIR)/src/share/bin $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/bin
LIBJLI_CFLAGS := $(CFLAGS_JDKLIB) $(foreach dir, $(BUILD_LIBJLI_SRC_DIRS), -I$(dir))

BUILD_LIBJLI_FILES := \
    java.c \
    splashscreen_stubs.c \
    parse_manifest.c \
    version_comp.c \
    wildcard.c \
    jli_util.c

ifeq ($(JVM_VARIANT_ZERO), true)
  ERGO_FAMILY := zero
else
  ifeq ($(OPENJDK_TARGET_CPU_ARCH), x86)
    ERGO_FAMILY := i586
  else
    ERGO_FAMILY := $(OPENJDK_TARGET_CPU_ARCH)
  endif
endif

ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBJLI_CFLAGS += -I$(JDK_TOPDIR)/src/macosx/bin
  BUILD_LIBJLI_SRC_DIRS += $(JDK_TOPDIR)/src/macosx/bin
  BUILD_LIBJLI_FILES += java_md_common.c java_md_macosx.c

  BUILD_LIBJLI_java_md_macosx.c_CFLAGS := -x objective-c
  BUILD_LIBJLI_STATIC_java_md_macosx.c_CFLAGS := -x objective-c
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  BUILD_LIBJLI_FILES += java_md.c \
      cmdtoargs.c
  # Staticically link with c runtime on windows.
  LIBJLI_CFLAGS := $(filter-out -MD, $(LIBJLI_CFLAGS))
else ifneq ($(OPENJDK_TARGET_OS), macosx)

  BUILD_LIBJLI_FILES += java_md_common.c
  BUILD_LIBJLI_FILES += java_md_solinux.c ergo.c

  ERGO_ARCH_FILE = ergo_$(ERGO_FAMILY).c

  # if the architecture specific ergo file exists then
  # use it, else use the generic definitions from ergo.c
  ifneq ($(wildcard $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/bin/$(ERGO_ARCH_FILE)), )
    BUILD_LIBJLI_FILES += $(ERGO_ARCH_FILE)
  else # !ERGO_ARCH_FILE
    LIBJLI_CFLAGS += -DUSE_GENERIC_ERGO
  endif # ERGO_ARCH_FILE
endif #WINDOWS

# Append defines depending on target platform
LIBJLI_CFLAGS += $(OPENJDK_TARGET_CPU_JLI_CFLAGS)

ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBJLI_CFLAGS += -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
endif

ifneq ($(USE_EXTERNAL_LIBZ), true)
  BUILD_LIBJLI_SRC_DIRS += $(JDK_TOPDIR)/src/share/native/java/util/zip/zlib-1.2.5
  LIBJLI_CFLAGS += $(ZLIB_CPPFLAGS)
  BUILD_LIBJLI_FILES += \
      inflate.c \
      inftrees.c \
      inffast.c \
      zadler32.c \
      zcrc32.c \
      zutil.c
endif

ifeq ($(OPENJDK_TARGET_OS), windows)
  LIBJLI_OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE)
else
  LIBJLI_OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE)/jli
endif

$(eval $(call SetupNativeCompilation,BUILD_LIBJLI, \
    LIBRARY := jli, \
    OUTPUT_DIR := $(LIBJLI_OUTPUT_DIR), \
    SRC := $(BUILD_LIBJLI_SRC_DIRS), \
    INCLUDE_FILES := $(BUILD_LIBJLI_FILES), \
    LANG := C, \
    OPTIMIZATION := HIGH, \
    CFLAGS := $(LIBJLI_CFLAGS), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjli/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
    LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
    LDFLAGS_macosx := -framework Cocoa -framework Security -framework ApplicationServices, \
    LDFLAGS_SUFFIX_solaris := $(LIBZ) $(LIBDL) -lc, \
    LDFLAGS_SUFFIX_linux := $(LIBZ) $(LIBDL) -lc -lpthread, \
    LDFLAGS_SUFFIX_macosx := $(LIBZ), \
    LDFLAGS_SUFFIX_windows := \
        -export:JLI_Launch \
        -export:JLI_ManifestIterate \
        -export:JLI_SetTraceLauncher \
        -export:JLI_ReportErrorMessage \
        -export:JLI_ReportErrorMessageSys \
        -export:JLI_ReportMessage \
        -export:JLI_ReportExceptionDescription \
        -export:JLI_MemAlloc \
        -export:JLI_CmdToArgs \
        -export:JLI_GetStdArgc \
        -export:JLI_GetStdArgs \
        advapi32.lib \
        comctl32.lib \
        user32.lib, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=jli.dll" \
        -D "JDK_INTERNAL_NAME=jli" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjli, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBJLI)

# On windows, the static library has the same suffix as the import library created by
# with the shared library, so the static library is given a different name. No harm
# in doing it for all platform to reduce complexity.
ifeq ($(OPENJDK_TARGET_OS), windows)
  $(eval $(call SetupNativeCompilation,BUILD_LIBJLI_STATIC, \
      STATIC_LIBRARY := jli_static, \
      OUTPUT_DIR := $(JDK_OUTPUTDIR)/objs, \
      SRC := $(BUILD_LIBJLI_SRC_DIRS), \
      INCLUDE_FILES := $(BUILD_LIBJLI_FILES), \
      LANG := C, \
      OPTIMIZATION := HIGH, \
      CFLAGS := $(STATIC_LIBRARY_FLAGS) $(LIBJLI_CFLAGS), \
      ARFLAGS := $(ARFLAGS), \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjli_static, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBJLI_STATIC)

else ifeq ($(OPENJDK_TARGET_OS), macosx)
  #
  # On macosx they do partial (incremental) linking of libjli_static.a
  # code it here...rather than add support to NativeCompilation
  # as this is first time I see it
  $(eval $(call SetupNativeCompilation,BUILD_LIBJLI_STATIC, \
      LIBRARY := jli_static, \
      OUTPUT_DIR := $(JDK_OUTPUTDIR)/objs, \
      SRC := $(BUILD_LIBJLI_SRC_DIRS), \
      INCLUDE_FILES := $(BUILD_LIBJLI_FILES), \
      LANG := C, \
      OPTIMIZATION := HIGH, \
      CFLAGS := $(CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
      LDFLAGS := -nostdlib -r, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjli_static, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(JDK_OUTPUTDIR)/objs/libjli_static.a: $(BUILD_LIBJLI_STATIC)
	$(call install-file)

  BUILD_LIBRARIES += $(JDK_OUTPUTDIR)/objs/libjli_static.a
endif

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

ifndef OPENJDK
  ifeq ($(ENABLE_JFR), true)

    $(eval $(call SetupNativeCompilation,BUILD_LIBJFR, \
        LIBRARY := jfr, \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(JDK_TOPDIR)/src/closed/share/native/oracle/jfr, \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) \
            -I$(JDK_TOPDIR)/src/closed/share/javavm/export, \
        MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjfr/mapfile-vers, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(call SET_SHARED_LIBRARY_ORIGIN), \
        LDFLAGS_SUFFIX_solaris := -lc, \
        VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
        RC_FLAGS := $(RC_FLAGS) \
            -D "JDK_FNAME=jfr.dll" \
            -D "JDK_INTERNAL_NAME=jfr" \
            -D "JDK_FTYPE=0x2L", \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjfr, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    BUILD_LIBRARIES += $(BUILD_LIBJFR)

endif
endif

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

ifndef OPENJDK

  BUILD_LIBKCMS_EXCLUDE_FILES :=
  ifeq ($(OPENJDK_TARGET_OS), windows)
    BUILD_LIBKCMS_EXCLUDE_FILES += ukcpmgr.c unixmem.c
  else
    BUILD_LIBKCMS_EXCLUDE_FILES += cmmdll.c registry.c spxffile.c sysinfo.c winmem.c wkcpmgr.c
  endif

  BUILD_LIBKCMS_FLAGS := $(CFLAGS_JDKLIB)

  ifeq ($(OPENJDK_TARGET_OS), solaris)
    # This particular library uses a feature called PIC_CODE_SMALL (on solaris)
    # implement it like this...since it's only used here
    BUILD_LIBKCMS_FLAGS := $(patsubst -KPIC, -Kpic, $(BUILD_LIBKCMS_FLAGS))
  else ifeq ($(OPENJDK_TARGET_CPU_ARCH), ppc)
    BUILD_LIBKCMS_FLAGS := $(patsubst -fPIC, -fpic, $(BUILD_LIBKCMS_FLAGS))
  endif

  $(eval $(call SetupNativeCompilation,BUILD_LIBKCMS, \
      LIBRARY := kcms, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/closed/share/native/sun/java2d/cmm/kcms, \
      LANG := C, \
      EXCLUDE_FILES := $(BUILD_LIBKCMS_EXCLUDE_FILES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(BUILD_LIBKCMS_FLAGS) \
          -DJAVACMM -DFUT_CALC_EX -DNO_FUT_GCONST, \
      CFLAGS_linux := -Wno-missing-field-initializers, \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libkcms/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX_linux := -lc -lpthread, \
      LDFLAGS_SUFFIX_solaris := -lc, \
      LDFLAGS_SUFFIX_windows := $(WIN_JAVA_LIB) advapi32.lib user32.lib version.lib, \
      LDFLAGS_SUFFIX_posix := -lm -ljava -ljvm, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/closed/share/native/sun/java2d/cmm/kcms/cmm.rc, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/closed/share/native/sun/java2d/cmm/kcms/cmm.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=kcms.dll" \
          -D "JDK_INTERNAL_NAME=kcms" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libkcms, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBKCMS): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBKCMS)

endif

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

ifndef OPENJDK
  ifeq ($(OPENJDK_TARGET_OS), solaris)
    ifneq ($(OPENJDK_TARGET_CPU), x86_64)

      ifeq ($(shell if test "$(OS_VERSION_MAJOR)" -eq 5 -a "$(OS_VERSION_MINOR)" -le 10; then $(ECHO) ok; fi), ok)

        SUNWJDGA_MAPFILE :=
        ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
          SUNWJDGA_MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjdga/mapfile-vers
        endif

        $(eval $(call SetupNativeCompilation,BUILD_LIBSUNWJDGA, \
            LIBRARY := sunwjdga, \
            OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
            SRC := $(JDK_TOPDIR)/src/solaris/native/sun/jdga, \
            LANG := C, \
            OPTIMIZATION := LOW, \
            CFLAGS := $(CFLAGS_JDKLIB) \
                -I$(JDK_TOPDIR)/src/share/javavm/export \
                -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/javavm/export \
                -I$(OPENWIN_HOME)/include, \
            MAPFILE := $(SUNWJDGA_MAPFILE), \
            LDFLAGS := $(LDFLAGS_JDKLIB) \
                $(call SET_SHARED_LIBRARY_ORIGIN), \
            LDFLAGS_SUFFIX := -L$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR) -R$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR) -ldga -lX11 $(LIBDL) -lc, \
            OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libsunwjdga, \
            DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

        BUILD_LIBRARIES += $(BUILD_LIBSUNWJDGA)

      endif
    endif
  endif
endif

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

ifeq ($(BUILD_HEADLESS), true)
  ifneq ($(OPENJDK_TARGET_OS), windows)

    LIBAWT_HEADLESS_DIRS := $(JDK_TOPDIR)/src/share/native/sun/font \
        $(JDK_TOPDIR)/src/share/native/sun/java2d/opengl \
        $(JDK_TOPDIR)/src/solaris/native/sun/font \
        $(JDK_TOPDIR)/src/solaris/native/sun/awt \
        $(JDK_TOPDIR)/src/solaris/native/sun/java2d/opengl \
        $(JDK_TOPDIR)/src/solaris/native/sun/java2d/x11

    ifeq ($(OPENJDK_TARGET_OS), macosx)
      LIBAWT_HEADLESS_DIRS += $(JDK_TOPDIR)/src/macosx/native/sun/font
    endif

    LIBAWT_HEADLESS_CFLAGS := -DHEADLESS=true \
        -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
        $(CUPS_CFLAGS) \
        $(X_CFLAGS) \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/java2d \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
        -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
        -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/jdga \
        $(foreach dir, $(LIBAWT_HEADLESS_DIRS), -I$(dir))

    ifeq ($(OPENJDK_TARGET_OS), macosx)
      LIBAWT_HEADLESS_CFLAGS += \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks
    endif

    LIBAWT_HEADLESS_FILES := \
        awt_Font.c \
        HeadlessToolkit.c \
        fontpath.c \
        VDrawingArea.c \
        X11Color.c \
        X11Renderer.c \
        X11PMBlitLoops.c \
        X11SurfaceData.c \
        X11FontScaler_md.c \
        X11TextRenderer_md.c \
        OGLBlitLoops.c \
        OGLBufImgOps.c \
        OGLContext.c \
        OGLFuncs.c \
        OGLMaskBlit.c \
        OGLMaskFill.c \
        OGLPaints.c \
        OGLRenderQueue.c \
        OGLRenderer.c \
        OGLSurfaceData.c \
        OGLTextRenderer.c \
        OGLVertexCache.c \
        GLXGraphicsConfig.c \
        GLXSurfaceData.c \
        AccelGlyphCache.c \
        CUPSfuncs.c

    ifeq ($(OPENJDK_TARGET_OS), macosx)
      LIBAWT_HEADLESS_FILES += \
          AWTFont.m \
          AWTStrike.m \
          CCharToGlyphMapper.m \
          CGGlyphImages.m \
          CGGlyphOutlines.m \
          CoreTextSupport.m
    endif

    LIBAWT_HEADLESS_REORDER :=
    ifeq ($(OPENJDK_TARGET_OS), solaris)
      ifneq ($(OPENJDK_TARGET_CPU), x86_64)
        LIBAWT_HEADLESS_REORDER := $(JDK_TOPDIR)/makefiles/mapfiles/libawt_headless/reorder-$(OPENJDK_TARGET_CPU)
      endif
    endif

    $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_HEADLESS, \
        LIBRARY := awt_headless, \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(LIBAWT_HEADLESS_DIRS), \
        INCLUDE_FILES := $(LIBAWT_HEADLESS_FILES), \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_HEADLESS_CFLAGS), \
        MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libawt_headless/mapfile-vers, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(call SET_SHARED_LIBRARY_ORIGIN), \
        LDFLAGS_linux := $(call SET_SHARED_LIBRARY_ORIGIN,/..), \
        LDFLAGS_solaris := $(call SET_SHARED_LIBRARY_ORIGIN,/..) \
            -R/usr/dt/lib$(OPENJDK_TARGET_CPU_ISADIR) \
            -R$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR), \
        LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN)., \
        REORDER := $(LIBAWT_HEADLESS_REORDER), \
        LDFLAGS_SUFFIX_linux := -ljvm -lawt -lm $(LIBDL) -ljava, \
        LDFLAGS_SUFFIX_solaris := $(LIBDL) -ljvm -lawt -lm -ljava $(LIBCXX) -lc, \
        LDFLAGS_SUFFIX_macosx := -ljvm $(LIBCXX) -lawt $(LIBDL) -ljava \
            -framework Accelerate \
            -framework ApplicationServices \
            -framework Cocoa \
            -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
            -framework JavaNativeFoundation \
            -framework JavaRuntimeSupport, \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libawt_headless, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    $(BUILD_LIBAWT_HEADLESS): $(BUILD_LIBAWT)

    BUILD_LIBRARIES += $(BUILD_LIBAWT_HEADLESS)

  endif
endif

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

ifndef BUILD_HEADLESS_ONLY
  LIBSPLASHSCREEN_DIRS := \
    $(JDK_TOPDIR)/src/share/native/sun/awt/image/jpeg \
    $(JDK_TOPDIR)/src/share/native/sun/awt/libpng \
    $(JDK_TOPDIR)/src/share/native/sun/awt/splashscreen

  ifeq ($(USE_EXTERNAL_LIBGIF), true)
    GIFLIB_LDFLAGS := -lgif
  else
    LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/share/native/sun/awt/giflib
    GIFLIB_CFLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/awt/giflib
  endif

  ifneq ($(OPENJDK_TARGET_OS), macosx)
    LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/awt/splashscreen
  else
    LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/macosx/native/sun/awt/splashscreen
  endif

  LIBSPLASHSCREEN_CFLAGS := -DSPLASHSCREEN -DPNG_NO_MMX_CODE \
      $(foreach dir, $(LIBSPLASHSCREEN_DIRS), -I$(dir))

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    LIBSPLASHSCREEN_CFLAGS := -I$(JDK_TOPDIR)/src/macosx/native/sun/awt/splashscreen \
        $(LIBSPLASHSCREEN_CFLAGS) \
        -F/System/Library/Frameworks/JavaVM.framework/Frameworks
    LIBSPLASHSCREEN_CFLAGS += -DWITH_MACOSX
    LIBSPLASHSCREEN_CFLAGS += -I$(JDK_TOPDIR)/src/macosx/native/sun/osxapp

    LIBSPLASHSCREEN_java_awt_SplashScreen.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_gfx_impl.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_gif.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_impl.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_jpeg.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_png.c_CFLAGS := -x objective-c -O0
    LIBSPLASHSCREEN_splashscreen_sys.m_CFLAGS := -O0

  else ifneq ($(OPENJDK_TARGET_OS), windows)
    LIBSPLASHSCREEN_CFLAGS += -DWITH_X11 -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
  else
    LIBSPLASHSCREEN_CFLAGS += -DWITH_WIN32
  endif

  LIBSPLASHSCREEN_LDFLAGS_SUFFIX :=

  ifneq ($(USE_EXTERNAL_LIBZ), true)
    LIBSPLASHSCREEN_DIRS += $(JDK_TOPDIR)/src/share/native/java/util/zip/zlib-1.2.5
    LIBSPLASHSCREEN_CFLAGS += $(ZLIB_CPPFLAGS)
  endif

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    LIBSPLASHSCREEN_LDFLAGS_SUFFIX += $(LIBM) -lpthread -liconv -losxapp \
        -framework ApplicationServices \
        -framework Foundation \
        -framework Cocoa \
        -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
        -framework JavaNativeFoundation
  else ifneq ($(OPENJDK_TARGET_OS), windows)
    LIBSPLASHSCREEN_LDFLAGS_SUFFIX += -L$(OPENWIN_LIB)$(OPENJDK_TARGET_CPU_ISADIR) -lX11 -lXext $(LIBM) -lpthread
  else # OPENJDK_TARGET_OS
    LIBSPLASHSCREEN_LDFLAGS_SUFFIX += kernel32.lib user32.lib gdi32.lib delayimp.lib -DELAYLOAD:user32.dll
  endif # OPENJDK_TARGET_OS

  $(eval $(call SetupNativeCompilation,LIBSPLASHSCREEN, \
      LIBRARY := splashscreen, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBSPLASHSCREEN_DIRS), \
      EXCLUDE_FILES := imageioJPEG.c jpegdecoder.c pngtest.c, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(LIBSPLASHSCREEN_CFLAGS) $(CFLAGS_JDKLIB) $(GIFLIB_CFLAGS), \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libsplashscreen/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(LIBSPLASHSCREEN_LDFLAGS_SUFFIX) $(LIBZ) $(GIFLIB_LDFLAGS), \
      LDFLAGS_SUFFIX_solaris := -lc, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=splashscreen.dll" \
          -D "JDK_INTERNAL_NAME=splashscreen" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libsplashscreen, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(LIBSPLASHSCREEN)

  ifeq ($(OPENJDK_TARGET_OS), macosx)
    $(LIBSPLASHSCREEN): $(INSTALL_LIBRARIES_HERE)/$(LIBRARY_PREFIX)osxapp$(SHARED_LIBRARY_SUFFIX)
  endif

endif

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

ifndef OPENJDK

  LIBDCPR_SRC_DIRS := \
      $(JDK_TOPDIR)/src/closed/share/native/sun/dc/doe \
      $(JDK_TOPDIR)/src/closed/share/native/sun/dc/path \
      $(JDK_TOPDIR)/src/closed/share/native/sun/dc/pr \
      $(JDK_TOPDIR)/src/closed/share/native/sun/dc/util

  LIBDCPR_CFLAGS := $(foreach dir, $(LIBDCPR_SRC_DIRS), -I$(dir)) \
      -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe

  $(eval $(call SetupNativeCompilation,BUILD_LIBDCPR, \
      LIBRARY := dcpr, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBDCPR_SRC_DIRS), \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(LIBDCPR_CFLAGS), \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libdcpr/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(LIBM) $(LDFLAGS_JDKLIB_SUFFIX), \
      LDFLAGS_SUFFIX_posix := -lm, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=dcpr.dll" \
          -D "JDK_INTERNAL_NAME=dcpr" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libdcpr, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBDCPR): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBDCPR)

endif

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

$(eval $(call SetupNativeCompilation,BUILD_LIBJ2PCSC, \
    LIBRARY := j2pcsc, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/sun/security/smartcardio \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/smartcardio, \
    LANG := C, \
    CFLAGS_posix := -D__sun_jdk, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        -I$(JDK_TOPDIR)/src/share/native/sun/security/smartcardio \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/smartcardio \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/smartcardio/MUSCLE, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libj2pcsc/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_posix := $(LIBDL), \
    LDFLAGS_SUFFIX_windows := winscard.lib, \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=j2pcsc.dll" \
        -D "JDK_INTERNAL_NAME=j2pcsc" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libj2pcsc, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBJ2PCSC)

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

ifneq ($(OPENJDK_TARGET_OS), windows)
  $(eval $(call SetupNativeCompilation,BUILD_LIBJ2GSS, \
      LIBRARY := j2gss, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/share/native/sun/security/jgss/wrapper \
          $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/jgss/wrapper, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/share/native/sun/security/jgss/wrapper \
          -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/jgss/wrapper, \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libj2gss/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(LIBDL), \
      LDFLAGS_SUFFIX_solaris := -lc, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libj2gss, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBJ2GSS)
endif

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

ifneq ($(BUILD_CRYPTO), no)
  BUILD_LIBKRB5_NAME :=
  ifeq ($(OPENJDK_TARGET_OS), windows)
    BUILD_LIBKRB5_NAME := w2k_lsa_auth
    BUILD_LIBKRB5_SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/krb5
    BUILD_LIBKRB5_LIBS := advapi32.lib Secur32.lib netapi32.lib kernel32.lib user32.lib \
        gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib \
        ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib
  else ifeq ($(OPENJDK_TARGET_OS), macosx)
    BUILD_LIBKRB5_NAME := osxkrb5
    BUILD_LIBKRB5_SRC := $(JDK_TOPDIR)/src/share/native/sun/security/krb5
    BUILD_LIBKRB5_LIBS := -framework Kerberos
  endif

  ifneq ($(BUILD_LIBKRB5_NAME), )
    $(eval $(call SetupNativeCompilation,BUILD_LIBKRB5, \
        LIBRARY := $(BUILD_LIBKRB5_NAME), \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(BUILD_LIBKRB5_SRC), \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) \
            -I$(JDK_TOPDIR)/src/share/native/sun/security/krb5 \
            -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/krb5, \
        LDFLAGS := $(LDFLAGS_JDKLIB) \
            $(call SET_SHARED_LIBRARY_ORIGIN), \
        LDFLAGS_SUFFIX := $(BUILD_LIBKRB5_LIBS), \
        VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
        RC_FLAGS := $(RC_FLAGS) \
            -D "JDK_FNAME=$(BUILD_LIBKRB5_NAME).dll" \
            -D "JDK_INTERNAL_NAME=$(BUILD_LIBKRB5_NAME)" \
            -D "JDK_FTYPE=0x2L", \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libkrb5, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    BUILD_LIBRARIES += $(BUILD_LIBKRB5)
  endif
endif

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

ifeq ($(OPENJDK_TARGET_OS), windows)

  $(eval $(call SetupNativeCompilation,BUILD_LIBSUNMSCAPI, \
      LIBRARY := sunmscapi, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/mscapi, \
      LANG := C++, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/mscapi, \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := Crypt32.Lib advapi32.lib, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=sunmscapi.dll" \
          -D "JDK_INTERNAL_NAME=sunmscapi" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libsunmscapi, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBSUNMSCAPI)
endif

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

$(eval $(call SetupNativeCompilation,BUILD_LIBJ2PKCS11, \
    LIBRARY := j2pkcs11, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(JDK_TOPDIR)/src/share/native/sun/security/pkcs11 \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/pkcs11 \
        $(JDK_TOPDIR)/src/share/native/sun/security/pkcs11/wrapper \
        $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/pkcs11/wrapper, \
    LANG := C, \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        -I$(JDK_TOPDIR)/src/share/native/sun/security/pkcs11 \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/pkcs11 \
        -I$(JDK_TOPDIR)/src/share/native/sun/security/pkcs11/wrapper \
        -I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/security/pkcs11/wrapper, \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libj2pkcs11/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_SUFFIX_posix := $(LIBDL), \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=j2pkcs11.dll" \
        -D "JDK_INTERNAL_NAME=j2pkcs11" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libj2pkcs11, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

BUILD_LIBRARIES += $(BUILD_LIBJ2PKCS11)

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

ifeq ($(ENABLE_INTREE_EC), yes)

  BUILD_LIBSUNEC_FLAGS := -I$(JDK_TOPDIR)/src/share/native/sun/security/ec \
      -I$(JDK_TOPDIR)/src/share/native/sun/security/ec/impl

  #
  # On sol-sparc...all libraries are compiled with -xregs=no%appl
  # (set in CFLAGS_REQUIRED_sparc)
  #
  # except!!! libsunec.so
  #
  ECC_JNI_SOLSPARC_FILTER :=
  ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
    ECC_JNI_SOLSPARC_FILTER := -xregs=no%appl
  endif

  $(eval $(call SetupNativeCompilation,BUILD_LIBSUNEC, \
      LIBRARY := sunec, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/share/native/sun/security/ec \
          $(JDK_TOPDIR)/src/share/native/sun/security/ec/impl, \
      LANG := C++, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CFLAGS_JDKLIB)) \
          $(BUILD_LIBSUNEC_FLAGS) \
          -DMP_API_COMPATIBLE -DNSS_ECC_MORE_THAN_SUITE_B, \
      CXXFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CXXFLAGS_JDKLIB)) \
          $(BUILD_LIBSUNEC_FLAGS), \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libsunec/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK), \
      LDFLAGS_macosx := $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(LIBCXX), \
      LDFLAGS_SUFFIX_linux := -lc, \
      LDFLAGS_SUFFIX_solaris := -lc, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=sunec.dll" \
          -D "JDK_INTERNAL_NAME=sunec" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libsunec, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBSUNEC)
endif

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

LIBJSOUND_SRC_DIRS := \
    $(JDK_TOPDIR)/src/share/native/com/sun/media/sound \
    $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/com/sun/media/sound

LIBJSOUND_SRC_FILES := Utilities.c Platform.c

LIBJSOUND_LANG := C
LIBJSOUND_CFLAGS := $(foreach dir, $(LIBJSOUND_SRC_DIRS), -I$(dir))

EXTRA_SOUND_JNI_LIBS :=

LIBJSOUND_MIDIFILES := \
    MidiInDevice.c \
    MidiInDeviceProvider.c \
    MidiOutDevice.c \
    MidiOutDeviceProvider.c \
    PlatformMidi.c

# files needed for ports
LIBJSOUND_PORTFILES := \
    PortMixerProvider.c \
    PortMixer.c

# files needed for direct audio
LIBJSOUND_DAUDIOFILES := \
    DirectAudioDeviceProvider.c \
    DirectAudioDevice.c

ifeq ($(OPENJDK_TARGET_OS), windows)
  EXTRA_SOUND_JNI_LIBS += jsoundds
  LIBJSOUND_CFLAGS += -DX_PLATFORM=X_WINDOWS \
      -DUSE_PLATFORM_MIDI_OUT=TRUE \
      -DUSE_PLATFORM_MIDI_IN=TRUE \
      -DUSE_PORTS=TRUE
  LIBJSOUND_SRC_FILES += \
      PLATFORM_API_WinOS_MidiIn.cpp \
      PLATFORM_API_WinOS_MidiOut.c \
      PLATFORM_API_WinOS_Util.c \
      PLATFORM_API_WinOS_Ports.c
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_MIDIFILES)
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_PORTFILES)
endif # OPENJDK_TARGET_OS windows

ifeq ($(OPENJDK_TARGET_OS), linux)
  EXTRA_SOUND_JNI_LIBS += jsoundalsa
  LIBJSOUND_CFLAGS += -DX_PLATFORM=X_LINUX
endif # OPENJDK_TARGET_OS linux

ifeq ($(OPENJDK_TARGET_OS), macosx)
  LIBJSOUND_LANG := C++
  LIBJSOUND_CFLAGS += -DX_PLATFORM=X_MACOSX \
      -DUSE_PORTS=TRUE \
      -DUSE_DAUDIO=TRUE \
      -DUSE_PLATFORM_MIDI_OUT=TRUE \
      -DUSE_PLATFORM_MIDI_IN=TRUE
  LIBJSOUND_SRC_DIRS += $(JDK_TOPDIR)/src/macosx/native/com/sun/media/sound
  LIBJSOUND_SRC_FILES += \
      PLATFORM_API_MacOSX_Utils.cpp \
      PLATFORM_API_MacOSX_PCM.cpp \
      PLATFORM_API_MacOSX_Ports.cpp \
      PLATFORM_API_MacOSX_MidiIn.c \
      PLATFORM_API_MacOSX_MidiOut.c \
      PLATFORM_API_MacOSX_MidiUtils.c
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_MIDIFILES)
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_PORTFILES)
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_DAUDIOFILES)
endif # OPENJDK_TARGET_OS macosx

ifeq ($(OPENJDK_TARGET_OS), solaris)
  LIBJSOUND_CFLAGS += -DX_PLATFORM=X_SOLARIS \
      -DUSE_PORTS=TRUE \
      -DUSE_DAUDIO=TRUE
  LIBJSOUND_SRC_FILES += \
      PLATFORM_API_SolarisOS_Utils.c \
      PLATFORM_API_SolarisOS_Ports.c \
      PLATFORM_API_SolarisOS_PCM.c
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_MIDIFILES)
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_PORTFILES)
  LIBJSOUND_SRC_FILES += $(LIBJSOUND_DAUDIOFILES)
endif # OPENJDK_TARGET_OS solaris


ifeq ($(JVM_VARIANT_ZERO), true)
  LIBJSOUND_CFLAGS += -DX_ARCH=X_ZERO
else
  ifeq ($(OPENJDK_TARGET_CPU), x86)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_I586
  endif

  ifeq ($(OPENJDK_TARGET_CPU), sparc)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_SPARC
  endif

  ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_SPARCV9
  endif

  ifeq ($(OPENJDK_TARGET_CPU), x86_64)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_AMD64
  endif

  ifeq ($(OPENJDK_TARGET_CPU), arm)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_ARM
  endif

  ifeq ($(OPENJDK_TARGET_CPU), ppc)
    LIBJSOUND_CFLAGS += -DX_ARCH=X_PPC
  endif
endif

LIBJSOUND_CFLAGS += -DEXTRA_SOUND_JNI_LIBS='"$(EXTRA_SOUND_JNI_LIBS)"'

$(eval $(call SetupNativeCompilation,BUILD_LIBJSOUND, \
    LIBRARY := jsound, \
    OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
    SRC := $(LIBJSOUND_SRC_DIRS), \
    INCLUDE_FILES := $(LIBJSOUND_SRC_FILES), \
    LANG := $(LIBJSOUND_LANG), \
    OPTIMIZATION := LOW, \
    CFLAGS := $(CFLAGS_JDKLIB) \
        $(LIBJSOUND_CFLAGS), \
    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(LIBJSOUND_CFLAGS), \
    MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjsound/mapfile-vers, \
    LDFLAGS := $(LDFLAGS_JDKLIB) \
        $(call SET_SHARED_LIBRARY_ORIGIN), \
    LDFLAGS_macosx := -framework CoreAudio -framework CoreFoundation \
        -framework CoreServices -framework AudioUnit $(LIBCXX) \
        -framework CoreMIDI -framework AudioToolbox, \
    LDFLAGS_windows := $(WIN_JAVA_LIB) advapi32.lib winmm.lib, \
    LDFLAGS_SUFFIX_posix := -ljava -ljvm, \
    LDFLAGS_SUFFIX_solaris := -lc, \
    VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
    RC_FLAGS := $(RC_FLAGS) \
        -D "JDK_FNAME=jsound.dll" \
        -D "JDK_INTERNAL_NAME=jsound" \
        -D "JDK_FTYPE=0x2L", \
    OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjsound, \
    DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

$(BUILD_LIBJSOUND): $(BUILD_LIBJAVA)

BUILD_LIBRARIES += $(BUILD_LIBJSOUND)

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

ifneq ($(filter jsoundalsa, $(EXTRA_SOUND_JNI_LIBS)), )

  $(eval $(call SetupNativeCompilation,BUILD_LIBJSOUNDALSA, \
      LIBRARY := jsoundalsa, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBJSOUND_SRC_DIRS), \
      INCLUDE_FILES := Utilities.c $(LIBJSOUND_MIDIFILES) $(LIBJSOUND_PORTFILES) \
          $(LIBJSOUND_DAUDIOFILES) \
          PLATFORM_API_LinuxOS_ALSA_CommonUtils.c \
          PLATFORM_API_LinuxOS_ALSA_PCM.c \
          PLATFORM_API_LinuxOS_ALSA_PCMUtils.c \
          PLATFORM_API_LinuxOS_ALSA_MidiIn.c \
          PLATFORM_API_LinuxOS_ALSA_MidiOut.c \
          PLATFORM_API_LinuxOS_ALSA_MidiUtils.c \
          PLATFORM_API_LinuxOS_ALSA_Ports.c, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) $(ALSA_CFLAGS) \
          $(LIBJSOUND_CFLAGS) \
          -DUSE_DAUDIO=TRUE \
          -DUSE_PORTS=TRUE \
          -DUSE_PLATFORM_MIDI_OUT=TRUE \
          -DUSE_PLATFORM_MIDI_IN=TRUE, \
      MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libjsoundalsa/mapfile-vers, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(ALSA_LIBS) -ljava -ljvm, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjsoundalsa, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBJSOUNDALSA): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBJSOUNDALSA)

endif

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

ifneq ($(filter jsoundds, $(EXTRA_SOUND_JNI_LIBS)), )

  $(eval $(call SetupNativeCompilation,BUILD_LIBJSOUNDDS, \
      LIBRARY := jsoundds, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBJSOUND_SRC_DIRS), \
      INCLUDE_FILES := Utilities.c $(LIBJSOUND_DAUDIOFILES) \
          PLATFORM_API_WinOS_DirectSound.cpp, \
      LANG := C++, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(LIBJSOUND_CFLAGS) \
          -DUSE_DAUDIO=TRUE, \
      LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := $(LDFLAGS_JDKLIB_SUFFIX) dsound.lib winmm.lib user32.lib ole32.lib, \
      VERSIONINFO_RESOURCE := $(JDK_TOPDIR)/src/windows/resource/version.rc, \
      RC_FLAGS := $(RC_FLAGS) \
          -D "JDK_FNAME=jsoundds.dll" \
          -D "JDK_INTERNAL_NAME=jsoundds" \
          -D "JDK_FTYPE=0x2L", \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjsoundds, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBJSOUNDDS): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBJSOUNDDS)

endif

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

ifeq ($(OPENJDK_TARGET_OS), solaris)
  ifndef OPENJDK

    $(eval $(call SetupNativeCompilation,BUILD_LIBJ2UCRYPTO, \
        LIBRARY := j2ucrypto, \
        OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
        SRC := $(JDK_TOPDIR)/src/closed/solaris/native/com/oracle/security/ucrypto, \
        LANG := C, \
        OPTIMIZATION := LOW, \
        CFLAGS := $(CFLAGS_JDKLIB) \
            -I$(JDK_TOPDIR)/src/closed/solaris/native/com/oracle/security/ucrypto, \
        MAPFILE := $(JDK_TOPDIR)/makefiles/mapfiles/libj2ucrypto/mapfile-vers, \
        LDFLAGS := $(LDFLAGS_JDKLIB), \
        LDFLAGS_SUFFIX := $(LIBDL), \
        LDFLAGS_SUFFIX_solaris := -lc, \
        OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libj2ucrypto, \
        DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

    $(BUILD_LIBJ2UCRYPTO): $(BUILD_LIBJAVA)

    BUILD_LIBRARIES += $(BUILD_LIBJ2UCRYPTO)

  endif
endif

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

ifeq ($(OPENJDK_TARGET_OS), macosx)

  $(eval $(call SetupNativeCompilation,BUILD_LIBAPPLESCRIPTENGINE, \
      LIBRARY := AppleScriptEngine, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/macosx/native/apple/applescript, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/macosx/native/apple/applescript \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX := -framework Cocoa \
          -framework Carbon \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -framework JavaNativeFoundation \
          $(LDFLAGS_JDKLIB_SUFFIX), \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libAppleScriptEngine, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  $(BUILD_LIBAPPLESCRIPTENGINE): $(BUILD_LIBJAVA)

  BUILD_LIBRARIES += $(BUILD_LIBAPPLESCRIPTENGINE)

endif

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

ifeq ($(OPENJDK_TARGET_OS), macosx)

  $(eval $(call SetupNativeCompilation,BUILD_LIBOSXAPP, \
      LIBRARY := osxapp, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/macosx/native/sun/osxapp, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/macosx/native/sun/osxapp \
          -I$(JDK_OUTPUTDIR)/gensrc/sun/osxapp \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX_macosx := \
          -framework Accelerate \
          -framework ApplicationServices \
          -framework AudioToolbox \
          -framework Carbon \
          -framework Cocoa \
          -framework Security \
          -framework ExceptionHandling \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -framework OpenGL \
          -framework IOSurface \
          -framework QuartzCore, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libosxapp, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBOSXAPP)

endif

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

ifeq ($(OPENJDK_TARGET_OS), macosx)

  LIBOSX_DIRS := \
      $(JDK_TOPDIR)/src/macosx/native/com/apple/concurrent \
      $(JDK_TOPDIR)/src/macosx/native/java/util \
      $(JDK_TOPDIR)/src/macosx/native/com/apple/eio \
      $(JDK_TOPDIR)/src/macosx/native/apple/security \
      $(JDK_TOPDIR)/src/macosx/native/apple/launcher

  $(eval $(call SetupNativeCompilation,BUILD_LIBOSX, \
      LIBRARY := osx, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBOSX_DIRS), \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          $(foreach dir, $(LIBOSX_DIRS), -I$(dir)) \
          -I$(JDK_TOPDIR)/src/macosx/native/sun/osxapp \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX_macosx := \
          -losxapp \
          -framework Cocoa \
          -framework ApplicationServices \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -framework Security \
          -framework SystemConfiguration \
          $(LDFLAGS_JDKLIB_SUFFIX), \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libosx, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBOSX)

  $(BUILD_LIBOSX): $(BUILD_LIBOSXAPP)

  $(BUILD_LIBOSX): $(BUILD_LIBJAVA)

endif

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

ifeq ($(OPENJDK_TARGET_OS), macosx)

  LIBAWT_LWAWT_FILES := \
      awt.m \
      ApplicationDelegate.m \
      CFRetainedResource.m \
      CGLGraphicsConfig.m \
      CGLSurfaceData.m \
      CGLLayer.m \
      CGraphicsConfig.m \
      CGraphicsDevice.m \
      CGraphicsEnv.m \
      CCharToGlyphMapper.m \
      CSystemColors.m \
      AWTFont.m \
      CGGlyphOutlines.m \
      CGGlyphImages.m \
      CoreTextSupport.m \
      AWTStrike.m \
      InitIDs.m \
      AWTEvent.m \
      AWTView.m \
      AWTWindow.m \
      AWTSurfaceLayers.m \
      CCursorManager.m \
      CClipboard.m \
      CDataTransferer.m \
      CDragSource.m \
      CDragSourceContextPeer.m \
      CDropTarget.m \
      CDropTargetContextPeer.m \
      CInputMethod.m \
      CDesktopPeer.m \
      OSVersion.m \
      DnDUtilities.m \
      CFileDialog.m \
      CImage.m \
      CMenu.m \
      CMenuBar.m \
      CMenuComponent.m \
      CMenuItem.m \
      CPopupMenu.m \
      CRobot.m \
      CTrayIcon.m \
      CWrapper.m \
      JavaAccessibilityAction.m \
      JavaAccessibilityUtilities.m \
      JavaComponentAccessibility.m \
      JavaTextAccessibility.m \
      LWCToolkit.m \
      GeomUtilities.m \
      CPrinterJob.m \
      PrintModel.m \
      PrinterSurfaceData.m \
      PrinterView.m \
      QuartzSurfaceData.m \
      QuartzRenderer.m \
      CTextPipe.m \
      ImageSurfaceData.m \
      awt_DrawingSurface.m \
      \
      OGLBlitLoops.c \
      OGLBufImgOps.c \
      OGLContext.c \
      OGLFuncs.c \
      OGLMaskBlit.c \
      OGLMaskFill.c \
      OGLPaints.c \
      OGLRenderQueue.c \
      OGLRenderer.c \
      OGLSurfaceData.c \
      OGLTextRenderer.c \
      OGLVertexCache.c \
      AccelGlyphCache.c \
      CUPSfuncs.c


  LIBAWT_LWAWT_DIRS := \
      $(JDK_TOPDIR)/src/macosx/native/sun/awt \
      $(JDK_TOPDIR)/src/macosx/native/sun/font \
      $(JDK_TOPDIR)/src/macosx/native/sun/java2d/opengl \
      $(JDK_TOPDIR)/src/solaris/native/sun/awt \
      $(JDK_TOPDIR)/src/share/native/sun/font \
      $(JDK_TOPDIR)/src/share/native/sun/java2d/opengl \

  $(eval $(call SetupNativeCompilation,BUILD_LIBAWT_LWAWT, \
      LIBRARY := awt_lwawt, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(LIBAWT_LWAWT_DIRS), \
      LANG := C, \
      INCLUDE_FILES := $(LIBAWT_LWAWT_FILES), \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
      $(X_CFLAGS) \
      $(X_LIBS) \
      $(foreach dir, $(LIBAWT_LWAWT_DIRS), -I$(dir)) \
          -I$(JDK_TOPDIR)/src/macosx/native/sun/osxapp \
          -I$(JDK_TOPDIR)/src/share/native/sun/java2d \
          -I$(JDK_TOPDIR)/src/solaris/native/sun/java2d \
          -I$(JDK_TOPDIR)/src/share/native/sun/awt/image \
          -I$(JDK_TOPDIR)/src/share/native/sun/awt/image/cvutils \
          -I$(JDK_TOPDIR)/src/share/native/sun/java2d/loops \
          -I$(JDK_TOPDIR)/src/share/native/sun/java2d/pipe \
          -I$(JDK_TOPDIR)/src/share/native/sun/awt/debug \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -F/System/Library/Frameworks/ApplicationServices.framework/Frameworks, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN), \
      LDFLAGS_SUFFIX_macosx := -lawt -lmlib_image -losxapp -ljvm $(LIBM) \
          -framework Accelerate \
          -framework ApplicationServices \
          -framework AudioToolbox \
          -framework Carbon \
          -framework Cocoa \
          -framework Security \
          -framework ExceptionHandling \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -framework OpenGL \
          -framework QuartzCore -ljava, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libawt_lwawt, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBAWT_LWAWT)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBAWT)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBMLIB_IMAGE)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBOSXAPP)

  $(BUILD_LIBAWT_LWAWT): $(BUILD_LIBJAVA)

endif

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

ifeq ($(OPENJDK_TARGET_OS), macosx)

  $(eval $(call SetupNativeCompilation,BUILD_LIBOSXUI, \
      LIBRARY := osxui, \
      OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
      SRC := $(JDK_TOPDIR)/src/macosx/native/com/apple/laf, \
      LANG := C, \
      OPTIMIZATION := LOW, \
      CFLAGS := $(CFLAGS_JDKLIB) \
          -I$(JDK_TOPDIR)/src/macosx/native/com/apple/laf \
          -I$(JDK_TOPDIR)/src/macosx/native/sun/osxapp \
          -I$(JDK_TOPDIR)/src/macosx/native/sun/awt \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks, \
      LDFLAGS := $(LDFLAGS_JDKLIB) \
          $(call SET_SHARED_LIBRARY_ORIGIN) \
          -Xlinker -rpath -Xlinker @loader_path, \
      LDFLAGS_SUFFIX_macosx := -lawt -losxapp -lawt_lwawt \
          -framework Cocoa \
          -framework Carbon \
          -framework ApplicationServices \
          -F/System/Library/Frameworks/JavaVM.framework/Frameworks \
          -framework JavaNativeFoundation \
          -framework JavaRuntimeSupport \
          -ljava -ljvm, \
      OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libosxui, \
      DEBUG_SYMBOLS := $(DEBUG_ALL_BINARIES)))

  BUILD_LIBRARIES += $(BUILD_LIBOSXUI)

  $(BUILD_LIBOSXUI): $(BUILD_LIBAWT)

  $(BUILD_LIBOSXUI): $(BUILD_LIBOSXAPP)

  $(BUILD_LIBOSXUI): $(BUILD_LIBAWT_LWAWT)

  #$(BUILD_LIBOSXUI): $(BUILD_LIBJAVA)

endif

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

ifndef OPENJDK
  ifeq ($(OPENJDK_TARGET_OS), windows)

    ACCESSBRIDGE_SRCDIR := $(JDK_TOPDIR)/src/closed/windows/native/sun/bridge

    define SetupAccessBridge
      # Parameter 1 Suffix
      # Parameter 2 Machine
      # Parameter 3 ACCESSBRIDGE_ARCH_ suffix

      $(call SetupNativeCompilation,BUILD_JAWTACCESSBRIDGE$1, \
          LIBRARY = JAWTAccessBridge$1, \
          OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
          SRC := $(ACCESSBRIDGE_SRCDIR), \
          INCLUDE_FILES := JAWTAccessBridge.cpp, \
          LANG := C++, \
          OPTIMIZATION := LOW, \
          CFLAGS := $(CFLAGS_JDKLIB) \
              -DACCESSBRIDGE_ARCH_$3, \
          LDFLAGS := $(LDFLAGS_JDKLIB) kernel32.lib user32.lib gdi32.lib \
              winspool.lib jawt.lib comdlg32.lib advapi32.lib shell32.lib \
              ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
              -subsystem:windows -machine:$2 \
              -def:$(ACCESSBRIDGE_SRCDIR)/JAWTAccessBridge.DEF, \
          VERSIONINFO_RESOURCE := $(ACCESSBRIDGE_SRCDIR)/AccessBridgeStatusWindow.rc, \
          RC_FLAGS := $(RC_FLAGS), \
          OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjawtaccessbridge$1, \
          DEBUG_SYMBOLS := true)

      $$(BUILD_JAWTACCESSBRIDGE$1): $(JDK_OUTPUTDIR)/lib/$(LIBRARY_PREFIX)jawt$(STATIC_LIBRARY_SUFFIX)

      $(call SetupNativeCompilation,BUILD_JAVAACCESSBRIDGE$1, \
          LIBRARY = JavaAccessBridge$1, \
          OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
          SRC := $(ACCESSBRIDGE_SRCDIR), \
          INCLUDE_FILES := AccessBridgeATInstance.cpp AccessBridgeDebug.cpp \
              AccessBridgeJavaEntryPoints.cpp \
              AccessBridgeMessages.cpp JavaAccessBridge.cpp, \
          LANG := C++, \
          OPTIMIZATION := LOW, \
          CFLAGS := $(CFLAGS_JDKLIB) \
              -DACCESSBRIDGE_ARCH_$3, \
          LDFLAGS := $(LDFLAGS_JDKLIB) kernel32.lib user32.lib gdi32.lib \
              winspool.lib comdlg32.lib advapi32.lib shell32.lib \
              ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
              -subsystem:windows -machine:$2 \
              -def:$(ACCESSBRIDGE_SRCDIR)/JavaAccessBridge.DEF, \
          VERSIONINFO_RESOURCE := $(ACCESSBRIDGE_SRCDIR)/AccessBridgeStatusWindow.rc, \
          RC_FLAGS := $(RC_FLAGS), \
          OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libjavaaccessbridge$1, \
          DEBUG_SYMBOLS := true)

      $(call SetupNativeCompilation,BUILD_WINDOWSACCESSBRIDGE$1, \
          LIBRARY = WindowsAccessBridge$1, \
          OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
          SRC := $(ACCESSBRIDGE_SRCDIR), \
          INCLUDE_FILES := AccessBridgeJavaVMInstance.cpp AccessBridgeMessageQueue.cpp \
              AccessBridgeMessages.cpp AccessBridgeWindowsEntryPoints.cpp \
              WinAccessBridge.cpp AccessBridgeDebug.cpp \
              AccessBridgeEventHandler.cpp, \
          LANG := C++, \
          OPTIMIZATION := LOW, \
          CFLAGS := $(filter-out -MD, $(CFLAGS_JDKLIB)) -MT \
              -DACCESSBRIDGE_ARCH_$3, \
          LDFLAGS := $(LDFLAGS_JDKLIB) kernel32.lib user32.lib gdi32.lib \
              winspool.lib comdlg32.lib advapi32.lib shell32.lib \
              ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
              -subsystem:windows -machine:$2 \
              -def:$(ACCESSBRIDGE_SRCDIR)/WinAccessBridge.DEF, \
          VERSIONINFO_RESOURCE := $(ACCESSBRIDGE_SRCDIR)/AccessBridgeStatusWindow.rc, \
          RC_FLAGS := $(RC_FLAGS), \
          OBJECT_DIR := $(JDK_OUTPUTDIR)/objs/libwindowsaccessbridge$1, \
          DEBUG_SYMBOLS := true)

      BUILD_LIBRARIES += $$(BUILD_JAWTACCESSBRIDGE$1) $$(BUILD_JAVAACCESSBRIDGE$1) \
          $$(BUILD_WINDOWSACCESSBRIDGE$1)

    endef

    ifeq ($(OPENJDK_TARGET_CPU_BITS), 32)
      $(eval $(call SetupAccessBridge,-32,I386,32))
      $(eval $(call SetupAccessBridge,,I386,LEGACY))
    else
      $(eval $(call SetupAccessBridge,-64,X64,64))
    endif
  endif
endif


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

all: $(COPY_FILES) $(BUILD_LIBRARIES)

.PHONY: all