# Makefile for UnZip, UnZipSFX and fUnZip                       23 July 1994
#
# - for Microsoft C, version 6.00 or higher, for use under OS/2 1.x (16-bit)
# - for Watcom C/386, version 9.0 or higher, for use under OS/2 2.x (32-bit)
# - for IBM C/C++ Set/2, for use under OS/2 2.x (32-bit)
# - for Borland C++, for use under OS/2 2.x (32-bit)
# - for GNU gcc (emx kit), version 0.8e or higher, for use under OS/2 2.x
#
# cross-compilation:
# - for Microsoft C, version 6.00 or higher, for use under MS-DOS (16-bit)
# - for GNU gcc (emx), version 0.8h or higher, for use under MS-DOS (32-bit)

# To use, enter "{d,n}make -f makefile.os2" (this makefile depends on its
# name being "makefile.os2", and it must be in the main unzip directory).

# Notes on Microsoft C 6.00 compilation for OS/2:
#
#   The resulting programs can be used under OS/2 1.x or 2.x protected
#   mode only, not under DOS.  A larger stack has to be used for OS/2
#   because system calls use more stack than under DOS; 8k is recommended
#   by Microsoft.

# Notes on IBM C Set/2, Watcom C/386, Borland C++ or emx+gcc compilation:
#
#   The resulting programs can be used under protected mode of OS/2 2.x
#   only, not under OS/2 1.x and not under DOS.
#
#   The NFLAGS macro is used to work around an optimization bug in the IBM
#   C++ Set compiler; this is fixed by CSD #4, so NFLAGS="" can be used for
#   all targets below.  We'll leave it as is for this release...
#
#   For Watcom C/386, edit the os2$(OBJ) target so that os2/os2.c reads
#   os2\os2.c instead.  Watcom can't handle forward slashes; gcc can't
#   handle backslashes.  We'll see about making this a macro next time...

default:
	@echo "Enter `$(MAKE) -f makefile.os2 target' with makefile.os2 copied"
	@echo "to the main UnZip directory and where target is one of:"
	@echo "   msc mscdos ibm ibmdyn ibmdebug ibmprof"
	@echo "   watcom borland gcc gccdyn gccdebug gccdos"

# MS C 6.00 for OS/2, 16-bit (should figure out way to split unzip/funzip 
# compiles so former is always large model and latter always small model...)
msc:
	$(MAKE) -f makefile.os2 all \
	CC="cl -nologo -AL -Ocegit -Gs -I. $(FP)" \
	CFLAGS="-G2 -Zp1 -W3 -DOS2 -DMSC $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-Lp -Fe" \
	LDFLAGS2="-link /noe" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip16.def"

# cross-compilation for MS-DOS with MS C 6.00 (same comment as above...formerly;
# now unzip is small model again, with [almost] all strings in far memory)
mscdos:
	$(MAKE) -f makefile.os2 all \
	CC="cl -nologo -AS -Oaict -Gs -I. $(FP)" \
	CFLAGS="-Zp1 -W3 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-F 0c00 -Lr -Fe" \
	LDFLAGS2="-link /noe /exe" \
	OUT="-Fo" \
	OBJ=".obj" \
	OBJU2="msdos.obj" \
	OBJX2="msdos_.obj"

# IBM C Set/2, statically linked runtime
ibm:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, dynamically linked runtime
ibmdyn:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -Gd -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, debug version
ibmdebug:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -Ti -I." \
	CFLAGS="-Sm -Sp1 -D__DEBUG_ALLOC__ -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# IBM C Set/2, profiling version for PROFIT
ibmprof:
	$(MAKE) -f makefile.os2 all \
	CC="icc -Q -O -Gs -Gh -Ti -I." \
	CFLAGS="-Sm -Sp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="-O-" \
	LDFLAGS="-Fe" \
	LDFLAGS2="profit.obj" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF="os2\unzip.def"

# Watcom C/386 9.0
watcom:
	$(MAKE) -f makefile.os2 all \
	CC="wcl386 -zq -Ox -s -I." \
	CFLAGS="-Zp1 -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-k0x40000 -x -Fe=" \
	LDFLAGS2="" \
	OUT="-Fo" \
	OBJ=".obj" \
	DEF=""

# Borland C++
borland:
	$(MAKE) -f makefile.os2 all \
	CC="bcc -O -I." \
	CFLAGS="-w- -D__cdecl -D__32BIT__ -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-e" \
	LDFLAGS2="" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="-sDos2\unzip.def"

# emx 0.8f and later, gcc, OMF format, statically linked C runtime and emx
gcc:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -Zomf -Zsys -O -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s -los2" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="os2/unzip.def"

# emx 0.8g and later, gcc, OMF format, dynamically linked C runtime and emx
# (for 0.8f or earlier, change -Zmtd to -Zmt)
gccdyn:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -Zomf -Zmtd -O -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s -los2" \
	OUT="-o" \
	OBJ=".obj" \
	DEF="os2/unzip.def"

# emx, gcc, a.out format, with debug info for gdb
gccdebug:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -g -I." \
	CFLAGS="-Wall -DOS2 $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-los2" \
	OUT="-o" \
	OBJ=".o"

# emx, gcc, a.out format, for MS-DOS
gccdos:
	$(MAKE) -f makefile.os2 all \
	CC="gcc -O -I." \
	CFLAGS="-Wall -DMSDOS $(LOCAL_UNZIP)" \
	NFLAGS="" \
	LDFLAGS="-o ./" \
	LDFLAGS2="-s" \
	OUT="-o" \
	OBJ=".o" \
	OBJU2="msdos.o" \
	OBJX2="msdos_.o"

# variables
OBJU  = unzip$(OBJ) crypt$(OBJ) envargs$(OBJ) explode$(OBJ) \
	extract$(OBJ) file_io$(OBJ) inflate$(OBJ) match$(OBJ) \
	unreduce$(OBJ) unshrink$(OBJ) zipinfo$(OBJ)
OBJU2 = os2$(OBJ)
OBJX  = unzip_$(OBJ) crypt$(OBJ) extract_$(OBJ) file_io$(OBJ) \
	inflate$(OBJ) match$(OBJ)
OBJX2 = os2_$(OBJ)
OBJF  = funzip$(OBJ) crypt_$(OBJ) inflate_$(OBJ)

.SUFFIXES:	.c $(OBJ)

.c$(OBJ):
	$(CC) -c $(CFLAGS) $<

all:	unzip.exe funzip.exe unzipsfx.exe
#all:	unzipsfx.exe

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

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

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


envargs$(OBJ):	envargs.c unzip.h
explode$(OBJ):	explode.c unzip.h
extract$(OBJ):	extract.c unzip.h crypt.h
file_io$(OBJ):	file_io.c unzip.h crypt.h tables.h
funzip$(OBJ):	funzip.c unzip.h crypt.h tables.h
inflate$(OBJ):	inflate.c unzip.h
match$(OBJ):	match.c unzip.h
unreduce$(OBJ):	unreduce.c unzip.h
unshrink$(OBJ):	unshrink.c unzip.h
unzip$(OBJ):	unzip.c unzip.h crypt.h version.h
zipinfo$(OBJ):	zipinfo.c unzip.h

msdos$(OBJ):	msdos/msdos.c unzip.h			# MS-DOS only
	$(CC) -c $(CFLAGS) msdos/msdos.c

msdos_$(OBJ):	msdos/msdos.c unzip.h			# MS-DOS unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ msdos/msdos.c

os2$(OBJ):	os2/os2.c unzip.h			# OS/2 only
	$(CC) -c $(CFLAGS) os2/os2.c

os2_$(OBJ):	os2/os2.c unzip.h			# OS/2 unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ os2/os2.c

# NFLAGS are solely used as work-around for optimization bug in IBM C++ Set
crypt$(OBJ):	crypt.c unzip.h crypt.h zip.h
	$(CC) -c $(CFLAGS) $(NFLAGS) crypt.c

crypt_$(OBJ):	crypt.c unzip.h zip.h crypt.h		# funzip only
	$(CC) -c $(CFLAGS) $(NFLAGS) -DFUNZIP $(OUT)$@ crypt.c

extract_$(OBJ):	extract.c unzip.h crypt.h		# unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ extract.c

inflate_$(OBJ):	inflate.c inflate.h unzip.h crypt.h	# funzip only
	$(CC) -c $(CFLAGS) -DFUNZIP $(OUT)$@ inflate.c

unzip_$(OBJ):	unzip.c unzip.h crypt.h version.h	# unzipsfx only
	$(CC) -c $(CFLAGS) -DSFX $(OUT)$@ unzip.c
