# Makefile for gzip (GNU zip)    -*- Indented-Text -*-

# Elate vpcc version, written by Aaron "Optimizer" Digulla <digulla@hepe.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

CC = vpcc

CFLAGS = -O3 {-DSTDC_HEADERS=1} {-DHAVE_UNISTD_H=1} {-DDIRENT=1} {-DNO_CHOWN}
O = .o
EXE = .00
LIBS = -lsys
VERSION = 1.2.4
REVISION = 2

SRCS = gzip.c zip.c deflate.c trees.c bits.c unzip.c inflate.c util.c crypt.c\
       lzw.c unlzw.c unpack.c unlzh.c makecrc.c getopt.c

OBJS = gzip$O zip$O deflate$O trees$O bits$O unzip$O inflate$O util$O \
       crypt$O lzw$O unlzw$O unpack$O unlzh$O getopt$O

HDRS = gzip.h lzw.h tailor.h revision.h crypt.h getopt.h

all:	gzip$(EXE)

install:
	mkdir -p /app/stdio
	$(CC) $(LDFLAGS) -cp app/stdio -o gzip $(OBJS) $(LIBS)
	chmod +x gunzip
	cp -p gunzip zcat zgrep gzip.html /app/stdio/

# To create a distribution, you must set ELATEROOT.
ELATEROOT=$(HOME)/packages/AROS/Amie
dist:
	make clean ; \
	cd .. ; \
	tar cvzf gzip-$(VERSION)-$(REVISION).tar.gz gzip
	pwd="`cd .. ; pwd`" ; \
	cd $(ELATEROOT) ; \
	tar cvzf $$pwd/gzip-$(VERSION)-$(REVISION).bin.tar.gz \
	    app/stdio/gzip.00 \
	    app/stdio/gunzip \
	    app/stdio/zcat \
	    app/stdio/zgrep \
	    app/stdio/gzip.html
	cp README.Elate ../gzip-$(VERSION)-$(REVISION).readme
	cp README.Elate ../gzip-$(VERSION)-$(REVISION).bin.readme

clean :
	-rm -f *.o
	-rm -f _gztest*
	-rm -f gzip.00 vpcc.log

# A simple test case: Compress texinfo.tex, check the size,
# uncompress it and check that it's exactly the same as the original.
check : gzip$(EXE)
	./gzip -6 < ./texinfo.tex > _gztest.gz
	case $${!cmd {wc -c _gztest.gz}} {*30890*} { echo {Size-Test OK} ; } {*} { echo {FAILED gzip test: incorrect size} ; exit 1 ; }
	@rm -f _gztest
	@./gzip -d _gztest.gz
	@if {cmp _gztest texinfo.tex} { echo {gzip test OK} ; } { echo {FAILED gzip test: incorrect decompress} ; }
	@rm -f _gztest*
	@echo {All tests OK}

.PHONY: default all

gzip$(EXE): $(OBJS)
	$(CC) $(LDFLAGS) -o gzip $(OBJS) $(LIBS)

.c.o:
	$(CC) -c $(DEFS) $(CFLAGS) $<

gzip$O zip$O deflate$O trees$O bits$O unzip$O inflate$O: gzip.h tailor.h
util$O lzw$O unlzw$O unpack$O unlzh$O crypt$O: gzip.h tailor.h

gzip$O unlzw$O: revision.h lzw.h

bits$O unzip$O util$O zip$O: crypt.h

gzip$O getopt$O: getopt.h

