WIN32.mk (8586B)
1 # 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 # 7 # Configuration common to all versions of Windows NT 8 # and Windows 95 9 # 10 11 DEFAULT_COMPILER = cl 12 13 ifdef NS_USE_GCC 14 CC = gcc 15 CCC = g++ 16 LD = ld 17 AR = ar 18 AR += cr $@ 19 RANLIB = ranlib 20 BSDECHO = echo 21 RC = windres.exe -O coff --use-temp-file 22 LINK_DLL = $(CC) $(OS_DLLFLAGS) $(DLLFLAGS) 23 else 24 CC = cl 25 CCC = cl 26 LD = link 27 LDFLAGS += -nologo 28 AR = lib 29 AR += -nologo -OUT:$@ 30 RANLIB = echo 31 BSDECHO = echo 32 RC = rc.exe 33 MT = mt.exe 34 # Check for clang-cl 35 CLANG_CL := $(shell expr `$(CC) -? 2>&1 | grep -w clang | wc -l` \> 0) 36 # Determine compiler version 37 ifeq ($(CLANG_CL),1) 38 # clang-cl pretends to be MSVC 2012. 39 CC_VERSION := 17.00.00.00 40 else 41 CC_VERSION := $(shell $(CC) 2>&1 | sed -ne \ 42 's|.* \([0-9]\+\.[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\).*|\1|p') 43 endif 44 # Change the dots to spaces. 45 _CC_VERSION_WORDS := $(subst ., ,$(CC_VERSION)) 46 _CC_VMAJOR := $(word 1,$(_CC_VERSION_WORDS)) 47 _CC_VMINOR := $(word 2,$(_CC_VERSION_WORDS)) 48 _CC_RELEASE := $(word 3,$(_CC_VERSION_WORDS)) 49 _CC_BUILD := $(word 4,$(_CC_VERSION_WORDS)) 50 _MSC_VER = $(_CC_VMAJOR)$(_CC_VMINOR) 51 _MSC_VER_6 = 1200 52 # VC10 (2010) is 16.00.30319.01, VC10SP1 is 16.00.40219.01. 53 _MSC_VER_GE_10SP1 := $(shell expr $(_MSC_VER) \> 1600 \| \ 54 $(_MSC_VER) = 1600 \& $(_CC_RELEASE) \>= 40219) 55 # VC11 (2012). 56 _MSC_VER_GE_11 := $(shell expr $(_MSC_VER) \>= 1700) 57 # VC12 (2013). 58 _MSC_VER_GE_12 := $(shell expr $(_MSC_VER) \>= 1800) 59 # VC14 (2015). 60 _MSC_VER_GE_14 := $(shell expr $(_MSC_VER) \>= 1900) 61 ifeq ($(_CC_VMAJOR),14) 62 # -DYNAMICBASE is only supported on VC8SP1 or newer, 63 # so be very specific here! 64 # VC8 is 14.00.50727.42, VC8SP1 is 14.00.50727.762 65 ifeq ($(_CC_RELEASE).$(_CC_BUILD),50727.42) 66 USE_DYNAMICBASE = 67 else 68 ifeq ($(_CC_RELEASE).$(_CC_BUILD),50727.762) 69 USE_DYNAMICBASE = 1 70 else 71 _LOSER := $(error Unknown compiler version $(CC_VERSION)) 72 endif 73 endif 74 endif 75 # if $(_CC_VMAJOR) >= 15 76 # NOTE: 'sort' sorts the words in lexical order, so this test works 77 # only if $(_CC_VMAJOR) is two digits. 78 ifeq ($(firstword $(sort $(_CC_VMAJOR) 15)),15) 79 USE_DYNAMICBASE = 1 80 endif 81 endif 82 83 ifdef BUILD_TREE 84 NSINSTALL_DIR = $(BUILD_TREE)/nss 85 else 86 NSINSTALL_DIR = $(CORE_DEPTH)/coreconf/nsinstall 87 endif 88 NSINSTALL = nsinstall 89 90 INSTALL = $(NSINSTALL) 91 GARBAGE += $(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb 92 XP_DEFINE += -DXP_PC 93 ifdef NS_USE_GCC 94 LIB_SUFFIX = a 95 else 96 LIB_SUFFIX = lib 97 endif 98 DLL_SUFFIX = dll 99 100 define MAKE_OBJDIR 101 if test ! -d $(@D); then mkdir -p $(@D); fi 102 endef 103 104 ifdef NS_USE_GCC 105 OS_CFLAGS += -mwindows 106 _GEN_IMPORT_LIB=-Wl,--out-implib,$(IMPORT_LIBRARY) 107 DLLFLAGS += -mwindows -o $@ -shared -Wl,--export-all-symbols $(if $(IMPORT_LIBRARY),$(_GEN_IMPORT_LIB)) 108 ifdef BUILD_OPT 109 ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE)) 110 OPTIMIZER += -Os 111 else 112 OPTIMIZER += -O2 113 endif 114 DEFINES += -UDEBUG -DNDEBUG 115 else 116 OPTIMIZER += -g 117 DEFINES += -DDEBUG -UNDEBUG 118 endif 119 else # !NS_USE_GCC 120 WARNING_CFLAGS = -W3 -nologo -D_CRT_SECURE_NO_WARNINGS \ 121 -D_CRT_NONSTDC_NO_WARNINGS 122 OS_DLLFLAGS += -nologo -DLL -SUBSYSTEM:WINDOWS 123 ifndef NSS_ENABLE_WERROR 124 NSS_ENABLE_WERROR = 1 125 endif 126 ifeq ($(NSS_ENABLE_WERROR),1) 127 WARNING_CFLAGS += -WX 128 endif 129 ifeq ($(_MSC_VER),$(_MSC_VER_6)) 130 ifndef MOZ_DEBUG_SYMBOLS 131 OS_DLLFLAGS += -PDB:NONE 132 endif 133 endif 134 ifdef USE_DYNAMICBASE 135 OS_DLLFLAGS += -DYNAMICBASE 136 endif 137 # 138 # Define USE_DEBUG_RTL if you want to use the debug runtime library 139 # (RTL) in the debug build. 140 # Define USE_STATIC_RTL if you want to use the static RTL. 141 # 142 ifdef USE_DEBUG_RTL 143 ifdef USE_STATIC_RTL 144 OS_CFLAGS += -MTd 145 else 146 OS_CFLAGS += -MDd 147 endif 148 OS_CFLAGS += -D_CRTDBG_MAP_ALLOC 149 else 150 ifdef USE_STATIC_RTL 151 OS_CFLAGS += -MT 152 else 153 OS_CFLAGS += -MD 154 endif 155 endif 156 ifdef BUILD_OPT 157 ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE)) 158 OPTIMIZER += -O1 159 else 160 OPTIMIZER += -O2 161 endif 162 DEFINES += -UDEBUG -DNDEBUG 163 DLLFLAGS += -OUT:$@ 164 ifdef MOZ_DEBUG_SYMBOLS 165 ifdef MOZ_DEBUG_FLAGS 166 OPTIMIZER += $(MOZ_DEBUG_FLAGS) -Fd$(OBJDIR)/ 167 else 168 OPTIMIZER += -Zi -Fd$(OBJDIR)/ 169 endif 170 DLLFLAGS += -DEBUG -OPT:REF 171 LDFLAGS += -DEBUG -OPT:REF 172 endif 173 else 174 OPTIMIZER += -Zi -Fd$(OBJDIR)/ -Od 175 NULLSTRING := 176 DEFINES += -DDEBUG -UNDEBUG 177 DLLFLAGS += -DEBUG -OUT:$@ 178 LDFLAGS += -DEBUG 179 ifeq ($(_MSC_VER),$(_MSC_VER_6)) 180 ifndef MOZ_DEBUG_SYMBOLS 181 LDFLAGS += -PDB:NONE 182 endif 183 endif 184 # Purify requires /FIXED:NO when linking EXEs. 185 LDFLAGS += /FIXED:NO 186 # So the linker will find main in the gtestutil library 187 LDFLAGS += -SUBSYSTEM:CONSOLE 188 endif 189 ifneq ($(_MSC_VER),$(_MSC_VER_6)) 190 # NSS has too many of these to fix, downgrade the warning 191 # Disable C4267: conversion from 'size_t' to 'type', possible loss of data 192 # Disable C4244: conversion from 'type1' to 'type2', possible loss of data 193 # Disable C4018: 'expression' : signed/unsigned mismatch 194 # Disable C4312: 'type cast': conversion from 'type1' to 'type2' of greater size 195 OS_CFLAGS += -w44267 -w44244 -w44018 -w44312 196 ifeq ($(_MSC_VER_GE_12),1) 197 OS_CFLAGS += -FS 198 endif 199 endif # !MSVC6 200 endif # NS_USE_GCC 201 202 ifdef USE_64 203 DEFINES += -DWIN64 204 else 205 DEFINES += -DWIN32 206 endif 207 208 ifeq (,$(filter-out x386 x86_64,$(CPU_ARCH))) 209 ifdef USE_64 210 DEFINES += -D_AMD64_ 211 # Use subsystem 5.02 to allow running on Windows XP. 212 ifeq ($(_MSC_VER_GE_11),1) 213 LDFLAGS += -SUBSYSTEM:CONSOLE,5.02 214 endif 215 CPU_ARCH = x86_64 216 else 217 DEFINES += -D_X86_ 218 # VS2012 defaults to -arch:SSE2. Use -arch:IA32 to avoid requiring 219 # SSE2. Clang-cl gets confused by -arch:IA32, so don't add it. 220 # (See https://llvm.org/bugs/show_bug.cgi?id=24335) 221 # Use subsystem 5.01 to allow running on Windows XP. 222 ifeq ($(_MSC_VER_GE_11),1) 223 ifneq ($(CLANG_CL),1) 224 OS_CFLAGS += -arch:IA32 225 endif 226 LDFLAGS += -SUBSYSTEM:CONSOLE,5.01 227 endif 228 CPU_ARCH = x386 229 endif 230 endif 231 ifeq ($(CPU_ARCH), ALPHA) 232 DEFINES += -D_ALPHA_=1 233 endif 234 235 ifdef MAPFILE 236 ifndef NS_USE_GCC 237 DLLFLAGS += -DEF:$(MAPFILE) 238 endif 239 endif 240 # Change PROCESS to put the mapfile in the correct format for this platform 241 PROCESS_MAP_FILE = cp $< $@ 242 243 244 # 245 # The following is NOT needed for the NSPR 2.0 library. 246 # 247 248 DEFINES += -D_WINDOWS 249 250 # override default, which is ASFLAGS = CFLAGS 251 ifdef NS_USE_GCC 252 AS = $(CC) 253 ASFLAGS = $(INCLUDES) 254 else 255 ifdef USE_64 256 AS = ml64.exe 257 ASFLAGS = -nologo -Cp -Sn -Zi $(INCLUDES) 258 else 259 AS = ml.exe 260 ASFLAGS = -nologo -Cp -Sn -Zi -coff -safeseh $(INCLUDES) 261 endif 262 endif 263 264 # clear any CSTD and CXXSTD unless we're using GCC 265 ifndef NS_USE_GCC 266 CSTD = 267 CXXSTD = 268 endif 269 270 # 271 # override the definitions of RELEASE_TREE found in tree.mk 272 # 273 ifndef RELEASE_TREE 274 ifdef BUILD_SHIP 275 ifdef USE_SHIPS 276 RELEASE_TREE = $(NTBUILD_SHIP) 277 else 278 RELEASE_TREE = //redbuild/components 279 endif 280 else 281 RELEASE_TREE = //redbuild/components 282 endif 283 endif 284 285 # 286 # override the definitions of IMPORT_LIB_PREFIX, LIB_PREFIX, and 287 # DLL_PREFIX in prefix.mk 288 # 289 290 ifndef IMPORT_LIB_PREFIX 291 ifdef NS_USE_GCC 292 IMPORT_LIB_PREFIX = lib 293 else 294 IMPORT_LIB_PREFIX = $(NULL) 295 endif 296 endif 297 298 ifndef LIB_PREFIX 299 ifdef NS_USE_GCC 300 LIB_PREFIX = lib 301 else 302 LIB_PREFIX = $(NULL) 303 endif 304 endif 305 306 ifndef DLL_PREFIX 307 DLL_PREFIX = $(NULL) 308 endif 309 310 # 311 # override the definitions of various _SUFFIX symbols in suffix.mk 312 # 313 314 # 315 # Object suffixes 316 # 317 ifndef OBJ_SUFFIX 318 ifdef NS_USE_GCC 319 OBJ_SUFFIX = .o 320 else 321 OBJ_SUFFIX = .obj 322 endif 323 endif 324 325 # 326 # Assembler source suffixes 327 # 328 ifndef ASM_SUFFIX 329 ifdef NS_USE_GCC 330 ASM_SUFFIX = .s 331 else 332 ASM_SUFFIX = .asm 333 endif 334 endif 335 336 # 337 # Library suffixes 338 # 339 340 ifndef IMPORT_LIB_SUFFIX 341 IMPORT_LIB_SUFFIX = .$(LIB_SUFFIX) 342 endif 343 344 ifndef DYNAMIC_LIB_SUFFIX_FOR_LINKING 345 DYNAMIC_LIB_SUFFIX_FOR_LINKING = $(IMPORT_LIB_SUFFIX) 346 endif 347 348 # 349 # Program suffixes 350 # 351 ifndef PROG_SUFFIX 352 PROG_SUFFIX = .exe 353 endif 354 355 # 356 # When the processor is NOT 386-based on Windows NT, override the 357 # value of $(CPU_TAG). For WinNT, 95, 16, not CE. 358 # 359 ifneq ($(CPU_ARCH),x386) 360 CPU_TAG = _$(CPU_ARCH) 361 endif 362 363 # 364 # override the TARGETS defined in ruleset.mk, adding IMPORT_LIBRARY 365 # 366 ifndef TARGETS 367 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY) $(PROGRAM) 368 endif