#
# makefile for pngmeta

ZLIB=../zlib
LIBPNG=../libpng

# Compile with GNU cc
CC=gcc
EXTRA_CC_FLAGS=-W -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wpointer-arith -Wshadow -Wstrict-prototypes

# If you are not using gcc, set these options (must be an ANSI C compiler)
#CC=cc
#EXTRA_CC_FLAGS=


CFLAGS= $(EXTRA_CC_FLAGS) -I$(LIBPNG) -I$(ZLIB) -g
LDFLAGS=-L$(LIBPNG) -L$(ZLIB) -lpng -lz -lm

# Need ranlib?
#RANLIB=ranlib
RANLIB=echo

INSTALL=install

# hierarchy where make install puts pngmeta
prefix=/usr/local


# Nothing needs configuring below here

PACKAGE=pngmeta
VERSION=1.6

TEMPDIR=/tmp

DISTFILES=Makefile README test1.out test2.out test3.out pngmeta.1 Changes \
	pngmeta.c 8859.png ctzn0g04.png ct1n0g04.png


OBJS = pngmeta.o

all: build

build: pngmeta

pngmeta: $(OBJS)
	$(CC) -o pngmeta $(CCFLAGS) pngmeta.o $(LDFLAGS)

test: pngmeta
	@echo 'Testing uncompressed text chunk - tEXT (plain format)'
	@pngmeta -quiet ct1n0g04.png | diff -c test1.out -
	@echo 'Testing compressed text chunk   - zTXT (SOIF format)'
	@pngmeta -soif -quiet ctzn0g04.png | diff -c test2.out -
	@echo 'Testing HTML output'
	@pngmeta -html -quiet 8859.png | diff -c test3.out -

results: pngmeta
	pngmeta -quiet ct1n0g04.png > test1.out
	pngmeta -soif -quiet ctzn0g04.png > test2.out
	pngmeta -html -quiet 8859.png > test3.out

install: pngmeta
	-@mkdir $(prefix)/bin
	$(INSTALL) -c pngmeta $(prefix)/bin

pngmeta.man: pngmeta.1
	nroff -man $? > pngmeta.man

dist: $(DISTFILES)
	PACKNAME=$(PACKAGE)-$(VERSION); \
	PACKTAR=$$PACKNAME.tar; \
	PACKTARGZ=$$PACKTAR.gz; \
	$(MAKE) clean; \
	rm -rf dist; \
	mkdir dist dist/$$PACKNAME; \
	gnutar -c -f - `ls -1d $(DISTFILES)|sort -u` | (cd dist/$$PACKNAME; gnutar -x -f -); \
	chmod -R u+w dist/$$PACKNAME; \
	chmod -R go-w dist/$$PACKNAME; \
	cd dist; gnutar cf $(TEMPDIR)/$$PACKTAR $$PACKNAME; cd ..; \
	gzip -9 < $(TEMPDIR)/$$PACKTAR > $$PACKTARGZ; \
	rm -rf dist $(TEMPDIR)/$$PACKTAR

clean:
	rm -f *.o dist pngmeta.man pngmeta *~
