Initial fix for setting SRC automatically + HEADER_FLAGS. ihse-jdk-library-branch
authorihse
Mon, 16 Apr 2018 11:48:41 +0200
branchihse-jdk-library-branch
changeset 56433 c3cf838aa2da
parent 56421 92bea2b7732a
child 56434 69b4183fd7b8
Initial fix for setting SRC automatically + HEADER_FLAGS.
make/common/JdkNativeCompilation.gmk
make/common/MakeBase.gmk
make/lib/Awt2dLibraries.gmk
make/lib/CoreLibraries.gmk
make/lib/Lib-java.base.gmk
make/lib/Lib-java.desktop.gmk
make/lib/Lib-java.instrument.gmk
make/lib/Lib-java.management.gmk
make/lib/Lib-java.prefs.gmk
make/lib/Lib-java.rmi.gmk
make/lib/Lib-java.security.jgss.gmk
make/lib/Lib-java.smartcardio.gmk
make/lib/Lib-jdk.accessibility.gmk
make/lib/Lib-jdk.attach.gmk
make/lib/Lib-jdk.crypto.cryptoki.gmk
make/lib/Lib-jdk.crypto.ec.gmk
make/lib/Lib-jdk.crypto.mscapi.gmk
make/lib/Lib-jdk.crypto.ucrypto.gmk
make/lib/Lib-jdk.hotspot.agent.gmk
make/lib/Lib-jdk.internal.le.gmk
make/lib/Lib-jdk.jdi.gmk
make/lib/Lib-jdk.jdwp.agent.gmk
make/lib/Lib-jdk.management.agent.gmk
make/lib/Lib-jdk.management.gmk
make/lib/Lib-jdk.net.gmk
make/lib/Lib-jdk.pack.gmk
make/lib/Lib-jdk.sctp.gmk
make/lib/Lib-jdk.security.auth.gmk
--- a/make/common/JdkNativeCompilation.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/common/JdkNativeCompilation.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -32,6 +32,22 @@
 
 include NativeCompilation.gmk
 
+# FIXME:LIBS
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, lib/LibCommon.gmk))
+
+FindSrcDirsForLib += \
+  $(call uniq, $(wildcard \
+      $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/lib$(strip $2) \
+      $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/lib$(strip $2) \
+      $(TOPDIR)/src/$(strip $1)/share/native/lib$(strip $2)))
+
+FindSrcDirsForComponent += \
+  $(call uniq, $(wildcard \
+      $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/$(strip $2) \
+      $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/$(strip $2) \
+      $(TOPDIR)/src/$(strip $1)/share/native/$(strip $2)))
+
 # Setup make rules for creating a native shared library with suitable defaults
 # for the OpenJDK project.
 #
@@ -39,8 +55,9 @@
 # and the targets generated are listed in a variable by that name.
 #
 # Remaining parameters are named arguments. These are all passed on to
-# SetupNativeCompilation, except for 
+# SetupNativeCompilation, except for
 #   EXTRA_RC_FLAGS -- additional RC_FLAGS to append.
+#   HEADER_FLAGS - where to look for headers! FIXME:LIBS
 SetupJdkLibrary = $(NamedParamsMacroTemplate)
 define SetupJdkLibraryBody
   ifeq ($$($1_OUTPUT_DIR), )
@@ -51,6 +68,10 @@
     $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/lib$$($1_NAME)
   endif
 
+  ifeq ($$($1_SRC), )
+    $1_SRC := $$(call FindSrcDirsForLib, $$(MODULE), $$($1_NAME))
+  endif
+
   ifeq ($$($1_VERSIONINFO_RESOURCE), )
     $1_VERSIONINFO_RESOURCE := $$(GLOBAL_VERSION_INFO_RESOURCE)
   else ifeq ($$($1_VERSIONINFO_RESOURCE), DISABLE)
@@ -66,6 +87,11 @@
     $1_RC_FLAGS :=
   endif
 
+  ifneq ($$($1_HEADERS_FROM_SRC), false)
+    $1_SRC_HEADER_FLAGS := $$(foreach dir, $$($1_SRC), -I$$(dir))
+  endif
+  $1_CFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_HEADER_FLAGS)
+  $1_CXXFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_HEADER_FLAGS)
   $1_RC_FLAGS += $$($1_EXTRA_RC_FLAGS)
 
   # Since we reuse the rule name ($1), all our arguments will pass through.
@@ -80,7 +106,7 @@
 # and the targets generated are listed in a variable by that name.
 #
 # Remaining parameters are named arguments. These are all passed on to
-# SetupNativeCompilation, except for 
+# SetupNativeCompilation, except for
 #   EXTRA_RC_FLAGS -- additional RC_FLAGS to append.
 SetupJdkExecutable = $(NamedParamsMacroTemplate)
 define SetupJdkExecutableBody
--- a/make/common/MakeBase.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/common/MakeBase.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -634,7 +634,7 @@
 ################################################################################
 # Filter out duplicate sub strings while preserving order. Keeps the first occurance.
 uniq = \
-    $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
+    $(strip $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))))
 
 # Returns all whitespace-separated words in $2 where at least one of the
 # whitespace-separated words in $1 is a substring.
--- a/make/lib/Awt2dLibraries.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Awt2dLibraries.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -31,22 +31,15 @@
 
 BUILD_LIBMLIB_SRC := $(TOPDIR)/src/java.desktop/share/native/libmlib_image \
     $(TOPDIR)/src/java.desktop/share/native/common/awt/medialib
-BUILD_LIBMLIB_CFLAGS := -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES \
-    $(addprefix -I, $(BUILD_LIBMLIB_SRC)) \
-    -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libmlib_image
 
-BUILD_LIBMLIB_LDLIBS :=
+BUILD_LIBMLIB_CFLAGS := -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES -DMLIB_NO_LIBSUNMATH
 
-BUILD_LIBMLIB_CFLAGS += -DMLIB_NO_LIBSUNMATH
+BUILD_LIBMLIB_HEADER_FLAGS := -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libmlib_image
 
 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 SetupJdkLibrary, BUILD_LIBMLIB_IMAGE, \
     NAME := mlib_image, \
     SRC := $(BUILD_LIBMLIB_SRC), \
@@ -54,10 +47,11 @@
     OPTIMIZATION := HIGHEST, \
     CFLAGS := $(CFLAGS_JDKLIB) \
         $(BUILD_LIBMLIB_CFLAGS), \
+    HEADER_FLAGS := $(BUILD_LIBMLIB_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
-    LIBS := $(BUILD_LIBMLIB_LDLIBS) \
-        $(JDKLIB_LIBS), \
+    LIBS := $(JDKLIB_LIBS), \
+    LIBS_unix := $(LIBM) $(LIBDL), \
 ))
 
 $(BUILD_LIBMLIB_IMAGE): $(call FindLib, java.base, java)
@@ -68,14 +62,13 @@
 
 ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)
 
-  LIBMLIB_IMAGE_V_SRC := $(TOPDIR)/src/java.desktop/share/native/libmlib_image \
-      $(TOPDIR)/src/java.desktop/unix/native/libmlib_image \
-      $(TOPDIR)/src/java.desktop/share/native/common/awt/medialib \
-      $(TOPDIR)/src/java.desktop/unix/native/common/awt/medialib \
-      #
-  LIBMLIB_IMAGE_V_CFLAGS := $(TOPDIR)/src/java.desktop/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il \
-      $(addprefix -I, $(LIBMLIB_IMAGE_V_SRC)) \
-      #
+  LIBMLIB_IMAGE_V_SRC := \
+    $(call FindSrcDirsForLib, java.desktop, mlib_image) \
+    $(call FindSrcDirsForComponent, java.desktop, common/awt/medialib) \
+    #
+
+  LIBMLIB_IMAGE_V_CFLAGS := -xarch=sparcvis -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES \
+      $(TOPDIR)/src/java.desktop/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il
 
   BUILD_LIBMLIB_IMAGE_V_EXFILES := \
       awt_ImagingLib.c \
@@ -95,16 +88,13 @@
       mlib_c_ImageLookUp_f.c \
       #
 
-  LIBMLIB_IMAGE_V_CFLAGS += $(filter-out -DMLIB_NO_LIBSUNMATH, $(BUILD_LIBMLIB_CFLAGS))
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBMLIB_IMAGE_V, \
       NAME := mlib_image_v, \
       SRC := $(LIBMLIB_IMAGE_V_SRC), \
       EXCLUDE_FILES := $(BUILD_LIBMLIB_IMAGE_V_EXFILES), \
       OPTIMIZATION := HIGHEST, \
-      CFLAGS := -xarch=sparcvis \
-          $(LIBMLIB_IMAGE_V_CFLAGS) \
-          $(CFLAGS_JDKLIB), \
+      CFLAGS := $(CFLAGS_JDKLIB) \
+          $(LIBMLIB_IMAGE_V_CFLAGS), \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
       LIBS := -ljava -ljvm $(BUILD_LIBMLIB_LDLIBS), \
@@ -118,20 +108,11 @@
 
 ################################################################################
 
-LIBAWT_DIRS := $(TOPDIR)/src/java.desktop/share/native/libawt \
-    $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt \
-    $(TOPDIR)/src/java.desktop/share/native/common/awt/debug \
-    $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
+LIBAWT_DIRS := \
+    $(call FindSrcDirsForLib, java.desktop, awt) \
+    $(call FindSrcDirsForComponent, java.desktop, common/awt) \
     #
 
-ifeq ($(OPENJDK_TARGET_OS), aix)
-  LIBAWT_DIRS += $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS)/native/libawt
-endif
-
-ifeq ($(OPENJDK_TARGET_OS), windows)
-  LIBAWT_DIRS += $(TOPDIR)/src/java.desktop/share/native/common/awt/utility
-endif
-
 ifneq ($(filter $(OPENJDK_TARGET_OS), solaris linux macosx aix), )
   LIBAWT_EXFILES += awt_Font.c CUPSfuncs.c fontpath.c X11Color.c
 endif
@@ -140,27 +121,22 @@
   LIBAWT_EXFILES += initIDs.c awt/image/cvutils/img_colors.c
 endif
 
-LIBAWT_CFLAGS += -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
-    $(addprefix -I, $(shell find $(LIBAWT_DIRS) -type d)) \
+LIBAWT_HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
     $(LIBJAVA_HEADER_FLAGS) \
     $(addprefix -I, $(BUILD_LIBMLIB_IMAGE_SRC)) \
+    $(addprefix -I, $(shell find $(LIBAWT_DIRS) -type d)) \
     #
+    # FIXME:LIBS: I wish this FIND was not needed.
+
 
 LIBAWT_CFLAGS += -D__MEDIALIB_OLD_NAMES -D__USE_J2D_NAMES $(X_CFLAGS)
 
-ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU_ARCH), solaris-sparc)
-  LIBAWT_CFLAGS += -DMLIB_ADD_SUFF
-  LIBAWT_CFLAGS += -xarch=sparcvis
-
-  LIBAWT_CFLAGS += $(TOPDIR)/src/java.desktop/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il
-  LIBAWT_DIRS += $(TOPDIR)/src/java.desktop/share/native/common/awt/medialib
+ifeq ($(OPENJDK_TARGET_OS)-$(OPENJDK_TARGET_CPU), solaris-sparcv9)
+  LIBAWT_CFLAGS += -xarch=sparcvis -DMLIB_ADD_SUFF \
+      $(TOPDIR)/src/java.desktop/unix/native/libmlib_image/vis_$(OPENJDK_TARGET_CPU_BITS).il
   LIBAWT_EXFILES += java2d/loops/MapAccelFunc.c
 
-  ifeq ($(OPENJDK_TARGET_CPU), sparcv9)
-    LIBAWT_ASFLAGS = -P -xarch=v9a
-  else
-    LIBAWT_ASFLAGS = -P -xarch=v8plusa
-  endif
+  LIBAWT_ASFLAGS = -P -xarch=v9a
 else
   LIBAWT_EXCLUDES += \
       $(TOPDIR)/src/java.desktop/unix/native/libawt/awt/medialib \
@@ -177,9 +153,10 @@
   LIBAWT_DIRS += $(TOPDIR)/src/java.desktop/share/native/common/font \
       $(TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \
       $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt/systemscale \
+      #
+
   # Why does libawt need java.base headers?
-  LIBAWT_CFLAGS += -I$(TOPDIR)/src/java.desktop/share/native/common/font \
-      -I$(TOPDIR)/src/java.desktop/share/native/common/java2d/opengl \
+  LIBAWT_HEADER_FLAGS +=
       -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/java2d/opengl \
       -I$(TOPDIR)/src/java.desktop/windows/native/include \
       -I$(TOPDIR)/src/java.desktop/share/native/include \
@@ -220,6 +197,7 @@
     EXCLUDE_FILES := $(LIBAWT_EXFILES), \
     OPTIMIZATION := LOW, \
     CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_CFLAGS), \
+    HEADER_FLAGS := $(LIBAWT_HEADER_FLAGS), \
     DISABLED_WARNINGS_gcc := sign-compare unused-result maybe-uninitialized \
         format-nonliteral parentheses, \
     DISABLED_WARNINGS_clang := logical-op-parentheses extern-initializer, \
@@ -284,7 +262,7 @@
 
     LIBAWT_XAWT_EXCLUDES := medialib
 
-    LIBAWT_XAWT_CFLAGS := $(addprefix -I, $(shell $(FIND) $(LIBAWT_XAWT_DIRS) -type d)) \
+    LIBAWT_XAWT_HEADER_FLAGS := \
         -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
         -I$(TOPDIR)/src/java.desktop/share/native/include \
         -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS)/native/include \
@@ -296,8 +274,10 @@
         -I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
         -I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image \
         -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/font \
-        $(LIBJAVA_HEADER_FLAGS)
+        $(LIBJAVA_HEADER_FLAGS) \
+        $(addprefix -I, $(shell $(FIND) $(LIBAWT_XAWT_DIRS) -type d)) \
         #
+        # FIXME:LIBS: I wish this FIND was not needed!!!
 
     LIBAWT_XAWT_CFLAGS += -DXAWT -DXAWT_HACK \
         -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
@@ -338,6 +318,7 @@
         OPTIMIZATION := LOW, \
         CFLAGS := $(CFLAGS_JDKLIB) $(LIBAWT_XAWT_CFLAGS) \
             $(X_CFLAGS), \
+        HEADER_FLAGS := $(LIBAWT_XAWT_HEADER_FLAGS), \
         WARNINGS_AS_ERRORS_xlc := false, \
         DISABLED_WARNINGS_gcc := type-limits pointer-to-int-cast \
             unused-result maybe-uninitialized format \
@@ -349,10 +330,6 @@
             $(call SET_SHARED_LIBRARY_ORIGIN) \
             -L$(INSTALL_LIBRARIES_HERE), \
         LIBS :=  $(X_LIBS) $(LIBAWT_XAWT_LIBS), \
-        RC_FLAGS := $(RC_FLAGS) \
-            -D "JDK_FNAME=xawt.dll" \
-            -D "JDK_INTERNAL_NAME=xawt" \
-            -D "JDK_FTYPE=0x2L", \
     ))
 
     $(BUILD_LIBAWT_XAWT): $(call FindLib, java.base, java)
@@ -366,8 +343,7 @@
 
 ################################################################################
 
-LIBLCMS_SRC := $(TOPDIR)/src/java.desktop/share/native/liblcms
-LIBLCMS_CPPFLAGS += -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
+LIBLCMS_HEADER_FLAGS += -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
     -I$(TOPDIR)/src/java.desktop/share/native/libawt/java2d \
     -I$(TOPDIR)/src/java.desktop/share/native/common/awt/debug \
     $(LIBJAVA_HEADER_FLAGS) \
@@ -375,27 +351,29 @@
 # The fast floor code loses precision.
 LCMS_CFLAGS=-DCMS_DONT_USE_FAST_FLOOR
 
+LCMS_CFLAGS_JDKLIB := $(filter-out -xc99=%none, $(CFLAGS_JDKLIB))
+
 ifeq ($(USE_EXTERNAL_LCMS), true)
   # If we're using an external library, we'll just need the wrapper part.
   # By including it explicitly, all other files will be excluded.
   BUILD_LIBLCMS_INCLUDE_FILES := LCMS.c
+  # If we're using an external library, we'll can't include our own SRC path
+  # as includes, instead the system headers should be used.
+  LIBLCMS_HEADERS_FROM_SRC := false
 else
   BUILD_LIBLCMS_INCLUDE_FILES :=
-  # If we're using the bundled library, we'll need to include it in the
-  # include path explicitly. Otherwise the system headers will be used.
-  LIBLCMS_CPPFLAGS += $(addprefix -I, $(LIBLCMS_SRC))
 endif
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBLCMS, \
     NAME := lcms, \
-    SRC := $(LIBLCMS_SRC), \
     INCLUDE_FILES := $(BUILD_LIBLCMS_INCLUDE_FILES), \
     OPTIMIZATION := HIGHEST, \
-    CFLAGS := $(filter-out -xc99=%none, $(CFLAGS_JDKLIB)) \
-        $(LIBLCMS_CPPFLAGS) \
+    CFLAGS := $(LCMS_CFLAGS_JDKLIB) \
         $(LCMS_CFLAGS), \
     CFLAGS_solaris := -xc99=no_lib, \
     CFLAGS_windows := -DCMS_IS_WINDOWS_, \
+    HEADER_FLAGS := $(LIBLCMS_HEADER_FLAGS), \
+    HEADERS_FROM_SRC := $(LIBLCMS_HEADERS_FROM_SRC), \
     DISABLED_WARNINGS_gcc := format-nonliteral type-limits misleading-indentation, \
     DISABLED_WARNINGS_clang := tautological-compare, \
     DISABLED_WARNINGS_solstudio := E_STATEMENT_NOT_REACHED, \
@@ -417,8 +395,6 @@
 
 ################################################################################
 
-LIBJAVAJPEG_SRC += $(TOPDIR)/src/java.desktop/share/native/libjavajpeg
-
 # "DISABLED_WARNINGS_gcc := clobbered" rationale:
 # Suppress gcc warnings like "variable might be clobbered by 'longjmp'
 # or 'vfork'": this warning indicates that some variable is placed to
@@ -432,21 +408,26 @@
   BUILD_LIBJAVAJPEG_INCLUDE_FILES := \
       imageioJPEG.c \
       jpegdecoder.c
-  BUILD_LIBJAVAJPEG_HEADERS :=
+  # If we're using an external library, we'll can't include our own SRC path
+  # as includes, instead the system headers should be used.
+  LIBJPEG_HEADERS_FROM_SRC := false
 else
   LIBJPEG_LIBS :=
   BUILD_LIBJAVAJPEG_INCLUDE_FILES :=
-  BUILD_LIBJAVAJPEG_HEADERS := $(addprefix -I, $(LIBJAVAJPEG_SRC))
 endif
 
+LIBJPEG_HEADER_FLAGS := \
+    $(LIBJAVA_HEADER_FLAGS) \
+    -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
+    #
+
 $(eval $(call SetupJdkLibrary, BUILD_LIBJAVAJPEG, \
     NAME := javajpeg, \
-    SRC := $(LIBJAVAJPEG_SRC), \
     INCLUDE_FILES := $(BUILD_LIBJAVAJPEG_INCLUDE_FILES), \
     OPTIMIZATION := HIGHEST, \
-    CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBJAVAJPEG_HEADERS) \
-        $(LIBJAVA_HEADER_FLAGS) \
-        -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := $(LIBJPEG_HEADER_FLAGS), \
+    HEADERS_FROM_SRC := $(LIBJPEG_HEADERS_FROM_SRC), \
     DISABLED_WARNINGS_gcc := clobbered implicit-fallthrough shift-negative-value, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -471,8 +452,7 @@
       #
 
   LIBAWT_HEADLESS_EXCLUDES := medialib
-  LIBAWT_HEADLESS_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
-      $(addprefix -I, $(LIBAWT_HEADLESS_DIRS)) \
+  LIBAWT_HEADLESS_HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
       -I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image \
       -I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
       -I$(TOPDIR)/src/java.desktop/share/native/libawt/java2d \
@@ -487,18 +467,17 @@
       $(LIBJAVA_HEADER_FLAGS) \
       #
 
+  LIBAWT_HEADLESS_CFLAGS := $(CUPS_CFLAGS) $(FONTCONFIG_CFLAGS) $(X_CFLAGS) \
+      -DHEADLESS=true -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
+
   $(eval $(call SetupJdkLibrary, BUILD_LIBAWT_HEADLESS, \
       NAME := awt_headless, \
       SRC := $(LIBAWT_HEADLESS_DIRS), \
       EXCLUDES := $(LIBAWT_HEADLESS_EXCLUDES), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(CFLAGS_JDKLIB) \
-          -DHEADLESS=true \
-          -DPACKAGE_PATH=\"$(PACKAGE_PATH)\" \
-          $(CUPS_CFLAGS) \
-          $(FONTCONFIG_CFLAGS) \
-          $(X_CFLAGS) \
           $(LIBAWT_HEADLESS_CFLAGS), \
+      HEADER_FLAGS := $(LIBAWT_HEADLESS_HEADER_FLAGS), \
       DISABLED_WARNINGS_xlc := 1506-356, \
       DISABLED_WARNINGS_solstudio := E_EMPTY_TRANSLATION_UNIT, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
@@ -522,11 +501,14 @@
 ################################################################################
 
 ifeq ($(FREETYPE_TO_USE), system)
+  # For use by libfontmanager:
   LIBFREETYPE_CFLAGS := $(FREETYPE_CFLAGS)
   LIBFREETYPE_LIBS := $(FREETYPE_LIBS)
 else
-  LIBFREETYPE_SRC := $(TOPDIR)/src/java.desktop/share/native/libfreetype
-  BUILD_LIBFREETYPE_HEADERS := $(addprefix -I, $(LIBFREETYPE_SRC)/include)
+  BUILD_LIBFREETYPE_HEADERS := -I$(TOPDIR)/src/java.desktop/share/native/libfreetype/include
+  BUILD_LIBFREETYPE_CFLAGS := -DFT2_BUILD_LIBRARY $(EXPORT_ALL_SYMBOLS)
+
+  # For use by libfontmanager:
   LIBFREETYPE_CFLAGS := $(BUILD_LIBFREETYPE_HEADERS)
   ifeq ($(OPENJDK_TARGET_OS), windows)
     LIBFREETYPE_LIBS := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libfreetype/freetype.lib
@@ -536,10 +518,10 @@
 
   $(eval $(call SetupJdkLibrary, BUILD_LIBFREETYPE, \
       NAME := freetype, \
-      SRC := $(LIBFREETYPE_SRC)/src, \
       OPTIMIZATION := HIGHEST, \
-      CFLAGS := $(CFLAGS_JDKLIB) $(BUILD_LIBFREETYPE_HEADERS) \
-          -DFT2_BUILD_LIBRARY $(EXPORT_ALL_SYMBOLS), \
+      CFLAGS := $(CFLAGS_JDKLIB) \
+          $(BUILD_LIBFREETYPE_CFLAGS), \
+      HEADER_FLAGS := $(BUILD_LIBFREETYPE_HEADERS), \
       DISABLED_WARNINGS_solstudio := \
          E_STATEMENT_NOT_REACHED \
          E_END_OF_LOOP_CODE_NOT_REACHED, \
@@ -553,11 +535,8 @@
 
 ###########################################################################
 
-LIBFONTMANAGER_SRC := $(TOPDIR)/src/java.desktop/share/native/libfontmanager \
-    $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libfontmanager
-LIBFONTMANAGER_CFLAGS := \
+LIBFONTMANAGER_HEADER_FLAGS := \
     $(addprefix -I, $(shell $(FIND) \
-      $(LIBFONTMANAGER_SRC) \
       $(TOPDIR)/src/java.desktop/share/native/libawt \
       $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt \
       $(TOPDIR)/src/java.desktop/share/native/common \
@@ -566,6 +545,14 @@
     $(LIBJAVA_HEADER_FLAGS) \
     #
 
+LIBFONTMANAGER_HEADER_SRC := $(TOPDIR)/src/java.desktop/share/native/libfontmanager \
+    $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libfontmanager
+LIBFONTMANAGER_HEADER_FLAGS += \
+    $(addprefix -I, $(shell $(FIND) $(LIBFONTMANAGER_HEADER_SRC) -type d)) \
+    #
+    # FIXME:LIBS: I wish this was not needed
+
+
 #### Begin harfbuzz configuration
 
 HARFBUZZ_CFLAGS := -DHAVE_OT -DHAVE_FALLBACK -DHAVE_UCDN
@@ -602,7 +589,7 @@
   LIBFONTMANAGER_EXCLUDE_FILES += X11FontScaler.c \
       X11TextRenderer.c
   LIBFONTMANAGER_OPTIMIZATION := HIGHEST
-  LIBFONTMANAGER_CFLAGS += -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/windows
+  LIBFONTMANAGER_HEADER_FLAGS += -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/windows
 else ifeq ($(OPENJDK_TARGET_OS), macosx)
   LIBFONTMANAGER_EXCLUDE_FILES += X11FontScaler.c \
       X11TextRenderer.c \
@@ -613,7 +600,7 @@
       lcdglyph.c
 endif
 
-LIBFONTMANAGER_CFLAGS += $(FONT_HEADERS) $(X_CFLAGS) -DLE_STANDALONE -DHEADLESS
+LIBFONTMANAGER_CFLAGS += $(X_CFLAGS) -DLE_STANDALONE -DHEADLESS
 
 ifeq ($(TOOLCHAIN_TYPE), gcc)
   # Turn off all warnings for sunFont.c. This is needed because the specific warning
@@ -625,12 +612,12 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBFONTMANAGER, \
     NAME := fontmanager, \
-    SRC := $(LIBFONTMANAGER_SRC), \
     EXCLUDE_FILES := $(LIBFONTMANAGER_EXCLUDE_FILES) \
         AccelGlyphCache.c, \
     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
     CFLAGS := $(CFLAGS_JDKLIB) $(LIBFONTMANAGER_CFLAGS), \
     CXXFLAGS := $(CXXFLAGS_JDKLIB) $(LIBFONTMANAGER_CFLAGS), \
+    HEADER_FLAGS := $(LIBFONTMANAGER_HEADER_FLAGS), \
     OPTIMIZATION := $(LIBFONTMANAGER_OPTIMIZATION), \
     CFLAGS_windows = -DCC_NOEX, \
     WARNINGS_AS_ERRORS_xlc := false, \
@@ -679,8 +666,8 @@
 ################################################################################
 
 ifeq ($(OPENJDK_TARGET_OS), windows)
-  LIBJAWT_SRC := $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libjawt
-  LIBJAWT_CFLAGS := -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/windows \
+
+  LIBJAWT_HEADER_FLAGS := -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libawt/windows \
       -I$(TOPDIR)/src/java.desktop/share/native/common/awt/debug \
       -I$(TOPDIR)/src/java.desktop/share/native/libawt/java2d \
       -I$(TOPDIR)/src/java.desktop/share/native/libawt/awt/image/cvutils \
@@ -691,17 +678,18 @@
       $(LIBJAVA_HEADER_FLAGS) \
       #
 
+  LIBJAWT_CFLAGS := -EHsc -DUNICODE -D_UNICODE
+
   ifeq ($(OPENJDK_TARGET_CPU), x86)
     KERNEL32_LIB := kernel32.lib
   endif
+
   $(eval $(call SetupJdkLibrary, BUILD_LIBJAWT, \
       NAME := jawt, \
-      SRC := $(LIBJAWT_SRC), \
-      INCLUDE_FILES := $(LIBJAWT_INCLUDE_FILES), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(CXXFLAGS_JDKLIB) \
-          -EHsc -DUNICODE -D_UNICODE \
           $(LIBJAWT_CFLAGS), \
+      HEADER_FLAGS := $(LIBJAWT_HEADER_FLAGS), \
       LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK), \
       LIBS := $(JDKLIB_LIBS) $(KERNEL32_LIB) advapi32.lib $(WIN_AWT_LIB), \
   ))
@@ -719,12 +707,14 @@
 
 else # OPENJDK_TARGET_OS not windows
 
+  ## FIXME:LIBS -- solve this situation better?
   ifeq ($(OPENJDK_TARGET_OS), macosx)
     LIBJAWT_SRC := $(TOPDIR)/src/java.desktop/macosx/native/libjawt
   else
     LIBJAWT_SRC := $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/libjawt
   endif
-  LIBJAWT_CFLAGS := \
+
+  LIBJAWT_HEADER_FLAGS := \
       -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/common/awt \
       -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS)/native/include \
       -I$(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/native/include \
@@ -743,7 +733,9 @@
       JAWT_LIBS += -lawt_xawt
     else
       JAWT_LIBS += -lawt_headless
-      HEADLESS_CFLAG += -DHEADLESS
+      ifeq ($(OPENJDK_TARGET_OS), linux)
+        JAWT_CFLAGS += -DHEADLESS
+      endif
     endif
   endif
 
@@ -753,9 +745,8 @@
       INCLUDE_FILES := $(JAWT_FILES), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(CFLAGS_JDKLIB) \
-          $(LIBJAWT_CFLAGS), \
-      CFLAGS_linux := $(HEADLESS_CFLAG), \
-      CFLAGS_macosx := $(LIBJAWT_CFLAGS_macosx), \
+          $(JAWT_CFLAGS), \
+      HEADER_FLAGS := $(LIBJAWT_HEADER_FLAGS), \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
       LDFLAGS_unix := -L$(INSTALL_LIBRARIES_HERE), \
@@ -792,14 +783,14 @@
     GIFLIB_LIBS := -lgif
     LIBSPLASHSCREEN_EXCLUDES := giflib
   else
-    LIBSPLASHSCREEN_CFLAGS += -I$(TOPDIR)/src/java.desktop/share/native/libsplashscreen/giflib
+    LIBSPLASHSCREEN_HEADER_FLAGS += -I$(TOPDIR)/src/java.desktop/share/native/libsplashscreen/giflib
   endif
 
   ifeq ($(USE_EXTERNAL_LIBJPEG), true)
     LIBJPEG_LIBS := -ljpeg
   else
     LIBSPLASHSCREEN_DIRS += $(TOPDIR)/src/java.desktop/share/native/libjavajpeg
-    LIBJPEG_CFLAGS := -I$(TOPDIR)/src/java.desktop/share/native/libjavajpeg
+    LIBSPLASHSCREEN_HEADER_FLAGS += -I$(TOPDIR)/src/java.desktop/share/native/libjavajpeg
   endif
 
   ifeq ($(USE_EXTERNAL_LIBPNG), false)
@@ -821,14 +812,13 @@
   ifeq ($(OPENJDK_TARGET_OS), windows)
     LIBSPLASHSCREEN_DIRS += $(TOPDIR)/src/java.desktop/windows/native/common/awt/systemscale
   endif
-  LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE -DPNG_ARM_NEON_OPT=0 \
-      $(addprefix -I, $(LIBSPLASHSCREEN_DIRS)) \
-      $(LIBJAVA_HEADER_FLAGS) \
-      #
+  LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE -DPNG_ARM_NEON_OPT=0
+
+  LIBSPLASHSCREEN_HEADER_FLAGS += $(LIBJAVA_HEADER_FLAGS)
 
   ifeq ($(OPENJDK_TARGET_OS), macosx)
     LIBSPLASHSCREEN_CFLAGS += -DWITH_MACOSX
-    LIBSPLASHSCREEN_CFLAGS += -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp
+    LIBSPLASHSCREEN_HEADER_FLAGS += -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp
 
     BUILD_LIBSPLASHSCREEN_java_awt_SplashScreen.c_CFLAGS := -x objective-c -O0
     BUILD_LIBSPLASHSCREEN_splashscreen_gfx_impl.c_CFLAGS := -x objective-c -O0
@@ -881,6 +871,7 @@
       OPTIMIZATION := LOW, \
       CFLAGS := $(LIBSPLASHSCREEN_CFLAGS) $(CFLAGS_JDKLIB) \
           $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
+      HEADER_FLAGS := $(LIBSPLASHSCREEN_HEADER_FLAGS), \
       DISABLED_WARNINGS_gcc := sign-compare type-limits unused-result \
           maybe-uninitialized shift-negative-value implicit-fallthrough, \
       DISABLED_WARNINGS_clang := incompatible-pointer-types, \
@@ -915,8 +906,7 @@
       $(TOPDIR)/src/java.desktop/share/native/common/java2d \
       #
 
-  LIBAWT_LWAWT_CFLAGS := \
-      $(addprefix -I, $(LIBAWT_LWAWT_DIRS)) \
+  LIBAWT_LWAWT_HEADER_FLAGS := \
       -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
       -I$(TOPDIR)/src/java.desktop/macosx/native/libawt_lwawt/awt \
       -I$(TOPDIR)/src/java.desktop/unix/native/libawt_xawt/awt \
@@ -937,6 +927,8 @@
       $(LIBJAVA_HEADER_FLAGS) \
       #
 
+  LIBAWT_LWAWT_CFLAGS := $(X_CFLAGS) $(X_LIBS)
+
   LIBAWT_LWAWT_EXFILES := fontpath.c awt_Font.c X11Color.c
   LIBAWT_LWAWT_EXCLUDES := $(TOPDIR)/src/java.desktop/unix/native/common/awt/medialib
 
@@ -948,9 +940,8 @@
       EXCLUDES := $(LIBAWT_LWAWT_EXCLUDES), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(CFLAGS_JDKLIB) \
-          $(X_CFLAGS) \
-          $(X_LIBS) \
           $(LIBAWT_LWAWT_CFLAGS), \
+      HEADER_FLAGS := $(LIBAWT_LWAWT_HEADER_FLAGS), \
       DISABLED_WARNINGS_clang := incomplete-implementation enum-conversion \
           deprecated-declarations objc-method-access bitwise-op-parentheses \
           incompatible-pointer-types parentheses-equality extra-tokens, \
@@ -987,17 +978,19 @@
 
 ifeq ($(OPENJDK_TARGET_OS), macosx)
 
+  LIBOSXUI_HEADER_FLAGS := \
+      -I$(TOPDIR)/src/java.desktop/macosx/native/libawt_lwawt/awt \
+      -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp \
+      -I$(TOPDIR)/src/java.base/share/native/libjava \
+      -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
+      -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
+      #
+
   $(eval $(call SetupJdkLibrary, BUILD_LIBOSXUI, \
       NAME := osxui, \
-      SRC := $(TOPDIR)/src/java.desktop/macosx/native/libosxui, \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) \
-          -I$(TOPDIR)/src/java.desktop/macosx/native/libosxui \
-          -I$(TOPDIR)/src/java.desktop/macosx/native/libawt_lwawt/awt \
-          -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp \
-          -I$(TOPDIR)/src/java.base/share/native/libjava \
-          -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
-          -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop,  \
+      CFLAGS := $(CFLAGS_JDKLIB), \
+      HEADER_FLAGS := $(LIBOSXUI_HEADER_FLAGS), \
       DISABLED_WARNINGS_clang := deprecated-declarations, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN) \
--- a/make/lib/CoreLibraries.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/CoreLibraries.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -104,7 +104,6 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBVERIFY, \
     NAME := verify, \
-    SRC := $(TOPDIR)/src/java.base/share/native/libverify, \
     OPTIMIZATION := $(LIBVERIFY_OPTIMIZATION), \
     CFLAGS := $(CFLAGS_JDKLIB), \
     DISABLED_WARNINGS_gcc := implicit-fallthrough, \
@@ -119,13 +118,7 @@
 
 ##########################################################################################
 
-# Allow a custom makefile to add extra src dirs
-LIBJAVA_SRC_DIRS += $(call FindSrcDirsForLib, java.base, java)
-
-LIBJAVA_CFLAGS := $(addprefix -I, $(LIBJAVA_SRC_DIRS)) \
-    -I$(TOPDIR)/src/java.base/share/native/libfdlibm \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-    -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"'
+LIBJAVA_CFLAGS := -DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"'
 
 ifeq ($(OPENJDK_TARGET_OS), macosx)
   BUILD_LIBJAVA_java_props_md.c_CFLAGS := -x objective-c
@@ -134,12 +127,14 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
     NAME := java, \
-    SRC := $(LIBJAVA_SRC_DIRS), \
     OPTIMIZATION := HIGH, \
     CFLAGS := $(CFLAGS_JDKLIB) \
         $(LIBJAVA_CFLAGS), \
     System.c_CFLAGS := $(VERSION_CFLAGS), \
     jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/java.base/share/native/libfdlibm \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.base, \
     WARNINGS_AS_ERRORS_xlc := false, \
     DISABLED_WARNINGS_gcc := unused-result, \
     DISABLED_WARNINGS_solstudio := E_STATEMENT_NOT_REACHED, \
@@ -180,14 +175,14 @@
 $(eval $(call SetupJdkLibrary, BUILD_LIBZIP, \
     NAME := zip, \
     OPTIMIZATION := LOW, \
-    SRC := $(TOPDIR)/src/java.base/share/native/libzip, \
     EXCLUDES := $(LIBZIP_EXCLUDES), \
     CFLAGS := $(CFLAGS_JDKLIB) \
-        $(LIBZ_CFLAGS) \
+        $(LIBZ_CFLAGS), \
+    CFLAGS_unix := $(BUILD_LIBZIP_MMAP) -UDEBUG, \
+    HEADER_FLAGS := \
         -I$(TOPDIR)/src/java.base/share/native/libjava \
         -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
         -I$(SUPPORT_OUTPUTDIR)/headers/java.base, \
-    CFLAGS_unix := $(BUILD_LIBZIP_MMAP) -UDEBUG, \
     DISABLED_WARNINGS_gcc := implicit-fallthrough, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -201,22 +196,16 @@
 
 ##########################################################################################
 
-JIMAGELIB_CPPFLAGS := \
-    -I$(TOPDIR)/src/java.base/share/native/libjava \
-    -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
-    -I$(TOPDIR)/src/java.base/share/native/libjimage \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-    #
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBJIMAGE, \
     NAME := jimage, \
     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
     OPTIMIZATION := LOW, \
-    SRC := $(TOPDIR)/src/java.base/share/native/libjimage \
-        $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjimage, \
-    EXCLUDES := $(LIBJIMAGE_EXCLUDES), \
-    CFLAGS := $(CFLAGS_JDKLIB) $(JIMAGELIB_CPPFLAGS), \
-    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(JIMAGELIB_CPPFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/java.base/share/native/libjava \
+        -I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjava \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.base, \
+    CXXFLAGS := $(CXXFLAGS_JDKLIB), \
     DISABLED_WARNINGS_gcc := implicit-fallthrough, \
     CFLAGS_unix := -UDEBUG, \
     LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
@@ -232,10 +221,6 @@
 
 ##########################################################################################
 
-LIBJLI_SRC_DIRS := $(call FindSrcDirsForLib, java.base, jli)
-
-LIBJLI_CFLAGS := $(CFLAGS_JDKLIB)
-
 ifeq ($(call check-jvm-variant, zero), true)
   ERGO_FAMILY := zero
 else
@@ -264,7 +249,7 @@
 
 ifeq ($(OPENJDK_TARGET_OS), windows)
   # Staticically link with c runtime on windows.
-  LIBJLI_CFLAGS := $(filter-out -MD, $(LIBJLI_CFLAGS))
+  LIBJLI_CFLAGS_JDKLIB := $(filter-out -MD, $(CFLAGS_JDKLIB))
   LIBJLI_OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE)
   # Supply the name of the C runtime lib.
   LIBJLI_CFLAGS += -DMSVCR_DLL_NAME='"$(notdir $(MSVCR_DLL))"'
@@ -272,11 +257,10 @@
     LIBJLI_CFLAGS += -DMSVCP_DLL_NAME='"$(notdir $(MSVCP_DLL))"'
   endif
 else
+  LIBJLI_CFLAGS_JDKLIB := $(CFLAGS_JDKLIB)
   LIBJLI_OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE)/jli
 endif
 
-LIBJLI_CFLAGS += $(addprefix -I, $(LIBJLI_SRC_DIRS))
-
 LIBJLI_CFLAGS += $(LIBZ_CFLAGS)
 
 ifneq ($(USE_EXTERNAL_LIBZ), true)
@@ -294,11 +278,10 @@
 $(eval $(call SetupJdkLibrary, BUILD_LIBJLI, \
     NAME := jli, \
     OUTPUT_DIR := $(LIBJLI_OUTPUT_DIR), \
-    SRC := $(LIBJLI_SRC_DIRS), \
     EXCLUDE_FILES := $(LIBJLI_EXCLUDE_FILES), \
     EXTRA_FILES := $(LIBJLI_EXTRA_FILES), \
     OPTIMIZATION := HIGH, \
-    CFLAGS := $(LIBJLI_CFLAGS), \
+    CFLAGS := $(LIBJLI_CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
     DISABLED_WARNINGS_gcc := maybe-uninitialized, \
     DISABLED_WARNINGS_solstudio := \
         E_ASM_DISABLES_OPTIMIZATION \
@@ -317,6 +300,8 @@
 
 TARGETS += $(BUILD_LIBJLI)
 
+LIBJLI_SRC_DIRS := $(call FindSrcDirsForLib, java.base, jli)
+
 # 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.
@@ -329,7 +314,7 @@
       EXCLUDE_FILES := $(LIBJLI_EXCLUDE_FILES), \
       EXTRA_FILES := $(LIBJLI_EXTRA_FILES), \
       OPTIMIZATION := HIGH, \
-      CFLAGS := $(STATIC_LIBRARY_FLAGS) $(LIBJLI_CFLAGS), \
+      CFLAGS := $(STATIC_LIBRARY_FLAGS) $(LIBJLI_CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
       ARFLAGS := $(ARFLAGS), \
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjli_static, \
   ))
@@ -348,7 +333,7 @@
       EXCLUDE_FILES := $(LIBJLI_EXCLUDE_FILES), \
       EXTRA_FILES := $(LIBJLI_EXTRA_FILES), \
       OPTIMIZATION := HIGH, \
-      CFLAGS := $(CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
+      CFLAGS := $(LIBJLI_CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
       LDFLAGS := -nostdlib $(ARFLAGS), \
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjli_static, \
   ))
@@ -372,7 +357,7 @@
       EXCLUDE_FILES := $(LIBJLI_EXCLUDE_FILES), \
       EXTRA_FILES := $(LIBJLI_EXTRA_FILES), \
       OPTIMIZATION := HIGH, \
-      CFLAGS := $(STATIC_LIBRARY_FLAGS) $(LIBJLI_CFLAGS), \
+      CFLAGS := $(STATIC_LIBRARY_FLAGS) $(LIBJLI_CFLAGS_JDKLIB) $(LIBJLI_CFLAGS), \
       ARFLAGS := $(ARFLAGS), \
       OBJECT_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjli_static))
 
--- a/make/lib/Lib-java.base.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.base.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -45,10 +45,10 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBNET, \
     NAME := net, \
-    SRC := $(LIBNET_SRC_DIRS), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-        $(LIBJAVA_HEADER_FLAGS) $(addprefix -I, $(LIBNET_SRC_DIRS)), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
+        $(LIBJAVA_HEADER_FLAGS), \
     DISABLED_WARNINGS_gcc := format-nonliteral, \
     DISABLED_WARNINGS_clang := parentheses-equality constant-logical-operand, \
     DISABLED_WARNINGS_microsoft := 4244 4047 4133 4996, \
@@ -72,31 +72,21 @@
 ################################################################################
 # Create the nio library
 
-BUILD_LIBNIO_SRC := \
-    $(TOPDIR)/src/java.base/share/native/libnio \
-    $(TOPDIR)/src/java.base/share/native/libnio/ch \
-    $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libnio \
-    $(sort $(wildcard \
-      $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libnio/ch \
-      $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libnio/fs \
-      $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libnio/ch \
-      $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libnio/fs)) \
+BUILD_LIBNIO_EXTRA_HEADERS := \
+    $(call FindSrcDirsForComponent, java.base, libnio/ch) \
+    $(call FindSrcDirsForComponent, java.base, libnio/fs) \
     #
 
-BUILD_LIBNIO_CFLAGS := \
-    $(addprefix -I, $(BUILD_LIBNIO_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-    $(LIBJAVA_HEADER_FLAGS) \
-    $(addprefix -I, $(BUILD_LIBNET_SRC))
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
     NAME := nio, \
-    SRC := $(BUILD_LIBNIO_SRC), \
-    EXCLUDE_FILES := $(BUILD_LIBNIO_EXFILES), \
     OPTIMIZATION := HIGH, \
     WARNINGS_AS_ERRORS_xlc := false, \
-    CFLAGS := $(CFLAGS_JDKLIB) \
-        $(BUILD_LIBNIO_CFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
+        $(LIBJAVA_HEADER_FLAGS) \
+        $(addprefix -I, $(BUILD_LIBNET_SRC)) \
+        $(addprefix -I, $(BUILD_LIBNIO_EXTRA_HEADERS)), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_unix := -ljava -lnet, \
@@ -122,17 +112,12 @@
   # JavaNativeFoundation framework not supported in static builds
   ifneq ($(STATIC_BUILD), true)
 
-    LIBOSXSECURITY_DIRS := $(TOPDIR)/src/java.base/macosx/native/libosxsecurity
-    LIBOSXSECURITY_CFLAGS := -I$(LIBOSXSECURITY_DIRS) \
-        $(LIBJAVA_HEADER_FLAGS) \
-        -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-
     $(eval $(call SetupJdkLibrary, BUILD_LIBOSXSECURITY, \
         NAME := osxsecurity, \
-        SRC := $(LIBOSXSECURITY_DIRS), \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
-            $(LIBOSXSECURITY_CFLAGS), \
+        CFLAGS := $(CFLAGS_JDKLIB), \
+        HEADER_FLAGS := $(LIBJAVA_HEADER_FLAGS) \
+            -I$(SUPPORT_OUTPUTDIR)/headers/java.base, \
         DISABLED_WARNINGS_clang := deprecated-declarations, \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
             -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.base \
@@ -158,7 +143,6 @@
 ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)
   ifeq ($(STATIC_BUILD), false)
 
-    LIBJSIG_SRC_DIR := $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjsig
     LIBJSIG_MAPFILE := $(wildcard $(TOPDIR)/make/mapfiles/libjsig/mapfile-vers-$(OPENJDK_TARGET_OS))
 
     ifeq ($(OPENJDK_TARGET_OS), linux)
@@ -168,7 +152,6 @@
 
     $(eval $(call SetupJdkLibrary, BUILD_LIBJSIG, \
         NAME := jsig, \
-        SRC := $(LIBJSIG_SRC_DIR), \
         CFLAGS := $(CFLAGS_JDKLIB) $(LIBJSIG_CFLAGS), \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
             $(call SET_SHARED_LIBRARY_ORIGIN), \
--- a/make/lib/Lib-java.desktop.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.desktop.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -43,16 +43,8 @@
 
 ifneq ($(OPENJDK_TARGET_OS), aix)
 
-  LIBJSOUND_SRC_DIRS := $(wildcard \
-      $(TOPDIR)/src/java.desktop/share/native/libjsound \
-      $(TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS)/native/libjsound \
-      )
-
   LIBJSOUND_CFLAGS := \
-      -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
       $(ALSA_CFLAGS) \
-      $(LIBJAVA_HEADER_FLAGS) \
-      $(foreach dir, $(LIBJSOUND_SRC_DIRS), -I$(dir)) \
       -DX_PLATFORM=X_$(OPENJDK_TARGET_OS_UPPERCASE) \
       -DUSE_PORTS=TRUE \
       -DUSE_DAUDIO=TRUE \
@@ -71,11 +63,13 @@
 
   $(eval $(call SetupJdkLibrary, BUILD_LIBJSOUND, \
       NAME := jsound, \
-      SRC := $(LIBJSOUND_SRC_DIRS), \
       TOOLCHAIN := $(LIBJSOUND_TOOLCHAIN), \
       OPTIMIZATION := LOW, \
       CFLAGS := $(CFLAGS_JDKLIB) \
           $(LIBJSOUND_CFLAGS), \
+      HEADER_FLAGS := \
+          $(LIBJAVA_HEADER_FLAGS) \
+          -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
       CXXFLAGS := $(CXXFLAGS_JDKLIB) $(LIBJSOUND_CFLAGS), \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -97,15 +91,11 @@
 # Create the macosx specific osxapp and osx libraries
 
 ifeq ($(OPENJDK_TARGET_OS), macosx)
-  LIBOSXAPP_SRC := $(TOPDIR)/src/java.desktop/macosx/native/libosxapp
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBOSXAPP, \
       NAME := osxapp, \
-      SRC := $(LIBOSXAPP_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) \
-          $(addprefix -I, $(LIBOSXAPP_SRC)) \
-          -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
+      CFLAGS := $(CFLAGS_JDKLIB), \
+      HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
       DISABLED_WARNINGS_clang := objc-method-access objc-root-class \
           deprecated-declarations, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
@@ -129,19 +119,14 @@
 
   ##############################################################################
 
-  LIBOSX_DIRS := $(TOPDIR)/src/java.desktop/macosx/native/libosx
-  LIBOSX_CFLAGS := -I$(LIBOSX_DIRS) \
-      -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp \
-      $(LIBJAVA_HEADER_FLAGS) \
-      -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop \
-      #
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBOSX, \
       NAME := osx, \
-      SRC := $(LIBOSX_DIRS), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) \
-          $(LIBOSX_CFLAGS), \
+      CFLAGS := $(CFLAGS_JDKLIB), \
+      HEADER_FLAGS := \
+          -I$(TOPDIR)/src/java.desktop/macosx/native/libosxapp \
+          $(LIBJAVA_HEADER_FLAGS) \
+          -I$(SUPPORT_OUTPUTDIR)/headers/java.desktop, \
       DISABLED_WARNINGS_clang := deprecated-declarations, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           -L$(SUPPORT_OUTPUTDIR)/modules_libs/java.desktop \
--- a/make/lib/Lib-java.instrument.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.instrument.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -30,32 +30,27 @@
 
 ################################################################################
 
-LIBINSTRUMENT_SRC := $(TOPDIR)/src/java.instrument/share/native/libinstrument \
-    $(TOPDIR)/src/java.instrument/$(OPENJDK_TARGET_OS_TYPE)/native/libinstrument \
-    #
-LIBINSTRUMENT_CFLAGS := $(CFLAGS_JDKLIB) \
-    $(addprefix -I, $(LIBINSTRUMENT_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.instrument \
-    -I$(TOPDIR)/src/java.base/share/native/libjli \
-    -I$(TOPDIR)/src/java.base/share/native/libjava \
-    #
-
 ifeq ($(OPENJDK_TARGET_OS), windows)
   # 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))
+  LIBINSTRUMENT_CFLAGS_JDKLIB := $(filter-out -MD, $(CFLAGS_JDKLIB))
   # equivalent of strcasecmp is stricmp on Windows
-  LIBINSTRUMENT_CFLAGS += -Dstrcasecmp=stricmp
+  LIBINSTRUMENT_CFLAGS := -Dstrcasecmp=stricmp
+else
+  LIBINSTRUMENT_CFLAGS_JDKLIB := $(CFLAGS_JDKLIB)
 endif
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBINSTRUMENT, \
     NAME := instrument, \
-    SRC := $(LIBINSTRUMENT_SRC), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(LIBINSTRUMENT_CFLAGS), \
+    CFLAGS := $(LIBINSTRUMENT_CFLAGS_JDKLIB) $(LIBINSTRUMENT_CFLAGS), \
     CFLAGS_debug := -DJPLIS_LOGGING, \
     CFLAGS_release := -DNO_JPLIS_LOGGING, \
+    HEADER_FLAGS := \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.instrument \
+        -I$(TOPDIR)/src/java.base/share/native/libjli \
+        -I$(TOPDIR)/src/java.base/share/native/libjava, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN) \
         $(LIBINSTRUMENT_LDFLAGS), \
--- a/make/lib/Lib-java.management.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.management.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -30,13 +30,6 @@
 
 ################################################################################
 
-LIBMANAGEMENT_SRC += $(TOPDIR)/src/java.management/share/native/libmanagement
-LIBMANAGEMENT_CFLAGS := -I$(TOPDIR)/src/hotspot/share/include \
-    $(addprefix -I,$(LIBMANAGEMENT_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.management \
-    $(LIBJAVA_HEADER_FLAGS) \
-    #
-
 LIBMANAGEMENT_OPTIMIZATION := HIGH
 ifneq ($(findstring $(OPENJDK_TARGET_OS), solaris linux), )
   ifeq ($(COMPILE_WITH_DEBUG_SYMBOLS), true)
@@ -46,9 +39,12 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBMANAGEMENT, \
     NAME := management, \
-    SRC := $(LIBMANAGEMENT_SRC), \
     OPTIMIZATION := $(LIBMANAGEMENT_OPTIMIZATION), \
-    CFLAGS := $(CFLAGS_JDKLIB) $(LIBMANAGEMENT_CFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/hotspot/share/include \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.management \
+        $(LIBJAVA_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS := $(JDKLIB_LIBS), \
--- a/make/lib/Lib-java.prefs.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.prefs.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,6 +27,7 @@
 
 ################################################################################
 
+# libprefs on macosx do not use the unix code, so we need to specify this explicitly.
 ifeq ($(OPENJDK_TARGET_OS), macosx)
   LIBPREF_SRC_DIRS := $(TOPDIR)/src/java.prefs/macosx/native/libprefs
 else
@@ -37,8 +38,8 @@
     NAME := prefs, \
     SRC := $(LIBPREF_SRC_DIRS), \
     OPTIMIZATION := HIGH, \
-    CFLAGS := $(CFLAGS_JDKLIB) $(addprefix -I, $(LIBPREF_SRC_DIRS)) \
-        $(LIBJAVA_HEADER_FLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := $(LIBJAVA_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_unix := -ljvm, \
--- a/make/lib/Lib-java.rmi.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.rmi.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,9 +29,9 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBRMI, \
     NAME := rmi, \
-    SRC := $(TOPDIR)/src/java.rmi/share/native/librmi, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -I$(SUPPORT_OUTPUTDIR)/headers/java.rmi, \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/java.rmi, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_unix := -ljvm, \
--- a/make/lib/Lib-java.security.jgss.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.security.jgss.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -28,16 +28,11 @@
 ################################################################################
 
 ifneq ($(OPENJDK_TARGET_OS), windows)
-  LIBJ2GSS_SRC := $(TOPDIR)/src/java.security.jgss/share/native/libj2gss \
-      $(TOPDIR)/src/java.security.jgss/$(OPENJDK_TARGET_OS_TYPE)/native/libj2gss \
-      #
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBJ2GSS, \
       NAME := j2gss, \
-      SRC := $(LIBJ2GSS_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) $(addprefix -I, $(LIBJ2GSS_SRC)) \
-          $(LIBJAVA_HEADER_FLAGS) \
+      CFLAGS := $(CFLAGS_JDKLIB), \
+      HEADER_FLAGS := $(LIBJAVA_HEADER_FLAGS) \
           -I$(SUPPORT_OUTPUTDIR)/headers/java.security.jgss, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -52,14 +47,11 @@
 ifneq ($(BUILD_CRYPTO), false)
 
   ifeq ($(OPENJDK_TARGET_OS), windows)
-    BUILD_LIBW2K_LSA_AUTH_SRC := $(call FindSrcDirsForLib, $(MODULE), w2k_lsa_auth)
-
     $(eval $(call SetupJdkLibrary, BUILD_LIBW2K_LSA_AUTH, \
         NAME := w2k_lsa_auth, \
-        SRC := $(BUILD_LIBW2K_LSA_AUTH_SRC), \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
-            $(addprefix -I, $(BUILD_LIBW2K_LSA_AUTH_SRC)) \
+        CFLAGS := $(CFLAGS_JDKLIB), \
+        HEADER_FLAGS := \
             -I$(SUPPORT_OUTPUTDIR)/headers/java.security.jgss, \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
             $(call SET_SHARED_LIBRARY_ORIGIN), \
@@ -72,16 +64,13 @@
   endif
 
   ifeq ($(OPENJDK_TARGET_OS), macosx)
-    BUILD_LIBOSXKRB5_SRC := $(call FindSrcDirsForLib, $(MODULE), osxkrb5)
-
     # libosxkrb5 needs to call deprecated krb5 APIs so that java
     # can use the native credentials cache.
     $(eval $(call SetupJdkLibrary, BUILD_LIBOSXKRB5, \
         NAME := osxkrb5, \
-        SRC := $(BUILD_LIBOSXKRB5_SRC), \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
-            $(addprefix -I, $(BUILD_LIBOSXKRB5_SRC)) \
+        CFLAGS := $(CFLAGS_JDKLIB), \
+        HEADER_FLAGS := \
             -I$(SUPPORT_OUTPUTDIR)/headers/java.security.jgss, \
         DISABLED_WARNINGS_clang := deprecated-declarations, \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
--- a/make/lib/Lib-java.smartcardio.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-java.smartcardio.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,18 +27,14 @@
 
 ################################################################################
 
-LIBJ2PCSC_SRC := $(TOPDIR)/src/java.smartcardio/share/native/libj2pcsc \
-    $(TOPDIR)/src/java.smartcardio/$(OPENJDK_TARGET_OS_TYPE)/native/libj2pcsc
-LIBJ2PCSC_CPPFLAGS := $(addprefix -I,$(LIBJ2PCSC_SRC)) \
-    -I$(TOPDIR)/src/java.smartcardio/$(OPENJDK_TARGET_OS_TYPE)/native/libj2pcsc/MUSCLE \
-    -I$(SUPPORT_OUTPUTDIR)/headers/java.smartcardio
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBJ2PCSC, \
     NAME := j2pcsc, \
-    SRC := $(LIBJ2PCSC_SRC), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
     CFLAGS_unix := -D__sun_jdk, \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/java.smartcardio/$(OPENJDK_TARGET_OS_TYPE)/native/libj2pcsc/MUSCLE \
+        -I$(SUPPORT_OUTPUTDIR)/headers/java.smartcardio, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) $(LIBJ2PCSC_CPPFLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_unix := $(LIBDL), \
--- a/make/lib/Lib-jdk.accessibility.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.accessibility.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -33,9 +33,6 @@
   JAVA_AB_SRCDIR := $(ROOT_SRCDIR)/libjavaaccessbridge $(ROOT_SRCDIR)/common
   WIN_AB_SRCDIR := $(ROOT_SRCDIR)/libwindowsaccessbridge $(ROOT_SRCDIR)/common
   SYSINFO_SRCDIR := $(ROOT_SRCDIR)/libjabsysinfo
-  ACCESSBRIDGE_CFLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/jdk.accessibility \
-      -I$(TOPDIR)/src/java.desktop/windows/native/include \
-      -I$(TOPDIR)/src/java.desktop/share/native/include
 
   define SetupJavaDLL
     # Parameter 1 Suffix
@@ -46,10 +43,13 @@
         SRC := $(JAVA_AB_SRCDIR), \
         OPTIMIZATION := LOW, \
         DISABLED_WARNINGS_microsoft := 4311 4302 4312, \
-        CFLAGS := $(CFLAGS_JDKLIB) $(ACCESSBRIDGE_CFLAGS) \
-            $(addprefix -I,$(JAVA_AB_SRCDIR)) \
-            -I$(ROOT_SRCDIR)/include/bridge \
+        CFLAGS := $(CFLAGS_JDKLIB) \
             -DACCESSBRIDGE_ARCH_$2, \
+        HEADER_FLAGS := \
+            -I$(SUPPORT_OUTPUTDIR)/headers/jdk.accessibility \
+            -I$(TOPDIR)/src/java.desktop/windows/native/include \
+            -I$(TOPDIR)/src/java.desktop/share/native/include
+            -I$(ROOT_SRCDIR)/include/bridge, \
         LDFLAGS := $(LDFLAGS_JDKLIB), \
         LIBS := kernel32.lib user32.lib gdi32.lib \
             winspool.lib comdlg32.lib advapi32.lib shell32.lib \
@@ -71,10 +71,13 @@
         SRC := $(WIN_AB_SRCDIR), \
         OPTIMIZATION := LOW, \
         DISABLED_WARNINGS_microsoft := 4311 4302 4312, \
-        CFLAGS := $(filter-out -MD, $(CFLAGS_JDKLIB)) -MT $(ACCESSBRIDGE_CFLAGS) \
-            $(addprefix -I,$(WIN_AB_SRCDIR)) \
-            -I$(ROOT_SRCDIR)/include/bridge \
+        CFLAGS := $(filter-out -MD, $(CFLAGS_JDKLIB)) -MT \
             -DACCESSBRIDGE_ARCH_$2, \
+        HEADER_FLAGS := \
+            -I$(SUPPORT_OUTPUTDIR)/headers/jdk.accessibility \
+            -I$(TOPDIR)/src/java.desktop/windows/native/include \
+            -I$(TOPDIR)/src/java.desktop/share/native/include
+            -I$(ROOT_SRCDIR)/include/bridge, \
         LDFLAGS := $(LDFLAGS_JDKLIB) \
             -def:$(ROOT_SRCDIR)/libwindowsaccessbridge/WinAccessBridge.DEF, \
         LIBS := kernel32.lib user32.lib gdi32.lib \
@@ -93,7 +96,11 @@
         NAME := jabsysinfo, \
         SRC := $(SYSINFO_SRCDIR), \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) $(ACCESSBRIDGE_CFLAGS), \
+        CFLAGS := $(CFLAGS_JDKLIB), \
+        HEADER_FLAGS := \
+            -I$(SUPPORT_OUTPUTDIR)/headers/jdk.accessibility \
+            -I$(TOPDIR)/src/java.desktop/windows/native/include \
+            -I$(TOPDIR)/src/java.desktop/share/native/include, \
         LDFLAGS := $(LDFLAGS_JDKLIB), \
         VERSIONINFO_RESOURCE := $(ROOT_SRCDIR)/common/AccessBridgeStatusWindow.rc, \
     )
--- a/make/lib/Lib-jdk.attach.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.attach.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -36,12 +36,12 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBATTACH, \
     NAME := attach, \
-    SRC := $(call FindSrcDirsForLib, jdk.attach, attach), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) \
+    CFLAGS := $(CFLAGS_JDKLIB) $(LIBATTACH_CFLAGS), \
+    CFLAGS_windows := /Gy, \
+    HEADER_FLAGS := \
         -I$(SUPPORT_OUTPUTDIR)/headers/jdk.attach \
-        $(LIBJAVA_HEADER_FLAGS) $(LIBATTACH_CFLAGS), \
-    CFLAGS_windows := /Gy, \
+        $(LIBJAVA_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS := $(JDKLIB_LIBS), \
--- a/make/lib/Lib-jdk.crypto.cryptoki.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.crypto.cryptoki.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,14 +27,11 @@
 
 ################################################################################
 
-LIBJ2PKCS11_SRC := $(TOPDIR)/src/jdk.crypto.cryptoki/share/native/libj2pkcs11 \
-    $(TOPDIR)/src/jdk.crypto.cryptoki/$(OPENJDK_TARGET_OS_TYPE)/native/libj2pkcs11
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBJ2PKCS11, \
     NAME := j2pkcs11, \
-    SRC := $(LIBJ2PKCS11_SRC), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) $(addprefix -I, $(LIBJ2PKCS11_SRC)) \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := \
         $(LIBJAVA_HEADER_FLAGS) \
         -I$(SUPPORT_OUTPUTDIR)/headers/jdk.crypto.cryptoki, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
--- a/make/lib/Lib-jdk.crypto.ec.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.crypto.ec.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -28,31 +28,23 @@
 ################################################################################
 
 ifeq ($(ENABLE_INTREE_EC), true)
-
-  LIBSUNEC_SRC := $(TOPDIR)/src/jdk.crypto.ec/share/native/libsunec
-  BUILD_LIBSUNEC_FLAGS := $(addprefix -I, $(SUNEC_SRC))
-
-  #
   # On sol-sparc...all libraries are compiled with -xregs=no%appl
-  # (set in CFLAGS_REQUIRED_sparc)
-  #
-  # except!!! libsunec.so
-  #
-  ECC_JNI_SOLSPARC_FILTER :=
+  # (set in CFLAGS_REQUIRED_sparc) except libsunec.so
   ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
-    ECC_JNI_SOLSPARC_FILTER := -xregs=no%appl
+    BUILD_LIBSUNEC_CFLAGS_JDKLIB := $(filter-out xregs=no%appl, $(CFLAGS_JDKLIB))
+    BUILD_LIBSUNEC_CXXFLAGS_JDKLIB := $(filter-out xregs=no%appl, $(CXXFLAGS_JDKLIB))
+  else
+    BUILD_LIBSUNEC_CFLAGS_JDKLIB := $(CFLAGS_JDKLIB)
+    BUILD_LIBSUNEC_CXXFLAGS_JDKLIB := $(CXXFLAGS_JDKLIB)
   endif
 
   $(eval $(call SetupJdkLibrary, BUILD_LIBSUNEC, \
       NAME := sunec, \
-      SRC := $(LIBSUNEC_SRC), \
       TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CFLAGS_JDKLIB)) \
-          $(BUILD_LIBSUNEC_FLAGS) \
+      CFLAGS := $(BUILD_LIBSUNEC_CFLAGS_JDKLIB) \
           -DMP_API_COMPATIBLE -DNSS_ECC_MORE_THAN_SUITE_B, \
-      CXXFLAGS := $(filter-out $(ECC_JNI_SOLSPARC_FILTER), $(CXXFLAGS_JDKLIB)) \
-          $(BUILD_LIBSUNEC_FLAGS), \
+      CXXFLAGS := $(BUILD_LIBSUNEC_CXXFLAGS_JDKLIB), \
       DISABLED_WARNINGS_gcc := sign-compare implicit-fallthrough, \
       DISABLED_WARNINGS_microsoft := 4101 4244 4146 4018, \
       LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK), \
--- a/make/lib/Lib-jdk.crypto.mscapi.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.crypto.mscapi.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,14 +29,10 @@
 
 ifeq ($(OPENJDK_TARGET_OS), windows)
 
-  LIBSUNMSCAPI_SRC := $(TOPDIR)/src/jdk.crypto.mscapi/$(OPENJDK_TARGET_OS_TYPE)/native/libsunmscapi
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBSUNMSCAPI, \
       NAME := sunmscapi, \
-      SRC := $(LIBSUNMSCAPI_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) \
-          -I$(LIBSUNMSCAPI_SRC), \
+      CFLAGS := $(CFLAGS_JDKLIB), \
       LDFLAGS := $(LDFLAGS_JDKLIB) $(LDFLAGS_CXX_JDK) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
       LIBS := crypt32.lib advapi32.lib, \
--- a/make/lib/Lib-jdk.crypto.ucrypto.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.crypto.ucrypto.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,14 +29,10 @@
 
 ifeq ($(OPENJDK_TARGET_OS), solaris)
 
-  LIBJ2UCRYPTO_SRC := $(TOPDIR)/src/jdk.crypto.ucrypto/solaris/native/libj2ucrypto
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBJ2UCRYPTO, \
       NAME := j2ucrypto, \
-      SRC := $(LIBJ2UCRYPTO_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) \
-          $(addprefix -I, $(LIBJ2UCRYPTO_SRC)), \
+      CFLAGS := $(CFLAGS_JDKLIB), \
       LDFLAGS := $(LDFLAGS_JDKLIB), \
       LIBS := $(LIBDL), \
   ))
--- a/make/lib/Lib-jdk.hotspot.agent.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.hotspot.agent.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,19 +29,6 @@
 
 ################################################################################
 
-SA_TOPDIR := $(TOPDIR)/src/jdk.hotspot.agent
-
-SA_SRC += \
-    $(SA_TOPDIR)/share/native/libsaproc \
-    $(SA_TOPDIR)/$(OPENJDK_TARGET_OS)/native/libsaproc \
-    #
-
-SA_INCLUDES := \
-    $(addprefix -I, $(SA_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/jdk.hotspot.agent \
-    -I$(TOPDIR)/src/hotspot/os/$(OPENJDK_TARGET_OS) \
-    #
-
 ifeq ($(OPENJDK_TARGET_OS), linux)
   SA_CFLAGS := -D_FILE_OFFSET_BITS=64
 
@@ -68,9 +55,11 @@
     DISABLED_WARNINGS_microsoft := 4267, \
     DISABLED_WARNINGS_gcc := sign-compare, \
     DISABLED_WARNINGS_CXX_solstudio := truncwarn unknownpragma, \
-    SRC := $(SA_SRC), \
-    CFLAGS := $(CFLAGS_JDKLIB) $(SA_INCLUDES) $(SA_CFLAGS) $(SA_CUSTOM_CFLAGS), \
-    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(SA_INCLUDES) $(SA_CFLAGS) $(SA_CXXFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB) $(SA_CFLAGS), \
+    CXXFLAGS := $(CXXFLAGS_JDKLIB) $(SA_CFLAGS) $(SA_CXXFLAGS), \
+    HEADER_FLAGS := \
+        -I$(SUPPORT_OUTPUTDIR)/headers/jdk.hotspot.agent \
+        -I$(TOPDIR)/src/hotspot/os/$(OPENJDK_TARGET_OS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) $(SA_LDFLAGS), \
     LIBS_linux := -lthread_db $(LIBDL), \
     LIBS_solaris := -ldl -ldemangle -lthread -lproc, \
--- a/make/lib/Lib-jdk.internal.le.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.internal.le.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,19 +29,12 @@
 
 ifeq ($(OPENJDK_TARGET_OS), windows)
 
-  LIBLE_SRC := $(TOPDIR)/src/jdk.internal.le/$(OPENJDK_TARGET_OS_TYPE)/native/lible \
-      #
-  LIBLE_CPPFLAGS := \
-      $(addprefix -I, $(LIBLE_SRC)) \
-      -I$(SUPPORT_OUTPUTDIR)/headers/jdk.internal.le \
-      #
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBLE, \
       NAME := le, \
-      SRC := $(LIBLE_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) $(LIBJAVA_HEADER_FLAGS)\
-          $(LIBLE_CPPFLAGS), \
+      CFLAGS := $(CFLAGS_JDKLIB) $(LIBJAVA_HEADER_FLAGS), \
+      HEADER_FLAGS := \
+          -I$(SUPPORT_OUTPUTDIR)/headers/jdk.internal.le, \
       LDFLAGS := $(LDFLAGS_JDKLIB), \
       LIBS := $(JDKLIB_LIBS) user32.lib, \
   ))
--- a/make/lib/Lib-jdk.jdi.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.jdi.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,22 +29,15 @@
 
 ifeq ($(OPENJDK_TARGET_OS), windows)
 
-  LIBDT_SHMEM_SRC := $(TOPDIR)/src/jdk.jdi/share/native/libdt_shmem \
-      $(TOPDIR)/src/jdk.jdi/$(OPENJDK_TARGET_OS_TYPE)/native/libdt_shmem \
-      #
-  LIBDT_SHMEM_CPPFLAGS := -I$(INCLUDEDIR) -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
-      $(addprefix -I, $(LIBDT_SHMEM_SRC)) \
-      -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
-      -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include \
-      -I$(SUPPORT_OUTPUTDIR)/headers/jdk.jdi \
-      #
-
   $(eval $(call SetupJdkLibrary, BUILD_LIBDT_SHMEM, \
       NAME := dt_shmem, \
-      SRC := $(LIBDT_SHMEM_SRC), \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
-          $(LIBDT_SHMEM_CPPFLAGS), \
+      CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP, \
+      HEADER_FLAGS := \
+          -I$(JDK_OUTPUTDIR)/include/$(OPENJDK_TARGET_OS) \
+          -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
+          -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include \
+          -I$(SUPPORT_OUTPUTDIR)/headers/jdk.jdi, \
       LDFLAGS := $(LDFLAGS_JDKLIB), \
       LIBS := $(JDKLIB_LIBS), \
   ))
--- a/make/lib/Lib-jdk.jdwp.agent.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.jdwp.agent.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,21 +27,15 @@
 
 ################################################################################
 
-LIBDT_SOCKET_SRC := $(TOPDIR)/src/jdk.jdwp.agent/share/native/libdt_socket \
-    $(TOPDIR)/src/jdk.jdwp.agent/$(OPENJDK_TARGET_OS_TYPE)/native/libdt_socket
-LIBDT_SOCKET_CPPFLAGS := \
-    $(addprefix -I, $(LIBDT_SOCKET_SRC)) \
-    -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
-    -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp \
-    -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include \
-    #
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBDT_SOCKET, \
     NAME := dt_socket, \
-    SRC := $(LIBDT_SOCKET_SRC), \
     OPTIMIZATION := LOW, \
     CFLAGS := $(CFLAGS_JDKLIB) -DUSE_MMAP \
         $(LIBDT_SOCKET_CPPFLAGS), \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
+        -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp \
+        -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_linux := -lpthread, \
@@ -56,21 +50,15 @@
 
 ################################################################################
 
-LIBJDWP_SRC := $(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp \
-    $(TOPDIR)/src/jdk.jdwp.agent/$(OPENJDK_TARGET_OS_TYPE)/native/libjdwp
-LIBJDWP_CPPFLAGS := \
-    -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
-    -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include \
-    $(addprefix -I, $(LIBJDWP_SRC))
-
 # JDWP_LOGGING causes log messages to be compiled into the library.
 $(eval $(call SetupJdkLibrary, BUILD_LIBJDWP, \
     NAME := jdwp, \
-    SRC := $(LIBJDWP_SRC), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -DJDWP_LOGGING \
-        $(LIBJDWP_CPPFLAGS) \
-        -I$(SUPPORT_OUTPUTDIR)/headers/jdk.jdwp.agent, \
+    CFLAGS := $(CFLAGS_JDKLIB) -DJDWP_LOGGING, \
+    HEADER_FLAGS := \
+      -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/libjdwp/export \
+      -I$(TOPDIR)/src/jdk.jdwp.agent/share/native/include \
+      -I$(SUPPORT_OUTPUTDIR)/headers/jdk.jdwp.agent, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS := $(JDKLIB_LIBS), \
--- a/make/lib/Lib-jdk.management.agent.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.management.agent.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,17 +27,13 @@
 
 ################################################################################
 
-LIBMANAGEMENT_AGENT_SRC += $(TOPDIR)/src/jdk.management.agent/$(OPENJDK_TARGET_OS_TYPE)/native/libmanagement_agent
-LIBMANAGEMENT_AGENT_CFLAGS := $(addprefix -I,$(LIBMANAGEMENT_AGENT_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/jdk.management.agent \
-    $(LIBJAVA_HEADER_FLAGS) \
-    #
-
 $(eval $(call SetupJdkLibrary, BUILD_LIBMANAGEMENT_AGENT, \
     NAME := management_agent, \
-    SRC := $(LIBMANAGEMENT_AGENT_SRC), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) $(LIBMANAGEMENT_AGENT_CFLAGS), \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := \
+        -I$(SUPPORT_OUTPUTDIR)/headers/jdk.management.agent \
+        $(LIBJAVA_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS := $(JDKLIB_LIBS), \
--- a/make/lib/Lib-jdk.management.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.management.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -30,15 +30,6 @@
 
 ################################################################################
 
-LIBMANAGEMENT_EXT_SRC += $(TOPDIR)/src/jdk.management/share/native/libmanagement_ext \
-    $(TOPDIR)/src/jdk.management/$(OPENJDK_TARGET_OS_TYPE)/native/libmanagement_ext       \
-    $(TOPDIR)/src/jdk.management/$(OPENJDK_TARGET_OS)/native/libmanagement_ext
-LIBMANAGEMENT_EXT_CFLAGS := -I$(TOPDIR)/src/java.management/share/native/include \
-    $(addprefix -I,$(LIBMANAGEMENT_EXT_SRC)) \
-    -I$(SUPPORT_OUTPUTDIR)/headers/jdk.management \
-    $(LIBJAVA_HEADER_FLAGS) \
-    #
-
 ifeq ($(OPENJDK_TARGET_OS), windows)
   # In (at least) VS2013 and later, -DPSAPI_VERSION=1 is needed to generate
   # a binary that is compatible with windows versions older than 7/2008R2.
@@ -55,10 +46,12 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBMANAGEMENT_EXT, \
     NAME := management_ext, \
-    SRC := $(LIBMANAGEMENT_EXT_SRC), \
-    LANG := C, \
     OPTIMIZATION := $(LIBMANAGEMENT_EXT_OPTIMIZATION), \
     CFLAGS := $(CFLAGS_JDKLIB) $(LIBMANAGEMENT_EXT_CFLAGS), \
+    HEADER_FLAGS := \
+        -I$(TOPDIR)/src/java.management/share/native/include \
+        -I$(SUPPORT_OUTPUTDIR)/headers/jdk.management \
+        $(LIBJAVA_HEADER_FLAGS), \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS := $(JDKLIB_LIBS), \
--- a/make/lib/Lib-jdk.net.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.net.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -31,9 +31,9 @@
 
   $(eval $(call SetupJdkLibrary, BUILD_LIBEXTNET, \
       NAME := extnet, \
-      SRC := $(TOPDIR)/src/jdk.net/$(OPENJDK_TARGET_OS)/native/libextnet, \
       OPTIMIZATION := LOW, \
-      CFLAGS := $(CFLAGS_JDKLIB) -I$(SUPPORT_OUTPUTDIR)/headers/jdk.net, \
+      CFLAGS := $(CFLAGS_JDKLIB), \
+      HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/jdk.net, \
       LDFLAGS := $(LDFLAGS_JDKLIB) \
           $(call SET_SHARED_LIBRARY_ORIGIN), \
       LIBS := -ljava, \
--- a/make/lib/Lib-jdk.pack.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.pack.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -27,16 +27,20 @@
 
 ################################################################################
 
+LIBUNPACK_SRC := \
+    $(call FindSrcDirsForLib, jdk.pack, unpack) \
+    $(call FindSrcDirsForComponent, jdk.pack, common-unpack) \
+    #
+
 $(eval $(call SetupJdkLibrary, BUILD_LIBUNPACK, \
     NAME := unpack, \
-    SRC := $(TOPDIR)/src/jdk.pack/share/native/libunpack \
-        $(TOPDIR)/src/jdk.pack/share/native/common-unpack, \
+    SRC := $(LIBUNPACK_SRC), \
     TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CXXFLAGS_JDKLIB) \
-        -DNO_ZLIB -DUNPACK_JNI -DFULL \
+    CXXFLAGS := $(CXXFLAGS_JDKLIB) \
+        -DNO_ZLIB -DUNPACK_JNI -DFULL, \
+    HEADER_FLAGS := \
         -I$(SUPPORT_OUTPUTDIR)/headers/java.base \
-        -I$(TOPDIR)/src/jdk.pack/share/native/common-unpack \
         $(LIBJAVA_HEADER_FLAGS), \
     CFLAGS_release := -DPRODUCT, \
     DISABLED_WARNINGS_gcc := implicit-fallthrough, \
--- a/make/lib/Lib-jdk.sctp.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.sctp.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,12 +29,12 @@
 
 ifeq ($(OPENJDK_TARGET_OS_TYPE), unix)
 
-  ifeq (, $(filter $(OPENJDK_TARGET_OS), macosx aix))
+  ifeq ($(filter $(OPENJDK_TARGET_OS), macosx aix), )
     $(eval $(call SetupJdkLibrary, BUILD_LIBSCTP, \
         NAME := sctp, \
-        SRC := $(TOPDIR)/src/jdk.sctp/$(OPENJDK_TARGET_OS_TYPE)/native/libsctp, \
         OPTIMIZATION := LOW, \
-        CFLAGS := $(CFLAGS_JDKLIB) \
+        CFLAGS := $(CFLAGS_JDKLIB), \
+        HEADER_FLAGS := \
             -I $(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libnio/ch \
             -I $(TOPDIR)/src/java.base/share/native/libnio/ch \
             $(addprefix -I, $(call FindSrcDirsForLib, java.base, net)) \
--- a/make/lib/Lib-jdk.security.auth.gmk	Thu Apr 12 14:11:59 2018 +0200
+++ b/make/lib/Lib-jdk.security.auth.gmk	Mon Apr 16 11:48:41 2018 +0200
@@ -29,9 +29,9 @@
 
 $(eval $(call SetupJdkLibrary, BUILD_LIBJAAS, \
     NAME := jaas, \
-    SRC := $(call FindSrcDirsForLib, jdk.security.auth, jaas), \
     OPTIMIZATION := LOW, \
-    CFLAGS := $(CFLAGS_JDKLIB) -I$(SUPPORT_OUTPUTDIR)/headers/jdk.security.auth, \
+    CFLAGS := $(CFLAGS_JDKLIB), \
+    HEADER_FLAGS := -I$(SUPPORT_OUTPUTDIR)/headers/jdk.security.auth, \
     LDFLAGS := $(LDFLAGS_JDKLIB) \
         $(call SET_SHARED_LIBRARY_ORIGIN), \
     LIBS_windows := netapi32.lib user32.lib mpr.lib advapi32.lib $(JDKLIB_LIBS), \