1# WMAKE makefile for 16 bit MSDOS or 32 bit DOS extender (PMODE/W or DOS/4GW)
2# using Watcom C/C++ v11.0+, by Paul Kienitz, last revised 16 Feb 2008.
3# Makes UnZip.exe, fUnZip.exe, and UnZipSFX.exe.
4#
5# Invoke from UnZip source dir with "WMAKE -F MSDOS\MAKEFILE.WAT [targets]".
6# To make the PMODE/W version use "WMAKE PM=1 ..."
7# To make the DOS/4GW version use "WMAKE GW=1 ..." (overrides PM=1)
8#   Note: specifying PM or GW without NOASM requires that the win32 source
9#   directory be present, so it can access the 32 bit assembly source.
10#   PMODE/W is recommended over DOS/4GW for best performance.
11# To build with debug info use "WMAKE DEBUG=1 ..."
12# To build with no assembly modules use "WMAKE NOASM=1 ..."
13# To omit unshrinking support use "WMAKE NO_LZW=1 ..."
14# To support unreducing, get the real unreduce.c and go "WMAKE OFFEND_RMS=1 ..."
15# To include support for bzip2 decompression (only for 32-bit), get the bzip2
16#  source distribution into the bzip2/ subfolder and start compilation
17#  with "WMAKE PM=1 USEBZ2=1 ..."
18#
19# Other options to be fed to the compiler can be specified in an environment
20# variable called LOCAL_UNZIP.
21
22variation = $(%LOCAL_UNZIP)
23
24# Stifle annoying "Delete this file?" questions when errors occur:
25.ERASE
26
27.EXTENSIONS:
28.EXTENSIONS: .exe .obj .obx .c .h .asm
29
30# We maintain multiple sets of object files in different directories so that
31# we can compile msdos, dos/4gw, and win32 versions of UnZip without their
32# object files interacting.  The following var must be a directory name
33# ending with a backslash.  All object file names must include this macro
34# at the beginning, for example "$(O)foo.obj".
35
36!ifdef GW
37PM = 1      # both protected mode formats use the same object files
38!endif
39
40!ifdef DEBUG
41!  ifdef PM
42OBDIR = od32d
43!  else
44OBDIR = od16d
45!  endif
46!else
47!  ifdef PM
48OBDIR = ob32d
49!  else
50OBDIR = ob16d
51!  endif
52!endif
53O = $(OBDIR)\   # comment here so backslash won't continue the line
54
55!ifdef NO_LZW
56cvars = $+$(cvars)$- -DLZW_CLEAN
57avars = $+$(avars)$- -DLZW_CLEAN
58# "$+$(foo)$-" means expand foo as it has been defined up to now; normally,
59# this Make defers inner expansion until the outer macro is expanded.
60!endif
61!ifdef OFFEND_RMS
62cvars = $+$(cvars)$- -DUSE_SMITH_CODE
63avars = $+$(avars)$- -DUSE_SMITH_CODE
64!endif
65
66IZ_BZIP2 = bzip2
67!ifdef USEBZ2
68!ifdef PM
69cvars = $+$(cvars)$- -DUSE_BZIP2 -I$(IZ_BZIP2)
70bz2errob = $(O)ubz2err.obj
71bz2errox = $(O)ubz2err.obj
72BZIPLIB = $(IZ_BZIP2)/$(OBDIR)/bz2.lib
73BZ2LNKLIB = lib {$(BZIPLIB)}
74!else
75bz2errob =
76bz2errox =
77BZIPLIB =
78BZ2LNKLIB =
79!endif
80!else
81bz2errob =
82bz2errox =
83BZIPLIB =
84BZ2LNKLIB =
85!endif
86
87# The assembly hot-spot code in crc_i[3]86.asm is optional.  This section
88# controls its usage.
89
90!ifdef NOASM
91crcaob =
92crcaof =
93crcaox =
94!else   # !NOASM
95cvars = $+$(cvars)$- -DASM_CRC
96!  ifdef PM
97crcaob = $(O)crc_i386.obj
98crcaof = $(O)crc_i38f.obj
99crcaox = $(O)crc_i386.obx
100crc_s = win32\crc_i386.asm   # requires that the win32 directory be present
101!  else
102crcaob = $(O)crc_i86.obj
103crcaof = $(O)crc_i8f.obj
104crcaox = $(O)crc_i86.obx
105crc_s = msdos\crc_i86.asm
106!  endif
107!endif
108
109# Our object files: OBJ[A-C] is for UnZip, OBJX for UnZipSFX, OBJF for fUnZip:
110
111OBJA1 = $(O)unzip.obj $(O)crc32.obj $(crcaob) $(O)crypt.obj $(O)envargs.obj
112OBJA  = $(OBJA1) $(O)explode.obj $(O)extract.obj $(O)fileio.obj $(O)globals.obj
113OBJB2 = $(O)inflate.obj $(O)list.obj $(O)match.obj $(O)process.obj
114OBJB  = $(OBJB2) $(O)ttyio.obj $(bz2errob) $(O)unreduce.obj
115OBJC  = $(O)unshrink.obj $(O)zipinfo.obj $(O)msdos.obj
116
117OBJX2 = $(O)unzip.obx $(O)crc32.obx $(crcaox) $(O)crypt.obx $(O)extract.obx
118OBJX1 = $(OBJX2) $(O)fileio.obx $(O)globals.obx $(O)inflate.obx $(O)match.obx
119OBJX  = $(OBJX1) $(O)process.obx $(bz2errox) $(O)ttyio.obx $(O)msdos.obx
120
121OBJF1  = $(O)funzip.obj $(O)crc32f.obj $(crcaof) $(O)cryptf.obj $(O)globalsf.obj
122OBJF  = $(OBJF1) $(O)inflatef.obj $(O)ttyiof.obj $(O)msdosf.obj
123
124# Common header files included by all C sources:
125
126UNZIP_H = unzip.h unzpriv.h globals.h msdos\doscfg.h
127
128# Now we have to pick out the proper compiler and options for it.  This gets
129# pretty complicated with the PM, GW, DEBUG, and NOASM options...
130
131link   = wlink
132asm    = wasm
133
134!ifdef PM
135cc     = wcc386
136# Use Pentium Pro timings, flat memory, static strings in code, max strictness:
137cflags = -bt=DOS -mf -6r -zt -zq -wx
138aflags = -bt=DOS -mf -3 -zq
139cflagf = $(cflags)
140aflagf = $(aflags)
141cflagx = $(cflags)
142aflagx = $(aflags)
143
144!  ifdef GW
145lflags = sys DOS4G
146!  else
147# THIS REQUIRES THAT PMODEW.EXE BE FINDABLE IN THE COMMAND PATH.
148# It does NOT require you to add a pmodew entry to wlink.lnk or wlsystem.lnk.
149defaultlibs = libpath %WATCOM%\lib386 libpath %WATCOM%\lib386\dos
150lflags = format os2 le op osname='PMODE/W' op stub=pmodew.exe $(defaultlibs)
151!  endif
152
153!else   # plain 16-bit DOS:
154
155cc     = wcc
156# Use plain 8086 code, large memory, static strings in code, max strictness:
157cflags = -bt=DOS -ml -0 -zt -zq -wx
158aflags = -bt=DOS -ml -0 -zq
159# for fUnZip, Deflate64 support requires the compact memory model:
160cflagf = -bt=DOS -mc -0 -zt -zq -wx
161aflagf = -bt=DOS -mc -0 -zq
162# for UnZipSFX (without Deflate64 support), use the small memory model:
163cflagx = -bt=DOS -ms -0 -zt -zq -wx
164aflagx = -bt=DOS -ms -0 -zq
165lflags = sys DOS
166!endif  # !PM
167
168cvars  = $+$(cvars)$- -DMSDOS $(variation)
169avars  = $+$(avars)$- $(variation)
170
171
172# Specify optimizations, or a nonoptimized debugging version:
173
174!ifdef DEBUG
175cdebug = -od -d2
176cdebux = -od -d2
177ldebug = d w all op symf
178!else
179!  ifdef PM
180cdebug = -s -obhikl+rt -oe=100 -zp8
181# -oa helps slightly but might be dangerous.
182!  else
183cdebug = -s -oehiklrt
184!  endif
185cdebux = -s -obhiklrs
186ldebug = op el
187!endif
188
189# How to compile sources:
190.c.obx:
191	$(cc) $(cdebux) $(cflagx) $(cvars) -DSFX $[@ -fo=$@
192
193.c.obj:
194	$(cc) $(cdebug) $(cflags) $(cvars) $[@ -fo=$@
195
196# Here we go!  By default, make all targets, except no UnZipSFX for PMODE:
197!ifdef PM
198all: UnZip.exe fUnZip.exe
199!else
200all: UnZip.exe fUnZip.exe UnZipSFX.exe
201!endif
202
203# Convenient shorthand options for single targets:
204u:   UnZip.exe     .SYMBOLIC
205f:   fUnZip.exe    .SYMBOLIC
206x:   UnZipSFX.exe  .SYMBOLIC
207
208UnZip.exe:	$(OBDIR) $(OBJA) $(OBJB) $(OBJC) $(BZIPLIB)
209	set WLK_VA=file {$(OBJA)}
210	set WLK_VB=file {$(OBJB)}
211        set WLK_VC=file {$(OBJC)} $(BZ2LNKLIB)
212	$(link) $(lflags) $(ldebug) name $@ @WLK_VA @WLK_VB @WLK_VC
213	set WLK_VA=
214	set WLK_VB=
215        set WLK_VC=
216# We use WLK_VA/WLK_VB/WLK_VC to keep the size of each command below 256 chars.
217
218UnZipSFX.exe:	$(OBDIR) $(OBJX) $(BZIPLIB)
219	set WLK_VX=file {$(OBJX)}
220	$(link) $(lflags) $(ldebug) name $@ @WLK_VX
221	set WLK_VX=
222
223fUnZip.exe:	$(OBDIR) $(OBJF)
224	set WLK_VF=file {$(OBJF)}
225	$(link) $(lflags) $(ldebug) name $@ @WLK_VF
226	set WLK_VF=
227
228
229# Source dependencies:
230
231#       for UnZip ...
232
233$(O)crc32.obj:    crc32.c $(UNZIP_H) zip.h crc32.h
234$(O)crypt.obj:    crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
235$(O)envargs.obj:  envargs.c $(UNZIP_H)
236$(O)explode.obj:  explode.c $(UNZIP_H)
237$(O)extract.obj:  extract.c $(UNZIP_H) crc32.h crypt.h
238$(O)fileio.obj:   fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
239$(O)globals.obj:  globals.c $(UNZIP_H)
240$(O)inflate.obj:  inflate.c inflate.h $(UNZIP_H)
241$(O)list.obj:     list.c $(UNZIP_H)
242$(O)match.obj:    match.c $(UNZIP_H)
243$(O)process.obj:  process.c $(UNZIP_H) crc32.h
244$(O)ttyio.obj:    ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
245$(O)ubz2err.obj:  ubz2err.c $(UNZIP_H)
246$(O)unreduce.obj: unreduce.c $(UNZIP_H)
247$(O)unshrink.obj: unshrink.c $(UNZIP_H)
248$(O)unzip.obj:    unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
249$(O)zipinfo.obj:  zipinfo.c $(UNZIP_H)
250
251#       for UnZipSFX ...
252
253$(O)crc32.obx:    crc32.c $(UNZIP_H) zip.h crc32.h
254$(O)crypt.obx:    crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
255$(O)extract.obx:  extract.c $(UNZIP_H) crc32.h crypt.h
256$(O)fileio.obx:   fileio.c $(UNZIP_H) crc32.h crypt.h ttyio.h ebcdic.h
257$(O)globals.obx:  globals.c $(UNZIP_H)
258$(O)inflate.obx:  inflate.c inflate.h $(UNZIP_H)
259$(O)match.obx:    match.c $(UNZIP_H)
260$(O)process.obx:  process.c $(UNZIP_H) crc32.h
261$(O)ttyio.obx:    ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
262$(O)ubz2err.obx:  ubz2err.c $(UNZIP_H)
263$(O)unzip.obx:    unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
264
265# Special case object files:
266
267$(O)msdos.obj:    msdos\msdos.c $(UNZIP_H)
268	$(cc) $(cdebug) $(cflags) $(cvars) msdos\msdos.c -fo=$@
269
270$(O)msdos.obx:    msdos\msdos.c $(UNZIP_H)
271	$(cc) $(cdebux) $(cflagx) $(cvars) -DSFX msdos\msdos.c -fo=$@
272
273!ifndef NOASM
274$(crcaob):        $(crc_s)
275	$(asm) $(aflags) $(avars) $(crc_s) -fo=$@
276
277$(crcaof):        $(crc_s)
278	$(asm) $(aflagf) $(avars) $(crc_s) -fo=$@
279
280$(crcaox):        $(crc_s)
281	$(asm) $(aflagx) $(avars) $(crc_s) -fo=$@
282!endif
283
284# Variant object files for fUnZip, using $(cflagf):
285
286$(O)funzip.obj:   funzip.c $(UNZIP_H) crc32.h crypt.h ttyio.h
287	$(cc) $(cdebux) $(cflagf) $(cvars) funzip.c -fo=$@
288
289$(O)crc32f.obj:   crc32.c $(UNZIP_H) zip.h crc32.h
290	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP crc32.c -fo=$@
291
292$(O)cryptf.obj:   crypt.c $(UNZIP_H) zip.h crypt.h crc32.h ttyio.h
293	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP crypt.c -fo=$@
294
295$(O)globalsf.obj: globals.c $(UNZIP_H)
296	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP globals.c -fo=$@
297
298$(O)inflatef.obj: inflate.c inflate.h $(UNZIP_H) crypt.h
299	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP inflate.c -fo=$@
300
301$(O)ttyiof.obj:   ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
302	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP ttyio.c -fo=$@
303
304$(O)msdosf.obj:    msdos\msdos.c $(UNZIP_H)
305	$(cc) $(cdebux) $(cflagf) $(cvars) -DFUNZIP msdos\msdos.c -fo=$@
306
307# The bzip2 (de)compression library for BZIP2 support:
308$(IZ_BZIP2)/$(OBDIR)/bz2.lib : .ALWAYS .RECHECK
309	$(MAKE) -h -f $(IZ_BZIP2)/makbz2iz.wat CC=$(cc) AR=lib386 &
310	CFLSYS="$(cdebug) $(cflags)" &
311	BZROOTDIR=$(IZ_BZIP2) BZOBDIR=$(IZ_BZIP2)/$(OBDIR)
312
313# Creation of subdirectory for intermediate files
314$(OBDIR):
315	-mkdir $@
316
317# Unwanted file removal:
318
319clean_bz2_lib: .SYMBOLIC
320	$(MAKE) -h -f $(IZ_BZIP2)/makbz2iz.wat &
321	BZROOTDIR=$(IZ_BZIP2) BZOBDIR=$(IZ_BZIP2)\$(OBDIR) clean
322
323clean:     clean_bz2_lib  .SYMBOLIC
324	del $(O)*.ob?
325
326cleaner:   clean  .SYMBOLIC
327	del UnZip.exe
328	del fUnZip.exe
329	del UnZipSFX.exe
330