#==============================================================================
# Makefile for UnZip, ZipInfo & FUnZip:  Unix, OS/2, MS-DOS ("real" makes only)
# Version:  5.0 (inflate,explode)                                20 August 1992
#==============================================================================
#
#
# INSTRUCTIONS (such as they are):
#
# "make vax"	-- makes UnZip on a VAX 11-780 BSD 4.3 in current directory
#		   (or a SysV VAX, or an 8600 running Ultrix, or...)
# "make"	-- uses environment variable SYSTEM to set the type
#		   system to compile for.  This doesn't work for some
#		   particularly brain-damaged versions of make (VAX BSD,
#		   Gould, and SCO Unix are in this group).  If SYSTEM not
#		   set, gives instructions on what to try instead.
# "make list"	-- lists all supported systems (targets), including related
#		   utilities' targets
# "make wombat" -- Chokes and dies if you haven't added the specifics
#		   for your Wombat 68000 (or whatever) to the systems list.
#
# CF are flags for the C compiler.  LF are flags for the loader.  LF2 are
# more flags for the loader, if they need to be at the end of the line
# instead of at the beginning (for example, some libraries).  LOCAL_UNZIP
# is an environment variable that can be used to add default C flags to
# your compile without editing the Makefile (e.g., -DDEBUG_STRUC, or -FPi87
# on PCs).
#
# My host (a VAX 11-780 running BSD 4.3) is hereafter referred to as "my host."
#
# My host's /usr/include/sys/param.h defines BSD for me.  You may have to add
# "-DBSD" to the list of CF for your system.
#
# Some versions of make do not define the macro "$(MAKE)" (my host did not).
# The makefile should now handle such systems correctly, more or less; the
# possible exception to this is if you've used a make command-line option
# (for example, the one which displays the commands which WOULD be executed,
# but doesn't actually execute them).  It probably needs some more tinkering.
# If things still don't work, use "make" instead of "$(MAKE)" in your system's
# makerule.  Or try adding the following line to your .login file:
#   setenv MAKE "make"
# (It didn't help on my host.)
#
# Memcpy and memset are provided for those systems that don't have them;
# they're found in misc.c and will be used if -DZMEM is included in the list
# of CF.  These days *almost* all systems have them (they're mandated by
# ANSI), but older systems might be lacking.  And at least one machine's
# version results in some serious performance degradation...
#
# Be sure to test your nice new UnZip; successful compilation does not always
# imply a working program.


#####################
# MACRO DEFINITIONS #
#####################

# Defaults most systems use (use LOCAL_UNZIP in environment to add flags, 
# such as -DNOMEMCPY).

CRYPTF =
CRYPTO =
# Uncomment next two lines for decryption version:
#CRYPTF = -DCRYPT
#CRYPTO = crypt$O

# general-purpose stuff
LN = cp
RM = rm -f
E = .code
O = .o
DEBUG = -O

# UnZip flags
CC = gcc
LD = gcc
LOC = $(LOCAL_UNZIP) $(CRYPTF)
CF = $(DEBUG) $(LOC) -O2
LF = $(DEBUG) -o unzip$E
LF2 = -lxp -lsmaky

# ZipInfo flags
ZC = -DZIPINFO -O2
ZL = -o zipinfo$E
ZL2 = -lxp -lsmaky

# FUnZip flags
FC = # not used
FL = -o funzip$E
FL2 =


INSTALL = cp#	 	   probably can change this to 'install' if you have it
BINDIR = /usr/local/bin#   target directory - where to install executables

# object files
OBJS1 = unzip$O $(CRYPTO) envargs$O explode$O extract$O file_io$O inflate$O
OBJS2 = mapname$O match$O misc$O unreduce$O unshrink$O
OBJS = $(OBJS1) $(OBJS2)
LOBJS = $(OBJS)
OS2_OBJS = $(OBJS:.o=.obj) os2unzip.obj
OBJZ = zipinfo$O envargs$O match$O misc_$O
OS2_OBJZ = $(OBJZ:.o=.obj) os2zinfo.obj
OBJF = funzip$O $(CRYPTO) inflate$O
OS2_OBJF = # not yet supported
UNZIPS = unzip$E # zipinfo$E funzip$E	# zipinfo, funzip not fully supported
#					#  yet (next release)

# list of supported systems/targets in this version
SYSTEMS1 = 386i 3Bx 7300 amdahl apollo aviion bsd bull c120 c210 coherent
SYSTEMS2 = convex cray cray_cc cray_v3 cyber_sgi dec dnix encore eta
SYSTEMS3 = gcc gcc_dos generic generic2 gould hk68 hp indigo linux
SYSTEMS4 = minix mips msc_dos next osf1 p_iris pyramid rs6000 rtaix
SYSTEMS5 = sco sco_dos sco_x286 sequent sgi stellar sun sysv sysv6300
SYSTEMS6 = tahoe ultrix vax wombat xos

SYS_UTIL1 = zi_dos zi_gcc zi_indigo zipinfo fu_gcc funzip
# SYS_UTIL2 = ship ship_dos ship_sysv


####################
# DEFAULT HANDLING #
####################

# The below will try to use your shell variable "SYSTEM" as the type system
# to use (e.g., if you type "make" with no parameters at the command line).
# The test for $(MAKE) is necessary for VAX BSD make (and Gould, apparently),
# as is the "goober" (else stupid makes see an "else ;" statement, which they
# don't like).  "goober" must then be made into a valid target for machines
# which DO define MAKE properly (and have SYSTEM set).  Quel kludge, non?
# And to top it all off, it appears that the VAX, at least, can't pick SYSTEM
# out of the environment either (which, I suppose, should not be surprising).
# [Btw, if the empty "goober" target causes someone else's make to barf, just
# add an "@echo > /dev/null" command (or whatever).  Works OK on the Amdahl
# and Crays, though.]


###############################################
# BASIC COMPILE INSTRUCTIONS AND DEPENDENCIES #
###############################################

.c$O :
	$(CC) -c $(CF) $*.c

unzips:		$(UNZIPS)

unzip$E:	$(OBJS)
	$(LD) $(LF) $(LOBJS) $(LF2)

crypt$O:        crypt.c unzip.h zip.h	# may or may not be in distribution
envargs$O:      envargs.c unzip.h
explode$O:      explode.c unzip.h
extract$O:      extract.c unzip.h
file_io$O:      file_io.c unzip.h
funzip$O:       funzip.c unzip.h
inflate$O:      inflate.c unzip.h
mapname$O:      mapname.c unzip.h
match$O:        match.c unzip.h
misc$O:         misc.c unzip.h
os2unzip$O:     os2unzip.c unzip.h	# for OS/2 only
os2zinfo$O:     os2unzip.c unzip.h	# for OS/2 only
unreduce$O:     unreduce.c unzip.h
unshrink$O:     unshrink.c unzip.h
unzip$O:        unzip.c unzip.h

all:	generic_msg generic zipinfo

generic_msg:
	@echo
	@echo '  Attempting "make generic" and "make zipinfo" now.  If this fails for some'
	@echo '  reason, type "make help" and/or "make list" for suggestions.'
	@echo

install:	$(UNZIPS)
	$(INSTALL) $(UNZIPS) $(BINDIR)

clean:
	rm -f $(OBJS) unzip$E $(OBJZ) zipinfo$E


################################
# INDIVIDUAL MACHINE MAKERULES #
################################

# these are the makerules for various systems
# TABS ARE REQUIRED FOR MANY VERSIONS OF "MAKE"!


# ---------------------------------------------------------------------------
#   Generic targets (can't assume make utility groks "$(MAKE)")
# ---------------------------------------------------------------------------

generic:	unzip	# first try if unknown

# ---------------------------------------------------------------------------
#   BSD group (for timezone structs [struct timeb]):
# ---------------------------------------------------------------------------

bsd:		_bsd	# generic BSD (BSD 4.2 & Ultrix handled in unzip.h)

_bsd:
	$(MAKE) unzip CF="$(CF) -DBSD"


#####################
# ZIPINFO MAKERULES #
#####################

# ZipInfo section:  less hand-holding here, but it should be pretty
# straightforward by now.

zipinfo$O:	zipinfo.c unzip.h
	$(CC) -c $(CF) zipinfo.c

misc_$O:	misc.c unzip.h
	$(LN) misc.c misc_.c
	$(CC) -c $(CF) $(ZC) misc_.c
	$(RM) misc_.c

os2zinfo$O:	os2unzip.c unzip.h
	$(LN) os2unzip.c os2zinfo.c
	$(CC) -c $(CF) $(ZC) os2zinfo.c
	$(RM) os2zinfo.c

zipinfo$E:	$(OBJZ)
	$(LD) $(ZL) $(OBJZ) $(ZL2)



####################
# FUNZIP MAKERULES #
####################

# FUnZip section:  FUnZip (Filter UnZip) is a last-minute addition to the
# UnZip suite and is still VERY raw.  Its purpose is to take a zipfile from 
# stdin and decompress the first entry to stdout.  Only non-encrypted, stored
# or deflated files are allowed at present.  FUnZip may be absorbed into
# regular UnZip in a subsequent release.  This target should work for some
# Unix systems but is not guaranteed to work for all (or even most).

funzip$E:	$(OBJF)
	$(LD) $(FL) $(OBJF) $(FL2)

fu_gcc:			# GNU gcc under Unix (if no strip, don't worry)
	$(MAKE) funzip CC=gcc LD=gcc FL2=""
	strip funzip


################
# ATTRIBUTIONS #
################

# Thanks to the following people for their help in testing and/or porting
# to various machines (and thanks to the many others who aren't listed
# here but should be):
#
#  (original Unix port:  Carl Mascott <cmascott@world.std.com>)
#  386i:	Richard Stephen <stephen@corp.telecom.co.nz>
#  3Bx:		Bob Kemp <hrrca!bobc@cbnewse.att.com>
#  7300:	Richard H. Gumpertz <rhg@cpsolv.CPS.COM>
#		Greg Roelofs <roelofs@amelia.nas.nasa.gov>
#  amdahl:	Kim DeVaughn <ked01@juts.ccc.amdahl.com>, Greg Roelofs
#  apollo:	Tim Geibelhaus
#  aviion:	Bruce Kahn <bkahn@archive.webo.dg.com>
#  bull:	Matt D'Errico <doc@magna.com>
#  c120:	Rafal Maszkowski <sgumk%pltumk11.bitnet>
#  coherent:	David Fenyes <dfenyes@thesis1.med.uth.tmc.edu>
#  convex:	Randy Wright <rwright@convex.com>
#  cray:	Greg Roelofs, Paul Borman <prb@cray.com>
#  cray_cc:	Greg Roelofs
#  cray_v3:	Greg Roelofs
#  cyber_sgi:	Clint Pulley <u001@cs910.cciw.ca>
#  dec:		"Moby" Dick O'Connor <djo7613@u.washington.edu>
#  dnix:	Bo Kullmar <bk@kullmar.se>
#  eta:		Greg Flint <afc@klaatu.cc.purdue.edu>
#  gcc:		Jean-loup Gailly <jloup@chorus.fr>
#  gcc_dos:	Onno van der Linden <linden@fwi.uva.nl>
#  gcc_os2:	Kai Uwe Rommel <rommel@informatik.tu-muenchen.de>
#  gould:	Onno van der Linden
#  hk68:	John Limpert <gronk!johnl@uunet.UU.NET>
#  hp:		Randy McCaskile <rmccask@seas.gwu.edu> (HP-UX)
#		Gershon Elber <gershon@cs.utah.edu> (HP BSD 4.3)
#  icc_os2:	Kai Uwe Rommel
#  indigo:	Kjetil Wiekhorst J|rgensen <jorgens@lise.unit.no>
#  linux:	Humberto Ortiz-Zuazaga <zuazaga@ucunix.san.uc.edu>
#  minix:	Kai Uwe Rommel (Minix 1.5)
#  mips:	Peter Jones <jones@mips1.uqam.ca>
#  msc_dos:	Greg Roelofs <roe2@ellis.uchicago.edu>
#		Piet W. Plomp <piet@icce.rug.nl>
#  msc_os2:	Wim Bonner <wbonner@yoda.eecs.wsu.edu>
#		Kai Uwe Rommel, Greg Roelofs
#  next:	Mark Adler <madler@piglet.caltech.edu>
#  osf1:	Kjetil Wiekhorst J{#  p_iris:	Valter V. Cavecchia <root@itnsg1.cineca.it>
#  pyramid:	James Dugal <jpd@usl.edu>
#  rs6000:	Filip Gieszczykiewicz <fmg@smi.med.pitt.edu>
#		Trevor Paquette <tpaquett@ita.lgc.com>
#  rtaix:	Erik-Jan Vens
#  sco:		Onno van der Linden (SCO Unix 3.2.0)
#   		Bill Davidsen <davidsen@crdos1.crd.ge.com> (Xenix/386)
#  sco_dos:	Bill Davidsen, Piet W. Plomp
#  sco_x286:	Ricky Mobley <ddi1!lrark!rick@uunet.UU.NET>
#  sequent:	Phil Howard <phil@ux1.cso.uiuc.edu>
#  sgi:		Greg Roelofs (Iris 4D/380?)
#  sun:		Onno van der Linden (Sun 4), Greg Roelofs (Sun 3, 4)
#  sysv:	Greg Roelofs
#  sysv6300:	Peter Mauzey <ptm@mtdcc.att.com>
#  tahoe:	Mark Edwards <mce%sdcc10@ucsd.edu>
#  ultrix:	Greg Flint (VAX)
#		Michael Graff <explorer@iastate.edu> (DECstation 2100?)
#		Greg Roelofs (DEC 5810)
#		Alex A Sergejew <aas@brain.wph.uq.oz.au>
#  vax:		Forrest Gehrke <feg@dodger.att.com> (SysV)
#		David Kirschbaum <kirsch@usasoc.soc.mil> (BSD 4.3)
#		Jim Steiner <steiner@pica.army.mil> (8600+Ultrix)
#  wombat:	Joe Isuzu <joe@trustme.isuzu.com>
#  xos:		Fulvio Marino <fulvio@iconet.ico.olivetti.com>
#  zi_dos:	Greg Roelofs
#  zi_icc:	Kai Uwe Rommel
#  zi_os2:	Greg Roelofs, Kai Uwe Rommel
#  zipinfo:	Greg Roelofs
