make/common/NativeCompilation.gmk

Wed, 27 Apr 2016 01:39:08 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:39:08 +0800
changeset 0
75a576e87639
child 1133
50aaf272884f
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/
changeset: 1170:d117f01bfb4f
tag: jdk8u25-b17

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

mercurial