1 # 2 # Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. 3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 # 5 # This code is free software; you can redistribute it and/or modify it 6 # under the terms of the GNU General Public License version 2 only, as 7 # published by the Free Software Foundation. Oracle designates this 8 # particular file as subject to the "Classpath" exception as provided 9 # by Oracle in the LICENSE file that accompanied this code. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # 27 # Makefile to specify compiler flags for programs and libraries 28 # targeted to Linux. Should not contain any rules. 29 # 30 # WARNING: This file is shared with other workspaces. 31 # So when it includes other files, it must use JDK_TOPDIR. 32 # 33 34 # Warning: the following variables are overriden by Defs.gmk. Set 35 # values will be silently ignored: 36 # CFLAGS (set $(OTHER_CFLAGS) instead) 37 # CPPFLAGS (set $(OTHER_CPPFLAGS) instead) 38 # CXXFLAGS (set $(OTHER_CXXFLAGS) instead) 39 # LDFLAGS (set $(OTHER_LDFAGS) instead) 40 # LDLIBS (set $(EXTRA_LIBS) instead) 41 # LDLIBS_COMMON (set $(EXTRA_LIBS) instead) 42 43 # Get shared JDK settings 44 include $(JDK_MAKE_SHARED_DIR)/Defs.gmk 45 46 # Part of INCREMENTAL_BUILD mechanism. 47 # Compiler emits things like: path/file.o: file.h 48 # We want something like: relative_path/file.o relative_path/file.d: file.h 49 CC_DEPEND = -MM 50 CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g' 51 52 ifndef PLATFORM_SRC 53 PLATFORM_SRC = $(BUILDDIR)/../src/solaris 54 endif # PLATFORM_SRC 55 56 # Location of the various .properties files specific to Linux platform 57 ifndef PLATFORM_PROPERTIES 58 PLATFORM_PROPERTIES = $(BUILDDIR)/../src/solaris/lib 59 endif # PLATFORM_SRC 60 61 # Platform specific closed sources 62 ifndef OPENJDK 63 ifndef CLOSED_PLATFORM_SRC 64 CLOSED_PLATFORM_SRC = $(BUILDDIR)/../src/closed/solaris 65 endif 66 endif 67 68 # platform specific include files 69 PLATFORM_INCLUDE_NAME = $(PLATFORM) 70 PLATFORM_INCLUDE = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME) 71 72 # suffix used for make dependencies files. 73 DEPEND_SUFFIX = d 74 # The suffix applied to the library name for FDLIBM 75 FDDLIBM_SUFFIX = a 76 # The suffix applied to scripts (.bat for windows, nothing for unix) 77 SCRIPT_SUFFIX = 78 # CC compiler object code output directive flag value 79 CC_OBJECT_OUTPUT_FLAG = -o #trailing blank required! 80 81 # The Full Debug Symbols (FDS) default for VARIANT == OPT builds is 82 # enabled with debug info files ZIP'ed to save space. For VARIANT != 83 # OPT builds, FDS is always enabled, after all a debug build without 84 # debug info isn't very useful. The ZIP_DEBUGINFO_FILES option only has 85 # meaning when FDS is enabled. 86 # 87 # If you invoke a build with FULL_DEBUG_SYMBOLS=0, then FDS will be 88 # disabled for a VARIANT == OPT build. 89 # 90 # Note: Use of a different variable name for the FDS override option 91 # versus the FDS enabled check is intentional (FULL_DEBUG_SYMBOLS 92 # versus ENABLE_FULL_DEBUG_SYMBOLS). For auto build systems that pass 93 # in options via environment variables, use of distinct variables 94 # prevents strange behaviours. For example, in a VARIANT != OPT build, 95 # the FULL_DEBUG_SYMBOLS environment variable will be 0, but the 96 # ENABLE_FULL_DEBUG_SYMBOLS make variable will be 1. If the same 97 # variable name is used, then different values can be picked up by 98 # different parts of the build. Just to be clear, we only need two 99 # variable names because the incoming option value can be overridden 100 # in some situations, e.g., a VARIANT != OPT build. 101 102 ifeq ($(VARIANT), OPT) 103 FULL_DEBUG_SYMBOLS ?= 1 104 ENABLE_FULL_DEBUG_SYMBOLS = $(FULL_DEBUG_SYMBOLS) 105 else 106 # debug variants always get Full Debug Symbols (if available) 107 ENABLE_FULL_DEBUG_SYMBOLS = 1 108 endif 109 _JUNK_ := $(shell \ 110 echo >&2 "INFO: ENABLE_FULL_DEBUG_SYMBOLS=$(ENABLE_FULL_DEBUG_SYMBOLS)") 111 # since objcopy is optional, we set ZIP_DEBUGINFO_FILES later 112 113 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 114 ifndef CROSS_COMPILE_ARCH 115 # Default OBJCOPY comes from GNU Binutils on Linux: 116 DEF_OBJCOPY=/usr/bin/objcopy 117 else 118 # Assume objcopy is part of the cross-compilation toolkit 119 DEF_OBJCOPY=$(COMPILER_PATH)/objcopy 120 endif 121 OBJCOPY=$(shell test -x $(DEF_OBJCOPY) && echo $(DEF_OBJCOPY)) 122 ifneq ($(ALT_OBJCOPY),) 123 _JUNK_ := $(shell echo >&2 "INFO: ALT_OBJCOPY=$(ALT_OBJCOPY)") 124 # disable .debuginfo support by setting ALT_OBJCOPY to a non-existent path 125 OBJCOPY=$(shell test -x $(ALT_OBJCOPY) && echo $(ALT_OBJCOPY)) 126 endif 127 128 # Setting ENABLE_FULL_DEBUG_SYMBOLS=1 (and OBJCOPY) above enables the 129 # JDK build to import .debuginfo or .diz files from the HotSpot build. 130 # However, adding FDS support to the JDK build will occur in phases 131 # so a different make variable (LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS 132 # and PROGRAM_SUPPORTS_FULL_DEBUG_SYMBOLS) is used to indicate that a 133 # particular library or program supports FDS. 134 135 ifeq ($(OBJCOPY),) 136 _JUNK_ := $(shell \ 137 echo >&2 "INFO: no objcopy cmd found so cannot create .debuginfo files. You may need to set ALT_OBJCOPY.") 138 ENABLE_FULL_DEBUG_SYMBOLS=0 139 else 140 _JUNK_ := $(shell \ 141 echo >&2 "INFO: $(OBJCOPY) cmd found so will create .debuginfo files.") 142 143 # Library stripping policies for .debuginfo configs: 144 # all_strip - strips everything from the library 145 # min_strip - strips most stuff from the library; leaves minimum symbols 146 # no_strip - does not strip the library at all 147 # 148 # Oracle security policy requires "all_strip". A waiver was granted on 149 # 2011.09.01 that permits using "min_strip" in the Java JDK and Java JRE. 150 # 151 # Currently, STRIP_POLICY is only used when Full Debug Symbols is enabled. 152 STRIP_POLICY ?= min_strip 153 154 _JUNK_ := $(shell \ 155 echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)") 156 157 ZIP_DEBUGINFO_FILES ?= 1 158 159 _JUNK_ := $(shell \ 160 echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)") 161 endif 162 endif 163 164 # 165 # Default optimization 166 # 167 168 ifndef OPTIMIZATION_LEVEL 169 ifeq ($(PRODUCT), java) 170 OPTIMIZATION_LEVEL = HIGHER 171 else 172 OPTIMIZATION_LEVEL = LOWER 173 endif 174 endif 175 ifndef FASTDEBUG_OPTIMIZATION_LEVEL 176 FASTDEBUG_OPTIMIZATION_LEVEL = LOWER 177 endif 178 179 CC_OPT/NONE = 180 CC_OPT/LOWER = -O2 181 CC_OPT/HIGHER = -O3 182 CC_OPT/HIGHEST = -O3 183 184 CC_OPT = $(CC_OPT/$(OPTIMIZATION_LEVEL)) 185 186 # For all platforms, do not omit the frame pointer register usage. 187 # We need this frame pointer to make it easy to walk the stacks. 188 # This should be the default on X86, but ia64 and amd64 may not have this 189 # as the default. 190 CFLAGS_REQUIRED_amd64 += -fno-omit-frame-pointer -D_LITTLE_ENDIAN 191 CFLAGS_REQUIRED_i586 += -fno-omit-frame-pointer -D_LITTLE_ENDIAN 192 CFLAGS_REQUIRED_ia64 += -fno-omit-frame-pointer -D_LITTLE_ENDIAN 193 CFLAGS_REQUIRED_sparcv9 += -m64 -mcpu=v9 194 LDFLAGS_COMMON_sparcv9 += -m64 -mcpu=v9 195 CFLAGS_REQUIRED_sparc += -m32 -mcpu=v9 196 LDFLAGS_COMMON_sparc += -m32 -mcpu=v9 197 CFLAGS_REQUIRED_arm += -fsigned-char -D_LITTLE_ENDIAN 198 CFLAGS_REQUIRED_ppc += -fsigned-char -D_BIG_ENDIAN 199 ifeq ($(ZERO_BUILD), true) 200 CFLAGS_REQUIRED = $(ZERO_ARCHFLAG) 201 ifeq ($(ZERO_ENDIANNESS), little) 202 CFLAGS_REQUIRED += -D_LITTLE_ENDIAN 203 endif 204 LDFLAGS_COMMON += $(ZERO_ARCHFLAG) 205 else 206 CFLAGS_REQUIRED = $(CFLAGS_REQUIRED_$(ARCH)) 207 LDFLAGS_COMMON += $(LDFLAGS_COMMON_$(ARCH)) 208 endif 209 210 # If this is a --hash-style=gnu system, use --hash-style=both 211 # The gnu .hash section won't work on some Linux systems like SuSE 10. 212 _HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | $(GREP) -- '--hash-style=gnu') 213 ifneq ($(_HAS_HASH_STYLE_GNU),) 214 LDFLAGS_HASH_STYLE = -Wl,--hash-style=both 215 endif 216 LDFLAGS_COMMON += $(LDFLAGS_HASH_STYLE) 217 218 # 219 # Selection of warning messages 220 # 221 GCC_INHIBIT = -Wno-unused -Wno-parentheses 222 GCC_STYLE = 223 GCC_WARNINGS = -W -Wall $(GCC_STYLE) $(GCC_INHIBIT) 224 225 # 226 # Treat compiler warnings as errors, if warnings not allowed 227 # 228 ifeq ($(COMPILER_WARNINGS_FATAL),true) 229 GCC_WARNINGS += -Werror 230 endif 231 232 # 233 # Misc compiler options 234 # 235 ifneq ($(ARCH),ppc) 236 CFLAGS_COMMON = -fno-strict-aliasing 237 endif 238 PIC_CODE_LARGE = -fPIC 239 PIC_CODE_SMALL = -fpic 240 GLOBAL_KPIC = $(PIC_CODE_LARGE) 241 CFLAGS_COMMON += $(GLOBAL_KPIC) $(GCC_WARNINGS) 242 ifeq ($(ARCH), amd64) 243 CFLAGS_COMMON += -pipe 244 endif 245 246 # Linux 64bit machines use Dwarf2, which can be HUGE, have fastdebug use -g1 247 DEBUG_FLAG = -g 248 ifeq ($(FASTDEBUG), true) 249 ifeq ($(ARCH_DATA_MODEL), 64) 250 DEBUG_FLAG = -g1 251 endif 252 endif 253 254 # DEBUG_BINARIES overrides everything, use full -g debug information 255 ifeq ($(DEBUG_BINARIES), true) 256 DEBUG_FLAG = -g 257 CFLAGS_REQUIRED += $(DEBUG_FLAG) 258 endif 259 260 # If Full Debug Symbols is enabled, then we want the same debug and 261 # optimization flags as used by FASTDEBUG. 262 # 263 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) 264 ifeq ($(LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS),1) 265 ifeq ($(VARIANT), OPT) 266 CC_OPT = $(DEBUG_FLAG) $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) 267 endif 268 endif 269 endif 270 271 CFLAGS_OPT = $(CC_OPT) 272 CFLAGS_DBG = $(DEBUG_FLAG) 273 CFLAGS_COMMON += $(CFLAGS_REQUIRED) 274 275 CXXFLAGS_COMMON = $(GLOBAL_KPIC) -DCC_NOEX $(GCC_WARNINGS) 276 CXXFLAGS_OPT = $(CC_OPT) 277 CXXFLAGS_DBG = $(DEBUG_FLAG) 278 CXXFLAGS_COMMON += $(CFLAGS_REQUIRED) 279 280 # FASTDEBUG: Optimize the code in the -g versions, gives us a faster debug java 281 ifeq ($(FASTDEBUG), true) 282 CFLAGS_DBG += $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) 283 CXXFLAGS_DBG += $(CC_OPT/$(FASTDEBUG_OPTIMIZATION_LEVEL)) 284 endif 285 286 CPP_ARCH_FLAGS = -DARCH='"$(ARCH)"' 287 288 # Alpha arch does not like "alpha" defined (potential general arch cleanup issue here) 289 ifneq ($(ARCH),alpha) 290 CPP_ARCH_FLAGS += -D$(ARCH) 291 else 292 CPP_ARCH_FLAGS += -D_$(ARCH)_ 293 endif 294 295 CPPFLAGS_COMMON = $(CPP_ARCH_FLAGS) -DLINUX $(VERSION_DEFINES) \ 296 -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_REENTRANT 297 298 ifeq ($(ARCH_DATA_MODEL), 64) 299 CPPFLAGS_COMMON += -D_LP64=1 300 endif 301 302 CPPFLAGS_OPT = -DNDEBUG 303 CPPFLAGS_DBG = -DDEBUG 304 ifneq ($(PRODUCT), java) 305 CPPFLAGS_DBG += -DLOGGING 306 endif 307 308 ifdef LIBRARY 309 # Libraries need to locate other libraries at runtime, and you can tell 310 # a library where to look by way of the dynamic runpaths (RPATH or RUNPATH) 311 # buried inside the .so. The $ORIGIN says to look relative to where 312 # the library itself is and it can be followed with relative paths from 313 # that. By default we always look in $ORIGIN, optionally we add relative 314 # paths if the Makefile sets LD_RUNPATH_EXTRAS to those relative paths. 315 # On Linux we add a flag -z origin, not sure if this is necessary, but 316 # doesn't seem to hurt. 317 # The environment variable LD_LIBRARY_PATH will over-ride these runpaths. 318 # Try: 'readelf -d lib*.so' to see these settings in a library. 319 # 320 Z_ORIGIN_FLAG/sparc = -Xlinker -z -Xlinker origin 321 Z_ORIGIN_FLAG/i586 = -Xlinker -z -Xlinker origin 322 Z_ORIGIN_FLAG/amd64 = -Xlinker -z -Xlinker origin 323 Z_ORIGIN_FLAG/ia64 = -Xlinker -z -Xlinker origin 324 Z_ORIGIN_FLAG/arm = 325 Z_ORIGIN_FLAG/ppc = 326 Z_ORIGIN_FLAG/zero = -Xlinker -z -Xlinker origin 327 328 LDFLAG_Z_ORIGIN = $(Z_ORIGIN_FLAG/$(ARCH_FAMILY)) 329 330 LDFLAGS_COMMON += $(LDFLAG_Z_ORIGIN) -Xlinker -rpath -Xlinker \$$ORIGIN 331 LDFLAGS_COMMON += $(LD_RUNPATH_EXTRAS:%=$(LDFLAG_Z_ORIGIN) -Xlinker -rpath -Xlinker \$$ORIGIN/%) 332 333 endif 334 335 EXTRA_LIBS += -lc 336 337 LDFLAGS_DEFS_OPTION = -Xlinker -z -Xlinker defs 338 LDFLAGS_COMMON += $(LDFLAGS_DEFS_OPTION) 339 340 # 341 # -L paths for finding and -ljava 342 # 343 LDFLAGS_OPT = -Xlinker -O1 344 LDFLAGS_COMMON += -L$(LIBDIR)/$(LIBARCH) 345 LDFLAGS_COMMON += -Wl,-soname=$(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX) 346 347 # 348 # -static-libgcc is a gcc-3 flag to statically link libgcc, gcc-2.9x always 349 # statically link libgcc but will print a warning with the flag. We don't 350 # want the warning, so check gcc version first. 351 # 352 ifeq ($(CC_MAJORVER),3) 353 OTHER_LDFLAGS += -static-libgcc 354 endif 355 356 # Automatic precompiled header option to use (if COMPILE_APPROACH=batch) 357 # (See Rules.gmk) The gcc 5 compiler might have an option for this? 358 AUTOMATIC_PCH_OPTION = 359 360 # 361 # Post Processing of libraries/executables 362 # 363 ifeq ($(VARIANT), OPT) 364 ifneq ($(NO_STRIP), true) 365 ifneq ($(DEBUG_BINARIES), true) 366 # Debug 'strip -g' leaves local function Elf symbols (better stack 367 # traces) 368 POST_STRIP_PROCESS = $(STRIP) -g 369 endif 370 endif 371 endif 372 373 # 374 # Use: ld $(LD_MAPFILE_FLAG) mapfile *.o 375 # 376 LD_MAPFILE_FLAG = -Xlinker --version-script -Xlinker 377 378 # 379 # Support for Quantify. 380 # 381 ifdef QUANTIFY 382 QUANTIFY_CMD = quantify 383 QUANTIFY_OPTIONS = -cache-dir=/tmp/quantify -always-use-cache-dir=yes 384 LINK_PRE_CMD = $(QUANTIFY_CMD) $(QUANTIFY_OPTIONS) 385 endif 386 387 # 388 # Path and option to link against the VM, if you have to. Note that 389 # there are libraries that link against only -ljava, but they do get 390 # -L to the -ljvm, this is because -ljava depends on -ljvm, whereas 391 # the library itself should not. 392 # 393 VM_NAME = server 394 JVMLIB = -L$(LIBDIR)/$(LIBARCH)/$(VM_NAME) -ljvm 395 JAVALIB = -ljava $(JVMLIB) 396 397 # 398 # We want to privatize JVM symbols on Solaris. This is so the user can 399 # write a function called FindClass and this should not override the 400 # FindClass that is inside the JVM. At this point in time we are not 401 # concerned with other JNI libraries because we hope that there will 402 # not be as many clashes there. 403 # 404 PRIVATIZE_JVM_SYMBOLS = false 405 406 USE_PTHREADS = true 407 override ALT_CODESET_KEY = _NL_CTYPE_CODESET_NAME 408 override AWT_RUNPATH = 409 override HAVE_ALTZONE = false 410 override HAVE_FILIOH = false 411 override HAVE_GETHRTIME = false 412 override HAVE_GETHRVTIME = false 413 override HAVE_SIGIGNORE = true 414 override LEX_LIBRARY = -lfl 415 ifeq ($(STATIC_CXX),true) 416 override LIBCXX = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic 417 else 418 override LIBCXX = -lstdc++ 419 endif 420 override LIBPOSIX4 = 421 override LIBSOCKET = 422 override LIBNSL = 423 override LIBSCF = 424 override LIBTHREAD = 425 override LIBDL = -ldl 426 override MOOT_PRIORITIES = true 427 override NO_INTERRUPTIBLE_IO = true 428 ifeq ($(ARCH), amd64) 429 override OPENWIN_LIB = $(OPENWIN_HOME)/lib64 430 else 431 override OPENWIN_LIB = $(OPENWIN_HOME)/lib 432 endif 433 override OTHER_M4FLAGS = -D__GLIBC__ -DGNU_ASSEMBLER 434 override SUN_CMM_SUBDIR = 435 override THREADS_FLAG = native 436 override USE_GNU_M4 = true 437 override USING_GNU_TAR = true 438 override WRITE_LIBVERSION = false 439 440 # USE_EXECNAME forces the launcher to look up argv[0] on $PATH, and put the 441 # resulting resolved absolute name of the executable in the environment 442 # variable EXECNAME. That executable name is then used that to locate the 443 # installation area. 444 override USE_EXECNAME = true 445 446 # If your platform has DPS, it will have Type1 fonts too, in which case 447 # it is best to enable DPS support until such time as 2D's rasteriser 448 # can fully handle Type1 fonts in all cases. Default is "yes". 449 # HAVE_DPS should only be "no" if the platform has no DPS headers or libs 450 # DPS (Displayable PostScript) is available on Solaris machines 451 HAVE_DPS = no 452 453 # 454 # Japanese manpages 455 # 456 JA_SOURCE_ENCODING = eucJP 457 JA_TARGET_ENCODINGS = UTF-8 458 459 # Settings for the JDI - Serviceability Agent binding. 460 HOTSPOT_SALIB_PATH = $(HOTSPOT_IMPORT_PATH)/jre/lib/$(LIBARCH) 461 SALIB_NAME = $(LIB_PREFIX)saproc.$(LIBRARY_SUFFIX) 462 SA_DEBUGINFO_NAME = $(LIB_PREFIX)saproc.debuginfo 463 SA_DIZ_NAME = $(LIB_PREFIX)saproc.diz 464 465 # The JDI - Serviceability Agent binding is not currently supported 466 # on Linux-ia64. 467 ifeq ($(ARCH), ia64) 468 INCLUDE_SA = false 469 else 470 INCLUDE_SA = true 471 endif 472 473 ifdef CROSS_COMPILE_ARCH 474 # X11 headers are not under /usr/include 475 OTHER_CFLAGS += -I$(OPENWIN_HOME)/include 476 OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include 477 OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include 478 endif