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 Windows builds.  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 # Get shared JDK settings
  35 include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
  36 
  37 # CC compiler object code output directive flag value
  38 CC_OBJECT_OUTPUT_FLAG = -Fo
  39 
  40 # The suffix applied to the library name for FDLIBM
  41 FDDLIBM_SUFFIX = lib
  42 # The suffix applied to scripts (.bat for windows, nothing for unix)
  43 SCRIPT_SUFFIX = .bat
  44 
  45 # LIB_LOCATION, which for windows identifies where .exe files go, may be
  46 # set by each GNUmakefile. The default is BINDIR.
  47 ifndef LIB_LOCATION
  48   LIB_LOCATION = $(BINDIR)
  49 endif # LIB_LOCATION
  50 
  51 ifndef PLATFORM_SRC
  52   PLATFORM_SRC  = $(BUILDDIR)/../src/windows
  53 endif # PLATFORM_SRC
  54 
  55 # Platform specific closed sources
  56 ifndef OPENJDK
  57   ifndef CLOSED_PLATFORM_SRC
  58     CLOSED_PLATFORM_SRC  = $(BUILDDIR)/../src/closed/windows
  59   endif
  60 endif
  61 
  62 # for backwards compatability, the old "win32" is used here instead of 
  63 # the more proper "windows"
  64 PLATFORM_INCLUDE_NAME = win32
  65 PLATFORM_INCLUDE      = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME)
  66 
  67 # The following DLL's are considered MS runtime libraries and should
  68 #     not to be REBASEd, see deploy/make/common/Release.gmk.
  69 #     msvcr*.dll: Microsoft runtimes
  70 ifeq ($(COMPILER_VERSION), VS2010)
  71   MSVCRNN_DLL = msvcr100.dll
  72   MSVCPNN_DLL = msvcp100.dll
  73   MS_RUNTIME_LIBRARIES = $(MSVCRNN_DLL)
  74 endif
  75 
  76 EXTRA_LFLAGS += /LIBPATH:$(DXSDK_LIB_PATH)
  77 
  78 # Full Debug Symbols has been enabled on Windows since JDK1.4.1.
  79 # The Full Debug Symbols (FDS) default for VARIANT == OPT builds is
  80 # enabled with debug info files ZIP'ed to save space. For VARIANT !=
  81 # OPT builds, FDS is always enabled, after all a debug build without
  82 # debug info isn't very useful. The ZIP_DEBUGINFO_FILES option only has
  83 # meaning when FDS is enabled.
  84 #
  85 # If you invoke a build with FULL_DEBUG_SYMBOLS=0, then FDS will be
  86 # disabled for a VARIANT == OPT build.
  87 #
  88 # Note: Use of a different variable name for the FDS override option
  89 # versus the FDS enabled check is intentional (FULL_DEBUG_SYMBOLS
  90 # versus ENABLE_FULL_DEBUG_SYMBOLS). For auto build systems that pass
  91 # in options via environment variables, use of distinct variables
  92 # prevents strange behaviours. For example, in a VARIANT != OPT build,
  93 # the FULL_DEBUG_SYMBOLS environment variable will be 0, but the
  94 # ENABLE_FULL_DEBUG_SYMBOLS make variable will be 1. If the same
  95 # variable name is used, then different values can be picked up by
  96 # different parts of the build. Just to be clear, we only need two
  97 # variable names because the incoming option value can be overridden
  98 # in some situations, e.g., a VARIANT != OPT build.
  99 
 100 ifeq ($(VARIANT), OPT)
 101   FULL_DEBUG_SYMBOLS ?= 1
 102   ENABLE_FULL_DEBUG_SYMBOLS = $(FULL_DEBUG_SYMBOLS)
 103 else
 104   # debug variants always get Full Debug Symbols (if available)
 105   ENABLE_FULL_DEBUG_SYMBOLS = 1
 106 endif
 107 _JUNK_ := $(shell \
 108   echo >&2 "INFO: ENABLE_FULL_DEBUG_SYMBOLS=$(ENABLE_FULL_DEBUG_SYMBOLS)")
 109 
 110 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 111   ZIP_DEBUGINFO_FILES ?= 1
 112 else
 113   ZIP_DEBUGINFO_FILES=0
 114 endif
 115 _JUNK_ := $(shell echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)")
 116 
 117 # C Compiler flag definitions
 118 
 119 #
 120 # Default optimization
 121 #
 122 
 123 ifndef OPTIMIZATION_LEVEL
 124   ifeq ($(PRODUCT), java)
 125     OPTIMIZATION_LEVEL = HIGHER
 126   else
 127     OPTIMIZATION_LEVEL = LOWER
 128   endif
 129 endif
 130 ifndef FASTDEBUG_OPTIMIZATION_LEVEL
 131   FASTDEBUG_OPTIMIZATION_LEVEL = LOWER
 132 endif
 133 
 134 ifeq ($(CC_VERSION),msvc)
 135   # Visual Studio compiler option definitions:
 136   #   -O1      Favors reduced size over speed (-Og     -Os -Oy -Ob2 -Gs -GF -Gy)
 137   #   -O2      Favors speed over reduced size (-Og -Oi -Ot -Oy -Ob2 -Gs -GF -Gy)
 138   #   -Ob2     More aggressive inlining
 139   #   -Og      Global optimizations
 140   #   -Oi      Replace some functions with intrinsic or special forms
 141   #   -fp:precise (should be the default)
 142   #            Improve floating point calculations (disables some optimizations)
 143   #   -Os      Favor small code
 144   #   -Ot      Favor faster code
 145   #   -Oy      Frame pointer omission
 146   #   -G6      Used to be -GB?
 147   #   -GF      Pool strings in read-only memory
 148   #   -Gf      Pool strings in read-write memory (the default)
 149   #   -Gs      Controls stack probess
 150   #   -GS      Adds buffer overflow checks on stacks (the default)
 151   #   -EHsc    Enables exception handling 
 152   #   -Gy      Function level linking only
 153   #
 154 
 155   CC_OPT/NONE    = -Od
 156   CC_OPT/LOWER   = -O2
 157   CC_OPT/HIGHER  = -O3
 158   CC_OPT/HIGHEST = -O3
 159   
 160   ifeq ($(COMPILER_VERSION), VS2010)
 161     # Automatic precompiled header option to use (if COMPILE_APPROACH=batch)
 162     AUTOMATIC_PCH_OPTION =
 163     GX_OPTION = -EHsc
 164     GZ_OPTION = -RTC1
 165     ifeq ($(ARCH_DATA_MODEL), 32)
 166       CC_OPT/HIGHEST = -O2
 167       CC_OPT/HIGHER  = -O1
 168       CC_OPT/LOWER   = -O1
 169     else
 170       CC_OPT/HIGHEST = -O2
 171       CC_OPT/HIGHER  = -O1
 172       CC_OPT/LOWER   = -O1
 173     endif
 174   endif
 175 
 176 else # CC_VERSION
 177   # GCC not supported, but left for historical reference...
 178   CC_OPT/NONE     =
 179   CC_OPT/LOWER    = -O2
 180   CC_OPT/HIGHER   = -O2
 181   CC_OPT/HIGHEST  = -O3
 182 
 183 endif
 184 
 185 CC_OPT = $(CC_OPT/$(OPTIMIZATION_LEVEL))
 186 
 187 # Select the runtime support library carefully, need to be consistent
 188 #
 189 # Visual Studio Runtime compiler option definitions:
 190 #   -MD        Use dynamic multi-threaded runtime library
 191 #   -MDd       Use debug version (don't use, doesn't mix with -MD DLL's)
 192 #   -MT        Use static multi-threaded runtime library (-ML is going away)
 193 #   -MTd       Use static debug version (better than -MDd, no runtime issues)
 194 #   -D_DEBUG   Change use of malloc/free/etc to use special debug ones (-MTd)
 195 #
 196 #      NOTE: We also will use /D _STATIC_CPPLIB  so we don't need msvcpnn.dll
 197 #
 198 # If MS_RUNTIME_STATIC is requested we may have a problem, it is no longer
 199 #     supported by VS2010
 200 ifneq ($(MS_RUNTIME_STATIC),true)
 201   MS_RUNTIME_OPTION=-MD
 202 endif
 203 # The _DEBUG macro option (changes things like malloc to use debug version)
 204 MS_RUNTIME_DEBUG_OPTION=
 205 MS_RC_DEBUG_OPTION=
 206 # Externally set environment variable can force any build to use the debug vers
 207 ifeq ($(MFC_DEBUG), true)
 208   ifeq ($(MS_RUNTIME_STATIC),true)
 209     MS_RUNTIME_OPTION=-MTd
 210   else
 211     # This MS debugging flag forces a dependence on the debug
 212     #     version of the runtime library (MSVCR*D.DLL), as does -MDd.
 213     #     We cannot re-distribute this debug runtime.
 214     MS_RUNTIME_OPTION=-MDd
 215   endif
 216   MS_RUNTIME_DEBUG_OPTION= -D_DEBUG
 217   MS_RC_DEBUG_OPTION= -d _DEBUG
 218 endif
 219 
 220 # Always add _STATIC_CPPLIB definition
 221 STATIC_CPPLIB_OPTION = /D _STATIC_CPPLIB
 222 
 223 # Silence the warning about using _STATIC_CPPLIB
 224 ifneq ($(SHOW_ALL_WARNINGS),true)
 225   # Needed with VS2010 to turn off the deprecated warning.
 226   STATIC_CPPLIB_OPTION += /D _DISABLE_DEPRECATE_STATIC_CPPLIB
 227 endif
 228 
 229 MS_RUNTIME_OPTION += $(STATIC_CPPLIB_OPTION)
 230 
 231 ifeq ($(CC_VERSION),msvc)
 232   # Visual Studio compiler option definitions:
 233   #   -Zi      Cause *.pdb file to be created, full debug information
 234   #   -Z7      Full debug inside the .obj, no .pdb
 235   #   -Zd      Basic debug, no local variables? In the .obj
 236   #   -Zl      Don't add runtime library name to obj file?
 237   #   -Od      Turns off optimization and speeds compilation
 238   #   -YX -Fp/.../foobar.pch   Use precompiled headers (try someday?)
 239   #   -nologo  Don't print out startup message
 240   #   /D _STATIC_CPPLIB
 241   #            Use static link for the C++ runtime (so msvcpnn.dll not needed)
 242   #   
 243   ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 244     CFLAGS_COMMON  += -Zi
 245   endif
 246   CFLAGS_COMMON  += -nologo
 247   CFLAGS_OPT      = $(CC_OPT)
 248   CFLAGS_DBG      = -Od $(MS_RUNTIME_DEBUG_OPTION)
 249 
 250   CFLAGS_VS2010 += -Zc:wchar_t-
 251 
 252   # All builds get the same runtime setting
 253   CFLAGS_COMMON += $(MS_RUNTIME_OPTION) $(CFLAGS_$(COMPILER_VERSION))
 254 
 255   ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 256     LDEBUG = /debug
 257   endif
 258   
 259   ifeq ($(VTUNE_SUPPORT), true)
 260     OTHER_CFLAGS = -Z7 -Ox 
 261     LDEBUG += /pdb:NONE
 262   endif
 263   
 264   # VS2010, always need safe exception handlers, not needed on 64bit
 265   ifeq ($(ARCH_DATA_MODEL), 32)
 266     LFLAGS_VS2010 +=  -SAFESEH
 267   endif
 268 
 269   # LFLAGS are the flags given to $(LINK) and used to build the actual DLL file
 270   BASELFLAGS = -nologo /opt:REF /incremental:no
 271 
 272   LFLAGS = $(BASELFLAGS) $(LDEBUG) $(EXTRA_LFLAGS) $(LFLAGS_$(COMPILER_VERSION))
 273   LDDFLAGS += $(LFLAGS_$(COMPILER_VERSION))
 274   
 275 endif
 276 
 277 #
 278 # Preprocessor macro definitions
 279 #
 280 CPPFLAGS_COMMON = -DWIN32 -DIAL -D_LITTLE_ENDIAN
 281 ifeq ($(ARCH), amd64)
 282   CPPFLAGS_COMMON += -D_AMD64_ -Damd64
 283 else
 284   CPPFLAGS_COMMON += -D_X86_ -Dx86 
 285 endif
 286 CPPFLAGS_COMMON += -DWIN32_LEAN_AND_MEAN
 287 
 288 #
 289 # Output options (use specific filenames to avoid parallel compile errors)
 290 #
 291 ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1)
 292   CFLAGS_COMMON += -Fd$(OBJDIR)/$(basename $(@F)).pdb -Fm$(OBJDIR)/$(basename $(@F)).map
 293 endif
 294 
 295 #
 296 # Use -wdNNNN to disable warning NNNN.
 297 #   C4800 is a warning about bool performance casts (can't make go away)
 298 #
 299 COMPILER_WARNINGS_TO_IGNORE = 4800
 300 CFLAGS_COMMON += $(COMPILER_WARNINGS_TO_IGNORE:%=-wd%)
 301 
 302 #
 303 # Treat compiler warnings as errors, if requested
 304 #
 305 CFLAGS_COMMON += -W$(COMPILER_WARNING_LEVEL)
 306 ifeq ($(COMPILER_WARNINGS_FATAL),true)
 307   CFLAGS_COMMON += -WX
 308 endif
 309 
 310 # Turn off some warnings by default, enable them all if asked.
 311 ifneq ($(SHOW_ALL_WARNINGS),true)
 312   # The -D _CRT_SECURE_NO_DEPRECATE turns off security/deprecated warnings on
 313   #    the standard C library functions like strcpy.
 314   CFLAGS_COMMON += -D _CRT_SECURE_NO_DEPRECATE
 315   # The -D _CRT_NONSTDC_NO_DEPRECATE turns off deprecation warnings about using
 316   #    non-standard C POSIX functions.
 317   CFLAGS_COMMON += -D _CRT_NONSTDC_NO_DEPRECATE
 318 endif
 319 
 320 CPPFLAGS_OPT    = -DNDEBUG
 321 CPPFLAGS_DBG    = -DDEBUG -DLOGGING
 322 
 323 CXXFLAGS_COMMON = $(CFLAGS_COMMON)
 324 CXXFLAGS_OPT    = $(CFLAGS_OPT)
 325 CXXFLAGS_DBG    = $(CFLAGS_DBG)
 326 
 327 ifneq ($(LIBRARY),fdlibm)
 328   EXTRA_LIBS += advapi32.lib
 329 endif
 330 
 331 #
 332 # Path and option to link against the VM, if you have to. 
 333 #
 334 JVMLIB = $(LIBDIR)/jvm.lib
 335 JAVALIB = $(LIBDIR)/java.lib
 336 
 337 ifeq ($(CC_VERSION), msvc)
 338   CC_DEPEND        = -FD
 339   CC_DEPEND_FILTER = 
 340 else # CC_VERSION
 341 # not supported, but left for historical reference...
 342   CC_DEPEND        = -MM
 343   CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)&!g'
 344 endif # CC_VERSION
 345 
 346 LIBRARY_SUFFIX = dll
 347 LIB_SUFFIX     = lib
 348 
 349 # Settings for the JDI - Serviceability Agent binding.
 350 HOTSPOT_SALIB_PATH   = $(HOTSPOT_IMPORT_PATH)/jre/bin
 351 SALIB_NAME = $(LIB_PREFIX)sawindbg.$(LIBRARY_SUFFIX)
 352 SAMAP_NAME = $(LIB_PREFIX)sawindbg.map
 353 SAPDB_NAME = $(LIB_PREFIX)sawindbg.pdb
 354 SA_DIZ_NAME = $(LIB_PREFIX)sawindbg.diz
 355 
 356 ifeq ($(ARCH), ia64)
 357   # SA will never be supported here.
 358   INCLUDE_SA = false
 359 else
 360   INCLUDE_SA = true
 361 endif
 362 
 363 # Settings for the VERSIONINFO tap on windows. 
 364 VERSIONINFO_RESOURCE = $(BUILDDIR)/../src/windows/resource/version.rc
 365 
 366 ifneq ($(JDK_BUILD_NUMBER),)
 367  COOKED_BUILD_NUMBER = $(shell $(ECHO) $(JDK_BUILD_NUMBER) | $(SED) -e 's/^b//' -e 's/^0//')
 368 else
 369  COOKED_BUILD_NUMBER = 0
 370 endif
 371 
 372 # If the update version contains non-numeric characters, we need
 373 # to massage it into a numeric format. 
 374 # We use the following formula:
 375 # JDK_UPDATE_VER = JDK_UPDATE_VERSION * 10 + EXCEPTION_VERSION
 376 #
 377 # Here are some examples:
 378 #     1.5.0    b01  ->  5,0,0,1
 379 #     1.5.0_10 b01  ->  5,0,100,1
 380 #     1.4.2 b01     ->  4,2,0,1
 381 #     1.4.2_02 b01  ->  4,2,20,1
 382 #     1.4.2_02a b01 ->  4,2,21,1
 383 #     1.4.2_02b b01 ->  4,2,22,1
 384 ifdef JDK_UPDATE_VERSION
 385   VTMP := $(shell $(ECHO) $(JDK_UPDATE_VERSION) | $(TR) "abcde" "12345")
 386   CAB_CHAR1 := $(shell $(ECHO) $(VTMP) | $(NAWK) '{print substr($$1, 1, 1);}')
 387   CAB_CHAR2 := $(shell $(ECHO) $(VTMP) | $(NAWK) '{print substr($$1, 2, 1);}')
 388   CAB_CHAR3 := $(shell $(ECHO) $(VTMP) | $(NAWK) '{print substr($$1, 3, 1);}')
 389   JDK_UPDATE_META_TAG := U$(MARKETING_NUMBER)
 390   ifeq ($(CAB_CHAR3),)
 391     CAB_CHAR3 := 0
 392   endif
 393   ifeq ($(CAB_CHAR1), 0)
 394     JDK_UPDATE_VER := $(CAB_CHAR2)$(CAB_CHAR3)
 395   else
 396     JDK_UPDATE_VER := $(CAB_CHAR1)$(CAB_CHAR2)$(CAB_CHAR3)
 397   endif
 398 else
 399   JDK_UPDATE_VER := 0
 400 endif
 401 
 402 RC_FLAGS = /l 0x409 /r
 403 
 404 ifeq ($(VARIANT), OPT)
 405   RC_FLAGS += -d NDEBUG 
 406 else
 407   RC_FLAGS += $(MS_RC_DEBUG_OPTION)
 408 endif 
 409 
 410 # Values for the RC variables defined in RC_FLAGS
 411 JDK_RC_BUILD_ID = $(FULL_VERSION)
 412 JDK_RC_COMPANY = $(COMPANY_NAME)
 413 JDK_RC_COMPONENT = $(PRODUCT_NAME) $(JDK_RC_PLATFORM_NAME) binary
 414 JDK_RC_VER = \
 415     $(JDK_MINOR_VERSION).$(JDK_MICRO_VERSION).$(JDK_UPDATE_VER).$(COOKED_BUILD_NUMBER)
 416 JDK_RC_COPYRIGHT = Copyright \xA9 $(COPYRIGHT_YEAR)
 417 JDK_RC_NAME = \
 418     $(PRODUCT_NAME) $(JDK_RC_PLATFORM_NAME) $(JDK_MINOR_VERSION) $(JDK_UPDATE_META_TAG)
 419 JDK_RC_FVER = \
 420     $(JDK_MINOR_VERSION),$(JDK_MICRO_VERSION),$(JDK_UPDATE_VER),$(COOKED_BUILD_NUMBER)
 421 
 422 # JDK name required here
 423 RC_FLAGS += -d "JDK_BUILD_ID=$(JDK_RC_BUILD_ID)" \
 424             -d "JDK_COMPANY=$(JDK_RC_COMPANY)" \
 425             -d "JDK_COMPONENT=$(JDK_RC_COMPONENT)" \
 426             -d "JDK_VER=$(JDK_RC_VER)" \
 427             -d "JDK_COPYRIGHT=$(JDK_RC_COPYRIGHT)" \
 428             -d "JDK_NAME=$(JDK_RC_NAME)" \
 429             -d "JDK_FVER=$(JDK_RC_FVER)"
 430 
 431 # Enable 7-Zip LZMA file (de)compression for Java Kernel if it is available
 432 ifeq ($(ARCH_DATA_MODEL), 32)
 433   ifneq ($(KERNEL), off)
 434     # This is a hack to use until  7-Zip (and UPX) bundles can be put
 435     # under /java/devtools.
 436     ifndef DEPLOY_TOPDIR
 437       DEPLOY_TOPDIR=$(JDK_TOPDIR)/../deploy
 438     endif
 439     # Uncomment this block to cause build failure if above assumption false
 440     #DCHK = $(shell if [ ! -d $(DEPLOY_TOPDIR) ] ; then \
 441     #  $(ECHO) deploy_not_a_peer_of_j2se ; \
 442     #fi )
 443     #ifeq ($(DCHK), deploy_not_a_peer_of_j2se)
 444     #  If a build failure points to control coming here it means
 445     #  it means deploy is not in the same directory
 446     #  as j2se. Java Kernel can't tolerate that for the time being.
 447     #endif
 448     EC_TMP = $(shell if [ -d $(DEPLOY_TOPDIR)/make/lzma ] ; then \
 449       $(ECHO) true ; \
 450     else \
 451       $(ECHO) false ; \
 452     fi )
 453     ifeq ($(EC_TMP), true)
 454       EXTRA_COMP_INSTALL_PATH = lib\\\\deploy\\\\lzma.dll
 455       # Crazy but true: deploy/make/plugin/jinstall/Makefile.jkernel does
 456       # not include deploy/make/common/Defs-windows.gmk, either directly
 457       # or indirectly. But it does include this file, so redundantly declare
 458       # these variables that are in deploy/make/common/Defs-windows.gmk for
 459       # the sake of the Java Kernel part of the deploy build. Whew!
 460       EXTRA_COMP_LIB_NAME = lzma.dll
 461       EXTRA_COMP_PATH = $(OUTPUTDIR)/tmp/deploy/lzma/win32/obj
 462       EXTRA_COMP_CMD_PATH = $(EXTRA_COMP_PATH)/lzma.exe
 463       EXTRA_COMP_LIB_PATH = $(EXTRA_COMP_PATH)/$(EXTRA_COMP_LIB_NAME)
 464     endif
 465   endif
 466 endif