1 #
   2 # Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 ifndef _JDK_NATIVE_COMPILATION_GMK
  27 _JDK_NATIVE_COMPILATION_GMK := 1
  28 
  29 ifeq ($(_MAKEBASE_GMK), )
  30   $(error You must include MakeBase.gmk prior to including JdkNativeCompilation.gmk)
  31 endif
  32 
  33 include NativeCompilation.gmk
  34 
  35 # Hook to include the corresponding custom file, if present.
  36 $(eval $(call IncludeCustomExtension, common/JdkNativeCompilation.gmk))
  37 
  38 FindSrcDirsForLib += \
  39   $(call uniq, $(wildcard \
  40       $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/lib$(strip $2) \
  41       $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/lib$(strip $2) \
  42       $(TOPDIR)/src/$(strip $1)/share/native/lib$(strip $2)))
  43 
  44 FindSrcDirsForComponent += \
  45   $(call uniq, $(wildcard \
  46       $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS)/native/$(strip $2) \
  47       $(TOPDIR)/src/$(strip $1)/$(OPENJDK_TARGET_OS_TYPE)/native/$(strip $2) \
  48       $(TOPDIR)/src/$(strip $1)/share/native/$(strip $2)))
  49 
  50 # Find a library
  51 # Param 1 - module name
  52 # Param 2 - library name
  53 # Param 3 - optional subdir for library
  54 FindLib = \
  55     $(call FindLibDirForModule, \
  56         $(strip $1))$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(SHARED_LIBRARY_SUFFIX)
  57 
  58 # Find a static library
  59 # Param 1 - module name
  60 # Param 2 - library name
  61 # Param 3 - optional subdir for library
  62 FindStaticLib = \
  63     $(addprefix $(SUPPORT_OUTPUTDIR)/native/, \
  64         $(strip $1)$(strip $3)/$(LIBRARY_PREFIX)$(strip $2)$(STATIC_LIBRARY_SUFFIX))
  65 
  66 # If only generating compile_commands.json, make these return empty to avoid
  67 # declaring dependencies.
  68 ifeq ($(GENERATE_COMPILE_COMMANDS_ONLY), true)
  69   FindLib =
  70   FindStaticLib =
  71 endif
  72 
  73 GetJavaHeaderDir = \
  74   $(wildcard $(SUPPORT_OUTPUTDIR)/headers/$(strip $1))
  75 
  76 # Process a dir description such as "java.base:headers" into a set of proper absolute paths.
  77 ProcessDir = \
  78   $(if $(findstring :, $1), \
  79     $(call FindSrcDirsForComponent, $(firstword $(subst :, , $1)), $(lastword $(subst :, , $1))) \
  80   , \
  81     $(if $(filter /%, $1), \
  82       $1 \
  83     , \
  84       $(call FindSrcDirsForComponent, $(MODULE), $1) \
  85     ) \
  86   )
  87 
  88 # Setup make rules for creating a native shared library with suitable defaults
  89 # for the OpenJDK project.
  90 #
  91 # Parameter 1 is the name of the rule. This name is used as variable prefix,
  92 # and the targets generated are listed in a variable by that name.
  93 #
  94 # Remaining parameters are named arguments. These are all passed on to
  95 # SetupNativeCompilation, except for
  96 #   EXTRA_RC_FLAGS -- additional RC_FLAGS to append.
  97 #   EXTRA_HEADER_DIRS -- additional directories to look for headers in
  98 #   EXTRA_SRC -- additional directories to look for source in
  99 #   EXCLUDE_SRC_PATTERNS -- exclude source dirs matching these patterns from
 100 #     appearing in SRC.
 101 #   HEADERS_FROM_SRC -- if false, does not add source dirs automatically as
 102 #     header include dirs. (Defaults to true.)
 103 #   SRC -- this is passed on, but preprocessed to accept source dir designations
 104 #     such as "java.base:headers".
 105 SetupJdkLibrary = $(NamedParamsMacroTemplate)
 106 define SetupJdkLibraryBody
 107   ifeq ($$($1_OUTPUT_DIR), )
 108     $1_OUTPUT_DIR := $$(call FindLibDirForModule, $$(MODULE))
 109   endif
 110 
 111   ifeq ($$($1_OBJECT_DIR), )
 112     $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/lib$$($1_NAME)
 113   endif
 114 
 115   ifeq ($$($1_SRC), )
 116     $1_SRC := $$(call FindSrcDirsForLib, $$(MODULE), $$($1_NAME))
 117   else
 118     $1_SRC := $$(foreach dir, $$($1_SRC), $$(call ProcessDir, $$(dir)))
 119   endif
 120   ifneq ($$($1_EXTRA_SRC), )
 121     $1_SRC += $$(foreach dir, $$($1_EXTRA_SRC), $$(call ProcessDir, $$(dir)))
 122   endif
 123 
 124   ifneq ($$($1_EXCLUDE_SRC_PATTERNS), )
 125     $1_EXCLUDE_SRC := $$(call containing, $$($1_EXCLUDE_SRC_PATTERNS), $$($1_SRC))
 126     $1_SRC := $$(filter-out $$($1_EXCLUDE_SRC), $$($1_SRC))
 127   endif
 128 
 129   ifeq ($$($1_VERSIONINFO_RESOURCE), )
 130     $1_VERSIONINFO_RESOURCE := $$(GLOBAL_VERSION_INFO_RESOURCE)
 131   else ifeq ($$($1_VERSIONINFO_RESOURCE), DISABLE)
 132     $1_VERSIONINFO_RESOURCE :=
 133   endif
 134 
 135   ifeq ($$($1_RC_FLAGS), )
 136     $1_RC_FLAGS :=  $(RC_FLAGS) \
 137         -D "JDK_FNAME=$$($1_NAME).dll" \
 138         -D "JDK_INTERNAL_NAME=$$($1_NAME)" \
 139         -D "JDK_FTYPE=0x2L"
 140   else ifeq ($$($1_RC_FLAGS), DISABLE)
 141     $1_RC_FLAGS :=
 142   endif
 143 
 144   ifneq ($$($1_HEADERS_FROM_SRC), false)
 145     $1_SRC_HEADER_FLAGS := $$(addprefix -I, $$(wildcard $$($1_SRC)))
 146   endif
 147   # Always add the java header dir
 148   $1_SRC_HEADER_FLAGS += $$(addprefix -I, $$(call GetJavaHeaderDir, $$(MODULE)))
 149 
 150   ifneq ($$($1_EXTRA_HEADER_DIRS), )
 151     $1_PROCESSED_EXTRA_HEADER_DIRS := $$(foreach dir, $$($1_EXTRA_HEADER_DIRS), \
 152         $$(call ProcessDir, $$(dir)))
 153     $1_EXTRA_HEADER_FLAGS := $$(addprefix -I, $$($1_PROCESSED_EXTRA_HEADER_DIRS))
 154   endif
 155 
 156   ifneq ($$($1_CFLAGS), )
 157     $1_CFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
 158   endif
 159   ifneq ($$($1_CXXFLAGS), )
 160     $1_CXXFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
 161   endif
 162   ifeq ($$($1_CFLAGS)$$($1_CXXFLAGS), )
 163     $1_CFLAGS += $$($1_SRC_HEADER_FLAGS) $$($1_EXTRA_HEADER_FLAGS)
 164   endif
 165   $1_RC_FLAGS += $$($1_EXTRA_RC_FLAGS)
 166 
 167   # Since we reuse the rule name ($1), all our arguments will pass through.
 168   # We lose in transparency, but gain in brevity in this call...
 169   $$(eval $$(call SetupNativeCompilation, $1, ))
 170 endef
 171 
 172 # Setup make rules for creating a native executable with suitable defaults for
 173 # the OpenJDK project.
 174 #
 175 # Parameter 1 is the name of the rule. This name is used as variable prefix,
 176 # and the targets generated are listed in a variable by that name.
 177 #
 178 # Remaining parameters are named arguments. These are all passed on to
 179 # SetupNativeCompilation, except for
 180 #   EXTRA_RC_FLAGS -- additional RC_FLAGS to append.
 181 SetupJdkExecutable = $(NamedParamsMacroTemplate)
 182 define SetupJdkExecutableBody
 183   $1_TYPE := EXECUTABLE
 184 
 185   ifeq ($$($1_OUTPUT_DIR), )
 186     $1_OUTPUT_DIR := $$(call FindExecutableDirForModule, $$(MODULE))
 187   endif
 188 
 189   ifeq ($$($1_OBJECT_DIR), )
 190     $1_OBJECT_DIR := $$(SUPPORT_OUTPUTDIR)/native/$$(MODULE)/$$($1_NAME)
 191   endif
 192 
 193   ifeq ($$($1_VERSIONINFO_RESOURCE), )
 194     $1_VERSIONINFO_RESOURCE := $$(GLOBAL_VERSION_INFO_RESOURCE)
 195   else ifeq ($$($1_VERSIONINFO_RESOURCE), DISABLE)
 196     $1_VERSIONINFO_RESOURCE :=
 197   endif
 198 
 199   ifeq ($$($1_RC_FLAGS), )
 200     $1_RC_FLAGS :=  $(RC_FLAGS) \
 201         -D "JDK_FNAME=$$($1_NAME).exe" \
 202         -D "JDK_INTERNAL_NAME=$$($1_NAME)" \
 203         -D "JDK_FTYPE=0x01L"
 204   else ifeq ($$($1_RC_FLAGS), DISABLE)
 205     $1_RC_FLAGS :=
 206   endif
 207 
 208   $1_RC_FLAGS += $$($1_EXTRA_RC_FLAGS)
 209 
 210   # Since we reuse the rule name ($1), all our arguments will pass through.
 211   # We lose in transparency, but gain in brevity in this call...
 212   $$(eval $$(call SetupNativeCompilation, $1))
 213 endef
 214 
 215 endif # _JDK_NATIVE_COMPILATION_GMK