# Makefile for Zip, ZipNote, ZipCloak and ZipSplit

# add -g to CC to debug
# add -d to BIND to debug
CC   = gcc
BIND = drlink
AS   = $(CC) -c
ASM  = AS
SQUEEZE = squeeze -v
E    =

# flags
#   CFLAGS    flags for C compile
#   LFLAGS1   flags after output file spec, before obj file list
#   LFLAGS2   flags after obj file list (libraries, etc)
#
LIB      =
CFLAGS   = -O2 -mstubs -mthrowback -DASMV
CFLAGS   = $(CFLAGS)
ASMFLAGS = -throwback -objasm -upper
LFLAGS1  = 
LFLAGS2  = $(LIB) C:o.stubs gcc:o.libgcc

# Uncomment the following line to enable support for Unix
# Extra Field (Timezone)
#CFLAGS  = $(CFLAGS) -DUSE_EF_UT_TIME

# object file lists
OBJZ = o.zip o.zipfile o.zipup o.fileio o.util o.globals o.crc32 o.crctab \
       o.crypt o.ttyio o.riscos o.acornzip o.swiven

OBJI = o.deflate o.trees
OBJA = o.match o.sendbits
OBJU = o.zipfile_ o.fileio_ o.util_ o.globals o.riscos o.acornzip_ o.swiven
OBJN = o.zipnote  $(OBJU)
OBJC = o.zipcloak $(OBJU) o.crctab o.crypt_ o.ttyio
OBJS = o.zipsplit $(OBJU)

ZIP_H = h.zip h.ziperr h.tailor acorn.h.osdep acorn.h.riscos acorn.h.swiven

all:      zip zipnote zipsplit zipcloak


install:  %.zip %.zipnote %.zipsplit %.zipcloak zip zipnote zipsplit zipcloak
        $(SQUEEZE) zip %.zip
        $(SQUEEZE) zipnote %.zipnote
        $(SQUEEZE) zipsplit %.zipsplit
        $(SQUEEZE) zipcloak %.zipcloak

# rules for zip, zipnote, zipcloak and zipsplit

o.api:		c.api
	$(CC) $(CFLAGS) -c c.api -o o.api
o.crc32:	c.crc32 $(ZIP_H)
	$(CC) $(CFLAGS) -c c.crc32 -o o.crc32
o.crctab:	c.crctab $(ZIP_H)
	$(CC) $(CFLAGS) -c c.crctab -o o.crctab
o.crypt:	c.crypt $(ZIP_H) h.crypt h.ttyio
	$(CC) $(CFLAGS) -c c.crypt -o o.crypt
o.deflate:	c.deflate $(ZIP_H)
	$(CC) $(CFLAGS) -c c.deflate -o o.deflate
o.fileio:	c.fileio $(ZIP_H)
	$(CC) $(CFLAGS) -c c.fileio -o o.fileio
o.globals:	c.globals $(ZIP_H)
	$(CC) $(CFLAGS) -c c.globals -o o.globals
o.mktime:	c.mktime
	$(CC) $(CFLAGS) -c c.mktime -o o.mktime
o.trees:	c.trees $(ZIP_H)
	$(CC) $(CFLAGS) -c c.trees -o o.trees
o.ttyio:	c.ttyio $(ZIP_H) h.crypt
	$(CC) $(CFLAGS) -c c.ttyio -o o.ttyio
o.util:		c.util $(ZIP_H)
	$(CC) $(CFLAGS) -c c.util -o o.util
o.zip:		c.zip $(ZIP_H) h.crypt h.revision h.ttyio
	$(CC) $(CFLAGS) -c c.zip -o o.zip
o.zipcloak:	c.zipcloak $(ZIP_H) h.crypt h.revision h.ttyio
	$(CC) $(CFLAGS) -c c.zipcloak -o o.zipcloak
o.zipfile:	c.zipfile $(ZIP_H)
	$(CC) $(CFLAGS) -c c.zipfile -o o.zipfile
o.zipnote:	c.zipnote $(ZIP_H) h.revision
	$(CC) $(CFLAGS) -c c.zipnote -o o.zipnote
o.zipsplit:	c.zipsplit $(ZIP_H) h.revision
	$(CC) $(CFLAGS) -c c.zipsplit -o o.zipsplit
o.zipup:	c.zipup $(ZIP_H) h.crypt h.revision
	$(CC) $(CFLAGS) -c c.zipup -o o.zipup

o.crypt_: c.crypt $(ZIP_H) h.crypt h.ttyio
        $(CC) $(CFLAGS) -DUTIL -c c.crypt -o o.crypt_
o.util_: c.util $(ZIP_H)
        $(CC) $(CFLAGS) -DUTIL -c c.util -o o.util_
o.fileio_: c.fileio $(ZIP_H)
        $(CC) $(CFLAGS) -DUTIL -c c.fileio -o o.fileio_
o.zipfile_: c.zipfile $(ZIP_H)
        $(CC) $(CFLAGS) -DUTIL -c c.zipfile -o o.zipfile_
o.acornzip_: acorn.c.acornzip $(ZIP_H)
        $(CC) $(CFLAGS) -I@ -DUTIL -c acorn.c.acornzip -o o.acornzip_

o.riscos: acorn.c.riscos acorn.h.riscos $(ZIP_H)
        $(CC) $(CFLAGS) -I@ -c acorn.c.riscos -o o.riscos

o.acornzip: acorn.c.acornzip $(ZIP_H)
        $(CC) $(CFLAGS) -I@ -c acorn.c.acornzip -o o.acornzip

o.match: acorn.s.match
        $(ASM) $(ASMFLAGS) -I@ acorn.s.match -o o.match

o.sendbits: acorn.s.sendbits
        $(ASM) $(ASMFLAGS) -I@ acorn.s.sendbits -o o.sendbits

o.swiven: acorn.s.swiven
        $(ASM) $(ASMFLAGS) -I@ acorn.s.swiven -o o.swiven

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

clean:  ;remove zip; remove zipcloak;
        remove zipsplit; remove zipnote;
        create o.!fake! 0
        wipe o.* ~cf

# end of Makefile
