Windows: Include winsock2.h before ws2tcpip.h
[heimdal.git] / windows / NTMakefile.w32
blob86b73debb09e364fb31d2004f9792440e3e78602
1 ########################################################################
3 # Copyright (c) 2009, Secure Endpoints Inc.
4 # All rights reserved.
5
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9
10 # - Redistributions of source code must retain the above copyright
11 #   notice, this list of conditions and the following disclaimer.
12
13 # - Redistributions in binary form must reproduce the above copyright
14 #   notice, this list of conditions and the following disclaimer in
15 #   the documentation and/or other materials provided with the
16 #   distribution.
17
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30
32 all::
34 clean::
36 test::
38 prep::
40 all:: prep
42 !include <Win32.Mak>
44 !ifdef NODEBUG
45 BUILD=rel
46 !else
47 BUILD=dbg
48 !endif
50 !if exist($(MAKEDIR)\windows\NTMakefile.w32)
51 SRC=$(MAKEDIR)
52 !elseif exist($(MAKEDIR)\..\windows\NTMakefile.w32)
53 SRC=$(MAKEDIR)\..
54 !elseif exist($(MAKEDIR)\..\..\windows\NTMakefile.w32)
55 SRC=$(MAKEDIR)\..\..
56 !elseif exist($(MAKEDIR)\..\..\..\windows\NTMakefile.w32)
57 SRC=$(MAKEDIR)\..\..\..
58 !else
59 !  error Cant determine source directory
60 !endif
62 !  if "$(CPU)"=="i386" || "$(CPU)"=="x86"
63 MCPU=x86
64 !  elseif "$(CPU)"=="AMD64"
65 MCPU=amd64
66 !  else
67 !    error Unknown CPU
68 !  endif
70 !include "NTMakefile.config"
72 #----------------------------------------------------------------
73 # Directory macros
75 DESTDIR=$(SRC)\out\dest_$(OUTDIR)
76 OBJDIR =$(SRC)\out\obj_$(OUTDIR)
78 INCDIR =$(DESTDIR)\inc
79 LIBDIR =$(DESTDIR)\lib
80 BINDIR =$(DESTDIR)\bin
81 SBINDIR=$(BINDIR)
82 LIBEXECDIR=$(BINDIR)
83 ASMDIR=$(BINDIR)
84 SDKDIR=$(SRC)\out
85 SDKINCDIR=$(SRC)\out\inc
86 SDKLIBDIR=$(SRC)\out\lib\$(CPU)
87 SDKSRCDIR=$(SRC)\out\src
89 !ifdef RELDIR
90 SRCDIR =$(SRC)\$(RELDIR)
91 OBJ    =$(OBJDIR)\$(RELDIR)
92 !else
93 OBJ    =$(OBJDIR)
94 !endif
96 # For tests:
97 PATH=$(PATH);$(BINDIR)
99 #----------------------------------------------------------------
100 # Command macros
102 RMAKE=nmake /nologo /f NTMakefile RECURSE=1
103 MKDIR=md
104 CP=copy /Y
105 LINK=link
106 LM=lib
107 RM=del /q
108 ECHO=echo
109 RC=rc
111 AWK=gawk.exe
112 YACC=bison.exe -y
113 LEX=flex.exe
114 PYTHON=python.exe
115 PERL=perl.exe
116 CMP=cmp.exe
117 SIGNTOOL=signtool.exe
118 MAKECAT=makecat.exe
120 # Only used for tests
121 SH=sh.exe
122 SED=sed.exe
124 #----------------------------------------------------------------
125 # External dependencies
127 # For pthread support to be enabled, both PTHREAD_INC and PTHREAD_LIB
128 # should be defined.  PTHREAD_INC should be the include directory
129 # where pthread.h is to be found (i.e. $(PTHREAD_INC)\pthread.h should
130 # exist), and PTHREAD_LIB is the full path to the pthread import
131 # library.
133 # Note that both paths should not contain any whitespace.
135 !ifdef PTHREAD_INC
136 pthreadinc= -I$(PTHREAD_INC)
137 !endif
139 #----------------------------------------------------------------
140 # Build options
142 cincdirs=$(cincdirs) -I$(INCDIR) -I$(INCDIR)\krb5 $(pthreadinc)
143 cdefines=$(cdefines) -DHAVE_CONFIG_H
145 # ---------------------------------------------------------------
146 # time_t issues
148 !if "$(MCPU)"=="x86"
149 cdefines=$(cdefines) -D_USE_32BIT_TIME_T
150 !endif
152 # Disable warnings:
154 # C4996: 'function' was declared deprecated
155 # C4127: Conditional expression is constant
156 # C4244: Conversion from 'type1' to 'type2', possible loss of data
157 # C4100: 'identifier': unreferenced formal parameter
158 # C4706: Assignment within conditional expression
159 # C4214: Nonstandard extension used
160 # C4267: '': Conversion from 'type1' to 'type2', possible loss of data
161 # C4018: '': Signed/unsigned mismatch
162 # C4204: Nonstandard extension used: non-constant aggregate initializer
163 # C4221: Nonstandard extension used: 'v1': cannot be initialized using address of automatic variable 'v2'
164 # C4295: '': Array is too small to include a terminating null character
166 cwarn=$(cwarn) -D_CRT_SECURE_NO_WARNINGS -wd4996 -wd4127 -wd4244 -wd4100 -wd4706
167 cwarn=$(cwarn) -wd4214 -wd4267 -wd4018 -wd4389 -wd4204 -wd4221 -wd4295
169 !if "$(CPU)"=="i386"
170 libmach=/machine:X86
171 !elseif "$(CPU)"=="AMD64"
172 libmach=/machine:X64
173 !else
174 !  error Unknown CPU value
175 !endif
177 !ifndef STATICRUNTIME
179 C2OBJ_C = $(CC) $(cdebug) $(cflags) $(cvarsdll) $(AUXCFLAGS) $(intcflags) $(cdefines) $(cincdirs) $(cwarn)
180 EXECONLINK_C = $(LINK) $(ldebug) $(conlflags) $(conlibsdll) $(libmach)
181 EXEGUILINK_C = $(LINK) $(ldebug) $(guilflags) $(guilibsdll) $(libmach)
182 DLLCONLINK_C = $(LINK) $(ldebug) $(dlllflags) $(conlibsdll) $(libmach)
183 DLLGUILINK_C = $(LINK) $(ldebug) $(dlllflags) $(guilibsdll) $(libmach)
185 !else # STATICRUNTIME
187 C2OBJ_C = $(CC) $(cdebug) $(cflags) $(cvarsmt) $(AUXCFLAGS) $(intcflags) $(cdefines) $(cincdirs) $(cwarn)
188 EXECONLINK_C = $(LINK) $(ldebug) $(conlflags) $(conlibsmt) $(libmach)
189 EXEGUILINK_C = $(LINK) $(ldebug) $(guilflags) $(guilibsmt) $(libmach)
190 DLLCONLINK_C = $(LINK) $(ldebug) $(dlllflags) $(conlibsmt) $(libmach)
191 DLLGUILINK_C = $(LINK) $(ldebug) $(dlllflags) $(guilibsmt) $(libmach)
193 !endif
195 LIBGUI_C = $(LM) /nologo $(libmach) /SUBSYSTEM:WINDOWS
196 LIBCON_C = $(LM) /nologo $(libmach) /SUBSYSTEM:CONSOLE
198 C2OBJ = $(C2OBJ_C) -Fo$@ -Fd$(@D)\ $**
199 C2OBJ_NP = $(C2OBJ_C) -MP $<
200 C2OBJ_P = $(C2OBJ_NP) -Fo$(OBJ)\ -Fd$(OBJ)\ #
201 EXECONLINK = $(EXECONLINK_C) -OUT:$@ $**
202 EXEGUILINK = $(EXEGUILINK_C) -OUT:$@ $**
203 DLLCONLINK = $(DLLCONLINK_C) -OUT:$@ $**
204 DLLGUILINK = $(DLLGUILINK_C) -OUT:$@ $**
205 LIBGUI = $(LIBGUI_C) /OUT:$@ $**
206 LIBCON = $(LIBCON_C) /OUT:$@ $**
208 # Preprocess files to stdout using config.h
209 CPREPROCESSOUT = $(CC) /EP /FI$(INCDIR)\config.h /TC /DCPP_ONLY=1
211 # Resources
213 RC2RES_C = $(RC) $(cincdirs) $(AUXRCFLAGS)
214 RC2RES = $(RC2RES_C) -fo $@ $**
216 #----------------------------------------------------------------------
217 # If this is the initial invocation, we check if all the build
218 # utilities are there.  Also show the commands macros.
220 !ifndef RECURSE
222 check-utils:
223         @for %%g in ( "$(AWK)" "$(YACC)" "$(LEX)" "$(PYTHON)" "$(PERL)" "$(CMP)" "$(SED)" "$(SIGNTOOL)" "$(MAKECAT)" ) do @( \
224         for /f %%f in ( "%%g" ) do @( \
225                 if exist %%f @( \
226                         echo Found %%f \
227                 ) else if "%%~$$PATH:f"=="" @( \
228                         echo Could not find %%f in PATH && \
229                         exit /b 1 \
230                 ) else @( \
231                         echo Found %%~$$PATH:f \
232                 ) \
233         ) \
234         )
235         @for %%g in ( "$(SH)" ) do @( \
236         for /f %%f in ( "%%g" ) do @( \
237                 if exist %%f @( \
238                         echo Found %%f \
239                 ) else if "%%~$$PATH:f"=="" @( \
240                         echo Could not find %%f in PATH && \
241                         echo Test targets may fail. \
242                 ) else @( \
243                         echo Found %%~$$PATH:f \
244                 ) \
245         ) \
246         )
249 prep:: check-utils
251 show-cmds:
252         @$(ECHO) C2OBJ=$(C2OBJ_C:\=\\)
253         @$(ECHO).
254         @$(ECHO) EXECONLINK=$(EXECONLINK_C)
255         @$(ECHO).
256         @$(ECHO) EXEGUILINK=$(EXEGUILINK_C)
257         @$(ECHO).
258         @$(ECHO) DLLCONLINK=$(DLLCONLINK_C)
259         @$(ECHO).
260         @$(ECHO) DLLGUILINK=$(DLLGUILINK_C)
261         @$(ECHO).
262         @$(ECHO) LIBGUI=$(LIBGUI_C)
263         @$(ECHO).
264         @$(ECHO) LIBCON=$(LIBCON_C)
266 prep:: show-cmds
268 !endif                          # RECURSE
270 {}.c{$(OBJ)}.obj::
271         $(C2OBJ_C) /Fd$(OBJ)\ /Fo$(OBJ)\ /MP @<<
275 {$(OBJ)}.c{$(OBJ)}.obj::
276         $(C2OBJ_C) /Fd$(OBJ)\ /Fo$(OBJ)\ /MP @<<
280 {}.cpp{$(OBJ)}.obj::
281         $(C2OBJ_C) /Fd$(OBJ)\ /Fo$(OBJ)\ /MP @<<
285 {$(OBJ)}.cpp{$(OBJ)}.obj::
286         $(C2OBJ_C) /Fd$(OBJ)\ /Fo$(OBJ)\ /MP @<<
290 {}.hin{$(INCDIR)}.h:
291         $(CP) $< $@
293 {}.h{$(INCDIR)}.h:
294         $(CP) $< $@
296 {}.h{$(INCDIR)\krb5}.h:
297         $(CP) $< $@
299 {$(OBJ)}.h{$(INCDIR)}.h:
300         $(CP) $< $@
302 {$(OBJ)}.x{$(OBJ)}.c:
303         $(CP) $< $@
305 {$(OBJ)}.hx{$(INCDIR)}.h:
306         $(CP) $< $@
308 {$(OBJ)}.hx{$(OBJ)}.h:
309         $(CP) $< $@
311 {}.rc{$(OBJ)}.res:
312         $(RC2RES)
314 #----------------------------------------------------------------------
315 # Announce the build directory
317 !ifdef RELDIR
318 all:: announce
320 all-tools:: announce-tools
322 test:: announce
324 clean:: announce
326 announce:
327         @echo.
328         @echo --------- Entering $(RELDIR:\= ):
330 announce-tools:
331         @echo.
332         @echo --------- Entering $(RELDIR:\= ) tools:
333 !endif
335 #----------------------------------------------------------------------
336 # Create any required directories if they don't already exist
338 prep:: mkdirs
340 mkdirs:
341 !  if !exist($(OBJ))
342         $(MKDIR) $(OBJ)
343 !  endif
344 !  if !exist($(DESTDIR))
345         $(MKDIR) $(DESTDIR)
346 !  endif
347 !  if !exist($(LIBDIR))
348         $(MKDIR) $(LIBDIR)
349 !  endif
350 !  if !exist($(BINDIR))
351         $(MKDIR) $(BINDIR)
352 !  endif
353 !  if !exist($(INCDIR))
354         $(MKDIR) $(INCDIR)
355 !  endif
356 !  if !exist($(INCDIR)\gssapi)
357         $(MKDIR) $(INCDIR)\gssapi
358 !  endif
359 !  if !exist($(INCDIR)\hcrypto)
360         $(MKDIR) $(INCDIR)\hcrypto
361 !  endif
362 !  if !exist($(INCDIR)\kadm5)
363         $(MKDIR) $(INCDIR)\kadm5
364 !  endif
365 !  if !exist($(INCDIR)\krb5)
366         $(MKDIR) $(INCDIR)\krb5
367 !  endif
369 #----------------------------------------------------------------------
370 # If SUBDIRS is defined, we should recurse into the subdirectories
372 !ifdef SUBDIRS
373 subdirs:
374         @for %%f in ( $(SUBDIRS) ) do @ (pushd %%f && $(RMAKE) && popd) || exit /b 1
376 clean-subdirs:
377         @for %%f in ( $(SUBDIRS) ) do @ (pushd %%f && $(RMAKE) clean && popd) || exit /b 1
379 test-subdirs:
380         @for %%f in ( $(SUBDIRS) ) do @ (pushd %%f && $(RMAKE) test && popd) || exit /b 1
382 all:: subdirs
384 clean:: clean-subdirs
386 test:: test-subdirs
388 !endif
390 #----------------------------------------------------------------------
391 # Clean targets
393 !ifdef CLEANFILES
394 clean::
395         -$(RM) $(CLEANFILES)
396 !endif
397 !ifdef RELDIR
398 clean::
399         -$(RM) $(OBJ)\*.*
400 !endif
402 .SUFFIXES: .c .cpp .hin .h .x .hx
404 #----------------------------------------------------------------------
405 # Manifest handling
407 # Starting with Visual Studio 8, the C compiler and the linker
408 # generate manifests so that the applications will link with the
409 # correct side-by-side DLLs at run-time.  These are required for
410 # correct operation under Windows XP and later.  We also have custom
411 # manifests which need to be merged with the manifests that VS
412 # creates.
414 # The syntax for invoking the _VC_MANIFEST_EMBED_FOO macro is:
415 # $(_VC_MANIFEST_EMBED_???) <additional manifests>
418 MT=mt.exe -nologo
420 _VC_MANIFEST_EMBED_EXE= \
421 ( if exist $@.manifest $(MT) -outputresource:$@;1 -manifest $@.manifest )
423 _VC_MANIFEST_EMBED_DLL= \
424 ( if exist $@.manifest $(MT) -outputresource:$@;2 -manifest $@.manifest )
426 # Note that if you are merging manifests, then the VS generated
427 # manifest should be cleaned up after calling _VC_MANIFEST_EMBED_???.
428 # This ensures that even if the DLL or EXE is executed in-place, the
429 # embedded manifest will be used.  Otherwise the $@.manifest file will
430 # be used.
432 _VC_MANIFEST_CLEAN= \
433 ( if exist $@.manifest $(RM) $@.manifest )
435 # End of manifest handling
437 #----------------------------------------------------------------------
438 # Code and assembly signing
440 # SIGNTOOL_C is any set of options required for certificate/private
441 # key selection for code signging.
443 # SIGNTOOL_O is any set of additional options to signtool.exe
445 # SIGNTOOL_T is the timestamp option
447 !ifdef CODESIGN
448 _CODESIGN=( $(CODESIGN) $@ )
449 !else
451 !ifdef SIGNTOOL_C
453 !ifndef SIGNTOOL_T
454 SIGNTOOL_T=/t http://timestamp.verisign.com/scripts/timstamp.dll
455 !endif
457 _CODESIGN=( $(SIGNTOOL) sign $(SIGNTOOL_O) $(SIGNTOOL_T) $(SIGNTOOL_C) /v $@ )
458 !else
459 _CODESIGN=( echo Skipping code sign )
460 !endif
462 !endif
464 #----------------------------------------------------------------------
465 # Convenience macros for preparing EXEs and DLLs.  These are multiline
466 # macros that deal with manifests and code signing.  Unless we need to
467 # include custom manifests, these are what we should be using to
468 # prepare binaries.
470 EXEPREP=\
471 ( $(_VC_MANIFEST_EMBED_EXE) && $(_VC_MANIFEST_CLEAN) && $(_CODESIGN) ) || $(RM) $@
473 EXEPREP_NODIST=\
474 ( $(_VC_MANIFEST_EMBED_EXE) && $(_VC_MANIFEST_CLEAN) ) || $(RM) $@
476 DLLPREP=\
477 ( $(_VC_MANIFEST_EMBED_DLL) && $(_VC_MANIFEST_CLEAN) && $(_CODESIGN) ) || $(RM) $@
479 DLLPREP_NODIST=\
480 ( $(_VC_MANIFEST_EMBED_DLL) && $(_VC_MANIFEST_CLEAN) ) || $(RM) $@
482 #----------------------------------------------------------------------
483 # Convenience macros for import libraries and assemblies
486 LIBASN1     =$(LIBDIR)\libasn1.lib
487 LIBCOMERR   =$(LIBDIR)\libcom_err.lib
488 LIBEDITLINE =$(LIBDIR)\libeditline.lib
489 LIBGSSAPI   =$(LIBDIR)\libgssapi.lib
490 LIBHCRYPTO  =$(LIBDIR)\libhcrypto.lib
491 LIBHDB      =$(LIBDIR)\libhdb.lib
492 LIBHEIMDAL  =$(LIBDIR)\heimdal.lib
493 LIBHEIMIPCC =$(LIBDIR)\libheim-ipcc.lib
494 LIBHEIMIPCS =$(LIBDIR)\libheim-ipcs.lib
495 LIBHEIMNTLM =$(LIBDIR)\libheimntlm.lib
496 LIBHX509    =$(LIBDIR)\libhx509.lib
497 LIBKADM5CLNT=$(LIBDIR)\libkadm5clnt.lib
498 LIBKADM5SRV =$(LIBDIR)\libkadm5srv.lib
499 LIBKDC      =$(LIBDIR)\libkdc.lib
500 LIBLTM      =$(LIBDIR)\libltm.lib
501 LIBKRB5     =$(LIBDIR)\libkrb5.lib
502 LIBROKEN    =$(LIBDIR)\libroken.lib
503 LIBSL       =$(LIBDIR)\libsl.lib
504 LIBSQLITE   =$(LIBDIR)\libsqlite.lib
505 LIBVERS     =$(LIBDIR)\libvers.lib
506 LIBWIND     =$(LIBDIR)\libwind.lib
508 ASMKRBNAME  =Heimdal.Kerberos
509 ASMGSSNAME  =Heimdal.GSSAPI
510 APPMANIFEST =$(INCDIR)\Heimdal.Application.$(MCPU).manifest