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