1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/make/common/NativeCompilation.gmk Wed Apr 27 01:39:08 2016 +0800 1.3 @@ -0,0 +1,594 @@ 1.4 +# 1.5 +# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 +# 1.8 +# This code is free software; you can redistribute it and/or modify it 1.9 +# under the terms of the GNU General Public License version 2 only, as 1.10 +# published by the Free Software Foundation. Oracle designates this 1.11 +# particular file as subject to the "Classpath" exception as provided 1.12 +# by Oracle in the LICENSE file that accompanied this code. 1.13 +# 1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 +# version 2 for more details (a copy is included in the LICENSE file that 1.18 +# accompanied this code). 1.19 +# 1.20 +# You should have received a copy of the GNU General Public License version 1.21 +# 2 along with this work; if not, write to the Free Software Foundation, 1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 +# 1.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 +# or visit www.oracle.com if you need additional information or have any 1.26 +# questions. 1.27 +# 1.28 + 1.29 +# When you read this source. Remember that $(sort ...) has the side effect 1.30 +# of removing duplicates. It is actually this side effect that is 1.31 +# desired whenever sort is used below! 1.32 + 1.33 +ifeq (,$(_MAKEBASE_GMK)) 1.34 + $(error You must include MakeBase.gmk prior to including NativeCompilation.gmk) 1.35 +endif 1.36 + 1.37 +ifeq ($(COMPILER_TYPE),CC) 1.38 + COMPILING_MSG=echo $(LOG_INFO) "Compiling $(notdir $1) (for $(notdir $2))" 1.39 + LINKING_MSG=echo $(LOG_INFO) "Linking $1" 1.40 + LINKING_EXE_MSG=echo $(LOG_INFO) "Linking executable $1" 1.41 + ARCHIVING_MSG=echo $(LOG_INFO) "Archiving $1" 1.42 +else 1.43 + COMPILING_MSG= 1.44 + LINKING_MSG= 1.45 + LINKING_EXE_MSG= 1.46 + ARCHIVING_MSG= 1.47 +endif 1.48 + 1.49 +define add_native_source 1.50 + # param 1 = BUILD_MYPACKAGE 1.51 + # parma 2 = the source file name (..../alfa.c or .../beta.cpp) 1.52 + # param 3 = the bin dir that stores all .o (.obj) and .d files. 1.53 + # param 4 = the c flags to the compiler 1.54 + # param 5 = the c compiler 1.55 + # param 6 = the c++ flags to the compiler 1.56 + # param 7 = the c++ compiler 1.57 + # param 8 = the flags to the assembler 1.58 + 1.59 + ifneq (,$$(filter %.c,$2)) 1.60 + # Compile as a C file 1.61 + $1_$2_FLAGS=$4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 1.62 + $1_$2_COMP=$5 1.63 + $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 1.64 + else ifneq (,$$(filter %.m,$2)) 1.65 + # Compile as a objective-c file 1.66 + $1_$2_FLAGS=-x objective-c $4 $$($1_$(notdir $2)_CFLAGS) -DTHIS_FILE='"$$(<F)"' -c 1.67 + $1_$2_COMP=$5 1.68 + $1_$2_DEP_FLAG:=$(C_FLAG_DEPS) 1.69 + else ifneq (,$$(filter %.s,$2)) 1.70 + # Compile as assembler file 1.71 + $1_$2_FLAGS=$8 -DTHIS_FILE='"$$(<F)"' 1.72 + $1_$2_COMP=$(AS) 1.73 + $1_$2_DEP_FLAG:= 1.74 + else 1.75 + # Compile as a C++ file 1.76 + $1_$2_FLAGS=$6 $$($1_$(notdir $2)_CXXFLAGS) -DTHIS_FILE='"$$(<F)"' -c 1.77 + $1_$2_COMP=$7 1.78 + $1_$2_DEP_FLAG:=$(CXX_FLAG_DEPS) 1.79 + endif 1.80 + # Generate the .o (.obj) file name and place it in the bin dir. 1.81 + $1_$2_OBJ:=$3/$$(patsubst %.cpp,%$(OBJ_SUFFIX),$$(patsubst %.c,%$(OBJ_SUFFIX),$$(patsubst %.m,%$(OBJ_SUFFIX),$$(patsubst %.s,%$(OBJ_SUFFIX),$$(notdir $2))))) 1.82 + # Only continue if this object file hasn't been processed already. This lets the first found 1.83 + # source file override any other with the same name. 1.84 + ifeq (,$$(findstring $$($1_$2_OBJ),$$($1_OBJS_SO_FAR))) 1.85 + $1_OBJS_SO_FAR+=$$($1_$2_OBJ) 1.86 + ifeq (,$$(filter %.s,$2)) 1.87 + # And this is the dependency file for this obj file. 1.88 + $1_$2_DEP:=$$(patsubst %$(OBJ_SUFFIX),%.d,$$($1_$2_OBJ)) 1.89 + # Include previously generated dependency information. (if it exists) 1.90 + -include $$($1_$2_DEP) 1.91 + 1.92 + ifeq ($(COMPILER_TYPE),CL) 1.93 + $1_$2_DEBUG_OUT_FLAGS:=-Fd$$(patsubst %$(OBJ_SUFFIX),%.pdb,$$($1_$2_OBJ)) \ 1.94 + -Fm$$(patsubst %$(OBJ_SUFFIX),%.map,$$($1_$2_OBJ)) 1.95 + endif 1.96 + endif 1.97 + 1.98 + $$($1_$2_OBJ) : $2 1.99 + ifeq ($(COMPILER_TYPE),CC) 1.100 + $$(call COMPILING_MSG,$2,$$($1_TARGET)) 1.101 + # The Sun studio compiler doesn't output the full path to the object file in the 1.102 + # generated deps files. Fixing it with sed. If compiling assembly, don't try this. 1.103 + ifeq ($(COMPILER_NAME)$$(filter %.s,$2),ossc) 1.104 + $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP).tmp $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 1.105 + $(SED) 's|^$$(@F):|$$@:|' $$($1_$2_DEP).tmp > $$($1_$2_DEP) 1.106 + else 1.107 + $$($1_$2_COMP) $$($1_$2_FLAGS) $$($1_$2_DEP_FLAG) $$($1_$2_DEP) $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 1.108 + endif 1.109 + endif 1.110 + # The Visual Studio compiler lacks a feature for generating make dependencies, but by 1.111 + # setting -showIncludes, all included files are printed. These are filtered out and 1.112 + # parsed into make dependences. 1.113 + ifeq ($(COMPILER_TYPE),CL) 1.114 + ($$($1_$2_COMP) $$($1_$2_FLAGS) -showIncludes $$($1_$2_DEBUG_OUT_FLAGS) \ 1.115 + $(CC_OUT_OPTION)$$($1_$2_OBJ) $2 ; echo $$$$? > $$($1_$2_DEP).exitvalue) \ 1.116 + | $(TEE) $$($1_$2_DEP).raw | $(GREP) -v "^Note: including file:" \ 1.117 + && exit `cat $$($1_$2_DEP).exitvalue` 1.118 + $(RM) $$($1_$2_DEP).exitvalue 1.119 + ($(ECHO) $$@: \\ \ 1.120 + && $(SED) -e '/^Note: including file:/!d' \ 1.121 + -e 's|Note: including file: *||' \ 1.122 + -e 's|\\|/|g' \ 1.123 + -e 's|^\([a-zA-Z]\):|/cygdrive/\1|g' \ 1.124 + -e '/$(subst /,\/,$(TOPDIR))/!d' \ 1.125 + -e 's|$$$$| \\|g' \ 1.126 + $$($1_$2_DEP).raw) > $$($1_$2_DEP) 1.127 + endif 1.128 + endif 1.129 +endef 1.130 + 1.131 +define SetupNativeCompilation 1.132 + # param 1 is for example BUILD_MYPACKAGE 1.133 + # param 2,3,4,5,6,7,8 are named args. 1.134 + # SRC one or more directory roots to scan for C/C++ files. 1.135 + # LANG C or C++ 1.136 + # CFLAGS the compiler flags to be used, used both for C and C++. 1.137 + # CXXFLAGS the compiler flags to be used for c++, if set overrides CFLAGS. 1.138 + # LDFLAGS the linker flags to be used, used both for C and C++. 1.139 + # LDFLAGS_SUFFIX the linker flags to be added last on the commandline 1.140 + # typically the libraries linked to. 1.141 + # ARFLAGS the archiver flags to be used 1.142 + # OBJECT_DIR the directory where we store the object files 1.143 + # LIBRARY the resulting library file 1.144 + # PROGRAM the resulting exec file 1.145 + # INCLUDES only pick source from these directories 1.146 + # EXCLUDES do not pick source from these directories 1.147 + # INCLUDE_FILES only compile exactly these files! 1.148 + # EXCLUDE_FILES with these names 1.149 + # VERSIONINFO_RESOURCE Input file for RC. Setting this implies that RC will be run 1.150 + # RC_FLAGS flags for RC. 1.151 + # MAPFILE mapfile 1.152 + # REORDER reorder file 1.153 + # DEBUG_SYMBOLS add debug symbols (if configured on) 1.154 + # CC the compiler to use, default is $(CC) 1.155 + # LDEXE the linker to use for linking executables, default is $(LDEXE) 1.156 + # OPTIMIZATION sets optimization level to NONE, LOW, HIGH, HIGHEST 1.157 + $(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)) 1.158 + $(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)) 1.159 + $(if $(27),$(error Internal makefile error: Too many arguments to SetupNativeCompilation, please update NativeCompilation.gmk)) 1.160 + 1.161 + ifneq (,$$($1_BIN)) 1.162 + $$(error BIN has been replaced with OBJECT_DIR) 1.163 + endif 1.164 + 1.165 + ifneq (,$$($1_LIB)) 1.166 + $$(error LIB has been replaced with LIBRARY) 1.167 + endif 1.168 + 1.169 + ifneq (,$$($1_EXE)) 1.170 + $$(error EXE has been replaced with PROGRAM) 1.171 + endif 1.172 + 1.173 + ifneq (,$$($1_LIBRARY)) 1.174 + ifeq (,$$($1_OUTPUT_DIR)) 1.175 + $$(error LIBRARY requires OUTPUT_DIR) 1.176 + endif 1.177 + 1.178 + ifneq ($$($1_LIBRARY),$(basename $$($1_LIBRARY))) 1.179 + $$(error directory of LIBRARY should be specified using OUTPUT_DIR) 1.180 + endif 1.181 + 1.182 + ifneq (,$(findstring $(SHARED_LIBRARY_SUFFIX),$$($1_LIBRARY))) 1.183 + $$(error LIBRARY should be specified without SHARED_LIBRARY_SUFFIX: $(SHARED_LIBRARY_SUFFIX)) 1.184 + endif 1.185 + 1.186 + ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_LIBRARY))) 1.187 + $$(error LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 1.188 + endif 1.189 + 1.190 + $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_LIBRARY)$(SHARED_LIBRARY_SUFFIX) 1.191 + $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 1.192 + 1.193 + endif 1.194 + 1.195 + ifneq (,$$($1_STATIC_LIBRARY)) 1.196 + ifeq (,$$($1_OUTPUT_DIR)) 1.197 + $$(error STATIC_LIBRARY requires OUTPUT_DIR) 1.198 + endif 1.199 + 1.200 + ifneq ($$($1_STATIC_LIBRARY),$(basename $$($1_STATIC_LIBRARY))) 1.201 + $$(error directory of STATIC_LIBRARY should be specified using OUTPUT_DIR) 1.202 + endif 1.203 + 1.204 + ifneq (,$(findstring $(STATIC_LIBRARY_SUFFIX),$$($1_STATIC_LIBRARY))) 1.205 + $$(error STATIC_LIBRARY should be specified without STATIC_LIBRARY_SUFFIX: $(STATIC_LIBRARY_SUFFIX)) 1.206 + endif 1.207 + 1.208 + ifneq (,$(findstring $(LIBRARY_PREFIX),$$($1_STATIC_LIBRARY))) 1.209 + $$(error STATIC_LIBRARY should be specified without LIBRARY_PREFIX: $(LIBRARY_PREFIX)) 1.210 + endif 1.211 + 1.212 + $1_BASENAME:=$(LIBRARY_PREFIX)$$($1_STATIC_LIBRARY)$(STATIC_LIBRARY_SUFFIX) 1.213 + $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 1.214 + endif 1.215 + 1.216 + ifneq (,$$($1_PROGRAM)) 1.217 + ifeq (,$$($1_OUTPUT_DIR)) 1.218 + $$(error PROGRAM requires OUTPUT_DIR) 1.219 + endif 1.220 + 1.221 + ifneq ($$($1_PROGRAM),$(basename $$($1_PROGRAM))) 1.222 + $$(error directory of PROGRAM should be specified using OUTPUT_DIR) 1.223 + endif 1.224 + 1.225 + ifneq (,$(findstring $(EXE_SUFFIX),$$($1_PROGRAM))) 1.226 + $$(error PROGRAM should be specified without EXE_SUFFIX: $(EXE_SUFFIX)) 1.227 + endif 1.228 + 1.229 + $1_BASENAME:=$$($1_PROGRAM)$(EXE_SUFFIX) 1.230 + $1_TARGET:=$$($1_OUTPUT_DIR)/$$($1_BASENAME) 1.231 + 1.232 + endif 1.233 + 1.234 + ifeq (,$$($1_TARGET)) 1.235 + $$(error Neither PROGRAM, LIBRARY nor STATIC_LIBRARY has been specified for SetupNativeCompilation) 1.236 + endif 1.237 + 1.238 + ifeq (,$$($1_LANG)) 1.239 + $$(error You have to specify LANG for native compilation $1) 1.240 + endif 1.241 + ifeq (C,$$($1_LANG)) 1.242 + ifeq ($$($1_LDEXE),) 1.243 + $1_LDEXE:=$(LDEXE) 1.244 + endif 1.245 + $1_LD:=$(LD) 1.246 + else 1.247 + ifeq (C++,$$($1_LANG)) 1.248 + $1_LD:=$(LDCXX) 1.249 + $1_LDEXE:=$(LDEXECXX) 1.250 + else 1.251 + $$(error Unknown native language $$($1_LANG) for $1) 1.252 + endif 1.253 + endif 1.254 + 1.255 + ifeq ($$($1_CC),) 1.256 + $1_CC:=$(CC) 1.257 + endif 1.258 + 1.259 + # Make sure the dirs exist. 1.260 + $$(eval $$(call MakeDir,$$($1_OBJECT_DIR) $$($1_OUTPUT_DIR))) 1.261 + $$(foreach d,$$($1_SRC), $$(if $$(wildcard $$d),,$$(error SRC specified to SetupNativeCompilation $1 contains missing directory $$d))) 1.262 + 1.263 + # Find all files in the source trees. Sort to remove duplicates. 1.264 + $1_ALL_SRCS := $$(sort $$(call CacheFind,$$($1_SRC))) 1.265 + # Extract the C/C++ files. 1.266 + $1_EXCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_EXCLUDE_FILES))) 1.267 + $1_INCLUDE_FILES:=$$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$($1_INCLUDE_FILES))) 1.268 + ifneq ($$($1_EXCLUDE_FILES),) 1.269 + $1_EXCLUDE_FILES:=$$(addprefix %,$$($1_EXCLUDE_FILES)) 1.270 + endif 1.271 + $1_SRCS := $$(filter-out $$($1_EXCLUDE_FILES),$$(filter %.s %.c %.cpp %.m,$$($1_ALL_SRCS))) 1.272 + ifneq (,$$(strip $$($1_INCLUDE_FILES))) 1.273 + $1_SRCS := $$(filter $$($1_INCLUDE_FILES),$$($1_SRCS)) 1.274 + endif 1.275 + ifeq (,$$($1_SRCS)) 1.276 + $$(error No sources found for $1 when looking inside the dirs $$($1_SRC)) 1.277 + endif 1.278 + # There can be only a single bin dir root, no need to foreach over the roots. 1.279 + $1_BINS := $$(wildcard $$($1_OBJECT_DIR)/*$(OBJ_SUFFIX)) 1.280 + # Now we have a list of all c/c++ files to compile: $$($1_SRCS) 1.281 + # and we have a list of all existing object files: $$($1_BINS) 1.282 + 1.283 + # Prepend the source/bin path to the filter expressions. Then do the filtering. 1.284 + ifneq ($$($1_INCLUDES),) 1.285 + $1_SRC_INCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_INCLUDES)))) 1.286 + $1_SRCS := $$(filter $$($1_SRC_INCLUDES),$$($1_SRCS)) 1.287 + endif 1.288 + ifneq ($$($1_EXCLUDES),) 1.289 + $1_SRC_EXCLUDES := $$(foreach i,$$($1_SRC),$$(addprefix $$i/,$$(addsuffix /%,$$($1_EXCLUDES)))) 1.290 + $1_SRCS := $$(filter-out $$($1_SRC_EXCLUDES),$$($1_SRCS)) 1.291 + endif 1.292 + 1.293 + # Calculate the expected output from compiling the sources (sort to remove duplicates. Also provides 1.294 + # a reproducable order on the input files to the linker). 1.295 + $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)))))))) 1.296 + # Are there too many object files on disk? Perhaps because some source file was removed? 1.297 + $1_SUPERFLOUS_OBJS:=$$(sort $$(filter-out $$($1_EXPECTED_OBJS),$$($1_BINS))) 1.298 + # Clean out the superfluous object files. 1.299 + ifneq ($$($1_SUPERFLUOUS_OBJS),) 1.300 + $$(shell $(RM) -f $$($1_SUPERFLUOUS_OBJS)) 1.301 + endif 1.302 + 1.303 + # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CFLAGS. 1.304 + $1_EXTRA_CFLAGS:=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CFLAGS_$(OPENJDK_TARGET_OS)) 1.305 + ifneq ($(DEBUG_LEVEL),release) 1.306 + # Pickup extra debug dependent variables for CFLAGS 1.307 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_debug) 1.308 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_debug) 1.309 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_debug) 1.310 + else 1.311 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_release) 1.312 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS_API)_release) 1.313 + $1_EXTRA_CFLAGS+=$$($1_CFLAGS_$(OPENJDK_TARGET_OS)_release) 1.314 + endif 1.315 + 1.316 + # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables for CXXFLAGS. 1.317 + $1_EXTRA_CXXFLAGS:=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)) 1.318 + ifneq ($(DEBUG_LEVEL),release) 1.319 + # Pickup extra debug dependent variables for CXXFLAGS 1.320 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_debug) 1.321 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_debug) 1.322 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_debug) 1.323 + else 1.324 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_release) 1.325 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS_API)_release) 1.326 + $1_EXTRA_CXXFLAGS+=$$($1_CXXFLAGS_$(OPENJDK_TARGET_OS)_release) 1.327 + endif 1.328 + 1.329 + ifneq (,$$($1_DEBUG_SYMBOLS)) 1.330 + ifeq ($(ENABLE_DEBUG_SYMBOLS), true) 1.331 + ifdef OPENJDK 1.332 + # Always add debug symbols 1.333 + $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS) 1.334 + $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS) 1.335 + else 1.336 + # Programs don't get the debug symbols added in the old build. It's not clear if 1.337 + # this is intentional. 1.338 + ifeq ($$($1_PROGRAM),) 1.339 + $1_EXTRA_CFLAGS+=$(CFLAGS_DEBUG_SYMBOLS) 1.340 + $1_EXTRA_CXXFLAGS+=$(CXXFLAGS_DEBUG_SYMBOLS) 1.341 + endif 1.342 + endif 1.343 + endif 1.344 + endif 1.345 + 1.346 + ifeq ($$($1_CXXFLAGS),) 1.347 + $1_CXXFLAGS:=$$($1_CFLAGS) 1.348 + endif 1.349 + ifeq ($$(strip $$($1_EXTRA_CXXFLAGS)),) 1.350 + $1_EXTRA_CXXFLAGS:=$$($1_EXTRA_CFLAGS) 1.351 + endif 1.352 + 1.353 + ifneq (,$$($1_REORDER)) 1.354 + $1_EXTRA_CFLAGS += $$(C_FLAG_REORDER) 1.355 + $1_EXTRA_CXXFLAGS += $$(CXX_FLAG_REORDER) 1.356 + endif 1.357 + 1.358 + ifeq (NONE, $$($1_OPTIMIZATION)) 1.359 + $1_EXTRA_CFLAGS += $(C_O_FLAG_NONE) 1.360 + $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NONE) 1.361 + else ifeq (LOW, $$($1_OPTIMIZATION)) 1.362 + $1_EXTRA_CFLAGS += $(C_O_FLAG_NORM) 1.363 + $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_NORM) 1.364 + else ifeq (HIGH, $$($1_OPTIMIZATION)) 1.365 + $1_EXTRA_CFLAGS += $(C_O_FLAG_HI) 1.366 + $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HI) 1.367 + else ifeq (HIGHEST, $$($1_OPTIMIZATION)) 1.368 + $1_EXTRA_CFLAGS += $(C_O_FLAG_HIGHEST) 1.369 + $1_EXTRA_CXXFLAGS += $(CXX_O_FLAG_HIGHEST) 1.370 + else ifneq (, $$($1_OPTIMIZATION)) 1.371 + $$(error Unknown value for OPTIMIZATION: $$($1_OPTIMIZATION)) 1.372 + endif 1.373 + 1.374 + # Now call add_native_source for each source file we are going to compile. 1.375 + $$(foreach p,$$($1_SRCS), \ 1.376 + $$(eval $$(call add_native_source,$1,$$p,$$($1_OBJECT_DIR), \ 1.377 + $$($1_CFLAGS) $$($1_EXTRA_CFLAGS),$$($1_CC), \ 1.378 + $$($1_CXXFLAGS) $$($1_EXTRA_CXXFLAGS),$(CXX),$$($1_ASFLAGS)))) 1.379 + 1.380 + # On windows we need to create a resource file 1.381 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.382 + ifneq (,$$($1_VERSIONINFO_RESOURCE)) 1.383 + $1_RES:=$$($1_OBJECT_DIR)/$$($1_BASENAME).res 1.384 + $$($1_RES): $$($1_VERSIONINFO_RESOURCE) 1.385 + $(RC) $$($1_RC_FLAGS) $(CC_OUT_OPTION)$$@ $$($1_VERSIONINFO_RESOURCE) 1.386 + endif 1.387 + ifneq (,$$($1_MANIFEST)) 1.388 + $1_GEN_MANIFEST:=$$($1_OBJECT_DIR)/$$($1_PROGRAM).manifest 1.389 + IMVERSIONVALUE:=$(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VERSION).$(COOKED_BUILD_NUMBER) 1.390 + $$($1_GEN_MANIFEST): $$($1_MANIFEST) 1.391 + $(SED) 's%IMVERSION%$$(IMVERSIONVALUE)%g;s%PROGRAM%$$($1_PROGRAM)%g' $$< > $$@ 1.392 + endif 1.393 + endif 1.394 + 1.395 + # mapfile doesnt seem to be implemented on macosx (yet??) 1.396 + ifneq ($(OPENJDK_TARGET_OS),macosx) 1.397 + ifneq ($(OPENJDK_TARGET_OS),windows) 1.398 + $1_REAL_MAPFILE:=$$($1_MAPFILE) 1.399 + ifneq (,$$($1_REORDER)) 1.400 + $1_REAL_MAPFILE:=$$($1_OBJECT_DIR)/mapfile 1.401 + 1.402 + $$($1_REAL_MAPFILE) : $$($1_MAPFILE) $$($1_REORDER) 1.403 + $$(MKDIR) -p $$(@D) 1.404 + $$(CP) $$($1_MAPFILE) $$@.tmp 1.405 + $$(SED) -e 's=OUTPUTDIR=$$($1_OBJECT_DIR)=' $$($1_REORDER) >> $$@.tmp 1.406 + $$(MV) $$@.tmp $$@ 1.407 + endif 1.408 + endif 1.409 + endif 1.410 + 1.411 + # Pickup extra OPENJDK_TARGET_OS_API and/or OPENJDK_TARGET_OS dependent variables 1.412 + # for LDFLAGS and LDFLAGS_SUFFIX 1.413 + $1_EXTRA_LDFLAGS:=$$($1_LDFLAGS_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) 1.414 + $1_EXTRA_LDFLAGS_SUFFIX:=$$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS_API)) $$($1_LDFLAGS_SUFFIX_$(OPENJDK_TARGET_OS)) 1.415 + ifneq (,$$($1_REAL_MAPFILE)) 1.416 + $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) 1.417 + endif 1.418 + 1.419 + $1 := $$($1_TARGET) 1.420 + ifneq (,$$($1_LIBRARY)) 1.421 + # Generating a dynamic library. 1.422 + $1_EXTRA_LDFLAGS+=$$(call SET_SHARED_LIBRARY_NAME,$$($1_BASENAME)) 1.423 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.424 + $1_EXTRA_LDFLAGS+="-implib:$$($1_OBJECT_DIR)/$$($1_LIBRARY).lib" 1.425 + endif 1.426 + 1.427 + $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) 1.428 + 1.429 + ifneq (,$$($1_DEBUG_SYMBOLS)) 1.430 + ifeq ($(ENABLE_DEBUG_SYMBOLS), true) 1.431 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.432 + $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_LIBRARY).pdb" \ 1.433 + "-map:$$($1_OBJECT_DIR)/$$($1_LIBRARY).map" 1.434 + endif 1.435 + 1.436 + ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR)) 1.437 + $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% 1.438 + $(CP) $$< $$@ 1.439 + endif 1.440 + 1.441 + ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X 1.442 + ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows 1.443 + ifeq ($(OPENJDK_TARGET_OS), solaris) 1.444 + # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set. 1.445 + # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from 1.446 + # empty section headers until a fixed $(OBJCOPY) is available. 1.447 + # An empty section header has sh_addr == 0 and sh_size == 0. 1.448 + # This problem has only been seen on Solaris X64, but we call this tool 1.449 + # on all Solaris builds just in case. 1.450 + # 1.451 + # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. 1.452 + # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. 1.453 + $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) \ 1.454 + $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) 1.455 + $(RM) $$@ 1.456 + $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$< 1.457 + $(OBJCOPY) --only-keep-debug $$< $$@ 1.458 + $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$< 1.459 + else # not solaris 1.460 + $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo : $$($1_TARGET) 1.461 + $(RM) $$@ 1.462 + $(OBJCOPY) --only-keep-debug $$< $$@ 1.463 + $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< 1.464 + endif # Touch to not retrigger rule on rebuild 1.465 + $(TOUCH) $$@ 1.466 + endif # !windows 1.467 + endif # !macosx 1.468 + 1.469 + ifeq ($(ZIP_DEBUGINFO_FILES), true) 1.470 +ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet 1.471 + $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz 1.472 + 1.473 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.474 + $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) 1.475 + $(CD) $$($1_OBJECT_DIR) \ 1.476 + && $(ZIP) -q $$@ $$($1_LIBRARY).map $$($1_LIBRARY).pdb 1.477 + else 1.478 + $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).diz : $$($1_TARGET) \ 1.479 + $$($1_OBJECT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo 1.480 + $(CD) $$($1_OBJECT_DIR) \ 1.481 + && $(ZIP) -q $$@ $$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo 1.482 + endif 1.483 +endif # no MacOS X support yet 1.484 + else 1.485 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.486 + $1 += $$($1_OUTPUT_DIR)/$$($1_LIBRARY).map \ 1.487 + $$($1_OUTPUT_DIR)/$$($1_LIBRARY).pdb 1.488 + else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files 1.489 + $1 += $$($1_OUTPUT_DIR)/$$(LIBRARY_PREFIX)$$($1_LIBRARY).debuginfo 1.490 + endif 1.491 + endif 1.492 + endif 1.493 + endif 1.494 + 1.495 + $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_REAL_MAPFILE) 1.496 + $$(call LINKING_MSG,$$($1_BASENAME)) 1.497 + $$($1_LD) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(LD_OUT_OPTION)$$@ \ 1.498 + $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \ 1.499 + $$($1_EXTRA_LDFLAGS_SUFFIX) 1.500 + 1.501 + endif 1.502 + 1.503 + ifneq (,$$($1_STATIC_LIBRARY)) 1.504 + # Generating a static library, ie object file archive. 1.505 + $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) 1.506 + $$(call ARCHIVING_MSG,$$($1_LIBRARY)) 1.507 + $(AR) $$($1_ARFLAGS) $(AR_OUT_OPTION)$$($1_TARGET) $$($1_EXPECTED_OBJS) \ 1.508 + $$($1_RES) $$($1_LDFLAGS_SUFFIX) $$($1_EXTRA_LDFLAGS_SUFFIX) 1.509 + endif 1.510 + 1.511 + ifneq (,$$($1_PROGRAM)) 1.512 + # A executable binary has been specified, setup the target for it. 1.513 + ifneq (,$$($1_DEBUG_SYMBOLS)) 1.514 + ifeq ($(ENABLE_DEBUG_SYMBOLS), true) 1.515 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.516 + $1_EXTRA_LDFLAGS+="-pdb:$$($1_OBJECT_DIR)/$$($1_PROGRAM).pdb" \ 1.517 + "-map:$$($1_OBJECT_DIR)/$$($1_PROGRAM).map" 1.518 + endif 1.519 + 1.520 + ifneq ($$($1_OUTPUT_DIR),$$($1_OBJECT_DIR)) 1.521 + $$($1_OUTPUT_DIR)/% : $$($1_OBJECT_DIR)/% 1.522 + $(CP) $$< $$@ 1.523 + endif 1.524 + 1.525 + ifneq ($(OPENJDK_TARGET_OS), macosx) # OBJCOPY is not used on MacOS X 1.526 + ifneq ($(OPENJDK_TARGET_OS), windows) # nor on Windows 1.527 + ifeq ($(OPENJDK_TARGET_OS), solaris) 1.528 + # gobjcopy crashes on "empty" section headers with the SHF_ALLOC flag set. 1.529 + # Use $(FIX_EMPTY_SEC_HDR_FLAGS) to clear the SHF_ALLOC flag (if set) from 1.530 + # empty section headers until a fixed $(OBJCOPY) is available. 1.531 + # An empty section header has sh_addr == 0 and sh_size == 0. 1.532 + # This problem has only been seen on Solaris X64, but we call this tool 1.533 + # on all Solaris builds just in case. 1.534 + # 1.535 + # $(OBJCOPY) --add-gnu-debuglink=... corrupts SUNW_* sections. 1.536 + # Use $(ADD_GNU_DEBUGLINK) until a fixed $(OBJCOPY) is available. 1.537 + $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) \ 1.538 + $(FIX_EMPTY_SEC_HDR_FLAGS) $(ADD_GNU_DEBUGLINK) 1.539 + $(RM) $$@ 1.540 + $(FIX_EMPTY_SEC_HDR_FLAGS) $(LOG_INFO) $$< 1.541 + $(OBJCOPY) --only-keep-debug $$< $$@ 1.542 + $(CD) $$(@D) && $(ADD_GNU_DEBUGLINK) $(LOG_INFO) $$(@F) $$< 1.543 + else # not solaris 1.544 + $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo : $$($1_TARGET) 1.545 + $(RM) $$@ 1.546 + $(OBJCOPY) --only-keep-debug $$< $$@ 1.547 + $(CD) $$(@D) && $(OBJCOPY) --add-gnu-debuglink=$$(@F) $$< 1.548 + endif 1.549 + $(TOUCH) $$@ 1.550 + endif # !windows 1.551 + endif # !macosx 1.552 + 1.553 + ifeq ($(ZIP_DEBUGINFO_FILES), true) 1.554 +ifneq ($(OPENJDK_TARGET_OS), macosx) # no MacOS X support yet 1.555 + $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).diz 1.556 + 1.557 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.558 + $$($1_OBJECT_DIR)/$$($1_PROGRAM).diz : $$($1_TARGET) 1.559 + $(CD) $$($1_OBJECT_DIR) \ 1.560 + && $(ZIP) -q $$@ $$($1_PROGRAM).map $$($1_PROGRAM).pdb 1.561 + else 1.562 + $$($1_OBJECT_DIR)/$$(PROGRAM_PREFIX)$$($1_PROGRAM).diz : $$($1_TARGET) \ 1.563 + $$($1_OBJECT_DIR)/$$($1_PROGRAM).debuginfo 1.564 + $(CD) $$($1_OBJECT_DIR) \ 1.565 + && $(ZIP) -q $$@ $$($1_PROGRAM).debuginfo 1.566 + endif 1.567 +endif # no MacOS X support yet 1.568 + else 1.569 + ifeq ($(OPENJDK_TARGET_OS), windows) 1.570 + $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).map \ 1.571 + $$($1_OUTPUT_DIR)/$$($1_PROGRAM).pdb 1.572 + else ifneq ($(OPENJDK_TARGET_OS), macosx) # MacOS X does not use .debuginfo files 1.573 + $1 += $$($1_OUTPUT_DIR)/$$($1_PROGRAM).debuginfo 1.574 + endif 1.575 + endif 1.576 + endif 1.577 + endif 1.578 + 1.579 + $1_EXTRA_LDFLAGS_SUFFIX += $(GLOBAL_LDFLAGS_SUFFIX) 1.580 + 1.581 + $$($1_TARGET) : $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_GEN_MANIFEST) 1.582 + $$(call LINKING_EXE_MSG,$$($1_BASENAME)) 1.583 + $$($1_LDEXE) $$($1_LDFLAGS) $$($1_EXTRA_LDFLAGS) $(EXE_OUT_OPTION)$$($1_TARGET) \ 1.584 + $$($1_EXPECTED_OBJS) $$($1_RES) $$($1_LDFLAGS_SUFFIX) \ 1.585 + $$($1_EXTRA_LDFLAGS_SUFFIX) 1.586 + ifneq (,$$($1_GEN_MANIFEST)) 1.587 + $(MT) -nologo -manifest $$($1_GEN_MANIFEST) -outputresource:$$@;#1 1.588 + endif 1.589 + # This only works if the openjdk_codesign identity is present on the system. Let 1.590 + # silently fail otherwise. 1.591 + ifneq (,$(CODESIGN)) 1.592 + ifneq (,$$($1_CODESIGN)) 1.593 + $(CODESIGN) -s openjdk_codesign $$@ 1.594 + endif 1.595 + endif 1.596 + endif 1.597 +endef