# Makefile for Zip, ZipCloak, ZipNote and ZipSplit for
# djgpp 2.x
#
# This simple modified version of makefile.dj2 adds bzip2 support
# to Zip for djgpp 2.x and was donated by Robert Riebisch.
#
# Given standard djgpp 2.x and bzip2 installations, this should create a
# version of Zip 3.0 with bzip2 support.  Additional information is in
# bzip2/install.txt.
#
# 27 June 2008

VPATH=.;msdos
# ------------- djgpp -------------
CPPFLAGS=-I. -DDOS -DASM_CRC -DBZIP2_SUPPORT $(LOCAL_ZIP)
ASFLAGS=$(CPPFLAGS)
CFLAGS=-Wall -O2 $(CPPFLAGS)
UTILFLAGS=-c -DUTIL $(CFLAGS) -o
CC=gcc
LD=gcc
LDFLAGS=-s

# ------------- file packer --------
# Laszlo Molnar who wrote DJ Packer and Markus F. X. J. Oberhumer who wrote
# the compression library used by the DJ Packer have collaborated on the
# Ultimate Packer for eXecutables, which has recently been released.  Look
# for upx???d.zip at     http://upx.sourceforge.net
# As an alternative, look for "djp.exe", now two years old, in the archive
# mlp107[b,s].zip, found in the same location as csdpmi?[b,s].zip (see below).
# If you have got an executable packer in your PATH, you may reduce the
# size of the disk image of the zip*.exe's by uncommenting the lines
# containing $(DJP) below where the exe's are built.
#DJP=djp -q
DJP=upx -qq --best

# variables

#set CRC32 to crc_gcc.o or nothing, depending on whether ASM_CRC is defined:
CRCA_O = crc_gcc.o

OBJZ = zip.o crypt.o ttyio.o zipfile.o zipup.o fileio.o util.o \
	crc32.o $(CRCA_O) globals.o
OBJI = deflate.o trees.o match.o msdos.o
OBJU = zipfile_.o fileio_.o util_.o globals.o msdos_.o
OBJN = zipnote.o $(OBJU)
OBJC = zipcloak.o crc32_.o crypt_.o ttyio.o $(OBJU)
OBJS = zipsplit.o $(OBJU)
LIBS = -lbz2

ZIP_H = zip.h ziperr.h tailor.h msdos/osdep.h

# rules

.SUFFIXES:    # Delete make's default suffix list
.SUFFIXES:    .exe .out .a .ln .o .c .cc .C .p .f .F .y .l .s .S .h

.c.o:
	$(CC) -c $(CFLAGS) $< -o $@

zips:	zip.exe zipnote.exe zipsplit.exe zipcloak.exe

zip.o:	      zip.c $(ZIP_H) revision.h crc32.h crypt.h ttyio.h

zipfile.o:    zipfile.c $(ZIP_H) crc32.h

zipup.o:      zipup.c $(ZIP_H) revision.h crc32.h crypt.h msdos/zipup.h

fileio.o:     fileio.c $(ZIP_H) crc32.h

util.o:       util.c $(ZIP_H)

globals.o:    globals.c $(ZIP_H)

deflate.o:    deflate.c $(ZIP_H)

trees.o:      trees.c $(ZIP_H)

crc_gcc.o:    crc_i386.S
	$(CC) $(ASFLAGS) -x assembler-with-cpp -c -o $@ crc_i386.S

crc32.o:      crc32.c $(ZIP_H) crc32.h

crypt.o:      crypt.c $(ZIP_H) crypt.h crc32.h ttyio.h

ttyio.o:      ttyio.c $(ZIP_H) crypt.h ttyio.h

msdos.o:      msdos/msdos.c $(ZIP_H)

zipcloak.o:   zipcloak.c $(ZIP_H) revision.h crc32.h crypt.h ttyio.h

zipnote.o:    zipnote.c $(ZIP_H) revision.h

zipsplit.o:   zipsplit.c $(ZIP_H) revision.h

zipfile_.o:   zipfile.c $(ZIP_H) crc32.h
	$(CC) $(UTILFLAGS) $@ zipfile.c

fileio_.o:    fileio.c $(ZIP_H) crc32.h
	$(CC) $(UTILFLAGS) $@ fileio.c

util_.o:      util.c $(ZIP_H)
	$(CC) $(UTILFLAGS) $@ util.c

crc32_.o:     crc32.c $(ZIP_H) crc32.h
	$(CC) $(UTILFLAGS) $@ crc32.c

crypt_.o:     crypt.c $(ZIP_H) crypt.h crc32.h ttyio.h
	$(CC) $(UTILFLAGS) $@ crypt.c

msdos_.o:     msdos/msdos.c $(ZIP_H)
	$(CC) $(UTILFLAGS) $@ msdos/msdos.c


match.o:      match.S
	$(CC) $(ASFLAGS) -x assembler-with-cpp -c -o $@ match.S

zip.exe: $(OBJZ) $(OBJI)
	echo $(OBJZ) > zip.rsp
	echo $(OBJI) >> zip.rsp
	echo $(LIBS) >> zip.rsp
	$(LD) $(LDFLAGS) -o $@ @zip.rsp
	del zip.rsp
#	stubedit $@ dpmi=cwsdpmi.exe
#	$(DJP) $@

zipcloak.exe: $(OBJC)
	$(LD) $(LDFLAGS) $(OBJC) -o $@
#	stubedit $@ dpmi=cwsdpmi.exe
#	$(DJP) $@

zipnote.exe: $(OBJN)
	$(LD) $(LDFLAGS) $(OBJN) -o $@
#	stubedit $@ dpmi=cwsdpmi.exe
#	$(DJP) $@

zipsplit.exe: $(OBJS)
	$(LD) $(LDFLAGS) $(OBJS) -o $@
#	stubedit $@ dpmi=cwsdpmi.exe
#	$(DJP) $@

# These stand alone executables require dpmi services to run.  When
# running in a DOS window under windows 3.1 or later, the dpmi server
# is automatically present.  Under DOS, if a dpmi server is not installed,
# by default the program will look for "cwsdpmi.exe." If found, it will
# be loaded for the duration of the program.
# cwsdpmi is a "free" dpmi server written by Charles W. Sandmann
# (sandman@clio.rice.edu).  It may be found, among other sites, on SimTel
# and its mirrors in the .../vendors/djgpp/v2misc directory.
