make/common/NativeCompilation.gmk

Wed, 18 Apr 2018 03:57:40 -0700

author
kevinw
date
Wed, 18 Apr 2018 03:57:40 -0700
changeset 2217
310b1d9c5772
parent 2215
7a73b8b4ac8a
child 2221
888144400d97
permissions
-rw-r--r--

8179079: Incremental HotSpot builds broken on Windows
Reviewed-by: erikj, tbell

ohair@425 1 #
kevinw@2206 2 # Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
ohair@425 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ohair@425 4 #
ohair@425 5 # This code is free software; you can redistribute it and/or modify it
ohair@425 6 # under the terms of the GNU General Public License version 2 only, as
ohair@425 7 # published by the Free Software Foundation. Oracle designates this
ohair@425 8 # particular file as subject to the "Classpath" exception as provided
ohair@425 9 # by Oracle in the LICENSE file that accompanied this code.
ohair@425 10 #
ohair@425 11 # This code is distributed in the hope that it will be useful, but WITHOUT
ohair@425 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ohair@425 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ohair@425 14 # version 2 for more details (a copy is included in the LICENSE file that
ohair@425 15 # accompanied this code).
ohair@425 16 #
ohair@425 17 # You should have received a copy of the GNU General Public License version
ohair@425 18 # 2 along with this work; if not, write to the Free Software Foundation,
ohair@425 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ohair@425 20 #
ohair@425 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@425 22 # or visit www.oracle.com if you need additional information or have any
ohair@425 23 # questions.
ohair@425 24 #
ohair@425 25
ohair@425 26 # When you read this source. Remember that $(sort ...) has the side effect
ohair@425 27 # of removing duplicates. It is actually this side effect that is
ohair@425 28 # desired whenever sort is used below!
ohair@425 29
ihse@839 30 ifeq (,$(_MAKEBASE_GMK))
ihse@839 31 $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
ohair@425 32 endif
ohair@425 33
kevinw@2206 34 ifneq ($(TOOLCHAIN_TYPE), microsoft)
ihse@839 35 COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))"
ihse@839 36 LINKING_MSG=echo $(LOG_INFO) "Linking $1"
ihse@839 37 LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1"
ihse@839 38 ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1"
ohair@425 39 else
ihse@839 40 COMPILING_MSG=
ihse@839 41 LINKING_MSG=
ihse@839 42 LINKING_EXE_MSG=
ihse@839 43 ARCHIVING_MSG=
ohair@425 44 endif
ohair@425 45
ohair@425 46 define add_native_source
ihse@839 47 # param 1 = BUILD_MYPACKAGE
ihse@839 48 # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
ihse@839 49 # param 3 = the bin dir that stores all .o (.obj) and .d files.
ihse@839 50 # param 4 = the c flags to the compiler
ihse@839 51 # param 5 = the c compiler
ihse@839 52 # param 6 = the c++ flags to the compiler
ihse@839 53 # param 7 = the c++ compiler
ihse@839 54 # param 8 = the flags to the assembler
ohair@425 55
ihse@839 56 ifneq (,$$(filter %.c,$2))
ihse@839 57 # Compile as a C file
ihse@839 58 $1_$2_FLAGS=$4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
ihse@839 59 $1_$2_COMP=$5
ihse@839 60 $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
ihse@839 61 else ifneq (,$$(filter %.m,$2))
ihse@839 62 # Compile as a objective-c file
ihse@839 63 $1_$2_FLAGS=-x objective-c $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
ihse@839 64 $1_$2_COMP=$5
ihse@839 65 $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
ihse@839 66 else ifneq (,$$(filter %.s,$2))
ihse@839 67 # Compile as assembler file
ihse@839 68 $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"'
ihse@839 69 $1_$2_COMP=$(AS)
ihse@839 70 $1_$2_DEP_FLAG:=
ihse@839 71 else
ihse@839 72 # Compile as a C++ file
ihse@839 73 $1_$2_FLAGS=$6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c
ihse@839 74 $1_$2_COMP=$7
ihse@839 75 $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
ihse@839 76 endif
ihse@839 77 # Generate the .o (.obj) file name and place it in the bin dir.
ihse@839 78 $1_$2_OBJ:=$3/$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $2)))))
ihse@839 79 # Only continue if this object file hasn't been processed already. This lets the first found
ihse@839 80 # source file override any other with the same name.
ihse@839 81 ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
ihse@839 82 $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
ihse@839 83 ifeq (,$$(filter %.s,$2))
ihse@839 84 # And this is the dependency file for this obj file.
ihse@839 85 $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
ihse@839 86 # Include previously generated dependency information. (if it exists)
ihse@839 87 -include $$($1_$2_DEP)
ihse@839 88
kevinw@2206 89 ifeq ($(TOOLCHAIN_TYPE), microsoft)
ihse@839 90 $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \
ihse@839 91 -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ))
ihse@839 92 endif
ohair@425 93 endif
ohair@425 94
ihse@839 95 $$($1_$2_OBJ) : $2
kevinw@2206 96 ifneq ($(TOOLCHAIN_TYPE), microsoft)
ihse@839 97 $$(call COMPILING_MSG,$2,$$($1_TARGET))
kevinw@2206 98 # The Solaris studio compiler doesn't output the full path to the object file in the
erikj@699 99 # generated deps files. Fixing it with sed. If compiling assembly, don't try this.
kevinw@2206 100 ifeq ($(TOOLCHAIN_TYPE)$$(filter %.s,$2), solstudio)
ihse@839 101 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
ihse@839 102 $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP)
erikj@699 103 else
ihse@839 104 $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
ihse@839 105 endif
erikj@699 106 endif
erikj@699 107 # The Visual Studio compiler lacks a feature for generating make dependencies, but by
ihse@839 108 # setting -showIncludes, all included files are printed. These are filtered out and
erikj@699 109 # parsed into make dependences.
kevinw@2206 110 ifeq ($(TOOLCHAIN_TYPE), microsoft)
ihse@839 111 ($$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \
ihse@839 112 $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 ; echo $$$$? > $$($1_$2_DEP).exitvalue) \
ihse@839 113 | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v "^Note: including file:" \
ihse@839 114 && exit `cat $$($1_$2_DEP).exitvalue`
ihse@839 115 $(RM) $$($1_$2_DEP).exitvalue
ihse@839 116 ($(ECHO) $$@: \\ \
ihse@839 117 && $(SED) -e '/^Note: including file:/!d' \
ihse@839 118 -e 's|Note: including file: *||' \
kevinw@2217 119 -e 's|\r||g' \
ihse@839 120 -e 's|\\|/|g' \
ihse@839 121 -e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \
ihse@839 122 -e '/$(subst /,\/,$(TOPDIR))/!d' \
ihse@839 123 -e 's|$$$$| \\|g' \
ihse@839 124 $$($1_$2_DEP).raw) > $$($1_$2_DEP)
ohair@425 125 endif
ihse@839 126 endif
ohair@425 127 endef
ohair@425 128
ohair@425 129 define SetupNativeCompilation
ihse@839 130 # param 1 is for example BUILD_MYPACKAGE
ihse@839 131 # param 2,3,4,5,6,7,8 are named args.
ihse@839 132 # SRC one or more directory roots to scan for C/C++ files.
ihse@839 133 # LANG C or C++
ihse@839 134 # CFLAGS the compiler flags to be used, used both for C and C++.
ihse@839 135 # CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
ihse@839 136 # LDFLAGS the linker flags to be used, used both for C and C++.
ihse@839 137 # LDFLAGS_SUFFIX the linker flags to be added last on the commandline
ihse@839 138 # typically the libraries linked to.
ihse@839 139 # ARFLAGS the archiver flags to be used
ihse@839 140 # OBJECT_DIR the directory where we store the object files
ihse@839 141 # LIBRARY the resulting library file
ihse@839 142 # PROGRAM the resulting exec file
ihse@839 143 # INCLUDES only pick source from these directories
ihse@839 144 # EXCLUDES do not pick source from these directories
ihse@839 145 # INCLUDE_FILES only compile exactly these files!
ihse@839 146 # EXCLUDE_FILES with these names
ihse@839 147 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
ihse@839 148 # RC_FLAGS flags for RC.
ihse@839 149 # MAPFILE mapfile
ihse@839 150 # REORDER reorder file
ihse@839 151 # DEBUG_SYMBOLS add debug symbols (if configured on)
ihse@839 152 # CC the compiler to use, default is $(CC)
ihse@839 153 # LDEXE the linker to use for linking executables, default is $(LDEXE)
ihse@839 154 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
ihse@839 155 $(foreach i,2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
ihse@839 156 $(call LogSetupMacroEntry,SetupNativeCompilation($1),$2,$3,$4,$5,$6,$7,$8,$9,$(10),$(11),$(12),$(13),$(14),$(15),$(16),$(17),$(18),$(19),$(20),$(21),$(22),$(23),$(24),$(25),$(26))
ihse@839 157 $(if $(27),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk))
erikj@458 158
ihse@839 159 ifneq (,$$($1_BIN))
ihse@839 160 $$(error BIN has been replaced with OBJECT_DIR)
ihse@839 161 endif
ihse@839 162
ihse@839 163 ifneq (,$$($1_LIB))
ihse@839 164 $$(error LIB has been replaced with LIBRARY)
ihse@839 165 endif
ihse@839 166
ihse@839 167 ifneq (,$$($1_EXE))
ihse@839 168 $$(error EXE has been replaced with PROGRAM)
ihse@839 169 endif
ihse@839 170
ihse@839 171 ifneq (,$$($1_LIBRARY))
ihse@839 172 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 173 $$(error LIBRARY requires OUTPUT_DIR)
erikj@458 174 endif
erikj@458 175
ihse@839 176 ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
ihse@839 177 $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
erikj@458 178 endif
erikj@458 179
ihse@839 180 ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY)))
ihse@839 181 $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX))
erikj@458 182 endif
erikj@458 183
ihse@839 184 ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY)))
ihse@839 185 $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
erikj@458 186 endif
erikj@458 187
ihse@839 188 $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$(SHARED_LIBRARY_SUFFIX)
ihse@839 189 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
erikj@458 190
ihse@839 191 endif
erikj@458 192
ihse@839 193 ifneq (,$$($1_STATIC_LIBRARY))
ihse@839 194 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 195 $$(error STATIC_LIBRARY requires OUTPUT_DIR)
erikj@458 196 endif
erikj@458 197
ihse@839 198 ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY)))
ihse@839 199 $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR)
erikj@458 200 endif
erikj@458 201
ihse@839 202 ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY)))
ihse@839 203 $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX))
erikj@458 204 endif
ohair@425 205
ihse@839 206 ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY)))
ihse@839 207 $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
ohair@425 208 endif
ohair@425 209
ihse@839 210 $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$(STATIC_LIBRARY_SUFFIX)
ihse@839 211 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
ihse@839 212 endif
ihse@839 213
ihse@839 214 ifneq (,$$($1_PROGRAM))
ihse@839 215 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 216 $$(error PROGRAM requires OUTPUT_DIR)
erikj@458 217 endif
erikj@458 218
ihse@839 219 ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM)))
ihse@839 220 $$(error directory of PROGRAM should be specified using OUTPUT_DIR)
ohair@425 221 endif
ohair@425 222
ihse@839 223 ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM)))
ihse@839 224 $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX))
ohair@494 225 endif
ohair@425 226
ihse@839 227 $1_BASENAME:=$$($1_PROGRAM)$(EXE_SUFFIX)
ihse@839 228 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
ihse@839 229
ihse@839 230 endif
ihse@839 231
ihse@839 232 ifeq (,$$($1_TARGET))
ihse@839 233 $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
ihse@839 234 endif
ihse@839 235
ihse@839 236 ifeq (,$$($1_LANG))
ihse@839 237 $$(error You have to specify LANG for native compilation $1)
ihse@839 238 endif
ihse@839 239 ifeq (C,$$($1_LANG))
ihse@839 240 ifeq ($$($1_LDEXE),)
ihse@839 241 $1_LDEXE:=$(LDEXE)
ihse@839 242 endif
ihse@839 243 $1_LD:=$(LD)
ihse@839 244 else
ihse@839 245 ifeq (C++,$$($1_LANG))
ihse@839 246 $1_LD:=$(LDCXX)
ihse@839 247 $1_LDEXE:=$(LDEXECXX)
ohair@425 248 else
ihse@839 249 $$(error Unknown native language $$($1_LANG) for $1)
ohair@425 250 endif
ihse@839 251 endif
ohair@425 252
ihse@839 253 ifeq ($$($1_CC),)
ihse@839 254 $1_CC:=$(CC)
ihse@839 255 endif
ihse@839 256
ihse@839 257 # Make sure the dirs exist.
ihse@839 258 $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)))
ihse@839 259 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
ihse@839 260
ihse@839 261 # Find all files in the source trees. Sort to remove duplicates.
ihse@839 262 $1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
ihse@839 263 # Extract the C/C++ files.
ihse@839 264 $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES)))
ihse@839 265 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
ihse@839 266 ifneq ($$($1_EXCLUDE_FILES),)
ihse@839 267 $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES))
ihse@839 268 endif
ihse@839 269 $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES),$$(filter %.s %.c %.cpp %.m,$$($1_ALL_SRCS)))
ihse@839 270 ifneq (,$$(strip $$($1_INCLUDE_FILES)))
ihse@839 271 $1_SRCS := $$(filter $$($1_INCLUDE_FILES),$$($1_SRCS))
ihse@839 272 endif
ihse@839 273 ifeq (,$$($1_SRCS))
ihse@839 274 $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
ihse@839 275 endif
ihse@839 276 # There can be only a single bin dir root, no need to foreach over the roots.
ihse@839 277 $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
ihse@839 278 # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
ihse@839 279 # and we have a list of all existing object files: $$($1_BINS)
ihse@839 280
ihse@839 281 # Prepend the source/bin path to the filter expressions. Then do the filtering.
ihse@839 282 ifneq ($$($1_INCLUDES),)
ihse@839 283 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
ihse@839 284 $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
ihse@839 285 endif
ihse@839 286 ifneq ($$($1_EXCLUDES),)
ihse@839 287 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
ihse@839 288 $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
ihse@839 289 endif
ihse@839 290
ihse@839 291 # Calculate the expected output from compiling the sources (sort to remove duplicates. Also provides
ihse@839 292 # a reproducable order on the input files to the linker).
ihse@839 293 $1_EXPECTED_OBJS:=$$(sort $$(addprefix $$($1_OBJECT_DIR)/,$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $$($1_SRCS))))))))
ihse@839 294 # Are there too many object files on disk? Perhaps because some source file was removed?
ihse@839 295 $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
ihse@839 296 # Clean out the superfluous object files.
ihse@839 297 ifneq ($$($1_SUPERFLUOUS_OBJS),)
ihse@839 298 $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
ihse@839 299 endif
ihse@839 300
gromero@1879 301 # Pickup extra OPENJDK_TARGET_OS_API, OPENJDK_TARGET_OS, and/or OPENJDK_TARGET_OS plus
gromero@1879 302 # OPENJDK_TARGET_CPU pair dependent variables for CFLAGS.
gromero@1879 303 $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) \
gromero@1879 304 $$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU))
ihse@839 305 ifneq ($(DEBUG_LEVEL),release)
ihse@839 306 # Pickup extra debug dependent variables for CFLAGS
ihse@839 307 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug)
ihse@839 308 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
ihse@839 309 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
gromero@1879 310 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_debug)
ihse@839 311 else
ihse@839 312 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release)
ihse@839 313 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_release)
ihse@839 314 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
gromero@1879 315 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_$(OPENJDK_TARGET_CPU)_release)
ihse@839 316 endif
ihse@839 317
ihse@839 318 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
ihse@839 319 $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
ihse@839 320 ifneq ($(DEBUG_LEVEL),release)
ihse@839 321 # Pickup extra debug dependent variables for CXXFLAGS
ihse@839 322 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug)
ihse@839 323 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
ihse@839 324 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
ihse@839 325 else
ihse@839 326 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release)
ihse@839 327 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_release)
ihse@839 328 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
ihse@839 329 endif
ihse@839 330
omajid@1409 331 ifeq ($$($1_CXXFLAGS),)
omajid@1409 332 $1_CXXFLAGS:=$$($1_CFLAGS)
omajid@1409 333 endif
omajid@1409 334 ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),)
omajid@1409 335 $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS)
omajid@1409 336 endif
omajid@1409 337
ihse@839 338 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 339 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
ihse@839 340 ifdef OPENJDK
ihse@839 341 # Always add debug symbols
ihse@839 342 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
ihse@839 343 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
ihse@839 344 else
ihse@839 345 # Programs don't get the debug symbols added in the old build. It's not clear if
ihse@839 346 # this is intentional.
ihse@839 347 ifeq ($$($1_PROGRAM),)
ihse@839 348 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
ihse@839 349 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
ihse@839 350 endif
ihse@839 351 endif
ohair@425 352 endif
ihse@839 353 endif
ohair@425 354
ihse@839 355 ifneq (,$$($1_REORDER))
ihse@839 356 $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
ihse@839 357 $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
ihse@839 358 endif
ihse@839 359
ihse@839 360 ifeq (NONE, $$($1_OPTIMIZATION))
ihse@839 361 $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE)
ihse@839 362 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE)
ihse@839 363 else ifeq (LOW, $$($1_OPTIMIZATION))
ihse@839 364 $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM)
ihse@839 365 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM)
ihse@839 366 else ifeq (HIGH, $$($1_OPTIMIZATION))
ihse@839 367 $1_EXTRA_CFLAGS += $(C_O_FLAG_HI)
ihse@839 368 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI)
ihse@839 369 else ifeq (HIGHEST, $$($1_OPTIMIZATION))
ihse@839 370 $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST)
ihse@839 371 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST)
ihse@839 372 else ifneq (, $$($1_OPTIMIZATION))
ihse@839 373 $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
ihse@839 374 endif
ihse@839 375
kevinw@2215 376 # Add sys root specific cflags last
kevinw@2215 377 $1_EXTRA_CFLAGS += $(SYSROOT_CFLAGS)
kevinw@2215 378 $1_EXTRA_CXXFLAGS += $(SYSROOT_CFLAGS)
kevinw@2215 379
ihse@839 380 # Now call add_native_source for each source file we are going to compile.
ihse@839 381 $$(foreach p,$$($1_SRCS), \
ihse@839 382 $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \
ihse@839 383 $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC), \
ihse@839 384 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS))))
ihse@839 385
ihse@839 386 # On windows we need to create a resource file
ihse@839 387 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 388 ifneq (,$$($1_VERSIONINFO_RESOURCE))
ihse@839 389 $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
ihse@839 390 $$($1_RES): $$($1_VERSIONINFO_RESOURCE)
ihse@839 391 $(RC) $$($1_RC_FLAGS) $(CC_OUT_OPTION)$$@ $$($1_VERSIONINFO_RESOURCE)
ohair@478 392 endif
ihse@839 393 ifneq (,$$($1_MANIFEST))
ihse@839 394 $1_GEN_MANIFEST:=$$($1_OBJECT_DIR)/$$($1_PROGRAM).manifest
ihse@839 395 IMVERSIONVALUE:=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VERSION).$(COOKED_BUILD_NUMBER)
ihse@839 396 $$($1_GEN_MANIFEST): $$($1_MANIFEST)
ihse@839 397 $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@
ihse@839 398 endif
ihse@839 399 endif
ohair@478 400
ihse@839 401 # mapfile doesnt seem to be implemented on macosx (yet??)
ihse@839 402 ifneq ($(OPENJDK_TARGET_OS),macosx)
ihse@839 403 ifneq ($(OPENJDK_TARGET_OS),windows)
ihse@839 404 $1_REAL_MAPFILE:=$$($1_MAPFILE)
ihse@839 405 ifneq (,$$($1_REORDER))
ihse@839 406 $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile
ohair@425 407
ihse@839 408 $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
erikj@445 409 $$(MKDIR) -p $$(@D)
erikj@445 410 $$(CP) $$($1_MAPFILE) $$@.tmp
erikj@458 411 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
erikj@445 412 $$(MV) $$@.tmp $$@
ihse@839 413 endif
erikj@445 414 endif
ihse@839 415 endif
ihse@839 416
ihse@839 417 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables
ihse@839 418 # for LDFLAGS and LDFLAGS_SUFFIX
ihse@839 419 $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
ihse@839 420 $1_EXTRA_LDFLAGS_SUFFIX:=$$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS))
ihse@839 421 ifneq (,$$($1_REAL_MAPFILE))
ihse@839 422 $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
ihse@839 423 endif
ihse@839 424
kevinw@2215 425 $1_EXTRA_LDFLAGS += $(SYSROOT_LDFLAGS)
kevinw@2215 426
ihse@839 427 $1 := $$($1_TARGET)
ihse@839 428 ifneq (,$$($1_LIBRARY))
ihse@839 429 # Generating a dynamic library.
ihse@839 430 $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
ihse@839 431 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 432 $1_EXTRA_LDFLAGS+="-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
ohair@425 433 endif
erikj@445 434
ihse@839 435 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
erikj@458 436
ihse@839 437 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 438 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
erikj@458 439 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 440 $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_LIBRARY).pdb" \
ihse@839 441 "-map:$$($1_OBJECT_DIR)/$$($1_LIBRARY).map"
erikj@458 442 endif
erikj@458 443
ihse@839 444 ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
ihse@839 445 $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
ihse@839 446 $(CP) $$< $$@
ihse@839 447 endif
erikj@458 448
dcubed@874 449 ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X
dcubed@874 450 ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows
dcubed@874 451 ifeq ($(OPENJDK_TARGET_OS), solaris)
dcubed@874 452 # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
dcubed@874 453 # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
dcubed@874 454 # empty section headers until a fixed $(OBJCOPY) is available.
dcubed@874 455 # An empty section header has sh_addr == 0 and sh_size == 0.
dcubed@874 456 # This problem has only been seen on Solaris X64, but we call this tool
dcubed@874 457 # on all Solaris builds just in case.
dcubed@874 458 #
dcubed@874 459 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
dcubed@874 460 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
dcubed@874 461 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \
dcubed@874 462 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
dcubed@874 463 $(RM) $$@
dcubed@874 464 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
dcubed@874 465 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 466 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
dcubed@874 467 else # not solaris
dcubed@874 468 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET)
dcubed@874 469 $(RM) $$@
dcubed@874 470 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 471 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
dcubed@874 472 endif # Touch to not retrigger rule on rebuild
ihse@839 473 $(TOUCH) $$@
dcubed@874 474 endif # !windows
dcubed@874 475 endif # !macosx
erikj@458 476
ihse@839 477 ifeq ($(ZIP_DEBUGINFO_FILES), true)
dcubed@874 478 ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet
ihse@839 479 $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz
erikj@458 480
ihse@839 481 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 482 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET)
ihse@839 483 $(CD) $$($1_OBJECT_DIR) \
ihse@839 484 && $(ZIP) -q $$@ $$($1_LIBRARY).map $$($1_LIBRARY).pdb
ihse@839 485 else
ihse@839 486 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) \
ihse@839 487 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 488 $(CD) $$($1_OBJECT_DIR) \
ihse@839 489 && $(ZIP) -q $$@ $$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 490 endif
dcubed@874 491 endif # no MacOS X support yet
ihse@839 492 else
ihse@839 493 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 494 $1 += $$($1_OUTPUT_DIR)/$$($1_LIBRARY).map \
ihse@839 495 $$($1_OUTPUT_DIR)/$$($1_LIBRARY).pdb
dcubed@874 496 else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files
ihse@839 497 $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 498 endif
ihse@839 499 endif
ihse@839 500 endif
erikj@738 501 endif
erikj@738 502
ihse@839 503 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE)
ihse@839 504 $$(call LINKING_MSG,$$($1_BASENAME))
ihse@839 505 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(LD_OUT_OPTION)$$@ \
ihse@839 506 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
ihse@839 507 $$($1_EXTRA_LDFLAGS_SUFFIX)
ihse@839 508
ihse@839 509 endif
ihse@839 510
ihse@839 511 ifneq (,$$($1_STATIC_LIBRARY))
ihse@839 512 # Generating a static library, ie object file archive.
ihse@839 513 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES)
ihse@839 514 $$(call ARCHIVING_MSG,$$($1_LIBRARY))
kvn@972 515 $(AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
ihse@839 516 $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
ihse@839 517 endif
ihse@839 518
ihse@839 519 ifneq (,$$($1_PROGRAM))
ihse@839 520 # A executable binary has been specified, setup the target for it.
ihse@839 521 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 522 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
erikj@738 523 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 524 $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_PROGRAM).pdb" \
ihse@839 525 "-map:$$($1_OBJECT_DIR)/$$($1_PROGRAM).map"
erikj@458 526 endif
erikj@458 527
ihse@839 528 ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
ihse@839 529 $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
ihse@839 530 $(CP) $$< $$@
erikj@738 531 endif
erikj@458 532
dcubed@874 533 ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X
dcubed@874 534 ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows
dcubed@874 535 ifeq ($(OPENJDK_TARGET_OS), solaris)
dcubed@874 536 # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
dcubed@874 537 # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
dcubed@874 538 # empty section headers until a fixed $(OBJCOPY) is available.
dcubed@874 539 # An empty section header has sh_addr == 0 and sh_size == 0.
dcubed@874 540 # This problem has only been seen on Solaris X64, but we call this tool
dcubed@874 541 # on all Solaris builds just in case.
dcubed@874 542 #
dcubed@874 543 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
dcubed@874 544 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
dcubed@874 545 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \
dcubed@874 546 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
dcubed@874 547 $(RM) $$@
dcubed@874 548 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
dcubed@874 549 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 550 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
dcubed@874 551 else # not solaris
dcubed@874 552 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET)
dcubed@874 553 $(RM) $$@
dcubed@874 554 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 555 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
dcubed@874 556 endif
dcubed@874 557 $(TOUCH) $$@
dcubed@874 558 endif # !windows
dcubed@874 559 endif # !macosx
erikj@458 560
ihse@839 561 ifeq ($(ZIP_DEBUGINFO_FILES), true)
dcubed@874 562 ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet
ihse@839 563 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).diz
erikj@458 564
ihse@839 565 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 566 $$($1_OBJECT_DIR)/$$($1_PROGRAM).diz : $$($1_TARGET)
ihse@839 567 $(CD) $$($1_OBJECT_DIR) \
ihse@839 568 && $(ZIP) -q $$@ $$($1_PROGRAM).map $$($1_PROGRAM).pdb
ihse@839 569 else
ihse@839 570 $$($1_OBJECT_DIR)/$$(PROGRAM_PREFIX)$$($1_PROGRAM).diz : $$($1_TARGET) \
ihse@839 571 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo
ihse@839 572 $(CD) $$($1_OBJECT_DIR) \
ihse@839 573 && $(ZIP) -q $$@ $$($1_PROGRAM).debuginfo
ihse@839 574 endif
dcubed@874 575 endif # no MacOS X support yet
ihse@839 576 else
ihse@839 577 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 578 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).map \
ihse@839 579 $$($1_OUTPUT_DIR)/$$($1_PROGRAM).pdb
dcubed@874 580 else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files
ihse@839 581 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).debuginfo
ihse@839 582 endif
erikj@458 583 endif
ihse@839 584 endif
erikj@738 585 endif
erikj@458 586
ihse@839 587 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
aharlap@703 588
ihse@839 589 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST)
ihse@839 590 $$(call LINKING_EXE_MSG,$$($1_BASENAME))
ihse@839 591 $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \
ihse@839 592 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
ihse@839 593 $$($1_EXTRA_LDFLAGS_SUFFIX)
erikj@445 594 ifneq (,$$($1_GEN_MANIFEST))
ihse@839 595 $(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1
erikj@445 596 endif
erikj@725 597 # This only works if the openjdk_codesign identity is present on the system. Let
erikj@725 598 # silently fail otherwise.
erikj@725 599 ifneq (,$(CODESIGN))
ihse@839 600 ifneq (,$$($1_CODESIGN))
ihse@839 601 $(CODESIGN) -s openjdk_codesign $$@
ihse@839 602 endif
erikj@725 603 endif
ihse@839 604 endif
ohair@425 605 endef

mercurial