# Makefile for UnZip, fUnZip and UnZipSFX
# for rsxntdj 1.6beta2 (with djgpp v2.3) under Windows 95 and Windows NT.
# By E-Yen Tan. Last updated 20th January 2002.

CC = gcc -Zwin32
CFLAGS = -O2 -Wall -I. -DWIN32 -DASM_CRC $(LOCAL_UNZIP)
AS = gcc
ASFLAGS = -Di386
LDFLAGS = -o ./
LDFLAGS2 = -lalias -L. $(L_ADVAPI32)
IMPLIBS = $(ADVAPI32LIB)

ADVAPI32 = advapi32
ADVAPI32LIB = lib$(ADVAPI32).a
L_ADVAPI32 = -l$(ADVAPI32)

OBJU1 = unzip.o crc_gcc.o crctab.o crypt.o envargs.o explode.o extract.o
OBJU2 = fileio.o globals.o inflate.o list.o match.o process.o ttyio.o
OBJU3 = unreduce.o unshrink.o zipinfo.o win32.o nt.o
OBJU  = $(OBJU1) $(OBJU2) $(OBJU3)
OBJX1 = unzipsf_.o crc_gcc.o crctab_.o crypt_.o extract_.o fileio_.o
OBJX2 = globals_.o inflate_.o match_.o process_.o ttyio_.o win32_.o nt_.o
OBJX  = $(OBJX1) $(OBJX2)
OBJF  = funzip.o crc_gcc.o cryptf.o inflatef.o globalsf.o ttyiof.o win32f.o

UNZIP_H = unzip.h unzpriv.h globals.h win32/w32cfg.h

# rules

.SUFFIXES: .c .o

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

.asm.o:
	$(AS) $(ASFLAGS) $<

all:	unzip.exe funzip.exe unzipsfx.exe

unzip.exe: $(OBJU) $(IMPLIBS)
	$(CC) $(LDFLAGS)$@ $(OBJU) $(LDFLAGS2)

funzip.exe: $(OBJF) $(IMPLIBS)
	$(CC) $(LDFLAGS)$@ $(OBJF) $(LDFLAGS2)

unzipsfx.exe: $(OBJX) $(IMPLIBS)
	$(CC) $(LDFLAGS)$@ $(OBJX) $(LDFLAGS2)

uzexampl.exe:	uzexampl$(OBJ)
	$(CC) $(LDFLAGS)$@ uzexampl$(OBJ) -lversion $(LDFLAGS2)

$(ADVAPI32LIB):
	makelib "$(windir)/system/advapi32.dll" -o ./$@

crctab.o:	crctab.c $(UNZIP_H) zip.h
envargs.o:	envargs.c $(UNZIP_H)
explode.o:	explode.c $(UNZIP_H)
extract.o:	extract.c $(UNZIP_H) crypt.h
fileio.o:	fileio.c $(UNZIP_H) crypt.h ttyio.h ebcdic.h
globals.o:	globals.c $(UNZIP_H)
inflate.o:	inflate.c $(UNZIP_H)
list.o:		list.c $(UNZIP_H)
match.o:	match.c $(UNZIP_H)
process.o:	process.c $(UNZIP_H)
ttyio.o:	ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
unreduce.o:	unreduce.c $(UNZIP_H)
unshrink.o:	unshrink.c $(UNZIP_H)
unzip.o:	unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
zipinfo.o:	zipinfo.c $(UNZIP_H)

funzip.o:	funzip.c $(UNZIP_H) crypt.h ttyio.h tables.h
	$(CC) -c $(CFLAGS) -o$@ funzip.c

uzexampl$(OBJ):	windll/uzexampl.c windll/uzexampl.h
	$(CC) -c $(CFLAGS) -o$@ windll/uzexampl.c

win32.o:	win32/win32.c $(UNZIP_H) win32/nt.h unzvers.h
	$(CC) -c $(CFLAGS) -o$@ win32/win32.c

win32f.o:	win32/win32.c $(UNZIP_H) win32/nt.h
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ win32/win32.c

win32_.o:	win32/win32.c $(UNZIP_H) win32/nt.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ win32/win32.c

nt.o:	win32/nt.c $(UNZIP_H) win32/nt.h
	$(CC) -c $(CFLAGS) -o$@ win32/nt.c

nt_.o:	win32/nt.c $(UNZIP_H) win32/nt.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ win32/nt.c

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

crypt.o:	crypt.c $(UNZIP_H) zip.h crypt.h ttyio.h
	$(CC) -c $(CFLAGS) -o$@ crypt.c

cryptf.o:	crypt.c $(UNZIP_H) zip.h crypt.h ttyio.h
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ crypt.c

crc32f.o:	crc32.c $(UNZIP_H) zip.h
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ crc32.c

globalsf.o:	globals.c $(UNZIP_H)
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ globals.c

inflatef.o:	inflate.c inflate.h $(UNZIP_H) crypt.h
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ inflate.c

ttyiof.o:	ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
	$(CC) -c $(CFLAGS) -DFUNZIP -o$@ ttyio.c

crctab_.o:	crctab.c $(UNZIP_H) zip.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ crctab.c

crypt_.o:	crypt.c $(UNZIP_H) zip.h crypt.h ttyio.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ crypt.c

extract_.o:	extract.c $(UNZIP_H) crypt.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ extract.c

fileio_.o:	fileio.c $(UNZIP_H) crypt.h ttyio.h ebcdic.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ fileio.c

globals_.o:	globals.c $(UNZIP_H)
	$(CC) -c $(CFLAGS) -DSFX -o$@ globals.c

inflate_.o:	inflate.c inflate.h $(UNZIP_H) crypt.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ inflate.c

match_.o:	match.c $(UNZIP_H)
	$(CC) -c $(CFLAGS) -DSFX -o$@ match.c

process_.o:	process.c $(UNZIP_H)
	$(CC) -c $(CFLAGS) -DSFX -o$@ process.c

ttyio_.o:	ttyio.c $(UNZIP_H) zip.h crypt.h ttyio.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ ttyio.c

unzipsf_.o:	unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
	$(CC) -c $(CFLAGS) -DSFX -o$@ unzip.c
