b094e4e927e4b7f88302f1d7352279da849513ee
[yazproxy-moved-to-github.git] / win / makefile
1 # Copyright (C) 1998-2011 Index Data
2 # All rights reserved.
3
4 ###########################################################
5 ############### Parameters 
6 ###########################################################
7
8 DEBUG=0   # 0 for release, 1 for debug
9
10 # YAZ and YAZ++
11 YAZ_DIR=..\..\yaz
12 YAZPP_DIR=..\..\yazpp
13
14 # iconv charcter conversion utility
15 HAVE_ICONV=1
16 ICONV_DIR=\iconv-1.9.2.win32
17
18 # libxslt
19 HAVE_LIBXSLT=1
20 LIBXSLT_DIR=\libxslt-1.1.26.win32
21
22 # libxml2 (used by libxslt)
23 HAVE_LIBXML2=1
24 LIBXML2_DIR=\libxml2-2.7.6.win32
25
26 # zlib compression (used by libxml2)
27 ZLIB_DIR=\zlib-1.2.3.win32
28
29 # get WIN32 binaries for libxslt, libxml, iconv, zlib from here:
30 # http://www.zlatkovic.com/libxml.en.html
31
32 default: all
33
34 all: dirs dll proxy iconv libxml2 libxslt yaz yazpp
35
36 NSIS="c:\program files\nsis\makensis-bz2.exe"
37
38 nsis: all
39         $(NSIS) yazpp.nsi
40
41 nsishelp:
42         $(NSIS)
43
44 # The current directory is supposed to be something like
45 # ..../yaz/win, everything is relative to that
46 ROOTDIR=..   # The home of yaz++
47
48 INCLDIR=$(ROOTDIR)\include  # our includes
49 LIBDIR=$(ROOTDIR)\lib       # We produce .lib, .exp etc there
50 BINDIR=$(ROOTDIR)\bin       # We produce exes and dlls there
51 WINDIR=$(ROOTDIR)\win       # all these Win make things
52 SRCDIR=$(ROOTDIR)\src       # for the case we move them under src
53 PROXYDIR=$(ROOTDIR)\proxy
54 ZOOMDIR=$(ROOTDIR)\zoom
55
56 !if $(DEBUG)
57 OBJDIR=$(WINDIR)\dobj       # where we store intermediate files
58 !else
59 OBJDIR=$(WINDIR)\obj        # where we store intermediate files
60 !endif
61
62 TMPDIR=$(ROOTDIR)\win\tmp
63 TMP=$(TMPDIR)
64
65 YAZPROXY_DLL=$(BINDIR)\yazproxy2.dll
66 YAZPROXY_IMPLIB=$(LIBDIR)\yazproxy2.lib
67
68 YAZPROXY=$(BINDIR)\yazproxy.exe
69
70 # shortcut names defined here
71 dll: $(YAZPROXY_DLL)
72 proxy: $(YAZPROXY)
73
74 !if $(DEBUG)
75 YAZD=yaz4d
76 YAZPPD=yazpp4d
77 !else
78 YAZD=yaz4
79 YAZPPD=yazpp4
80 !endif
81
82 # YAZ includes & libs
83 YAZ_LIB="$(YAZ_DIR)\lib\$(YAZD).lib"
84 YAZ_DEF=/DYAZ_HAVE_XML2=1 /DYAZ_USE_NEW_LOG=1 /I"$(YAZ_DIR)\include"
85
86 # Copy yaz.dll to our bin
87 yaz: $(BINDIR)\$(YAZD).dll
88 $(BINDIR)\$(YAZD).dll: "$(YAZ_DIR)\bin\$(YAZD).dll"
89   copy "$(YAZ_DIR)\bin\$(YAZD).dll" $(BINDIR)
90
91 # YAZ++ includes & libs
92 YAZPP_LIB="$(YAZPP_DIR)\lib\$(YAZPPD).lib"
93 YAZPP_DEF=/I"$(YAZPP_DIR)\include"
94
95 # Copy yazpp.dll to our bin
96 yazpp: $(BINDIR)\$(YAZPPD).dll
97 $(BINDIR)\$(YAZPPD).dll: "$(YAZPP_DIR)\bin\$(YAZPPD).dll"
98   copy "$(YAZPP_DIR)\bin\$(YAZPPD).dll" $(BINDIR)
99
100 !if $(HAVE_ICONV)
101 ICONV_DEF= \
102   /D HAVE_ICONV_H=1 \
103   /I"$(ICONV_DIR)\include"
104 ICONV_LIB= \
105   "$(ICONV_DIR)\lib\iconv.lib"
106 iconv: $(BINDIR)\iconv.dll
107
108 $(BINDIR)\iconv.dll:
109   copy "$(ICONV_DIR)\bin\iconv.dll" $(BINDIR)
110 !else
111 ICONV_DEF= \
112   /D HAVE_ICONV_H=0
113 ICONV_LIB=
114 iconv:
115
116 !endif
117
118 !if $(HAVE_LIBXML2)
119 LIBXML2_LIB="$(LIBXML2_DIR)\lib\libxml2.lib"
120 LIBXML2_DEF=/D HAVE_XML2=1 /I"$(LIBXML2_DIR)\include"
121 libxml2: $(BINDIR)\libxml2.dll $(BINDIR)\zlib1.dll
122
123 $(BINDIR)\libxml2.dll:
124   copy "$(LIBXML2_DIR)\bin\libxml2.dll" $(BINDIR)
125
126 $(BINDIR)\zlib1.dll:
127   copy "$(ZLIB_DIR)\bin\zlib1.dll" $(BINDIR)
128
129 !else
130 LIBXML2_LIB=
131 LIBXML2_DEF=/D HAVE_XML2=0
132 libxml2: 
133
134 !endif
135
136 !if $(HAVE_LIBXSLT)
137 LIBXSLT_LIB="$(LIBXSLT_DIR)\lib\libxslt.lib"
138 LIBXSLT_DEF=/D YAZ_HAVE_XSLT=1 /I"$(LIBXSLT_DIR)\include"
139 libxslt: $(BINDIR)\libxslt.dll $(BINDIR)\zlib1.dll
140
141 $(BINDIR)\libxslt.dll:
142   copy "$(LIBXSLT_DIR)\bin\libxslt.dll" $(BINDIR)
143
144 !else
145 LIBXSLT_LIB=
146 LIBXSLT_DEF=/D YAZ_HAVE_XSLT=0
147 libxslt: 
148
149 !endif
150
151
152 ### C and CPP compiler  (the same thing)
153 # Note: $(CPP) has already been defined in the environment
154 # (if you set things up right!)
155
156 COMMON_C_OPTIONS=          \
157   /nologo /W3 /EHsc /FD /c \
158   /D "_CRT_SECURE_NO_DEPRECATE" \
159   $(ICONV_DEF)             \
160   $(YAZ_DEF)               \
161   $(YAZPP_DEF)             \
162   $(LIBXML2_DEF)           \
163   $(LIBXSLT_DEF)           \
164   /D "_WINDOWS"            \
165   /D "WIN32"               \
166   /D "HAVE_WCHAR_H=1"      \
167   /FR"$(OBJDIR)\\"         \
168   /Fo"$(OBJDIR)\\"         \
169   /Fd"$(OBJDIR)\\" 
170
171 COMMON_C_INCLUDES= \
172   /I"$(ROOTDIR)\include"
173
174 DEBUG_C_OPTIONS=  \
175   /D "_DEBUG"      \
176   /MDd  /Od /Zi /Gm
177
178 RELEASE_C_OPTIONS=  \
179   /D "NDEBUG"        \
180   /MD /O2
181
182 # /W3  = warning level
183 # /EHsc= Enable exception handling
184 # /FD  = Generate file dependencies (what ever they are)
185 # /c   = compile without linking
186 # /FR  = Generate browse info (.sbr file that gets combined into .bsc)
187 # /Fo  = object file name (or at least path)
188 # /Fd  = debug database name (or path)
189 # /MD  = Runtime library: Multithread DLL
190 # /MDd = Runtime library: Multithread DLL (debug)
191 # /Od  = Disable optimising (debug)
192 # /O2  = Optimize for speed
193 # /Gm  = Minimal rebuild (some cpp class stuff)
194 # /Zi  = Program database for debuggers
195 # /ZI  = Pgm database with special "edit&continue" stuff - not available in C5
196
197
198 ### Linker options
199 LINK=link.exe
200
201 LINK_LIBS=kernel32.lib advapi32.lib ws2_32.lib \
202            $(YAZ_LIB) $(YAZPP_LIB) $(ICONV_LIB) $(LIBXML2_LIB) $(LIBXSLT_LIB)
203
204 COMMON_LNK_OPTIONS= /nologo /subsystem:windows /incremental:no
205
206 DEBUG_LNK_OPTIONS= /debug 
207
208 RELEASE_LNK_OPTIONS=
209
210 DLL_LINK_OPTIONS= /dll  
211 CLIENT_LINK_OPTIONS = /subsystem:console  
212
213 # Final opt variables
214 !if $(DEBUG)
215 COPT=   $(COMMON_C_OPTIONS)   $(DEBUG_C_OPTIONS)     $(COMMON_C_INCLUDES)
216 MTLOPT= $(COMMON_MTL_OPTIONS) $(DEBUG_MTL_OPTIONS)
217 RCOPT=  $(COMMON_RC_OPTIONS)  $(DEBUG_RC_OPTIONS)
218 LNKOPT= $(COMMON_LNK_OPTIONS) $(DEBUG_LNK_OPTIONS)   $(LNK_LIBS)
219 TCLOPT= $(COMMON_TCL_OPTIONS)
220
221 !else
222 COPT=   $(COMMON_C_OPTIONS)   $(RELEASE_C_OPTIONS)   $(COMMON_C_INCLUDES) 
223 MTLOPT= $(COMMON_MTL_OPTIONS) $(RELEASE_MTL_OPTIONS)
224 RCOPT=  $(COMMON_RC_OPTIONS)  $(RELEASE_RC_OPTIONS)
225 LNKOPT= $(COMMON_LNK_OPTIONS) $(RELEASE_LNK_OPTIONS) $(LNK_LIBS)
226 TCLOPT= $(COMMON_TCL_OPTIONS)
227 !endif
228
229 # Source and object modules
230
231 YAZPROXY_OBJS= \
232    "$(OBJDIR)\yaz-proxy-main.obj"
233
234 YAZPROXY_DLL_OBJS = \
235    "$(OBJDIR)\yaz-proxy.obj" \
236    "$(OBJDIR)\yaz-proxy-config.obj" \
237    "$(OBJDIR)\yaz-usemarcon.obj" \
238    "$(OBJDIR)\msg-thread.obj" \
239    "$(OBJDIR)\charset-converter.obj" \
240    "$(OBJDIR)\limit-connect.obj" \
241    "$(OBJDIR)\modules.obj" \
242    "$(OBJDIR)\yaz-bw.obj"
243
244 ###########################################################
245 ############### Compiling 
246 ###########################################################
247
248 # Note: This defines where to look for the necessary
249 # source files. Funny way of doing it, but it works.
250
251 {$(SRCDIR)}.cpp{$(OBJDIR)}.obj:
252         $(CPP) $(COPT) $< 
253
254 ###########################################################
255 ############### Resources
256 ###########################################################
257
258 ### The RC compiler (resource files)
259 RSC=rc.exe
260 COMMON_RC_OPTIONS= /l 0x406 /i"$(ROOTDIR)" 
261 DEBUG_RC_OPTIONS=/d "_DEBUG"
262 RELEASE_RC_OPTIONS=/d "NDEBUG"
263
264 !if $(DEBUG)
265 RSOPT=/d_DEBUG
266 !else
267 RSOPT=/d_NDEBUG
268 !endif
269
270 ###########################################################
271 ############### Linking
272 ###########################################################
273
274 $(YAZPROXY_DLL) $(YAZPROXY_IMPLIB): "$(BINDIR)" $(YAZPROXY_DLL_OBJS)
275         $(LINK) \
276                 $(LNKOPT)  \
277                 $(LINK_LIBS)  \
278                 $(DLL_LINK_OPTIONS) \
279                 $(YAZPP_IMPLIB) \
280                 $(YAZPROXY_DLL_OBJS) \
281                 /out:$(YAZPROXY_DLL)  \
282                 /implib:"$(YAZPROXY_IMPLIB)" \
283
284 $(YAZPROXY) : "$(BINDIR)" $(YAZPROXY_OBJS) $(YAZPROXY_IMPLIB)
285         $(LINK) \
286                 $(LNKOPT)  \
287                 $(CLIENT_LINK_OPTIONS) \
288                 $(LINK_LIBS)  \
289                 $(YAZPP_IMPLIB) \
290                 $(YAZPROXY_IMPLIB) \
291                 $(YAZPROXY_OBJS) \
292                 /out:$(YAZPROXY)
293
294 clean:
295         -del $(BINDIR)\*.exe
296         -del $(BINDIR)\*.dll
297         -del $(TMPDIR)\*.
298         -del $(LIBDIR)\*.LIB
299         -del $(OBJDIR)\*.OBJ
300
301 realclean: clean
302
303 ########### check directories and create if needed
304 dirs: $(OBJDIR) $(WINDIR) $(LIBDIR) $(BINDIR) $(TMPDIR)
305
306 $(OBJDIR) $(WINDIR) $(LIBDIR) $(BINDIR) $(TMPDIR):
307         if not exist "$@/$(NUL)" mkdir "$@"
308