###############################################################################
#
# File:         Makefile
# RCS:          $Header: Makefile,v 1.3 89/09/20 14:53:10 chip Rel $
# Description:  Xtiff makefile
# Author:       Chip Chapin, Hewlett-Packard Company
# Created:      Tue Jul 4, 1989
# Modified:     Wed Sep 20 14:53:10 1989 (Chip Chapin) chip@hpcllcc
# Language:     make
# Package:      xtiff
# Status:       Experimental (Do Not Distribute)
#
# $Log:	Makefile,v $
# Revision 1.3  89/09/20  14:53:10  14:53:10  chip (Chip Chapin)
# Public release 1.4
# 
# Revision 1.1  89/09/20  12:50:40  12:50:40  chip (Chip Chapin)
# Initial revision
# 
#
###############################################################################

SHELL	= /bin/sh

# Depends upon the availability of Sam Leffler's TIFF library
TIFFDIR	= ../libtiff
LIBTIFF	= $(TIFFDIR)/libtiff.a
IPATH	= -I$(TIFFDIR)

#CFLAGS	= -g
CFLAGS	= -O

COPTS	= $(IPATH)

# name of main program -- this determines a lot of other names
PROGRAM	= xtiff

# where to install this stuff
DEST	      = /usr/local
#DEST	      = $(HOME)/local
DESTBIN	      = $(DEST)/bin/X11
DESTLIB       = $(DEST)/lib
DESTMAN	      = $(DEST)/man
DESTMAN1      = $(DESTMAN)/man1.Z

# release directory.  Nobody should care about this but me
FTPHOME	      = /extra/users/ftp
RELEASEDIR    = $(FTPHOME)/pub/$(PROGRAM)

MAN	= $(PROGRAM).1
TARFILE	= $(PROGRAM).tar
DATA	=

# List of files controlled by RCS
RCSFILES=README Makefile $(MAN) $(PROGRAM).c $(PROGRAM).pkg

# List of test images
TESTFILES      = cramps.tif \
		jello.tif \
		logo-picio.tif \
		logo.tif \
		oxford.tif \
		quad-lzwCut.tif \
		text.tif

# Directory containing all images, both tests and extra ones.
IMAGEDIR      = ../Images

# List of files that go out on a distribution
DISTFILES=$(RCSFILES)


OBJS	=

LIBS	= $(LIBTIFF) -lX11 -lXt

LD	= cc

all:	$(PROGRAM)

$(PROGRAM):	$(PROGRAM).o $(LIBTIFF)
		@echo "Linking $@ ...\c"
		@$(LD) $(LDFLAGS) $@.o $(OBJS) $(LIBS) -o $@
		@echo " done."

install:	$(PROGRAM) $(DATA) $(MAN)
		@if [ ! -r $(DEST) ]; then mkdir $(DEST); fi
		@echo Installing $(PROGRAM) in $(DESTBIN)
		@-strip $(PROGRAM)
		@if [ ! -r $(DESTBIN) ]; then mkdir $(DESTBIN); fi
		@if [ $(DESTBIN) != . ]; then \
		((cd $(DESTBIN);rm -f $(PROGRAM)); \
		mv $(PROGRAM) $(DESTBIN)); fi
#		@echo Installing $(DATA) in $(DESTLIB)
#		@if [ ! -r $(DESTLIB) ]; then mkdir $(DESTLIB); fi
#		@if [ $(DESTLIB) != . ]; then \
#		mv $(DATA) $(DESTLIB); fi
		@if [ ! -r $(DESTMAN) ]; then mkdir $(DESTMAN); fi
		@echo Installing $(MAN) in $(DESTMAN1)
		@if [ ! -r $(DESTMAN1) ]; then mkdir $(DESTMAN1); fi
		@if [ $(DESTMAN1) != . ]; then \
		compress < $(MAN) > $(DESTMAN1)/$(MAN); fi

uninstall:;	@echo Un-installing $(PROGRAM), $(DATA) and $(MAN)
		rm -f $(DESTBIN)/$(PROGRAM)
#		rm -f $(DESTLIB)/$(DATA)
		rm -f $(DESTMAN1)/$(MAN)

shar: $(DISTFILES)
	shar -cstemv $(DISTFILES) > $(PROGRAM).shar

tar:		$(DISTFILES)
		tar cvf $(TARFILE) $(DISTFILES)
		compress < $(TARFILE) > $(TARFILE).Z
		rm -f $(TARFILE)
		touch tar

test:
		@echo "Running tests.  Verify that each image comes up OK."
		@for f in $(TESTFILES);do \
		echo "Testing $$f with no options"; \
		./$(PROGRAM) $(IMAGEDIR)/$$f; done
		@for f in $(TESTFILES);do \
		echo "Testing $$f with -p option"; \
		./$(PROGRAM) -p $(IMAGEDIR)/$$f; done
		@for f in ClaarTests/*.tif;do \
		echo "Testing $$f with -p option"; \
		./$(PROGRAM) -p $$f; done
		@echo "$(PROGRAM) testing complete."

checkin:	$(RCSFILES)
		ci -l $?
		touch checkin

relcheckin:	$(RCSFILES)
		@if [ "$(RELNAME)" = "" ]; \
		then echo "*** No RELNAME value specified ***"; \
		echo "*** Set RELNAME to release name and export it ***"; \
		exit 1; fi
		@if [ "$(CFLAGS)" != "-O" ]; \
		then echo "*** CFLAGS not set to -O for release ***"; \
		echo "*** Set CFLAGS to -O and export it ***"; \
		exit 1; fi
		ci -l -n"$(RELNAME)" -sRel $?
		echo "$(RELNAME)" > relcheckin

$(RCSFILES):;	co $@

# The nested makes are here because the timestamps don't get updated
# correctly from the ci -l otherwise.
release:	relcheckin
		make all
		strip $(PROGRAM)
#		make stdresults
		make tar
		@if [ ! -r $(RELEASEDIR) ]; then mkdir $(RELEASEDIR); fi
		if hp9000s800;then cp $(PROGRAM) $(RELEASEDIR)/$(PROGRAM).s800;fi
		@if [ ! -r $(RELEASEDIR)/Images ]; then \
			mkdir $(RELEASEDIR)/Images; fi
		cp $(IMAGEDIR)/* $(RELEASEDIR)/Images
		cp $(TARFILE).Z $(RELEASEDIR)
		compress < $(MAN) > $(RELEASEDIR)/$(MAN).Z
		cp README $(RELEASEDIR)/README.$(PROGRAM)
		touch release

#
.c.o:
	$(CC) $(CFLAGS) $(COPTS) -c $<
