#------------------------------------------------------------------------------
# Makefile for UnZip 5.5 and later                             Jean-loup Gailly
# Version:  Turbo C (edit and use makefile.bc for Turbo C++)          04 Mar 01
#------------------------------------------------------------------------------

#    GNU make doesn't like the return value from "rem"
#STRIP=rem
STRIP=echo  Ignore this line. :-)
#    If you don't have LZEXE or PKLITE, get one of them. Then define:
#STRIP=lzexe
#    or
#STRIP=pklite
#    This makes a big difference in .exe size (and possibly load time).

#    Optional nonstandard preprocessor flags (as -DCHECK_EOF or -DDOS_WILD)
#    should be added to the environment via "set LOCAL_UNZIP=-DFOO" or added
#    to the declaration of LOC here:
LOC = $(LOCAL_UNZIP)

# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc.
CPU_TYP = 0

# memory model for UnZip (conflicting reports on whether Turbo C can or
# cannot put strings into far memory; for now assume it can and use small
# model *with* ZipInfo enabled...if fails, either define NO_ZIPINFO or
# use large model)   [GRR 940712:  sigh, no go--inflate fails.  Back to
# large model...]
#UNMODEL = s
UNMODEL = l
# funzip can use small-model (compact-model when including Deflate64 support)
FUMODEL = c

# name of Flag to select memory model for assembler compiles, supported
# values are __SMALL__ , __MEDIUM__ , __COMPACT__ , __LARGE__ :
ASUNMODEL=__LARGE__	# keep in sync with UNMODEL definition !!
ASFUMODEL=__COMPACT__	# keep in sync with FUMODEL definition !!

# Uncomment the following three macros to use the optimized CRC32 assembler
# routine in UnZip and UnZipSFX:
ASMFLG = -DASM_CRC
ASMOBJS = crc_i86.obj
ASMOBJF = crc_i86_.obj

CC = tcc

AS = tasm

ASCPUFLAG = __$(CPU_TYP)86
ASFLAGS = -ml -m2 -w0 -D$(ASCPUFLAG) $(LOC)
CFLAGS = -O -Z -I. -DFar= $(ASMFLG) $(LOC)
UCFLAGS = -m$(UNMODEL) $(CFLAGS)
ULDFLAGS = -m$(UNMODEL)
FCFLAGS = -m$(FUMODEL) $(CFLAGS)
FLDFLAGS = -m$(FUMODEL)

LDFLAGS2 =

OBJS = unzip.obj crc32.obj crctab.obj crypt.obj envargs.obj explode.obj \
	extract.obj fileio.obj globals.obj inflate.obj list.obj match.obj \
	process.obj ttyio.obj unreduce.obj unshrink.obj zipinfo.obj \
	msdos.obj $(ASMOBJS)

OBJX = unzipsfx.obj crc32x.obj crctabx.obj cryptx.obj extractx.obj \
	fileiox.obj globalsx.obj inflatex.obj matchx.obj processx.obj \
	ttyiox.obj \
	msdosx.obj $(ASMOBJS)

OBJF = funzip.obj crc32_.obj crypt_.obj globals_.obj inflate_.obj ttyio_.obj \
	msdos_.obj $(ASMOBJF)

UNZIP_H = unzip.h unzpriv.h globals.h msdos/doscfg.h


default:        unzip.exe unzipsfx.exe funzip.exe

clean:
	rem Ignore any errors in the following...
	del *.ob
	del *.obu
	del *.obj
	del unzip.exe
	del funzip.exe
	del unzipsfx.exe

.asm.obj:
	$(AS) $(ASFLAGS) -D$(ASUNMODEL) $*.asm

.c.obj:
	$(CC) -c $(UCFLAGS) $*.c

crc_i86.obj:    msdos/crc_i86.asm
	$(AS) $(ASFLAGS) -D$(ASUNMODEL) msdos\crc_i86.asm, $*.obj ;

crc_i86_.obj:   msdos/crc_i86.asm
	$(AS) $(ASFLAGS) -D$(ASFUMODEL) msdos\crc_i86.asm, $*.obj ;

crc32.obj:      crc32.c $(UNZIP_H) zip.h

crc32_.obj:     crc32.c $(UNZIP_H) zip.h
	$(CC) -c $(FCFLAGS) -DFUNZIP -ocrc32_.obj crc32.c

crctab.obj:     crctab.c $(UNZIP_H) zip.h

crypt.obj:      crypt.c $(UNZIP_H) crypt.h ttyio.h zip.h

crypt_.obj:     crypt.c $(UNZIP_H) crypt.h ttyio.h zip.h
	$(CC) -c $(FCFLAGS) -DFUNZIP -ocrypt_.obj crypt.c

envargs.obj:    envargs.c $(UNZIP_H)

explode.obj:    explode.c $(UNZIP_H)

extract.obj:    extract.c $(UNZIP_H) crypt.h

extractx.obj:   extract.c $(UNZIP_H) crypt.h
	$(CC) -c $(UCFLAGS) -DSFX -oextractx.obj extract.c

fileio.obj:     fileio.c $(UNZIP_H) crypt.h ttyio.h ebcdic.h

funzip.obj:     funzip.c $(UNZIP_H) crypt.h ttyio.h tables.h
	$(CC) -c $(FCFLAGS) funzip.c

globals.obj:    globals.c $(UNZIP_H)

globals_.obj:   globals.c $(UNZIP_H)
	$(CC) -c $(FCFLAGS) -DFUNZIP -oglobals_.obj globals.c

inflate.obj:    inflate.c inflate.h $(UNZIP_H)

inflate_.obj:   inflate.c inflate.h $(UNZIP_H) crypt.h
	$(CC) -c $(FCFLAGS) -DFUNZIP -oinflate_.obj inflate.c

list.obj:       list.c $(UNZIP_H)

match.obj:      match.c $(UNZIP_H)

msdos.obj:      msdos/msdos.c $(UNZIP_H)
	$(CC) -c $(UCFLAGS) msdos/msdos.c

msdos_.obj:     msdos/msdos.c $(UNZIP_H)
	$(CC) -c $(FCFLAGS) -DFUNZIP -omsdos_.obj msdos/msdos.c

msdosx.obj:     msdos/msdos.c $(UNZIP_H)
	$(CC) -c $(UCFLAGS) -DSFX -omsdos_.obj msdos/msdos.c

process.obj:    process.c $(UNZIP_H)

processx.obj:   process.c $(UNZIP_H)
	$(CC) -c $(UCFLAGS) -DSFX -oprocess_.obj process.c

ttyio.obj:      ttyio.c $(UNZIP_H) crypt.h ttyio.h zip.h

ttyio_.obj:     ttyio.c $(UNZIP_H) crypt.h ttyio.h zip.h
	$(CC) -c $(FCFLAGS) -DFUNZIP -ottyio_.obj ttyio.c

unreduce.obj:   unreduce.c $(UNZIP_H)

unshrink.obj:   unshrink.c $(UNZIP_H)

unzip.obj:      unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h

unzipsfx.obj:   unzip.c $(UNZIP_H) crypt.h unzvers.h consts.h
	$(CC) -c $(UCFLAGS) -DSFX -ounzipsfx.obj unzip.c

zipinfo.obj:    zipinfo.c $(UNZIP_H)


# Turbo Make, which cannot deal with the MS-DOS 128-byte limit:
# ------------------------------------------------------------
unzip.exe:      $(OBJS)
	rem   Ignore any warnings in the following commands:
	del *.ob
	ren crc32_.obj *.ob
	ren crc_i86_.obj *.ob
	ren crypt_.obj *.ob
	ren extract_.obj *.ob
	ren funzip.obj *.ob
	ren globals_.obj *.ob
	ren inflate_.obj *.ob
	ren msdos_.obj *.ob
	ren process_.obj *.ob
	ren ttyio_.obj *.ob
	ren unzipsfx.obj *.ob
	$(CC) $(ULDFLAGS) -eunzip.exe *.obj
	ren *.ob *.obj
	@$(STRIP) unzip.exe

# GRR 970901
unzipsfx.exe:      $(OBJX)
	rem   Ignore any warnings in the following commands:
	del *.ob
	ren crc32_.obj *.ob
	ren crc_i86_.obj *.ob
	ren crypt_.obj *.ob
	ren envargs.obj *.ob
	ren explode.obj *.ob
	ren extract.obj *.ob
	ren funzip.obj *.ob
	ren globals_.obj *.ob
	ren inflate_.obj *.ob
	ren list.obj *.ob
	ren msdos.obj *.ob
	ren process.obj *.ob
	ren ttyio_.obj *.ob
	ren unreduce.obj *.ob
	ren unshrink.obj *.ob
	ren unzip.obj *.ob
	ren zipinfo.obj *.ob
	$(CC) $(ULDFLAGS) -eunzipsfx.exe *.obj
	ren *.ob *.obj
	@$(STRIP) unzipsfx.exe

# better makes that know how to deal with 128-char limit on command line:
# ----------------------------------------------------------------------
#unzip.exe:      $(OBJS)
#	$(CC) $(ULDFLAGS) $(OBJS) $(LDFLAGS2)
#	@$(STRIP) unzip.exe
#
#unzipsfx.exe:     $(OBJX)
#	$(CC) $(ULDFLAGS) $(OBJX) $(LDFLAGS2)
#	@$(STRIP) unzipsfx.exe

# both makes:
# ----------
funzip.exe:     $(OBJF)
	$(CC) $(FLDFLAGS) $(OBJF) $(LDFLAGS2)
	@$(STRIP) funzip.exe
