DESTDIR = /usr/local/libtiff
LIBDIR = /lib
#
AR=	ar
RANLIB=	ranlib
NULL=

# Put the location of your JPEG library interface header files here.
# If you don't have the JPEG library installed, you can't build JPEG
# decoding of tiff files into the tiff library, but you can still build
# it with all the rest of its function.  Just set JPEGHDR_DIR
# to NONE.
JPEGHDR_DIR = /usr/include/jpeg

IPATH=	-I.
CONF_LIBRARY=
CC=	gcc
COPTS=	-O2 
# For netpbm, we're going to forego all the code integrity options because 
# the code imported from the libtiff generates too many warnings.
#COPTS+= -ansi -pedantic -Wall -Wno-uninitialized
CFLAGS=	${COPTS} ${IPATH} ${CONF_LIBRARY} $(CDEBUG)

ifneq ($(JPEGHDR_DIR), NONE)
  IPATH+= -I$(JPEGHDR_DIR)
  CFLAGS+= -DJPEG_SUPPORT
endif

INTERFACE_HEADERS= tiff.h tiffio.h tiffconf.h

# The point of the variable SRCS is that not all the .c files in the 
# distribution are used for every platform.  For netpbm, we set SRCS to the 
# proper set for the platforms we know about.
SRCS	= \
	tif_aux.c \
	tif_close.c \
	tif_codec.c \
	tif_compress.c \
	tif_dir.c \
	tif_dirinfo.c \
	tif_dirread.c \
	tif_dirwrite.c \
	tif_dumpmode.c \
	tif_error.c \
	tif_fax3.c \
	tif_getimage.c \
	tif_jpeg.c \
	tif_flush.c \
	tif_luv.c \
	tif_lzw.c \
	tif_next.c \
	tif_open.c \
	tif_packbits.c \
	tif_pixarlog.c \
	tif_predict.c \
	tif_print.c \
	tif_read.c \
	tif_swab.c \
	tif_strip.c \
	tif_thunder.c \
	tif_tile.c \
	tif_unix.c \
	tif_version.c \
	tif_warning.c \
	tif_write.c \
	tif_zip.c \
	${NULL}
OBJS	= \
	tif_aux.o \
	tif_close.o \
	tif_codec.o \
	tif_compress.o \
	tif_dir.o \
	tif_dirinfo.o \
	tif_dirread.o \
	tif_dirwrite.o \
	tif_dumpmode.o \
	tif_error.o \
	tif_fax3.o \
	tif_fax3sm.o \
	tif_getimage.o \
	tif_jpeg.o \
	tif_flush.o \
	tif_luv.o \
	tif_lzw.o \
	tif_next.o \
	tif_open.o \
	tif_packbits.o \
	tif_pixarlog.o \
	tif_predict.o \
	tif_print.o \
	tif_read.o \
	tif_swab.o \
	tif_strip.o \
	tif_thunder.o \
	tif_tile.o \
	tif_unix.o \
	tif_version.o \
	tif_warning.o \
	tif_write.o \
	tif_zip.o \
	${NULL}

.PHONY: all
all:	 libtiff.a libtiff.so

libtiff.a: ${OBJS}
	${AR} rc libtiff.a $?
	${RANLIB} libtiff.a

# We need the symbolic link in this directory so that programs in the
# other netpbm source directories can compile against it.
libtiff.so: libtiff.so.3.5.4
	ln -sf libtiff.so.3.5.4 libtiff.so
libtiff.so.3.5.4: ${OBJS}
	gcc -shared -Wl,-soname,libtiff.so.3 -o libtiff.so.3.5.4 -lm ${OBJS}

mkg3states: mkg3states.c tif_fax3.h
	${CC} -o $@ ${CFLAGS} $<

# The finite state machine tables used by the G3/G4 decoders
# are generated by the mkg3states program.

tif_fax3sm.c: mkg3states 
	rm -f tif_fax3sm.c; ./mkg3states -c const $@

.PHONY: install
install: all installh
	${INSTALL} -c -m 644 libtiff.a ${DESTDIR}/lib/libtiff.a
	${RANLIB} ${DESTDIR}/lib/libtiff.a
	${INSTALL} -c -m 644 libtiff.so.3.5.4 ${LIBDIR}/libtiff.so.3.5.4

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

.PHONY: clean
clean:
	rm -f *.a *.o *.so* core a.out mkg3states tif_fax3sm.c

.PHONY: dep
dep Makefile.depend:
	$(CC) -MM $(IPATH) $(SRCS) >Makefile.depend

include Makefile.depend
