Don't double-close the input.
[metze/wireshark/wip.git] / epan / Makefile.nmake
1 ## Makefile for building wireshark.exe with Microsoft C and nmake
2 ## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
3 #
4
5 include ..\config.nmake
6 include <win32.mak>
7 include ..\Makefile.nmake.inc
8
9 include Makefile.common
10
11 LINK= link
12
13 #
14 # These are the flags for all source files.
15 #
16 COMMON_CFLAGS=\
17         $(STANDARD_CFLAGS) \
18         /I. /I.. $(GLIB_CFLAGS) \
19         $(ZLIB_CFLAGS) $(C_ARES_CFLAGS) \
20         $(LUA_CFLAGS) $(GNUTLS_CFLAGS) /I$(PCAP_DIR)\include \
21         $(SMI_CFLAGS) $(GEOIP_CFLAGS)
22
23 #
24 # These are the flags for generated source files; we don't include
25 # $(WARNINGS_ARE_ERRORS), so that we flex's non-LLP64-compliant output
26 # doesn't cause compilation to fail.
27 #
28 GENERATED_CFLAGS=\
29         $(COMMON_CFLAGS) -DWS_BUILD_DLL
30
31 #
32 # These are the flags for test programs; we don't include -DWS_BUILD_DLL,
33 # as we're building test programs that link with the library, not routines
34 # incorporated into the library, so they should *import* stuff from the
35 # library, not *export* stuff from the library.
36 #
37 TEST_CFLAGS=\
38         $(WARNINGS_ARE_ERRORS) $(COMMON_CFLAGS)
39
40 #
41 # These are flags for everything else; we include $(WARNINGS_ARE_ERRORS),
42 # as the code should be warning-free, and we include -DWS_BUILD_DLL,
43 # as these are library routines, not test programs.
44 #
45 CFLAGS=$(WARNINGS_ARE_ERRORS) $(GENERATED_CFLAGS) -DWS_BUILD_DLL
46
47 !IFDEF LUA_DIR
48 WSLUA_LIB=wslua\wslua.lib
49 WSLUA_DIR=wslua
50 !ELSE
51 WSLUA_LIB=
52 WSLUA_DIR=
53 !ENDIf
54
55 # For use when making libwireshark.dll
56 libwireshark_LIBS = \
57         $(GLIB_LIBS)    \
58         $(C_ARES_LIBS) \
59         $(KFW_LIBS) \
60         $(ZLIB_LIBS) \
61         $(GNUTLS_LIBS) \
62         $(LUA_LIBS) \
63         $(SMI_LIBS) \
64         $(GEOIP_LIBS) \
65         ..\wsutil\libwsutil.lib \
66         ..\wiretap\wiretap-$(WTAP_VERSION).lib \
67         compress\lzxpress.lib \
68         crypt\airpdcap.lib \
69         ftypes\ftypes.lib \
70         dfilter\dfilter.lib \
71         wmem\wmem.lib \
72         $(WSLUA_LIB) \
73         nghttp2\nghttp2.lib \
74         dissectors\dissectors.lib
75
76 .c.obj::
77         $(CC) $(CFLAGS) -Fd.\ -c $<
78
79 LIBWIRESHARK_OBJECTS = $(LIBWIRESHARK_ALL_SRC:.c=.obj)
80
81 EXTRA_OBJECTS = \
82 !IF defined(NASM) && "$(WIRESHARK_TARGET_PLATFORM)" == "win32"
83         asm_utils_win32_x86.obj
84 !ELSE
85         asm_utils.obj
86 !ENDIF
87
88 !IFDEF DOXYGEN
89 DOXYGEN_DEP=doxygen
90 !ENDIF
91
92 !IFDEF ENABLE_LIBWIRESHARK
93 all: compress crypt ftypes dfilter wmem $(WSLUA_DIR) nghttp2 dissectors libwireshark.dll
94 !ELSE
95 all: compress crypt ftypes dfilter wmem $(WSLUA_DIR) nghttp2 dissectors libwireshark.lib
96 !ENDIF
97
98 # For use when making libwireshark.dll
99 libwireshark.lib: libwireshark.dll
100 libwireshark.exp: libwireshark.dll
101
102 libwireshark.dll: ..\config.h $(LIBWIRESHARK_OBJECTS) compress crypt ftypes dfilter wmem $(WSLUA_DIR) nghttp2 dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
103                 crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib wmem\wmem.lib dissectors\dissectors.lib $(WSLUA_LIB) nghttp2\nghttp2.lib ..\image\libwireshark.res
104         @echo Linking libwireshark.dll
105         $(link) $(dlllflags) $(conlibsdll) shell32.lib psapi.lib \
106                 $(LOCAL_LDFLAGS) $(DLL_LDFLAGS) \
107                 /OUT:libwireshark.dll \
108                 /IMPLIB:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \
109                 $(libwireshark_LIBS) ..\image\libwireshark.res \
110                 dissectors\register.obj \
111                 $(EXTRA_OBJECTS)
112
113 libwireshark.lib        : ..\config.h $(LIBWIRESHARK_OBJECTS) compress crypt ftypes dfilter wmem $(WSLUA_DIR) nghttp2 dissectors $(DOXYGEN_DEP) $(EXTRA_OBJECTS) \
114                 crypt\airpdcap.lib ftypes\ftypes.lib dfilter\dfilter.lib wmem\wmem.lib $(WSLUA_LIB) nghttp2\nghttp2.lib dissectors\dissectors.lib
115         link /lib /out:libwireshark.lib $(LIBWIRESHARK_OBJECTS) \
116                 $(EXTRA_OBJECTS)
117
118 ..\config.h     : ..\config.h.win32 ..\config.nmake
119         cd ..
120         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake config.h
121         cd epan
122
123 clean-local:
124         rm -f $(LIBWIRESHARK_OBJECTS) $(EXTRA_OBJECTS) \
125                 libwireshark.lib libwireshark.dll *.manifest libwireshark.exp \
126                 *.nativecodeanalysis.xml *.pdb *.sbr doxygen.cfg html/*.* \
127                 exntest.obj exntest.exe exntest.exp reassemble_test.obj reassemble_test.exe tvbtest.obj tvbtest.exe tvbtest.exp oids_test.obj oids_test.exe oids_test.exp
128         if exist html rm -rf html
129
130 clean:  clean-local
131         cd compress
132         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
133         cd ../crypt
134         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
135         cd ../ftypes
136         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
137         cd ../dfilter
138         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
139         cd ../dissectors
140         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
141         cd ../wmem
142         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
143         cd ../wslua
144         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
145         cd ../nghttp2
146         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake clean
147         cd ..
148
149 #
150 # We remove the Flex-generated files with "distclean" because they need
151 # different #includes for UN*X and Windows (UN*X versions of Flex make it
152 # include <unistd.h>, but that's a UN*X-only header), so if you're going
153 # to build from source, you need to build those scanners from the
154 # corresponding ".l" files with Flex.
155 # This might not be necessary for "dtd_grammar.{c,h}", but we handle them
156 # the same for now.
157 #
158 distclean-local: clean-local
159         rm -f config.h register.c mkstemp.c \
160                 $(NODIST_LIBWIRESHARK_GENERATED_C_FILES) \
161                 $(NODIST_LIBWIRESHARK_GENERATED_HEADER_FILES) \
162                 $(LIBWIRESHARK_GENERATED_C_FILES) \
163                 $(LIBWIRESHARK_GENERATED_HEADER_FILES) \
164                 dtd_grammar.out
165
166 distclean: distclean-local
167         cd compress
168         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
169         cd ../crypt
170         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
171         cd ../ftypes
172         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
173         cd ../dfilter
174         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
175         cd ../dissectors
176         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
177         cd ../wmem
178         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
179         cd ../wslua
180         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
181         cd ../nghttp2
182         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake distclean
183         cd ..
184
185 maintainer-clean-local: distclean-local
186
187 maintainer-clean: maintainer-clean-local
188         cd compress
189         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
190         cd ../crypt
191         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
192         cd ../ftypes
193         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
194         cd ../dfilter
195         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
196         cd ../dissectors
197         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
198         cd ../wmem
199         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
200         cd ../wslua
201         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
202         cd ../nghttp2
203         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake maintainer-clean
204         cd ..
205
206 crypt:: ..\config.h
207         cd crypt
208         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
209         cd ..
210
211 compress:: ..\config.h
212         cd compress
213         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
214         cd ..
215
216 ftypes:: ..\config.h
217         cd ftypes
218         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
219         cd ..
220
221 dfilter:: ..\config.h
222         cd dfilter
223         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
224         cd ..
225
226 dissectors:: ..\config.h
227         cd dissectors
228         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
229         cd ..
230
231 wmem:: ..\config.h
232         cd wmem
233         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
234         cd ..
235
236 wslua:: ..\config.h
237         cd wslua
238         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
239         cd ..
240
241 nghttp2:: ..\config.h
242         cd nghttp2
243         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake
244         cd ..
245
246 doxygen.cfg: ..\config.nmake doxygen.cfg.in
247         sed -e s/@VERSION@/$(VERSION)/ \
248             < doxygen.cfg.in > $@
249
250 doxygen-run:
251 !IFDEF DOXYGEN
252         $(DOXYGEN) doxygen.cfg
253 !ENDIF
254
255 doxygen: doxygen.cfg doxygen-run
256
257 # Rules for making unit tests
258 exntest: exntest.exe
259 reassemble_test: reassemble_test.exe
260 tvbtest: tvbtest.exe
261 oids_test: oids_test.exe
262
263 # Object files for exntest
264 EXNTEST_OBJ=exntest.obj except.obj
265
266 exntest.exe: $(EXNTEST_OBJ)
267         @echo Linking $@
268         $(LINK) /OUT:$@ $(conflags) $(conlibsdll) $(LOCAL_LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console \
269                 $(GLIB_LIBS) $(EXNTEST_OBJ)
270 !IFDEF MANIFEST_INFO_REQUIRED
271         mt.exe -nologo -manifest "$@.manifest" -outputresource:$@;1
272 !ENDIF
273
274 # Object files for tvbtest
275 TVBTEST_OBJ=tvbtest.obj
276 TVBTEST_LIBS= ..\wiretap\wiretap-$(WTAP_VERSION).lib \
277         wsock32.lib user32.lib \
278         $(GLIB_LIBS) \
279         ..\wsutil\libwsutil.lib \
280         $(GNUTLS_LIBS) \
281 !IFDEF ENABLE_LIBWIRESHARK
282         libwireshark.lib \
283 !ELSE
284         dissectors\dissectors.lib \
285         wireshark.lib \
286         compress\lzxpress.lib \
287         crypt\airpdcap.lib \
288         dfilter\dfilter.lib \
289         ftypes\ftypes.lib \
290         $(C_ARES_LIBS) \
291         $(ZLIB_LIBS)
292 !ENDIF
293
294 tvbtest.exe: $(TVBTEST_OBJ)
295         @echo Linking $@
296         $(LINK) /OUT:$@ $(conflags) $(conlibsdll) $(LOCAL_LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console \
297                 $(TVBTEST_LIBS) $(GLIB_LIBS) $(ZLIB_LIBS) $(TVBTEST_OBJ)
298 !IFDEF MANIFEST_INFO_REQUIRED
299         mt.exe -nologo -manifest "$@.manifest" -outputresource:$@;1
300 !ENDIF
301
302 # Object files for oids_test
303 OIDS_TEST_OBJ=oids_test.obj
304 OIDS_TEST_LIBS= ..\wiretap\wiretap-$(WTAP_VERSION).lib \
305         wsock32.lib user32.lib \
306         $(GLIB_LIBS) \
307         ..\wsutil\libwsutil.lib \
308         $(GNUTLS_LIBS) \
309 !IFDEF ENABLE_LIBWIRESHARK
310         libwireshark.lib \
311 !ELSE
312         dissectors\dissectors.lib \
313         wireshark.lib \
314         compress\lzxpress.lib \
315         crypt\airpdcap.lib \
316         dfilter\dfilter.lib \
317         ftypes\ftypes.lib \
318         wmem\wmem.lib \
319         $(C_ARES_LIBS) \
320         $(ZLIB_LIBS)
321 !ENDIF
322
323 oids_test.exe: $(OIDS_TEST_OBJ)
324         @echo Linking $@
325         $(LINK) /OUT:$@ $(conflags) $(conlibsdll) $(LOCAL_LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console \
326                 $(OIDS_TEST_LIBS) $(GLIB_LIBS) $(ZLIB_LIBS) $(OIDS_TEST_OBJ)
327 !IFDEF MANIFEST_INFO_REQUIRED
328         mt.exe -nologo -manifest "$@.manifest" -outputresource:$@;1
329 !ENDIF
330
331 # Object files for reassemble_test
332 REASSEMBLE_TEST_OBJ=reassemble_test.obj
333 REASSEMBLE_TEST_LIBS= ..\wiretap\wiretap-$(WTAP_VERSION).lib \
334         wsock32.lib user32.lib \
335         $(GLIB_LIBS) \
336         ..\wsutil\libwsutil.lib \
337         $(GNUTLS_LIBS) \
338 !IFDEF ENABLE_LIBWIRESHARK
339         libwireshark.lib \
340 !ELSE
341         dissectors\dissectors.lib \
342         wireshark.lib \
343         compress\lzxpress.lib \
344         crypt\airpdcap.lib \
345         dfilter\dfilter.lib \
346         ftypes\ftypes.lib \
347         $(C_ARES_LIBS) \
348         $(ZLIB_LIBS)
349 !ENDIF
350
351 reassemble_test.exe: $(REASSEMBLE_TEST_OBJ)
352         @echo Linking $@
353         $(LINK) /OUT:$@ $(conflags) $(conlibsdll) $(LOCAL_LDFLAGS) /LARGEADDRESSAWARE /SUBSYSTEM:console \
354                 $(REASSEMBLE_TEST_LIBS) $(GLIB_LIBS) $(ZLIB_LIBS) $(REASSEMBLE_TEST_OBJ)
355 !IFDEF MANIFEST_INFO_REQUIRED
356         mt.exe -nologo -manifest "$@.manifest" -outputresource:$@;1
357 !ENDIF
358
359 exntest_install: exntest.exe
360         set copycmd=/y
361         xcopy exntest.exe ..\$(INSTALL_DIR) /d
362
363 tvbtest_install: tvbtest.exe
364         set copycmd=/y
365         xcopy tvbtest.exe ..\$(INSTALL_DIR) /d
366
367 oids_test_install: oids_test.exe
368         set copycmd=/y
369         xcopy oids_test.exe ..\$(INSTALL_DIR) /d
370
371 reassemble_test_install: reassemble_test.exe
372         set copycmd=/y
373         xcopy reassemble_test.exe ..\$(INSTALL_DIR) /d
374
375 test-programs: exntest_install tvbtest_install oids_test_install reassemble_test_install
376         cd wmem
377         $(MAKE) /$(MAKEFLAGS) -f Makefile.nmake test-programs
378         cd ..
379
380 #
381 # Compile some time critical code from assembler if NASM available
382 #
383 !IFDEF NASM
384 asm_utils_win32_x86.obj: asm_utils_win32_x86.asm
385         $(NASM) -f $(WIRESHARK_TARGET_PLATFORM) -o $@ $?
386 !ENDIF
387
388 update-sminmpec:
389         $(PERL) ../tools/make-sminmpec.pl
390
391 RUNLEX=../tools/runlex.sh
392
393 #
394 # We compile these specially because they're Flex-generated and thus
395 # "warnings are errors" will fail because there's a bunch of
396 # warnings we can't eliminate.
397 #
398 diam_dict_lex.h: diam_dict.c
399 diam_dict.obj : diam_dict.c
400         $(CC) $(GENERATED_CFLAGS) -Fd.\ -c $?
401
402 #
403 # This depends on dtd_grammar.h to force dtd_grammar.h to be
404 # built before we try to compile it, as dtd_parse.c includes
405 # dtd_grammar.h, and dtd_grammar.h is not distributed with
406 # the source (it's generated with Lemon).  That means we can't
407 # use $?, as that would make it try to compile dtd_grammar.h.
408 #
409 dtd_parse_lex.h: dtd_parse.c
410 dtd_parse.obj : dtd_grammar.h
411 dtd_parse.obj : dtd_parse.c
412         $(CC) $(GENERATED_CFLAGS) -Fd.\ -c dtd_parse.c
413
414 dtd_preparse_lex.h: dtd_preparse.c
415 dtd_preparse.obj : dtd_preparse.c
416         $(CC) $(GENERATED_CFLAGS) -Fd.\ -c $?
417
418 radius_dict_lex.h: radius_dict.c
419 radius_dict.obj : radius_dict.c
420         $(CC) $(GENERATED_CFLAGS) -Fd.\ -c $?
421
422 uat_load_lex.h: uat_load.c
423 uat_load.obj : uat_load.c
424         $(CC) $(GENERATED_CFLAGS) -Fd.\ -c $?
425
426 LEMON=..\tools\lemon
427
428 dtd_grammar.h: dtd_grammar.c
429 dtd_grammar.c: $(LEMON)\lemon.exe $(LEMON)\lempar.c dtd_grammar.lemon
430         $(LEMON)\lemon T=$(LEMON)\lempar.c dtd_grammar.lemon
431
432 #
433 # We compile these specially because they're test programs, not library
434 # routines, and thus they import stuff from the library rather than
435 # exporting stuff from the library.
436 #
437 exntest.obj: exntest.c
438         $(CC) $(TEST_CFLAGS) -Fd.\ -c $?
439
440 reassemble_test.obj: reassemble_test.c
441         $(CC) $(TEST_CFLAGS) -Fd.\ -c $?
442
443 tvbtest.obj: tvbtest.c
444         $(CC) $(TEST_CFLAGS) -Fd.\ -c $?
445
446 oids_test.obj: oids_test.c
447         $(CC) $(TEST_CFLAGS) -Fd.\ -c $?
448
449 ps.c: ..\tools\rdps.py print.ps
450         $(PYTHON) ..\tools\rdps.py print.ps ps.c
451
452 checkapi:
453         $(PERL) ../tools/checkAPIs.pl -g termoutput -build $(LIBWIRESHARK_SRC)
454
455 #
456 # Editor modelines  -  https://www.wireshark.org/tools/modelines.html
457 #
458 # Local variables:
459 # c-basic-offset: 8
460 # tab-width: 8
461 # indent-tabs-mode: t
462 # End:
463 #
464 # vi: set shiftwidth=8 tabstop=8 noexpandtab:
465 # :indentSize=8:tabSize=8:noTabs=false:
466 #