NativeCompilation.gmk 24.8 KB
Newer Older
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 27 28 29 30
#
# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.  Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# When you read this source. Remember that $(sort ...) has the side effect
# of removing duplicates. It is actually this side effect that is
# desired whenever sort is used below!

ifeq  (,$(_MAKEBASE_GMK))
31
    $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk)
32 33 34
endif

ifeq ($(COMPILER_TYPE),CC)
O
ohair 已提交
35 36 37 38
    COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))"
    LINKING_MSG=echo $(LOG_INFO) "Linking $1"
    LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1"
    ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1"
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
else
    COMPILING_MSG=
    LINKING_MSG=
    LINKING_EXE_MSG=
    ARCHIVING_MSG=
endif

define add_native_source
    # param 1 = BUILD_MYPACKAGE
    # parma 2 = the source file name (..../alfa.c or .../beta.cpp)
    # param 3 = the bin dir that stores all .o (.obj) and .d files.
    # param 4 = the c flags to the compiler
    # param 5 = the c compiler
    # param 6 = the c++ flags to the compiler
    # param 7 = the c++ compiler
54
    # param 8 = the flags to the assembler
55 56 57

    ifneq (,$$(filter %.c,$2))
        # Compile as a C file
58
        $1_$2_FLAGS=$4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
59
        $1_$2_COMP=$5
60 61 62
        $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
    else ifneq (,$$(filter %.m,$2))
        # Compile as a objective-c file
63
        $1_$2_FLAGS=-x objective-c $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c
64 65
        $1_$2_COMP=$5
        $1_$2_DEP_FLAG:=$(C_FLAG_DEPS)
66 67
    else ifneq (,$$(filter %.s,$2))
        # Compile as assembler file
68
        $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"'
69 70
        $1_$2_COMP=$(AS)
        $1_$2_DEP_FLAG:=
71 72
    else
        # Compile as a C++ file
73
        $1_$2_FLAGS=$6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c
74
        $1_$2_COMP=$7
75
        $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS)
76 77
    endif
    # Generate the .o (.obj) file name and place it in the bin dir.
78
    $1_$2_OBJ:=$3/$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $2)))))
79 80 81 82
    # Only continue if this object file hasn't been processed already. This lets the first found
    # source file override any other with the same name.
    ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR)))
        $1_OBJS_SO_FAR+=$$($1_$2_OBJ)
83 84 85 86 87
        ifeq (,$$(filter %.s,$2))
          # And this is the dependency file for this obj file.
          $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ))
          # Include previously generated dependency information. (if it exists)
          -include $$($1_$2_DEP)
88

89 90 91 92
          ifeq ($(COMPILER_TYPE),CL)
              $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \
                                     -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ))
          endif
93 94 95 96
        endif

        $$($1_$2_OBJ) : $2
        ifeq ($(COMPILER_TYPE),CC)
O
ohair 已提交
97
		$$(call COMPILING_MSG,$2,$$($1_TARGET))
98 99 100 101 102 103
          # The Sun studio compiler doesn't output the full path to the object file in the
          # generated deps files. Fixing it with sed. If compiling assembly, don't try this.
          ifeq ($(COMPILER_NAME)$$(filter %.s,$2),ossc)
		$$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
		$(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP)
          else
104
		$$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2
105
        endif
106 107 108 109
        endif
        # The Visual Studio compiler lacks a feature for generating make dependencies, but by
        # setting -showIncludes, all included files are printed. These are filtered out and 
        # parsed into make dependences.
110
        ifeq ($(COMPILER_TYPE),CL)
111 112 113 114 115 116 117 118 119
		$$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v "^Note: including file:"
		($(ECHO) $$@: \\ \
		 && $(SED) -e '/^Note: including file:/!d' \
			-e 's|Note: including file: *||' \
			-e 's|\\|/|g' \
			-e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \
			-e '/$(subst /,\/,$(TOPDIR))/!d' \
			-e 's|$$$$| \\|g' \
			$$($1_$2_DEP).raw) > $$($1_$2_DEP)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        endif
    endif
endef

define SetupNativeCompilation
    # param 1 is for example BUILD_MYPACKAGE
    # param 2,3,4,5,6,7,8 are named args.
    #    SRC one or more directory roots to scan for C/C++ files.
    #    LANG C or C++
    #    CFLAGS the compiler flags to be used, used both for C and C++.
    #    CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
    #    LDFLAGS the linker flags to be used, used both for C and C++.
    #    LDFLAGS_SUFFIX the linker flags to be added last on the commandline
    #        typically the libraries linked to.
    #    ARFLAGS the archiver flags to be used
135 136 137
    #    OBJECT_DIR the directory where we store the object files
    #    LIBRARY the resulting library file
    #    PROGRAM the resulting exec file
138 139 140 141 142 143
    #    INCLUDES only pick source from these directories
    #    EXCLUDES do not pick source from these directories
    #    INCLUDE_FILES only compile exactly these files!
    #    EXCLUDE_FILES with these names
    #    VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
    #    RC_FLAGS flags for RC.
144 145
    #    MAPFILE mapfile
    #    REORDER reorder file
146 147 148
    #    DEBUG_SYMBOLS add debug symbols (if configured on)
    #    CC the compiler to use, default is $(CC)
    #    LDEXE the linker to use for linking executables, default is $(LDEXE)
149
    #    OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
150 151 152
    $(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))
    $(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))
    $(if $(27),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk))
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229

    ifneq (,$$($1_BIN))
        $$(error BIN has been replaced with OBJECT_DIR)
    endif

    ifneq (,$$($1_LIB))
        $$(error LIB has been replaced with LIBRARY)
    endif

    ifneq (,$$($1_EXE))
        $$(error EXE has been replaced with PROGRAM)
    endif

    ifneq (,$$($1_LIBRARY))
        ifeq (,$$($1_OUTPUT_DIR))
            $$(error LIBRARY requires OUTPUT_DIR)
        endif

        ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
            $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
        endif

        ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY)))
            $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX))
        endif

        ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY)))
            $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
        endif

        $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$(SHARED_LIBRARY_SUFFIX)
        $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)

    endif

    ifneq (,$$($1_STATIC_LIBRARY))
        ifeq (,$$($1_OUTPUT_DIR))
            $$(error STATIC_LIBRARY requires OUTPUT_DIR)
        endif

        ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY)))
            $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR)
        endif

        ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY)))
            $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX))
        endif

        ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY)))
            $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
        endif

        $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$(STATIC_LIBRARY_SUFFIX)
        $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
    endif

    ifneq (,$$($1_PROGRAM))
        ifeq (,$$($1_OUTPUT_DIR))
            $$(error PROGRAM requires OUTPUT_DIR)
        endif

        ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM)))
            $$(error directory of PROGRAM should be specified using OUTPUT_DIR)
        endif

        ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM)))
            $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX))
        endif

        $1_BASENAME:=$$($1_PROGRAM)$(EXE_SUFFIX)
        $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)

    endif

    ifeq (,$$($1_TARGET))
        $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
    endif
230 231 232 233 234

    ifeq (,$$($1_LANG))
        $$(error You have to specify LANG for native compilation $1)
    endif
    ifeq (C,$$($1_LANG))
O
ohair 已提交
235
        ifeq ($$($1_LDEXE),)
236
	    $1_LDEXE:=$(LDEXE)
O
ohair 已提交
237
        endif
238 239 240 241 242 243 244 245 246 247
	$1_LD:=$(LD)
    else
       ifeq (C++,$$($1_LANG))
           $1_LD:=$(LDCXX)
	   $1_LDEXE:=$(LDEXECXX)
       else
           $$(error Unknown native language $$($1_LANG) for $1)
       endif
    endif

248 249 250 251
    ifeq ($$($1_CC),)
        $1_CC:=$(CC)
    endif

252
    # Make sure the dirs exist.
O
ohair 已提交
253 254 255
    $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)))
    $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))

256
    # Find all files in the source trees. Sort to remove duplicates.
257
    $1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
258 259 260 261 262 263
    # Extract the C/C++ files.
    $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES)))
    $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
    ifneq ($$($1_EXCLUDE_FILES),)
        $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES))
    endif
264
    $1_SRCS     := $$(filter-out $$($1_EXCLUDE_FILES),$$(filter %.s %.c %.cpp %.m,$$($1_ALL_SRCS)))
265 266 267 268 269 270 271
    ifneq (,$$(strip $$($1_INCLUDE_FILES)))
        $1_SRCS := $$(filter $$($1_INCLUDE_FILES),$$($1_SRCS))
    endif
    ifeq (,$$($1_SRCS))
        $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
    endif
    # There can be only a single bin dir root, no need to foreach over the roots.
272
    $1_BINS     := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
    # and we have a list of all existing object files: $$($1_BINS)

    # Prepend the source/bin path to the filter expressions. Then do the filtering.
    ifneq ($$($1_INCLUDES),)
        $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
        $1_SRCS         := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
    endif
    ifneq ($$($1_EXCLUDES),)
        $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
        $1_SRCS         := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
    endif

    # Calculate the expected output from compiling the sources (sort to remove duplicates. Also provides
    # a reproducable order on the input files to the linker).
288
    $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))))))))
289 290 291
    # Are there too many object files on disk? Perhaps because some source file was removed?
    $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
    # Clean out the superfluous object files.
O
ohair 已提交
292 293 294
    ifneq ($$($1_SUPERFLUOUS_OBJS),)
        $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
    endif
295

296 297
    # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CFLAGS.
    $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS))
298 299 300
    ifneq ($(DEBUG_LEVEL),release)
        # Pickup extra debug dependent variables for CFLAGS
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug)
301 302
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
303 304
    else
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release)
305 306
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_release)
        $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
307 308
    endif

309 310
    # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
    $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
311 312 313
    ifneq ($(DEBUG_LEVEL),release)
        # Pickup extra debug dependent variables for CXXFLAGS
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug)
314 315
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
316 317
    else
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release)
318 319
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_release)
        $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
320 321
    endif

322
    ifneq (,$$($1_DEBUG_SYMBOLS))	
323
        ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
324 325
	    ifdef OPENJDK
	        # Always add debug symbols
326 327
                $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
                $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
328 329 330 331 332 333 334
	    else
                # Programs don't get the debug symbols added in the old build. It's not clear if
                # this is intentional.
                ifeq ($$($1_PROGRAM),)
                    $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
                    $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
                endif
335 336 337 338
            endif
        endif
    endif

339 340 341 342 343 344 345
    ifeq ($$($1_CXXFLAGS),)
        $1_CXXFLAGS:=$$($1_CFLAGS)
    endif
    ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),)
        $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS)
    endif

346 347 348 349 350
    ifneq (,$$($1_REORDER))
          $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
          $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
    endif

351
    ifeq (NONE, $$($1_OPTIMIZATION))
352 353
        $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE)
        $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE)
354
    else ifeq (LOW, $$($1_OPTIMIZATION))
355 356
        $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM)
        $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM)
357
    else ifeq (HIGH, $$($1_OPTIMIZATION))
358 359
        $1_EXTRA_CFLAGS += $(C_O_FLAG_HI)
        $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI)
360
    else ifeq (HIGHEST, $$($1_OPTIMIZATION))
361 362
        $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST)
        $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST)
363
    else ifneq (, $$($1_OPTIMIZATION))
364
        $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
365 366
    endif

367 368
    # Now call add_native_source for each source file we are going to compile.
    $$(foreach p,$$($1_SRCS),\
369 370 371
        $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR),\
                        $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC),\
			$$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS))))
372 373

    # On windows we need to create a resource file
374
    ifeq ($(OPENJDK_TARGET_OS), windows)
375
        ifneq (,$$($1_VERSIONINFO_RESOURCE))
376
            $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
377 378 379
            $$($1_RES): $$($1_VERSIONINFO_RESOURCE)
		$(RC) $$($1_RC_FLAGS) $(CC_OUT_OPTION)$$@ $$($1_VERSIONINFO_RESOURCE)
        endif
380
        ifneq (,$$($1_MANIFEST))
381
            $1_GEN_MANIFEST:=$$($1_OBJECT_DIR)/$$($1_PROGRAM).manifest
382 383 384 385 386 387 388
            IMVERSIONVALUE:=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VERSION).$(COOKED_BUILD_NUMBER)
            $$($1_GEN_MANIFEST): $$($1_MANIFEST)
		$(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@
        endif
    endif

    # mapfile doesnt seem to be implemented on macosx (yet??)
389 390 391
    ifneq ($(OPENJDK_TARGET_OS),macosx)
    ifneq ($(OPENJDK_TARGET_OS),windows)
        $1_REAL_MAPFILE:=$$($1_MAPFILE)
392
        ifneq (,$$($1_REORDER))
393
            $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile
394 395 396 397

            $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
		$$(MKDIR) -p $$(@D)
		$$(CP) $$($1_MAPFILE) $$@.tmp
398
		$$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
399 400 401
		$$(MV) $$@.tmp $$@
        endif
    endif
402 403
    endif

404 405
    # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables
    # for LDFLAGS and LDFLAGS_SUFFIX
406 407
    $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
    $1_EXTRA_LDFLAGS_SUFFIX:=$$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS))
408
    ifneq (,$$($1_REAL_MAPFILE))
409
        $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
410 411
    endif

412 413 414 415 416 417 418 419
    $1 := $$($1_TARGET)
    ifneq (,$$($1_LIBRARY))
        # Generating a dynamic library.
        $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
        ifeq ($(OPENJDK_TARGET_OS), windows)
            $1_EXTRA_LDFLAGS+="-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
        endif

420 421
        $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)        

422
        ifneq (,$$($1_DEBUG_SYMBOLS))
423
            ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
424 425 426 427 428
                ifeq ($(OPENJDK_TARGET_OS), windows)
                    $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_LIBRARY).pdb" \
				      "-map:$$($1_OBJECT_DIR)/$$($1_LIBRARY).map"
                endif

429 430
                ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
                    $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
431
			$(CP) $$< $$@
432
                endif
433 434 435 436 437 438 439 440 441 442 443 444 445 446

                ifeq ($(OPENJDK_TARGET_OS), solaris)
                    # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
                    # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
                    # empty section headers until a fixed $(OBJCOPY) is available.
                    # An empty section header has sh_addr == 0 and sh_size == 0.
                    # This problem has only been seen on Solaris X64, but we call this tool
                    # on all Solaris builds just in case.
                    #
                    # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
                    # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
                    $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \
					$(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
			$(RM) $$@
O
ohair 已提交
447
			$(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
448
			$(OBJCOPY) --only-keep-debug $$< $$@
O
ohair 已提交
449
			$(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
450 451 452 453
                else # not solaris
                    $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET)
			$(RM) $$@
			$(OBJCOPY) --only-keep-debug $$< $$@
454 455 456
			$(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
                endif # Touch to not retrigger rule on rebuild
			$(TOUCH) $$@
457

458
                ifeq ($(ZIP_DEBUGINFO_FILES), true)
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
                    $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz

                    ifeq ($(OPENJDK_TARGET_OS), windows)
                        $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET)
				$(CD) $$($1_OBJECT_DIR) \
				&& $(ZIP) -q $$@ $$($1_LIBRARY).map $$($1_LIBRARY).pdb
                    else
                        $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) \
					$$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
				$(CD) $$($1_OBJECT_DIR) \
				&& $(ZIP) -q $$@ $$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo 
                    endif
                else
                    ifeq ($(OPENJDK_TARGET_OS), windows)
                        $1 += $$($1_OUTPUT_DIR)/$$($1_LIBRARY).map \
			      $$($1_OUTPUT_DIR)/$$($1_LIBRARY).pdb
                    else
                        $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
                    endif
                endif
            endif
        endif

        $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE)
		$$(call LINKING_MSG,$$($1_BASENAME))
		$$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(LD_OUT_OPTION)$$@ \
		$$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
		$$($1_EXTRA_LDFLAGS_SUFFIX)

    endif

    ifneq (,$$($1_STATIC_LIBRARY))
        # Generating a static library, ie object file archive.
        $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES)
	        $$(call ARCHIVING_MSG,$$($1_LIBRARY))
	        $(AR) $$($1_AR_FLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
495 496
			$$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
    endif
497 498

    ifneq (,$$($1_PROGRAM))
499
        # A executable binary has been specified, setup the target for it.
500
        ifneq (,$$($1_DEBUG_SYMBOLS))
501
            ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
502 503 504 505 506
                ifeq ($(OPENJDK_TARGET_OS), windows)
                    $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_PROGRAM).pdb" \
				      "-map:$$($1_OBJECT_DIR)/$$($1_PROGRAM).map"
                endif

507 508
                ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
                    $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
509
			$(CP) $$< $$@
510
                endif
511 512 513 514 515 516 517 518 519 520 521 522 523 524

                ifeq ($(OPENJDK_TARGET_OS), solaris)
                    # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
                    # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
                    # empty section headers until a fixed $(OBJCOPY) is available.
                    # An empty section header has sh_addr == 0 and sh_size == 0.
                    # This problem has only been seen on Solaris X64, but we call this tool
                    # on all Solaris builds just in case.
                    #
                    # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
                    # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
                    $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \
					$(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
			$(RM) $$@
O
ohair 已提交
525
			$(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
526
			$(OBJCOPY) --only-keep-debug $$< $$@
O
ohair 已提交
527
			$(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
528 529 530 531
                else # not solaris
                    $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET)
			$(RM) $$@
			$(OBJCOPY) --only-keep-debug $$< $$@
532
			$(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
533
                endif
534
			$(TOUCH) $$@
535

536
                ifeq ($(ZIP_DEBUGINFO_FILES), true)
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                    $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).diz

                    ifeq ($(OPENJDK_TARGET_OS), windows)
                        $$($1_OBJECT_DIR)/$$($1_PROGRAM).diz : $$($1_TARGET)
				$(CD) $$($1_OBJECT_DIR) \
				&& $(ZIP) -q $$@ $$($1_PROGRAM).map $$($1_PROGRAM).pdb
                    else
                        $$($1_OBJECT_DIR)/$$(PROGRAM_PREFIX)$$($1_PROGRAM).diz : $$($1_TARGET) \
					$$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo
				$(CD) $$($1_OBJECT_DIR) \
				&& $(ZIP) -q $$@ $$($1_PROGRAM).debuginfo 
                    endif
                else
                    ifeq ($(OPENJDK_TARGET_OS), windows)
                        $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).map \
			      $$($1_OUTPUT_DIR)/$$($1_PROGRAM).pdb
                    else
                        $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).debuginfo
                    endif
                endif
            endif
        endif

560 561
        $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)

562 563 564
        $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST)
	    	$$(call LINKING_EXE_MSG,$$($1_BASENAME))
		$$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \
565 566 567
			$$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
			$$($1_EXTRA_LDFLAGS_SUFFIX)
        ifneq (,$$($1_GEN_MANIFEST))
O
ohair 已提交
568
		$(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1
569
        endif
570 571 572 573 574 575 576
        # This only works if the openjdk_codesign identity is present on the system. Let
        # silently fail otherwise.
        ifneq (,$(CODESIGN))
            ifneq (,$$($1_CODESIGN))
		$(CODESIGN) -s openjdk_codesign $$@
            endif
        endif
577 578
    endif
endef