Add a script as a front-end for Flex, to work around various problems,
[jelmer/wireshark.git] / plugins / mate / Makefile.nmake
1 # Makefile.nmake
2 # nmake file for mate plugin
3 #
4 # $Id$
5 #
6
7 include ..\..\config.nmake
8 include ..\..\Makefile.nmake.inc
9
10 include moduleinfo.nmake
11
12 include Makefile.common
13
14 LEMON=..\..\tools\lemon
15
16 CFLAGS=/WX /DHAVE_CONFIG_H /I../.. /I../../wiretap $(GLIB_CFLAGS) /I$(LEMON)\
17         /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS)
18
19 .c.obj::
20         $(CC) $(CFLAGS) -Fd$(PACKAGE).pdb -c $<
21
22 LDFLAGS = $(PLUGIN_LDFLAGS)
23
24 !IFDEF ENABLE_LIBWIRESHARK
25 LINK_PLUGIN_WITH=..\..\epan\libwireshark.lib ..\..\wiretap\wiretap-$(WTAP_VERSION).lib
26 CFLAGS=/DHAVE_WIN32_LIBWIRESHARK_LIB /D_NEED_VAR_IMPORT_ $(CFLAGS)
27
28 DISSECTOR_OBJECTS = $(DISSECTOR_SRC:.c=.obj)
29
30 DISSECTOR_SUPPORT_OBJECTS = $(DISSECTOR_SUPPORT_SRC:.c=.obj)
31
32 OBJECTS = $(DISSECTOR_OBJECTS) $(DISSECTOR_SUPPORT_OBJECTS) plugin.obj
33
34 RESOURCE=$(PLUGIN_NAME).res
35
36 all: $(PLUGIN_NAME).dll
37
38 $(PLUGIN_NAME).rc : moduleinfo.nmake
39         sed -e s/@PLUGIN_NAME@/$(PLUGIN_NAME)/ \
40         -e s/@RC_MODULE_VERSION@/$(RC_MODULE_VERSION)/ \
41         -e s/@RC_VERSION@/$(RC_VERSION)/ \
42         -e s/@MODULE_VERSION@/$(MODULE_VERSION)/ \
43         -e s/@PACKAGE@/$(PACKAGE)/ \
44         -e s/@VERSION@/$(VERSION)/ \
45         -e s/@MSVC_VARIANT@/$(MSVC_VARIANT)/ \
46         < plugin.rc.in > $@
47
48 $(PLUGIN_NAME).dll $(PLUGIN_NAME).exp $(PLUGIN_NAME).lib : $(OBJECTS) $(LINK_PLUGIN_WITH) $(RESOURCE)
49         link -dll /out:$(PLUGIN_NAME).dll $(LDFLAGS) $(OBJECTS) $(LINK_PLUGIN_WITH) \
50         $(GLIB_LIBS) $(RESOURCE)
51
52 #
53 # Build plugin.c, which contains the plugin version[] string, a
54 # function plugin_register() that calls the register routines for all
55 # protocols, and a function plugin_reg_handoff() that calls the handoff
56 # registration routines for all protocols.
57 #
58 # We do this by scanning sources.  If that turns out to be too slow,
59 # maybe we could just require every .o file to have an register routine
60 # of a given name (packet-aarp.o -> proto_register_aarp, etc.).
61 #
62 # Formatting conventions:  The name of the proto_register_* routines an
63 # proto_reg_handoff_* routines must start in column zero, or must be
64 # preceded only by "void " starting in column zero, and must not be
65 # inside #if.
66 #
67 # DISSECTOR_SRC is assumed to have all the files that need to be scanned.
68 #
69 # For some unknown reason, having a big "for" loop in the Makefile
70 # to scan all the files doesn't work with some "make"s; they seem to
71 # pass only the first few names in the list to the shell, for some
72 # reason.
73 #
74 # Therefore, we have a script to generate the plugin.c file.
75 # The shell script runs slowly, as multiple greps and seds are run
76 # for each input file; this is especially slow on Windows.  Therefore,
77 # if Python is present (as indicated by PYTHON being defined), we run
78 # a faster Python script to do that work instead.
79 #
80 # The first argument is the directory in which the source files live.
81 # The second argument is "plugin", to indicate that we should build
82 # a plugin.c file for a plugin.
83 # All subsequent arguments are the files to scan.
84 #
85 plugin.c: $(DISSECTOR_SRC) ../../tools/make-dissector-reg.py ../../tools/make-dissector-reg
86 !IFDEF PYTHON
87         @echo Making plugin.c (using python)
88         @$(PYTHON) "../../tools/make-dissector-reg.py" . plugin $(DISSECTOR_SRC)
89 !ELSE
90         @echo Making plugin.c (using sh)
91         @$(SH) ../../tools/make-dissector-reg . plugin $(DISSECTOR_SRC)
92 !ENDIF
93
94 !ENDIF
95
96 clean:
97         rm -f $(OBJECTS) $(RESOURCE) plugin.c *.pdb \
98             $(PLUGIN_NAME).dll $(PLUGIN_NAME).dll.manifest $(PLUGIN_NAME).lib \
99             $(PLUGIN_NAME).exp $(PLUGIN_NAME).rc 
100
101 # We remove the generated files with "distclean" because one of them,
102 # "mate_parser.c", needs different #includes for UN*X and Windows
103 # (UN*X versions of Flex make it include <unistd.h>, but that's a
104 # UN*X-only header), so if you're going to build from source, you need
105 # to build "mate_parser.c" from "mate_parser.l" with Flex.
106 # This might not be necessary for "mate_grammar.{c,h}", but we handle them
107 # the same for now.
108 #
109 distclean: clean
110         rm -f mate_parser.c mate_parser_lex.h mate_grammar.c \
111         mate_grammar.h mate_grammar.out
112
113 maintainer-clean: distclean
114
115 RUNLEX = ..\..\tools\runlex.sh
116
117 mate_parser_lex.h : mate_parser.c
118 mate_parser.obj : mate_parser.c
119
120 mate_grammar.h : mate_grammar.c
121 mate_grammar.c : mate_grammar.lemon $(LEMON)\lemon.exe
122         $(LEMON)\lemon.exe t=$(LEMON)\lempar.c mate_grammar.lemon 
123
124 $(LEMON)\lemon.exe:
125         cd ../../tools/lemon
126         $(MAKE) /$(MAKEFLAGS) -f makefile.nmake
127         cd ../../plugins/mate