# Makefile for zlib
#   adapted from Makefile for libpng
# 32-bit Borland C++ (Note: All modules are compiled in C mode)
# To build the library, do:
#       "make -fmakefile.bc32"
#
# -------------------- 32-bit Borland C++ --------------------

### Absolutely necessary for this makefile to work
.AUTODEPEND

## Where zlib.h, zconf.h and zlib.lib are
ZLIB_DIR=.


## Compiler, linker and lib stuff
CC=bcc32
LD=bcc32
LIB=tlib

TARGET_CPU=3
# 3 = 386, 4 = 486, 5 = Pentium etc.
!ifndef TARGET_CPU
TARGET_CPU=5
!endif

# Use this if you don't want Borland's fancy exception handling
#NOEHLIB=noeh32.lib

!ifdef DEBUG
CDEBUG=-v
LDEBUG=-v
!else
CDEBUG=
LDEBUG=
!endif

# STACKOFLOW=1
!ifdef STACKOFLOW
CDEBUG=$(CDEBUG) -N
LDEBUG=$(LDEBUG) -N
!endif

# -X- turn on dependency generation in the object file
# -w  set all warnings on
# -O2 optimize for speed
# -Z  global optimization
CFLAGS=-O2 -Z -X- -w -I$(ZLIB_DIR) -$(TARGET_CPU) $(CDEBUG)

# -M  generate map file
LDFLAGS=-M -L$(ZLIB_DIR) $(LDEBUG)


## Variables
OBJS = \
   adler32.obj \
   compress.obj \
   crc32.obj \
   gzio.obj \
   uncompr.obj \
   deflate.obj \
   trees.obj \
   zutil.obj \
   inflate.obj \
   infblock.obj \
   inftrees.obj \
   infcodes.obj \
   infutil.obj \
   inffast.obj

LIBOBJS = \
   +adler32.obj \
   +compress.obj \
   +crc32.obj \
   +gzio.obj \
   +uncompr.obj \
   +deflate.obj \
   +trees.obj \
   +zutil.obj \
   +inflate.obj \
   +infblock.obj \
   +inftrees.obj \
   +infcodes.obj \
   +infutil.obj \
   +inffast.obj


LIBNAME=zlib.lib


## Implicit rules
# Braces let make "batch" calls to the compiler,
# 2 calls instead of 12; space is important.
.c.obj:
	$(CC) $(CFLAGS) -c {$*.c }

.c.exe:
	$(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) $(NOEHLIB)

.obj.exe:
	$(LD) $(LDFLAGS) $*.obj $(LIBNAME) $(NOEHLIB)


## Major targets
all: zlib.lib example.exe minigzip.exe

zlib: $(LIBNAME)

example: example.exe

minigzip: minigzip.exe

test: example.exe minigzip.exe
   example
	echo hello world | minigzip | minigzip -d 


## Minor Targets

adler32.obj: adler32.c
compress.obj: compress.c
crc32.obj: crc32.c
deflate.obj: deflate.c
gzio.obj: gzio.c
infblock.obj: infblock.c
infcodes.obj: infcodes.c
inflate.obj: inflate.c
inftrees.obj: inftrees.c
infutil.obj: infutil.c
inffast.obj: inffast.c
trees.obj: trees.c
uncompr.obj: uncompr.c
zutil.obj: zutil.c
example.obj: example.c
minigzip.obj: minigzip.c
example.exe: example.obj zlib.lib
minigzip.exe: minigzip.obj zlib.lib


$(LIBNAME): $(OBJS)
	-del $(LIBNAME)
	$(LIB) $(LIBNAME) @&&|
$(LIBOBJS), zlib
|


# Clean up anything else you want
clean:
	-del *.obj
	-del *.exe
	-del *.lib
	-del *.lst
	-del *.map
	-del *.tds


# End of makefile for zlib
