common/makefiles/NativeCompilation.gmk

Fri, 25 Oct 2013 10:15:33 -0700

author
dcubed
date
Fri, 25 Oct 2013 10:15:33 -0700
changeset 874
dfbc93f26f38
parent 855
ac09e62d5e6b
child 972
f3697e0783e2
permissions
-rw-r--r--

8027117: adapt JDK-7165611 to new build-infra whitespace/indent policy
Summary: Fix whitespace/indent issues.
Reviewed-by: hseigel, coleenp, erikj, ihse

ohair@425 1 #
dcubed@854 2 # Copyright (c) 2011, 2013, 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
ohair@425 34 ifeq ($(COMPILER_TYPE),CC)
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
ihse@839 89 ifeq ($(COMPILER_TYPE),CL)
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
ohair@425 96 ifeq ($(COMPILER_TYPE),CC)
ihse@839 97 $$(call COMPILING_MSG,$2,$$($1_TARGET))
erikj@699 98 # The Sun 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.
erikj@699 100 ifeq ($(COMPILER_NAME)$$(filter %.s,$2),ossc)
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.
ohair@425 110 ifeq ($(COMPILER_TYPE),CL)
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: *||' \
ihse@839 119 -e 's|\\|/|g' \
ihse@839 120 -e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \
ihse@839 121 -e '/$(subst /,\/,$(TOPDIR))/!d' \
ihse@839 122 -e 's|$$$$| \\|g' \
ihse@839 123 $$($1_$2_DEP).raw) > $$($1_$2_DEP)
ohair@425 124 endif
ihse@839 125 endif
ohair@425 126 endef
ohair@425 127
ohair@425 128 define SetupNativeCompilation
ihse@839 129 # param 1 is for example BUILD_MYPACKAGE
ihse@839 130 # param 2,3,4,5,6,7,8 are named args.
ihse@839 131 # SRC one or more directory roots to scan for C/C++ files.
ihse@839 132 # LANG C or C++
ihse@839 133 # CFLAGS the compiler flags to be used, used both for C and C++.
ihse@839 134 # CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS.
ihse@839 135 # LDFLAGS the linker flags to be used, used both for C and C++.
ihse@839 136 # LDFLAGS_SUFFIX the linker flags to be added last on the commandline
ihse@839 137 # typically the libraries linked to.
ihse@839 138 # ARFLAGS the archiver flags to be used
ihse@839 139 # OBJECT_DIR the directory where we store the object files
ihse@839 140 # LIBRARY the resulting library file
ihse@839 141 # PROGRAM the resulting exec file
ihse@839 142 # INCLUDES only pick source from these directories
ihse@839 143 # EXCLUDES do not pick source from these directories
ihse@839 144 # INCLUDE_FILES only compile exactly these files!
ihse@839 145 # EXCLUDE_FILES with these names
ihse@839 146 # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run
ihse@839 147 # RC_FLAGS flags for RC.
ihse@839 148 # MAPFILE mapfile
ihse@839 149 # REORDER reorder file
ihse@839 150 # DEBUG_SYMBOLS add debug symbols (if configured on)
ihse@839 151 # CC the compiler to use, default is $(CC)
ihse@839 152 # LDEXE the linker to use for linking executables, default is $(LDEXE)
ihse@839 153 # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST
ihse@839 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))
ihse@839 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))
ihse@839 156 $(if $(27),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk))
erikj@458 157
ihse@839 158 ifneq (,$$($1_BIN))
ihse@839 159 $$(error BIN has been replaced with OBJECT_DIR)
ihse@839 160 endif
ihse@839 161
ihse@839 162 ifneq (,$$($1_LIB))
ihse@839 163 $$(error LIB has been replaced with LIBRARY)
ihse@839 164 endif
ihse@839 165
ihse@839 166 ifneq (,$$($1_EXE))
ihse@839 167 $$(error EXE has been replaced with PROGRAM)
ihse@839 168 endif
ihse@839 169
ihse@839 170 ifneq (,$$($1_LIBRARY))
ihse@839 171 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 172 $$(error LIBRARY requires OUTPUT_DIR)
erikj@458 173 endif
erikj@458 174
ihse@839 175 ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY)))
ihse@839 176 $$(error directory of LIBRARY should be specified using OUTPUT_DIR)
erikj@458 177 endif
erikj@458 178
ihse@839 179 ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY)))
ihse@839 180 $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX))
erikj@458 181 endif
erikj@458 182
ihse@839 183 ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY)))
ihse@839 184 $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
erikj@458 185 endif
erikj@458 186
ihse@839 187 $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$(SHARED_LIBRARY_SUFFIX)
ihse@839 188 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
erikj@458 189
ihse@839 190 endif
erikj@458 191
ihse@839 192 ifneq (,$$($1_STATIC_LIBRARY))
ihse@839 193 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 194 $$(error STATIC_LIBRARY requires OUTPUT_DIR)
erikj@458 195 endif
erikj@458 196
ihse@839 197 ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY)))
ihse@839 198 $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR)
erikj@458 199 endif
erikj@458 200
ihse@839 201 ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY)))
ihse@839 202 $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX))
erikj@458 203 endif
ohair@425 204
ihse@839 205 ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY)))
ihse@839 206 $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX))
ohair@425 207 endif
ohair@425 208
ihse@839 209 $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$(STATIC_LIBRARY_SUFFIX)
ihse@839 210 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
ihse@839 211 endif
ihse@839 212
ihse@839 213 ifneq (,$$($1_PROGRAM))
ihse@839 214 ifeq (,$$($1_OUTPUT_DIR))
ihse@839 215 $$(error PROGRAM requires OUTPUT_DIR)
erikj@458 216 endif
erikj@458 217
ihse@839 218 ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM)))
ihse@839 219 $$(error directory of PROGRAM should be specified using OUTPUT_DIR)
ohair@425 220 endif
ohair@425 221
ihse@839 222 ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM)))
ihse@839 223 $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX))
ohair@494 224 endif
ohair@425 225
ihse@839 226 $1_BASENAME:=$$($1_PROGRAM)$(EXE_SUFFIX)
ihse@839 227 $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME)
ihse@839 228
ihse@839 229 endif
ihse@839 230
ihse@839 231 ifeq (,$$($1_TARGET))
ihse@839 232 $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation)
ihse@839 233 endif
ihse@839 234
ihse@839 235 ifeq (,$$($1_LANG))
ihse@839 236 $$(error You have to specify LANG for native compilation $1)
ihse@839 237 endif
ihse@839 238 ifeq (C,$$($1_LANG))
ihse@839 239 ifeq ($$($1_LDEXE),)
ihse@839 240 $1_LDEXE:=$(LDEXE)
ihse@839 241 endif
ihse@839 242 $1_LD:=$(LD)
ihse@839 243 else
ihse@839 244 ifeq (C++,$$($1_LANG))
ihse@839 245 $1_LD:=$(LDCXX)
ihse@839 246 $1_LDEXE:=$(LDEXECXX)
ohair@425 247 else
ihse@839 248 $$(error Unknown native language $$($1_LANG) for $1)
ohair@425 249 endif
ihse@839 250 endif
ohair@425 251
ihse@839 252 ifeq ($$($1_CC),)
ihse@839 253 $1_CC:=$(CC)
ihse@839 254 endif
ihse@839 255
ihse@839 256 # Make sure the dirs exist.
ihse@839 257 $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR)))
ihse@839 258 $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d)))
ihse@839 259
ihse@839 260 # Find all files in the source trees. Sort to remove duplicates.
ihse@839 261 $1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC)))
ihse@839 262 # Extract the C/C++ files.
ihse@839 263 $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES)))
ihse@839 264 $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES)))
ihse@839 265 ifneq ($$($1_EXCLUDE_FILES),)
ihse@839 266 $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES))
ihse@839 267 endif
ihse@839 268 $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES),$$(filter %.s %.c %.cpp %.m,$$($1_ALL_SRCS)))
ihse@839 269 ifneq (,$$(strip $$($1_INCLUDE_FILES)))
ihse@839 270 $1_SRCS := $$(filter $$($1_INCLUDE_FILES),$$($1_SRCS))
ihse@839 271 endif
ihse@839 272 ifeq (,$$($1_SRCS))
ihse@839 273 $$(error No sources found for $1 when looking inside the dirs $$($1_SRC))
ihse@839 274 endif
ihse@839 275 # There can be only a single bin dir root, no need to foreach over the roots.
ihse@839 276 $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX))
ihse@839 277 # Now we have a list of all c/c++ files to compile: $$($1_SRCS)
ihse@839 278 # and we have a list of all existing object files: $$($1_BINS)
ihse@839 279
ihse@839 280 # Prepend the source/bin path to the filter expressions. Then do the filtering.
ihse@839 281 ifneq ($$($1_INCLUDES),)
ihse@839 282 $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES))))
ihse@839 283 $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS))
ihse@839 284 endif
ihse@839 285 ifneq ($$($1_EXCLUDES),)
ihse@839 286 $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES))))
ihse@839 287 $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS))
ihse@839 288 endif
ihse@839 289
ihse@839 290 # Calculate the expected output from compiling the sources (sort to remove duplicates. Also provides
ihse@839 291 # a reproducable order on the input files to the linker).
ihse@839 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))))))))
ihse@839 293 # Are there too many object files on disk? Perhaps because some source file was removed?
ihse@839 294 $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS)))
ihse@839 295 # Clean out the superfluous object files.
ihse@839 296 ifneq ($$($1_SUPERFLUOUS_OBJS),)
ihse@839 297 $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS))
ihse@839 298 endif
ihse@839 299
ihse@839 300 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CFLAGS.
ihse@839 301 $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS))
ihse@839 302 ifneq ($(DEBUG_LEVEL),release)
ihse@839 303 # Pickup extra debug dependent variables for CFLAGS
ihse@839 304 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug)
ihse@839 305 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
ihse@839 306 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug)
ihse@839 307 else
ihse@839 308 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release)
ihse@839 309 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_release)
ihse@839 310 $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release)
ihse@839 311 endif
ihse@839 312
ihse@839 313 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS.
ihse@839 314 $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS))
ihse@839 315 ifneq ($(DEBUG_LEVEL),release)
ihse@839 316 # Pickup extra debug dependent variables for CXXFLAGS
ihse@839 317 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug)
ihse@839 318 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_debug)
ihse@839 319 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug)
ihse@839 320 else
ihse@839 321 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release)
ihse@839 322 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_release)
ihse@839 323 $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release)
ihse@839 324 endif
ihse@839 325
ihse@839 326 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 327 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
ihse@839 328 ifdef OPENJDK
ihse@839 329 # Always add debug symbols
ihse@839 330 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
ihse@839 331 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
ihse@839 332 else
ihse@839 333 # Programs don't get the debug symbols added in the old build. It's not clear if
ihse@839 334 # this is intentional.
ihse@839 335 ifeq ($$($1_PROGRAM),)
ihse@839 336 $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS)
ihse@839 337 $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS)
ihse@839 338 endif
ihse@839 339 endif
ohair@425 340 endif
ihse@839 341 endif
ohair@425 342
ihse@839 343 ifeq ($$($1_CXXFLAGS),)
ihse@839 344 $1_CXXFLAGS:=$$($1_CFLAGS)
ihse@839 345 endif
ihse@839 346 ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),)
ihse@839 347 $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS)
ihse@839 348 endif
ihse@839 349
ihse@839 350 ifneq (,$$($1_REORDER))
ihse@839 351 $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER)
ihse@839 352 $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER)
ihse@839 353 endif
ihse@839 354
ihse@839 355 ifeq (NONE, $$($1_OPTIMIZATION))
ihse@839 356 $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE)
ihse@839 357 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE)
ihse@839 358 else ifeq (LOW, $$($1_OPTIMIZATION))
ihse@839 359 $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM)
ihse@839 360 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM)
ihse@839 361 else ifeq (HIGH, $$($1_OPTIMIZATION))
ihse@839 362 $1_EXTRA_CFLAGS += $(C_O_FLAG_HI)
ihse@839 363 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI)
ihse@839 364 else ifeq (HIGHEST, $$($1_OPTIMIZATION))
ihse@839 365 $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST)
ihse@839 366 $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST)
ihse@839 367 else ifneq (, $$($1_OPTIMIZATION))
ihse@839 368 $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION))
ihse@839 369 endif
ihse@839 370
ihse@839 371 # Now call add_native_source for each source file we are going to compile.
ihse@839 372 $$(foreach p,$$($1_SRCS), \
ihse@839 373 $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \
ihse@839 374 $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC), \
ihse@839 375 $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS))))
ihse@839 376
ihse@839 377 # On windows we need to create a resource file
ihse@839 378 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 379 ifneq (,$$($1_VERSIONINFO_RESOURCE))
ihse@839 380 $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res
ihse@839 381 $$($1_RES): $$($1_VERSIONINFO_RESOURCE)
ihse@839 382 $(RC) $$($1_RC_FLAGS) $(CC_OUT_OPTION)$$@ $$($1_VERSIONINFO_RESOURCE)
ohair@478 383 endif
ihse@839 384 ifneq (,$$($1_MANIFEST))
ihse@839 385 $1_GEN_MANIFEST:=$$($1_OBJECT_DIR)/$$($1_PROGRAM).manifest
ihse@839 386 IMVERSIONVALUE:=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VERSION).$(COOKED_BUILD_NUMBER)
ihse@839 387 $$($1_GEN_MANIFEST): $$($1_MANIFEST)
ihse@839 388 $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@
ihse@839 389 endif
ihse@839 390 endif
ohair@478 391
ihse@839 392 # mapfile doesnt seem to be implemented on macosx (yet??)
ihse@839 393 ifneq ($(OPENJDK_TARGET_OS),macosx)
ihse@839 394 ifneq ($(OPENJDK_TARGET_OS),windows)
ihse@839 395 $1_REAL_MAPFILE:=$$($1_MAPFILE)
ihse@839 396 ifneq (,$$($1_REORDER))
ihse@839 397 $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile
ohair@425 398
ihse@839 399 $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER)
erikj@445 400 $$(MKDIR) -p $$(@D)
erikj@445 401 $$(CP) $$($1_MAPFILE) $$@.tmp
erikj@458 402 $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp
erikj@445 403 $$(MV) $$@.tmp $$@
ihse@839 404 endif
erikj@445 405 endif
ihse@839 406 endif
ihse@839 407
ihse@839 408 # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables
ihse@839 409 # for LDFLAGS and LDFLAGS_SUFFIX
ihse@839 410 $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS))
ihse@839 411 $1_EXTRA_LDFLAGS_SUFFIX:=$$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS))
ihse@839 412 ifneq (,$$($1_REAL_MAPFILE))
ihse@839 413 $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE))
ihse@839 414 endif
ihse@839 415
ihse@839 416 $1 := $$($1_TARGET)
ihse@839 417 ifneq (,$$($1_LIBRARY))
ihse@839 418 # Generating a dynamic library.
ihse@839 419 $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME))
ihse@839 420 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 421 $1_EXTRA_LDFLAGS+="-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib"
ohair@425 422 endif
erikj@445 423
ihse@839 424 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
erikj@458 425
ihse@839 426 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 427 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
erikj@458 428 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 429 $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_LIBRARY).pdb" \
ihse@839 430 "-map:$$($1_OBJECT_DIR)/$$($1_LIBRARY).map"
erikj@458 431 endif
erikj@458 432
ihse@839 433 ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
ihse@839 434 $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
ihse@839 435 $(CP) $$< $$@
ihse@839 436 endif
erikj@458 437
dcubed@874 438 ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X
dcubed@874 439 ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows
dcubed@874 440 ifeq ($(OPENJDK_TARGET_OS), solaris)
dcubed@874 441 # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
dcubed@874 442 # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
dcubed@874 443 # empty section headers until a fixed $(OBJCOPY) is available.
dcubed@874 444 # An empty section header has sh_addr == 0 and sh_size == 0.
dcubed@874 445 # This problem has only been seen on Solaris X64, but we call this tool
dcubed@874 446 # on all Solaris builds just in case.
dcubed@874 447 #
dcubed@874 448 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
dcubed@874 449 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
dcubed@874 450 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \
dcubed@874 451 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
dcubed@874 452 $(RM) $$@
dcubed@874 453 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
dcubed@874 454 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 455 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
dcubed@874 456 else # not solaris
dcubed@874 457 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET)
dcubed@874 458 $(RM) $$@
dcubed@874 459 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 460 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
dcubed@874 461 endif # Touch to not retrigger rule on rebuild
ihse@839 462 $(TOUCH) $$@
dcubed@874 463 endif # !windows
dcubed@874 464 endif # !macosx
erikj@458 465
ihse@839 466 ifeq ($(ZIP_DEBUGINFO_FILES), true)
dcubed@874 467 ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet
ihse@839 468 $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz
erikj@458 469
ihse@839 470 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 471 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET)
ihse@839 472 $(CD) $$($1_OBJECT_DIR) \
ihse@839 473 && $(ZIP) -q $$@ $$($1_LIBRARY).map $$($1_LIBRARY).pdb
ihse@839 474 else
ihse@839 475 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) \
ihse@839 476 $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 477 $(CD) $$($1_OBJECT_DIR) \
ihse@839 478 && $(ZIP) -q $$@ $$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 479 endif
dcubed@874 480 endif # no MacOS X support yet
ihse@839 481 else
ihse@839 482 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 483 $1 += $$($1_OUTPUT_DIR)/$$($1_LIBRARY).map \
ihse@839 484 $$($1_OUTPUT_DIR)/$$($1_LIBRARY).pdb
dcubed@874 485 else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files
ihse@839 486 $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo
ihse@839 487 endif
ihse@839 488 endif
ihse@839 489 endif
erikj@738 490 endif
erikj@738 491
ihse@839 492 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE)
ihse@839 493 $$(call LINKING_MSG,$$($1_BASENAME))
ihse@839 494 $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(LD_OUT_OPTION)$$@ \
ihse@839 495 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
ihse@839 496 $$($1_EXTRA_LDFLAGS_SUFFIX)
ihse@839 497
ihse@839 498 endif
ihse@839 499
ihse@839 500 ifneq (,$$($1_STATIC_LIBRARY))
ihse@839 501 # Generating a static library, ie object file archive.
ihse@839 502 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES)
ihse@839 503 $$(call ARCHIVING_MSG,$$($1_LIBRARY))
ihse@839 504 $(AR) $$($1_AR_FLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \
ihse@839 505 $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX)
ihse@839 506 endif
ihse@839 507
ihse@839 508 ifneq (,$$($1_PROGRAM))
ihse@839 509 # A executable binary has been specified, setup the target for it.
ihse@839 510 ifneq (,$$($1_DEBUG_SYMBOLS))
ihse@839 511 ifeq ($(ENABLE_DEBUG_SYMBOLS), true)
erikj@738 512 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 513 $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_PROGRAM).pdb" \
ihse@839 514 "-map:$$($1_OBJECT_DIR)/$$($1_PROGRAM).map"
erikj@458 515 endif
erikj@458 516
ihse@839 517 ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR))
ihse@839 518 $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/%
ihse@839 519 $(CP) $$< $$@
erikj@738 520 endif
erikj@458 521
dcubed@874 522 ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X
dcubed@874 523 ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows
dcubed@874 524 ifeq ($(OPENJDK_TARGET_OS), solaris)
dcubed@874 525 # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set.
dcubed@874 526 # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from
dcubed@874 527 # empty section headers until a fixed $(OBJCOPY) is available.
dcubed@874 528 # An empty section header has sh_addr == 0 and sh_size == 0.
dcubed@874 529 # This problem has only been seen on Solaris X64, but we call this tool
dcubed@874 530 # on all Solaris builds just in case.
dcubed@874 531 #
dcubed@874 532 # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections.
dcubed@874 533 # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available.
dcubed@874 534 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \
dcubed@874 535 $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK)
dcubed@874 536 $(RM) $$@
dcubed@874 537 $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$<
dcubed@874 538 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 539 $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$<
dcubed@874 540 else # not solaris
dcubed@874 541 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET)
dcubed@874 542 $(RM) $$@
dcubed@874 543 $(OBJCOPY) --only-keep-debug $$< $$@
dcubed@874 544 $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$<
dcubed@874 545 endif
dcubed@874 546 $(TOUCH) $$@
dcubed@874 547 endif # !windows
dcubed@874 548 endif # !macosx
erikj@458 549
ihse@839 550 ifeq ($(ZIP_DEBUGINFO_FILES), true)
dcubed@874 551 ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet
ihse@839 552 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).diz
erikj@458 553
ihse@839 554 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 555 $$($1_OBJECT_DIR)/$$($1_PROGRAM).diz : $$($1_TARGET)
ihse@839 556 $(CD) $$($1_OBJECT_DIR) \
ihse@839 557 && $(ZIP) -q $$@ $$($1_PROGRAM).map $$($1_PROGRAM).pdb
ihse@839 558 else
ihse@839 559 $$($1_OBJECT_DIR)/$$(PROGRAM_PREFIX)$$($1_PROGRAM).diz : $$($1_TARGET) \
ihse@839 560 $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo
ihse@839 561 $(CD) $$($1_OBJECT_DIR) \
ihse@839 562 && $(ZIP) -q $$@ $$($1_PROGRAM).debuginfo
ihse@839 563 endif
dcubed@874 564 endif # no MacOS X support yet
ihse@839 565 else
ihse@839 566 ifeq ($(OPENJDK_TARGET_OS), windows)
ihse@839 567 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).map \
ihse@839 568 $$($1_OUTPUT_DIR)/$$($1_PROGRAM).pdb
dcubed@874 569 else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files
ihse@839 570 $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).debuginfo
ihse@839 571 endif
erikj@458 572 endif
ihse@839 573 endif
erikj@738 574 endif
erikj@458 575
ihse@839 576 $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX)
aharlap@703 577
ihse@839 578 $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST)
ihse@839 579 $$(call LINKING_EXE_MSG,$$($1_BASENAME))
ihse@839 580 $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \
ihse@839 581 $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \
ihse@839 582 $$($1_EXTRA_LDFLAGS_SUFFIX)
erikj@445 583 ifneq (,$$($1_GEN_MANIFEST))
ihse@839 584 $(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1
erikj@445 585 endif
erikj@725 586 # This only works if the openjdk_codesign identity is present on the system. Let
erikj@725 587 # silently fail otherwise.
erikj@725 588 ifneq (,$(CODESIGN))
ihse@839 589 ifneq (,$$($1_CODESIGN))
ihse@839 590 $(CODESIGN) -s openjdk_codesign $$@
ihse@839 591 endif
erikj@725 592 endif
ihse@839 593 endif
ohair@425 594 endef

mercurial