#	$Header: /usr/people/sam/tiff/libtiff/RCS/Makefile.sun,v 1.27 91/08/23 17:09:22 sam Exp $
#
# Tag Image File Format Library
#
# Copyright (c) 1988, 1989, 1990, 1991 Sam Leffler
# Copyright (c) 1991 Silicon Graphics, Inc.
# 
# Permission to use, copy, modify, distribute, and sell this software and 
# its documentation for any purpose is hereby granted without fee, provided
# that (i) the above copyright notices and this permission notice appear in
# all copies of the software and related documentation, and (ii) the names of
# Sam Leffler and Silicon Graphics may not be used in any advertising or
# publicity relating to the software without the specific, prior written
# permission of Stanford and Silicon Graphics.
# 
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
# 
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
# OF THIS SOFTWARE.
#

ROOT=../../..
include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk


DESTDIR=.
#
AR=	ar
RANLIB=	true
#RANLIB=	/usr/bin/ranlib
NULL=

IPATH=	-I.
#
# Library-wide configuration defines:
#    SUBFILE_COMPAT	include compat code for bad SubFileType tag
#    JPEG_SUPPORT	add support for C-Cube JPEG tags & JPEG algorithm
#
# Compression configuration defines:
#    CCITT_SUPPORT	add support for CCITT Group 3 & 4 algorithms
#    PACKBITS_SUPPORT	add support for Macintosh PackBits algorithm
#    LZW_SUPPORT	add support for LZW algorithm
#    THUNDER_SUPPORT	add support for ThunderScan 4-bit RLE algorithm
#    NEXT_SUPPORT	add support for NeXT 2-bit RLE algorithm
#    JPEG_SUPPORT	add support for C-Cube JPEG tags & JPEG algorithm
#
# Note that if you change the library-wide configuration, you'll
# need to manual force a full rebuild.  Changing the configuration
# of which compression algorithms are included in the library is
# automatically handled (i.e. tif_compress.o has a dependency on
# the Makefile).
#
CONF_COMPRESSION=\
	-DPACKBITS_SUPPORT \
	-DLZW_SUPPORT \
	-DCCITT_SUPPORT \
	-DTHUNDER_SUPPORT  \
	-DNEXT_SUPPORT  \
	${NULL}
CONF_LIBRARY=\
	-DUSE_VARARGS=0 \
	-DUSE_PROTOTYPES=1 \
	${NULL}
#COPTS = -g
COPTS = -O2

CFLAGS=	${COPTS} ${IPATH} ${CONF_LIBRARY}

INCLUDES =		\
	tiff.h		\
	tiffio.h
BASES =			\
	tif_fax3	\
	tif_fax4	\
	tif_ccittrle	\
	tif_close	\
	tif_dir		\
	tif_compat	\
	tif_compress	\
	tif_dumpmode	\
	tif_error	\
	tif_jpeg	\
	tif_flush	\
	tif_lzw		\
	tif_open	\
	tif_next	\
	tif_packbits	\
	tif_print	\
	tif_read	\
	tif_swab	\
	tif_strip	\
	tif_thunder	\
	tif_tile	\
	tif_warning	\
	tif_write
C_SOURCES = ${BASES:%=%.c}
OBJECTS = ${BASES:%=$(PLATFORM)/%.o}

HEADERS = 		\
	g3states.h	\
	machdep.h	\
	prototypes.h	\
	t4.h		\
	tif_fax3.h	\
	tiff.h		\
	tiffcompat.h	\
	tiffio.h	\
	tiffioP.h
SOURCES =		\
	${C_SOURCES}	\
	${HEADERS}	\
	${OTHER_SOURCES}
OTHER_SOURCES =		\
	Makefile
ALL_SOURCES =		\
	${SOURCES}	\
	index.html	\
	source.html

.PHONY: all copy clean lib

all: lib

lib: $(PLATFORM) $(WAIT) g3states.h $(WAIT) $(PLATFORM)/libtiff.a

$(PLATFORM)/libtiff.a: ${OBJECTS}
	rm -rf $@
	${AR} rc $@ ${OBJECTS}
	${RANLIB} $@

tif_compress.o: tif_compress.c Makefile
	${CC} -c ${CFLAGS} ${CONF_COMPRESSION} tif_compress.c
tif_dir.o: tif_dir.c Makefile
	${CC} -c ${CFLAGS} tif_dir.c
${OBJECTS}:
	$(CC) -c ${CFLAGS} -o $@ $(@:$(PLATFORM)/%.o=%.c)

tif_fax3.c: g3states.h

g3states.h: mkg3states.c
	${CC} -o $(PLATFORM)/mkg3states ${CFLAGS} mkg3states.c
	./$(PLATFORM)/mkg3states > g3states.h

install: all installh
	-for i in ${ALL}; do \
		${INSTALL} -c -m 644 $$i ${DESTDIR}/lib/$$i; \
		${RANLIB} ${DESTDIR}/lib/$$i; \
	done

installh: ${INCLUDES}
	-for i in ${INCLUDES}; do \
	    h=`basename $$i`; \
	    cmp -s $$i ${DESTDIR}/include/$$h || \
	        ${INSTALL} -c -m 444 $$i ${DESTDIR}/include/$$h; \
	done

clean: site

copy: source.html
	set -e ;							\
	if [ "$(COPY_DIRECTORY)" = "" ] ;				\
	  then								\
	    echo "Please set COPY_DIRECTORY in `pwd`" ;			\
	    exit 1 ;							\
	  fi
	rm -rf $(COPY_DIRECTORY)
	mkdir -p $(COPY_DIRECTORY)
	cp ${ALL_SOURCES} $(COPY_DIRECTORY)

site:
	rm -rf $(PLATFORM)
	rm -f core g3states.h `ls | grep "~$$"`
 
source.html: Makefile ${SOURCES}
	@echo -n "Generating $@..."
	@rm -f $@
	@echo '<HTML>' > $@
	@echo '<Head>' >> $@
	@echo '<Title>PBMPlus LibTIFF Directory Source Files</Title>' >> $@
	@echo '</Head>' >> $@
	@echo '<Body>' >> $@
	@echo '<P>These are the source files for the' >> $@
	@echo '<A HRef="index.html">PBMPlus Download</A>' >> $@
	@echo 'top-level directory.</P>' >> $@
	@echo '<H1>' >> $@
	@echo 'PBMPlus LibTIFF Directory Source Files' >> $@
	@echo '</H1>' >> $@
	@echo '<P>The following source files are available:</P>' >> $@
	@echo '<UL>' >> $@
	@for i in `ls ${SOURCES} | sort` ; do 				\
		echo "  <LI><A HRef='$$i'>$$i</A></LI>" >> $@ ;		\
		done
	@echo '</UL>' >> $@
	@echo '<HR>' >> $@
	@echo '<Address>' >> $@
	@echo 'This page is' >> $@
	@echo '<A HRef="../../../../copyright.html">' >> $@
	@echo 'Copyright</A> (c) 1998 by' >> $@
	@echo '<A HRef="../../../../gramlich.html">' >> $@
	@echo 'Wayne Gramlich</A> All rights reserved.' >> $@
	@echo '</Address>' >> $@
	@echo '</Body>' >> $@
	@echo '</HTML>' >> $@
	@echo "Done"
	
$(PLATFORM):
	rm -rf $@
	mkdir $@
