# Makefile for Cygwin32 architecture

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
srcdir = @srcdir@
VPATH = $(srcdir)

CC = @CC@
AR = @AR@
SHELL = @SHELL@
RANLIB = @RANLIB@
EXEEXT = @EXEEXT@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

FLAGS_TO_PASS = \
        CPP="$(CC) -E" \
        prefix=$(prefix) \
        tooldir=$(tooldir) \
        CC="$(CC)" \
        AR=$(AR) RANLIB=$(RANLIB)

# Mostly original Makefile follows

CFLAGS=-Wall -O2 -fomit-frame-pointer -fno-strength-reduce

OBJS= blocksort.o  \
      huffman.o    \
      crctable.o   \
      randtable.o  \
      compress.o   \
      decompress.o \
      bzlib.o

.PHONY: all

all: bzip2$(EXEEXT)

libbz2.a: $(OBJS)
	rm -f libbz2.a
	$(AR) clq libbz2.a $(OBJS)

bzip2$(EXEEXT): libbz2.a bzip2.o
	$(CC) $(CFLAGS) -o bzip2$(EXEEXT) bzip2.o -L. -lbz2
	$(CC) $(CFLAGS) -o bzip2recover$(EXEEXT) bzip2recover.c

check test: bzip2
	@cat words1
	./bzip2 -1k sample1.ref
	mv sample1.ref.bz2 sample1.rb2
	./bzip2 -2k sample2.ref
	mv sample2.ref.bz2 sample2.rb2
	./bzip2 -dk sample1.bz2
	mv sample1 sample1.tst
	./bzip2 -dk sample2.bz2
	mv sample2 sample2.tst
	@cat words2
	cmp sample1.bz2 sample1.rb2 
	cmp sample2.bz2 sample2.rb2
	cmp sample1.tst sample1.ref
	cmp sample2.tst sample2.ref
	@cat words3

install: bzip2$(EXEEXT)
	$(INSTALL_PROGRAM) bzip2$(EXEEXT) $(bindir)
	$(INSTALL_PROGRAM) bzip2$(EXEEXT) $(bindir)/bunzip2$(EXEEXT)
	$(INSTALL_PROGRAM) bzip2$(EXEEXT) $(bindir)/bzcat$(EXEEXT)
	$(INSTALL_PROGRAM) bzip2recover$(EXEEXT) $(bindir)

info:

install-info:

clean: 
	rm -f *.o libbz2.a bzip2$(EXEEXT) bzip2recover sample1.rb2 sample2.rb2 sample1.tst sample2.tst

bzip2.o: bzlib.h
	$(CC) $(CFLAGS) -c bzip2.c

.c.o: $*.o bzlib.h bzlib_private.h
	$(CC) $(CFLAGS) -c $*.c -o $*.o

tarfile:
	tar cvf interim.tar *.c *.h Makefile manual.texi manual.ps LICENSE bzip2.1 bzip2.1.preformatted bzip2.txt words1 words2 words3 sample1.ref sample2.ref sample1.bz2 sample2.bz2 *.html README libbz2.def libbz2.dsp dlltest.dsp 

Makefile: Makefile-cygwin config.status
	$(SHELL) ./config.status
