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