# Makefile for Zip, ZipNote, ZipCloak and ZipSplit on BeOS

MAKE = make -f beos/Makefile
SHELL = /bin/sh

# For now, we don't have anything like links.
LN = cp

CC = mwcc
BIND = $(CC)
AS = $(CC) -c
E =
CPP = mwcc -E

# probably can change this to 'install' if you have it
INSTALL = install

# target directories - where to install executables and man pages to
prefix = /boot/usr/local
BINDIR = $(prefix)/bin
manext=1
MANDIR = $(prefix)/man/man$(manext)
VERSION = Version 2.2 of 7 August 1996

# flags
#   CFLAGS    flags for C compile
#   LFLAGS1   flags after output file spec, before obj file list
#   LFLAGS2   flags after obj file list (libraries, etc)
CFLAGS = -O7 -rostr -I. -DHAVE_DIRENT_H -DNO_MKTEMP \
         -DPASSWD_FROM_STDIN -w9 -ansi strict
LFLAGS1 = # -lmoto -warn # -L/boot/develop/libraries -lmoto
LFLAGS2 =

# object file lists
OBJZ = zip.o zipfile.o zipup.o fileio.o util.o globals.o crypt.o ttyio.o \
       beos.o crc32.o crctab.o
OBJI = deflate.o trees.o bits.o
OBJA =
OBJU = zipfile_.o fileio_.o util_.o globals.o
OBJN = zipnote.o  $(OBJU)
OBJC = zipcloak.o $(OBJU) crctab.o crypt_.o ttyio.o
OBJS = zipsplit.o $(OBJU)

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

# What to build?
ZIPS = zip$E zipnote$E zipsplit$E zipcloak$E

all: $(ZIPS)

# suffix rules
.SUFFIXES:
.SUFFIXES: _.o .o .c .doc .1
.c_.o:
	rm -f $*_.c; $(LN) $< $*_.c
	$(CC) -c $(CFLAGS) -DUTIL $*_.c
	rm -f $*_.c
.c.o:
	$(CC) -c $(CFLAGS) $<

.1.doc:
	nroff -man $< | col -b | uniq > $@

# rules for zip, zipnote, zipcloak, zipsplit, and zip.doc.
$(OBJZ): $(ZIP_H)
$(OBJI): $(ZIP_H)
$(OBJN): $(ZIP_H)
$(OBJS): $(ZIP_H)
$(OBJC): $(ZIP_H)
zip.o zipup.o crypt.o ttyio.o bits.o zipcloak.o crypt_.o: crypt.h
zip.o zipup.o zipnote.o zipcloak.o zipsplit.o: revision.h
zip.o crypt.o ttyio.o zipcloak.o crypt_.o: ttyio.h
zipup.o: beos/zipup.h

beos.o: beos/beos.c
	$(CC) -c $(CFLAGS) beos/beos.c

zips: $(ZIPS)
zipsman: zip zipnote zipsplit zipcloak zip.doc

zip$E: $(OBJZ) $(OBJI) $(OBJA)
	$(BIND) -o zip$E $(LFLAGS1) $(OBJZ) $(OBJI) $(OBJA) $(LFLAGS2)
zipnote$E: $(OBJN)
	$(BIND) -o zipnote$E $(LFLAGS1) $(OBJN) $(LFLAGS2)
zipcloak$E: $(OBJC)
	$(BIND) -o zipcloak$E $(LFLAGS1) $(OBJC) $(LFLAGS2)
zipsplit$E: $(OBJS)
	$(BIND) -o zipsplit$E $(LFLAGS1) $(OBJS) $(LFLAGS2)

# install
install:        $(ZIPS)
	$(INSTALL) -m755 $(ZIPS) beos/zipgrep $(BINDIR)
	$(INSTALL) -m644 man/zip.1 $(MANDIR)/zip.$(manext)
	$(INSTALL) -m644 man/zipgrep.1 $(MANDIR)/zipgrep.$(manext)

uninstall:
	-cd $(BINDIR); rm -f $(ZIPS)
	-cd $(MANDIR); rm -f zip.$(manext)

dist:
	zip -u9T zip`sed -e '/VERSION/!d' -e 's/.*"\(.*\)".*/\1/' \
			  -e s/[.]//g -e q revision.h` \
	  `awk '/^Makefile/,/vms_zip.rnh/ {print $$1}' < contents`

# These symbols, when #defined using -D have these effects on compilation:
# ZMEM                  - includes C language versions of memset(), memcpy(),
#                         and memcmp() (util.c).
# HAVE_DIRENT_H         - use <dirent.h> instead of <sys/dir.h>
# NODIR                 - for 3B1, which has neither getdents() nor opendir().
# HAVE_NDIR_H           - use <ndir.h> (unix/unix.c).
# HAVE_SYS_DIR_H        - use <sys/dir.h>
# HAVE_SYS_NDIR_H       - use <sys/ndir.h>
# UTIL                  - select routines for utilities (note, cloak, split)
# NO_RMDIR              - remove directories using a system("rmdir ...") call.
# NO_PROTO              - cannot handle ANSI prototypes
# NO_CONST              - cannot handle ANSI const

# clean up after making stuff and installing it
clean:
	rm -f *.o $(ZIPS) flags
	rm -rf $(PKGDIR)

# end of Makefile
