#
# GeoTIFF Library source for Makefile
#
DEPTH   = .

SRCDIR  = ${DEPTH}

#
SHELL   = /bin/sh
NULL    =
CD      = cd
CC      = @CC@
AR      = ar
LN      = @LN_S@
AROPTS  = r
RANLIB  = @RANLIB@
INSTALL = @INSTALL@
RM      = rm -f
MAKE    = make
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir	= @bindir@
libdir	= @libdir@
includedir = @includedir@
datadir = @datadir@/epsg_csv

BIN=${SRCDIR}/bin
LIB_XTIFF=${SRCDIR}/libxtiff
XTIFF=xtiff.o
XTIFFINC= xtiffio.h xtiffiop.h

VERSION_MAJOR	=	@VERSION_MAJOR@
VERSION_MINOR	=	@VERSION_MINOR@
VERSION_POINT	=	@VERSION_POINT@

LIBS=   @LIBS@
GEOTIFF_SO=@GEOTIFF_SO@
LD_SHARED=@LD_SHARED@

GT_INCLUDE_FILES = xtiffio.h xtiffiop.h geotiff.h geotiffio.h geovalues.h \
	geonames.h geokeys.h geo_tiffp.h geo_config.h geo_keyp.h \
	geo_normalize.h cpl_serv.h cpl_csv.h \
	epsg_datum.inc epsg_gcs.inc epsg_pm.inc epsg_units.inc geo_ctrans.inc\
	epsg_ellipse.inc epsg_pcs.inc epsg_proj.inc epsg_vertcs.inc geokeys.inc


#
IPATH   = -I. -I${SRCDIR} @TIFF_INC@ @PROJ_INC@
#
CONF_LIBRARY=\
	${NULL}
COPTS	= @CFLAGS@ -DCSV_DATA_DIR=\"$(datadir)\"
CFLAGS  = ${COPTS} ${IPATH} ${CONF_LIBRARY}
#
SRCS    = \
	${NULL}
CORE_OBJS    = \
	${XTIFF} \
	geo_free.o \
	geo_get.o \
	geo_names.o \
	geo_new.o \
	geo_print.o \
	geo_set.o \
	geo_tiffp.o \
	geo_write.o \
	geo_trans.o \
	geo_normalize.o \
	geotiff_proj4.o \
	geo_extra.o \
	cpl_serv.o \
	${NULL}

CSV_INCODE_OBJS = \
	cpl_csv_incode.o \
	csv/compd_cs.o \
	csv/ellips_alias.o \
	csv/ellipsoid.o \
	csv/gdatum_alias.o \
	csv/geod_datum.o \
	csv/geod_trf.o \
	csv/horiz_cs.o \
	csv/p_meridian.o \
	csv/trf_nonpolynomial.o \
	csv/trf_path.o \
	csv/uom_an_alias.o \
	csv/uom_angle.o \
	csv/uom_le_alias.o \
	csv/uom_length.o \
	csv/uom_sc_alias.o \
	csv/uom_scale.o \
	csv/vert_cs.o \
	csv/vert_datum.o \
	csv/vert_offset.o

CSV_FILE_OBJS = \
	cpl_csv.o

# CSV_SOURCE can be either $(CSV_FILE_OBJS) or $(CSV_INCODE_OBJS)
OBJS  =	$(CORE_OBJS) @CSV_SOURCE@

TARGETS = libgeotiff.a

all:    Makefile ${TARGETS} ${GEOTIFF_SO} Progs

libgeotiff.a: ${OBJS}
	${AR} ${AROPTS} libgeotiff.a $?
	${RANLIB} libgeotiff.a

libgeotiff.so.$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_POINT): ${OBJS}
	${LD_SHARED} ${OBJS} ${LIBS} -o $(GEOTIFF_SO)
	rm -f libgeotiff.so
	${LN} $(GEOTIFF_SO) libgeotiff.so

Progs:
	${CD} ${BIN};\
	${MAKE}

${OBJS}: ${SRCDIR}/geotiff.h ${SRCDIR}/geotiffio.h ${SRCDIR}/geo_config.h

${XTIFFINC}:
	${RM} ${XTIFFINC}
	${LN} ${LIB_XTIFF}/*.h .

${XTIFF}: ${LIB_XTIFF}/xtiff.c  ${XTIFFINC}
	${CC} -c ${CFLAGS}  ${LIB_XTIFF}/xtiff.c

geo_free.o: ${SRCDIR}/geo_free.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_free.c

geo_get.o: ${SRCDIR}/geo_get.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_get.c

geo_names.o: ${SRCDIR}/geo_names.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_names.c

geo_new.o: ${SRCDIR}/geo_new.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_new.c

geo_print.o: ${SRCDIR}/geo_print.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_print.c

geo_set.o: ${SRCDIR}/geo_set.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_set.c

geo_tiffp.o: ${SRCDIR}/geo_tiffp.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_tiffp.c

geo_write.o: ${SRCDIR}/geo_write.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_write.c

geo_trans.o: ${SRCDIR}/geo_trans.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_trans.c

geo_normalize.o: ${SRCDIR}/geo_normalize.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_normalize.c

geo_extra.o: ${SRCDIR}/geo_extra.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geo_extra.c

cpl_csv.o: ${SRCDIR}/cpl_csv.c
	${CC} -c ${CFLAGS} ${SRCDIR}/cpl_csv.c

cpl_serv.o: ${SRCDIR}/cpl_serv.c
	${CC} -c ${CFLAGS} ${SRCDIR}/cpl_serv.c

geotiff_proj4.o: ${SRCDIR}/geotiff_proj4.c
	${CC} -c ${CFLAGS} ${SRCDIR}/geotiff_proj4.c

${SRCDIR}/csv/%.o:	${SRCDIR}/csv/%.c
	${CC} -c ${CFLAGS} ${SRCDIR}/csv/$*.c -o ${SRCDIR}/csv/$*.o

clean:
	rm -f ${TARGETS} ${OBJS} ${XTIFFINC} core a.out

dist-clean: clean
	(cd bin; $(MAKE) clean)
	rm -rf config.* geo_config.h

config.status:	configure
	./configure

geo_config.h: geo_config.h.in config.status
	./config.status
	touch geo_config.h

Makefile:	Makefile.in config.status
	./config.status

dox:
	doxygen

configure:	configure.in aclocal.m4
	autoconf

install:
	$(INSTALL) -d $(libdir)
	$(INSTALL) libgeotiff.a ${libdir}
	$(INSTALL) -d $(includedir)
	$(INSTALL) $(GT_INCLUDE_FILES) $(includedir)
	$(INSTALL) -d $(datadir)
	$(INSTALL) csv/*.csv $(datadir)
	$(INSTALL) -d $(bindir)
	$(INSTALL) bin/listgeo bin/geotifcp $(bindir)
	if test ! -z "$(GEOTIFF_SO)" ; then \
	   $(INSTALL) $(GEOTIFF_SO) ${libdir}; \
	   rm -f ${libdir}/libgeotiff.so.$(VERSION_MAJOR).$(VERSION_MINOR); \
	   ${LN} ${libdir}/$(GEOTIFF_SO) ${libdir}/libgeotiff.so.$(VERSION_MAJOR).$(VERSION_MINOR); \
	   rm -f ${libdir}/libgeotiff.so.$(VERSION_MAJOR); \
	   ${LN} ${libdir}/libgeotiff.so.$(VERSION_MAJOR).$(VERSION_MINOR) \
		${libdir}/libgeotiff.so.$(VERSION_MAJOR); \
	   rm -f ${libdir}/libgeotiff.so; \
	   ${LN} ${libdir}/libgeotiff.so.$(VERSION_MAJOR) \
		${libdir}/libgeotiff.so; \
	fi


