SRCDIR = ..
include $(SRCDIR)/Makefile.config

NULL=

# For netpbm, we're going to forego all the code integrity options because 
# the code imported from the libtiff generates too many warnings.
CFLAGS = $(CFLAGS_SHLIB) -O2 $(IPATH) $(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
	rm -f $@
	ln -s $< $@
libtiff.so.3.5.4: ${OBJS}
	$(LD) $(LDSHLIB) -o $@ -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: libtiff.so.3.5.4
	${INSTALL} -c -m 655 libtiff.so.3.5.4 $(INSTALLLIBS)/libtiff.so.3.5.4
	cd $(INSTALLLIBS) ; ln -s libtiff.so.3.5.4 libtiff.so.3
	cd $(INSTALLLIBS) ; ln -s libtiff.so.3.5.4 libtiff.so

.PHONY: install.staticlib
install.staticlib: libtiff.a
	$(INSTALL) -m$(INSTALL_PERM_LIBS) $< $(INSTALLLIBS)/$<

.PHONY: install.hdr
install.hdr: $(INTERFACE_HEADERS)
	-for i in $(INTERFACE_HEADERS); do \
	    h=`basename $$i`; \
	    cmp -s $$i $(INSTALLHDRS)/$$h || \
	        ${INSTALL} -c -m 644 $$i $(INSTALLHDRS)/$$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
