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