afece49938aae2c3b871a6b4a55a9e1a7ff71e66
[platform/upstream/nss.git] / coreconf / WIN32.mk
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         LINK         = 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         LINK         = link
27         AR           = lib
28         AR          += -NOLOGO -OUT:$@
29         RANLIB       = echo
30         BSDECHO      = echo
31         RC           = rc.exe
32         MT           = mt.exe
33         # Determine compiler version
34         CC_VERSION  := $(shell $(CC) 2>&1 | sed -ne \
35                 's|.* \([0-9]\+\.[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\).*|\1|p')
36         # Change the dots to spaces.
37         _CC_VERSION_WORDS := $(subst ., ,$(CC_VERSION))
38         _CC_VMAJOR  := $(word 1,$(_CC_VERSION_WORDS))
39         _CC_VMINOR  := $(word 2,$(_CC_VERSION_WORDS))
40         _CC_RELEASE := $(word 3,$(_CC_VERSION_WORDS))
41         _CC_BUILD   := $(word 4,$(_CC_VERSION_WORDS))
42         _MSC_VER     = $(_CC_VMAJOR)$(_CC_VMINOR)
43         _MSC_VER_6   = 1200
44         # VC10 (2010) is 16.00.30319.01, VC10SP1 is 16.00.40219.01.
45         _MSC_VER_GE_10SP1 := $(shell expr $(_MSC_VER) \> 1600 \| \
46                 $(_MSC_VER) = 1600 \& $(_CC_RELEASE) \>= 40219)
47         # VC12 (2013).
48         _MSC_VER_GE_12 := $(shell expr $(_MSC_VER) \>= 1800)
49         ifeq ($(_CC_VMAJOR),14)
50             # -DYNAMICBASE is only supported on VC8SP1 or newer,
51             # so be very specific here!
52             # VC8 is 14.00.50727.42, VC8SP1 is 14.00.50727.762
53             ifeq ($(_CC_RELEASE).$(_CC_BUILD),50727.42)
54                 USE_DYNAMICBASE =
55             else
56             ifeq ($(_CC_RELEASE).$(_CC_BUILD),50727.762)
57                 USE_DYNAMICBASE = 1
58             else
59                 _LOSER := $(error Unknown compiler version $(CC_VERSION))
60             endif
61             endif
62         endif
63         # if $(_CC_VMAJOR) >= 15
64         # NOTE: 'sort' sorts the words in lexical order, so this test works
65         # only if $(_CC_VMAJOR) is two digits.
66         ifeq ($(firstword $(sort $(_CC_VMAJOR) 15)),15)
67             USE_DYNAMICBASE = 1
68         endif
69 endif
70
71 ifdef BUILD_TREE
72 NSINSTALL_DIR  = $(BUILD_TREE)/nss
73 else
74 NSINSTALL_DIR  = $(CORE_DEPTH)/coreconf/nsinstall
75 endif
76 NSINSTALL      = nsinstall
77
78 MKDEPEND_DIR    = $(CORE_DEPTH)/coreconf/mkdepend
79 MKDEPEND        = $(MKDEPEND_DIR)/$(OBJDIR_NAME)/mkdepend.exe
80 # Note: MKDEPENDENCIES __MUST__ be a relative pathname, not absolute.
81 # If it is absolute, gmake will crash unless the named file exists.
82 MKDEPENDENCIES  = $(OBJDIR_NAME)/depend.mk
83
84 INSTALL      = $(NSINSTALL)
85 MAKE_OBJDIR  = mkdir
86 MAKE_OBJDIR += $(OBJDIR)
87 GARBAGE     += $(OBJDIR)/vc20.pdb $(OBJDIR)/vc40.pdb
88 XP_DEFINE   += -DXP_PC
89 ifdef NS_USE_GCC
90 LIB_SUFFIX   = a
91 else
92 LIB_SUFFIX   = lib
93 endif
94 DLL_SUFFIX   = dll
95
96 ifdef NS_USE_GCC
97     # The -mnop-fun-dllimport flag allows us to avoid a drawback of
98     # the dllimport attribute that a pointer to a function marked as
99     # dllimport cannot be used as as a constant address.
100     OS_CFLAGS += -mwindows -mms-bitfields -mnop-fun-dllimport
101     _GEN_IMPORT_LIB=-Wl,--out-implib,$(IMPORT_LIBRARY)
102     DLLFLAGS  += -mwindows -o $@ -shared -Wl,--export-all-symbols $(if $(IMPORT_LIBRARY),$(_GEN_IMPORT_LIB))
103     ifdef BUILD_OPT
104         ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE))
105                 OPTIMIZER += -Os
106         else
107                 OPTIMIZER += -O2
108         endif
109         DEFINES    += -UDEBUG -U_DEBUG -DNDEBUG
110     else
111         OPTIMIZER  += -g
112         NULLSTRING :=
113         SPACE      := $(NULLSTRING) # end of the line
114         USERNAME   := $(subst $(SPACE),_,$(USERNAME))
115         USERNAME   := $(subst -,_,$(USERNAME))
116         DEFINES    += -DDEBUG -D_DEBUG -UNDEBUG -DDEBUG_$(USERNAME)
117     endif
118 else # !NS_USE_GCC
119     OS_CFLAGS += -W3 -nologo -D_CRT_SECURE_NO_WARNINGS \
120                  -D_CRT_NONSTDC_NO_WARNINGS
121     OS_DLLFLAGS += -nologo -DLL -SUBSYSTEM:WINDOWS
122     ifeq ($(_MSC_VER),$(_MSC_VER_6))
123     ifndef MOZ_DEBUG_SYMBOLS
124         OS_DLLFLAGS += -PDB:NONE
125     endif
126     endif
127     ifdef USE_DYNAMICBASE
128         OS_DLLFLAGS += -DYNAMICBASE
129     endif
130     ifdef BUILD_OPT
131         OS_CFLAGS  += -MD
132         ifeq (11,$(ALLOW_OPT_CODE_SIZE)$(OPT_CODE_SIZE))
133                 OPTIMIZER += -O1
134         else
135                 OPTIMIZER += -O2
136         endif
137         DEFINES    += -UDEBUG -U_DEBUG -DNDEBUG
138         DLLFLAGS   += -OUT:$@
139         ifdef MOZ_DEBUG_SYMBOLS
140                 ifdef MOZ_DEBUG_FLAGS
141                         OPTIMIZER += $(MOZ_DEBUG_FLAGS) -Fd$(OBJDIR)/
142                 else
143                         OPTIMIZER += -Zi -Fd$(OBJDIR)/
144                 endif
145                 DLLFLAGS += -DEBUG -OPT:REF
146                 LDFLAGS += -DEBUG -OPT:REF
147         endif
148     else
149         #
150         # Define USE_DEBUG_RTL if you want to use the debug runtime library
151         # (RTL) in the debug build
152         #
153         ifdef USE_DEBUG_RTL
154                 OS_CFLAGS += -MDd -D_CRTDBG_MAP_ALLOC
155         else
156                 OS_CFLAGS += -MD
157         endif
158         OPTIMIZER += -Zi -Fd$(OBJDIR)/ -Od
159         NULLSTRING :=
160         SPACE      := $(NULLSTRING) # end of the line
161         USERNAME   := $(subst $(SPACE),_,$(USERNAME))
162         USERNAME   := $(subst -,_,$(USERNAME))
163         DEFINES    += -DDEBUG -D_DEBUG -UNDEBUG -DDEBUG_$(USERNAME)
164         DLLFLAGS   += -DEBUG -OUT:$@
165         LDFLAGS    += -DEBUG 
166 ifeq ($(_MSC_VER),$(_MSC_VER_6))
167 ifndef MOZ_DEBUG_SYMBOLS
168         LDFLAGS    += -PDB:NONE 
169 endif
170 endif
171         # Purify requires /FIXED:NO when linking EXEs.
172         LDFLAGS    += /FIXED:NO
173     endif
174 ifneq ($(_MSC_VER),$(_MSC_VER_6))
175     # Convert certain deadly warnings to errors (see list at end of file)
176     OS_CFLAGS += -we4002 -we4003 -we4004 -we4006 -we4009 -we4013 \
177      -we4015 -we4028 -we4033 -we4035 -we4045 -we4047 -we4053 -we4054 -we4063 \
178      -we4064 -we4078 -we4087 -we4090 -we4098 -we4390 -we4551 -we4553 -we4715
179
180     ifeq ($(_MSC_VER_GE_12),1)
181         OS_CFLAGS += -FS
182     endif
183 endif # !MSVC6
184 endif # NS_USE_GCC
185
186 ifdef USE_64
187 DEFINES += -DWIN64
188 else
189 DEFINES += -DWIN32
190 endif
191
192 ifeq (,$(filter-out x386 x86_64,$(CPU_ARCH)))
193 ifdef USE_64
194         DEFINES += -D_AMD64_
195 else
196         DEFINES += -D_X86_
197 endif
198 endif
199 ifeq ($(CPU_ARCH), ALPHA)
200         DEFINES += -D_ALPHA_=1
201 endif
202
203 ifdef MAPFILE
204 ifndef NS_USE_GCC
205 DLLFLAGS += -DEF:$(MAPFILE)
206 endif
207 endif
208 # Change PROCESS to put the mapfile in the correct format for this platform
209 PROCESS_MAP_FILE = cp $< $@
210
211
212 #
213 #  The following is NOT needed for the NSPR 2.0 library.
214 #
215
216 DEFINES += -D_WINDOWS
217
218 # override default, which is ASFLAGS = CFLAGS
219 ifdef NS_USE_GCC
220         AS      = $(CC)
221         ASFLAGS = $(INCLUDES)
222 else
223 ifdef USE_64
224         AS      = ml64.exe
225         ASFLAGS = -nologo -Cp -Sn -Zi $(INCLUDES)
226 else
227         AS      = ml.exe
228         ASFLAGS = -nologo -Cp -Sn -Zi -coff $(INCLUDES)
229 endif
230 endif
231
232 #
233 # override the definitions of RELEASE_TREE found in tree.mk
234 #
235 ifndef RELEASE_TREE
236     ifdef BUILD_SHIP
237         ifdef USE_SHIPS
238             RELEASE_TREE = $(NTBUILD_SHIP)
239         else
240             RELEASE_TREE = //redbuild/components
241         endif
242     else
243         RELEASE_TREE = //redbuild/components
244     endif
245 endif
246
247 #
248 # override the definitions of IMPORT_LIB_PREFIX, LIB_PREFIX, and
249 # DLL_PREFIX in prefix.mk
250 #
251
252 ifndef IMPORT_LIB_PREFIX
253     ifdef NS_USE_GCC
254         IMPORT_LIB_PREFIX = lib
255     else
256         IMPORT_LIB_PREFIX = $(NULL)
257     endif
258 endif
259
260 ifndef LIB_PREFIX
261     ifdef NS_USE_GCC
262         LIB_PREFIX = lib
263     else
264         LIB_PREFIX = $(NULL)
265     endif
266 endif
267
268 ifndef DLL_PREFIX
269     DLL_PREFIX =  $(NULL)
270 endif
271
272 #
273 # override the definitions of various _SUFFIX symbols in suffix.mk
274 #
275
276 #
277 # Object suffixes
278 #
279 ifndef OBJ_SUFFIX
280     ifdef NS_USE_GCC
281         OBJ_SUFFIX = .o
282     else
283         OBJ_SUFFIX = .obj
284     endif
285 endif
286
287 #
288 # Assembler source suffixes
289 #
290 ifndef ASM_SUFFIX
291     ifdef NS_USE_GCC
292         ASM_SUFFIX = .s
293     else
294         ASM_SUFFIX = .asm
295     endif
296 endif
297
298 #
299 # Library suffixes
300 #
301
302 ifndef IMPORT_LIB_SUFFIX
303     IMPORT_LIB_SUFFIX = .$(LIB_SUFFIX)
304 endif
305
306 ifndef DYNAMIC_LIB_SUFFIX_FOR_LINKING
307     DYNAMIC_LIB_SUFFIX_FOR_LINKING = $(IMPORT_LIB_SUFFIX)
308 endif
309
310 #
311 # Program suffixes
312 #
313 ifndef PROG_SUFFIX
314     PROG_SUFFIX = .exe
315 endif
316
317 #
318 # When the processor is NOT 386-based on Windows NT, override the
319 # value of $(CPU_TAG).  For WinNT, 95, 16, not CE.
320 #
321 ifneq ($(CPU_ARCH),x386)
322     CPU_TAG = _$(CPU_ARCH)
323 endif
324
325 #
326 # override ruleset.mk, removing the "lib" prefix for library names, and
327 # adding the "32" after the LIBRARY_VERSION.
328 #
329 ifdef LIBRARY_NAME
330     SHARED_LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)32$(JDK_DEBUG_SUFFIX).dll
331     IMPORT_LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)32$(JDK_DEBUG_SUFFIX).lib
332 endif
333
334 #
335 # override the TARGETS defined in ruleset.mk, adding IMPORT_LIBRARY
336 #
337 ifndef TARGETS
338     TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY) $(PROGRAM)
339 endif
340
341 # list of MSVC warnings converted to errors above:
342 # 4002: too many actual parameters for macro 'identifier'
343 # 4003: not enough actual parameters for macro 'identifier'
344 # 4004: incorrect construction after 'defined'
345 # 4006: #undef expected an identifier
346 # 4009: string too big; trailing characters truncated
347 # 4015: 'identifier' : type of bit field must be integral
348 # 4028: formal parameter different from declaration
349 # 4033: 'function' must return a value
350 # 4035: 'function' : no return value
351 # 4045: 'identifier' : array bounds overflow
352 # 4047: 'function' : 'type 1' differs in levels of indirection from 'type 2'
353 # 4053: one void operand for '?:'
354 # 4054: 'conversion' : from function pointer 'type1' to data pointer 'type2'
355 # 4059: pascal string too big, length byte is length % 256
356 # 4063: case 'identifier' is not a valid value for switch of enum 'identifier'
357 # 4064: switch of incomplete enum 'identifier'
358 # 4078: case constant 'value' too big for the type of the switch expression
359 # 4087: 'function' : declared with 'void' parameter list
360 # 4090: 'function' : different 'const' qualifiers
361 # 4098: 'function' : void function returning a value
362 # 4390: ';' : empty controlled statement found; is this the intent?
363 # 4541: RTTI train wreck
364 # 4715: not all control paths return a value
365 # 4013: function undefined; assuming extern returning int
366 # 4553: '==' : operator has no effect; did you intend '='?
367 # 4551: function call missing argument list
368