# Makefile for zlib

# WARNING: the small model is supported but only for small values of
# MAX_WBITS and MAX_MEM_LEVEL. If you wish to reduce the memory
# requirements (default 256K for big objects plus a few K), you can add
# to CFLAGS below: -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14
# See zconf.h for details about the memory requirements.

!if "$(RM)" == ""
RM= erase
!endif

!ifndef FINAL
FINAL=0
!endif

!if "$(FINAL)" == "0"
CFLAGS=/Od $(CRTFLAG) /GX /Fo$@
_CRTFLAG=/MDd
!else if "$(FINAL)" == "hybrid"
CFLAGS=/Od $(CRTFLAG) /GX /Fo$@
_CRTFLAG=/MD
!else
CFLAGS=-O2 $(CRTFLAG) /GX /Fo$@
_CRTFLAG=/MD
!endif

!if "$(CRTFLAG)" == ""
CRTFLAG=$(_CRTFLAG)
!endif


CC=cl
LD=cl
LIB=tlib
LDFLAGS=$(MODEL)
O=.obj

!if "$(FINAL)" == "1"
LIBTARGET=..\..\lib\zlib.lib
D=Release
!else if "$(FINAL)" == "hybrid"
LIBTARGET=..\..\lib\zlibh.lib
D=Hybrid
!else
LIBTARGET=..\..\lib\zlibd.lib
D=Debug
!endif

# variables
OBJ1 = $D\adler32$(O) $D\compress$(O) $D\crc32$(O) $D\gzio$(O) \
  $D\uncompr$(O) $D\deflate$(O) $D\trees$(O)
OBJ2 = $D\zutil$(O) $D\inflate$(O) $D\infblock$(O) $D\inftrees$(O) \
  $D\infcodes$(O) $D\infutil$(O) $D\inffast$(O)

all: $D $(LIBTARGET)

$D:
    mkdir .\$D

$D\adler32.obj: adler32.c zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\compress.obj: compress.c zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\crc32.obj: crc32.c zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\gzio.obj: gzio.c zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\infblock.obj: infblock.c zutil.h zlib.h zconf.h infblock.h inftrees.h\
   infcodes.h infutil.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\infcodes.obj: infcodes.c zutil.h zlib.h zconf.h inftrees.h infutil.h\
   infcodes.h inffast.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\inflate.obj: inflate.c zutil.h zlib.h zconf.h infblock.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\infutil.obj: infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\trees.obj: trees.c deflate.h zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\uncompr.obj: uncompr.c zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

$D\zutil.obj: zutil.c zutil.h zlib.h zconf.h
	$(CC) -c $(CFLAGS) $(*B).c

LIBOBJECTS = $(OBJ1) $(OBJ2)

$(LIBTARGET): $(LIBOBJECTS)
        -erase $(LIBTARGET)
        lib @<<
-out:$(LIBTARGET)
$(LIBOBJECTS)
<<

clean:
    -$(RM) $D\*.obj
    -$(RM) *.exe
    -$(RM) *.sbr
    -$(RM) $(LIBTARGET)
