# **********************************************************************
# *
# * PostGIS - Spatial Types for PostgreSQL
# * http://postgis.net
# * Copyright 2008 Paul Ramsey, Mark Cave-Ayland
# *
# * This is free software; you can redistribute and/or modify it under
# * the terms of the GNU General Public Licence. See the COPYING file.
# *
# **********************************************************************

top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
builddir = @builddir@
srcdir = @srcdir@

CC=@CC@
SHELL = @SHELL@
LIBTOOL = @LIBTOOL@

LIBLWGEOM_LDFLAGS=../../../liblwgeom/.libs/liblwgeom.a
LIBLWGEOM_CFLAGS = -I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom
LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
PROJ_CFLAGS=@PROJ_CPPFLAGS@
PROJ_LDFLAGS=@PROJ_LDFLAGS@
GEOS_CFLAGS=@GEOS_CPPFLAGS@
GEOS_LDFLAGS=@GEOS_LDFLAGS@
CUNIT_LDFLAGS=@CUNIT_LDFLAGS@

RTCORE_CFLAGS = -I$(top_srcdir)/raster/rt_core
RTCORE_LDFLAGS = $(top_builddir)/raster/rt_core/librtcore.a

VPATH = $(srcdir)

CC=@CC@
CFLAGS = \
	-I$(top_builddir) \
	-I$(top_builddir)/raster \
	-I$(builddir) \
	-I$(builddir)/.. \
	-DPOSTGIS_TOP_SRC_DIR='"$(realpath $(top_srcdir))"' \
	$(LIBLWGEOM_CFLAGS) \
	$(RTCORE_CFLAGS) \
	$(PROJ_CFLAGS) \
	$(LIBGDAL_CFLAGS) \
	$(GEOS_CFLAGS) \
	@CUNIT_CPPFLAGS@ \
	@CFLAGS@

LDFLAGS = \
	$(RTCORE_LDFLAGS) \
	$(LIBLWGEOM_LDFLAGS) \
	$(LIBGDAL_LDFLAGS) \
	$(GEOS_LDFLAGS) \
	$(PROJ_LDFLAGS)


# ADD YOUR NEW TEST FILE HERE (1/1)
OBJS=	\
	cu_pixtype.o \
	cu_raster_basics.o \
	cu_band_basics.o \
	cu_raster_wkb.o \
	cu_raster_geometry.o \
	cu_raster_misc.o \
	cu_band_stats.o \
	cu_band_misc.o \
	cu_gdal.o \
	cu_spatial_relationship.o \
	cu_mapalgebra.o \
	cu_misc.o \
	cu_tester.o

# If we couldn't find the cunit library then display a helpful message
ifeq ($(CUNIT_LDFLAGS),)
all: requirements_not_met_cunit
check: requirements_not_met_cunit
else

# Build the unit tester
all: cu_tester

# Build and run the unit tester
check: cu_tester
	@./cu_tester

endif

# Build the main unit test executable
cu_tester: $(top_builddir)/raster/rt_core/librtcore.a $(OBJS)
	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(CUNIT_LDFLAGS)

# Command to build each of the .o files
$(OBJS): %.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(top_builddir)/raster/rt_core/librtcore.a:
	$(MAKE) -C $(top_builddir)/raster/rt_core

# Clean target
clean:
	rm -rf .libs
	rm -f $(OBJS)
	rm -f cu_tester

distclean: clean
	rm -f Makefile

# Requirements message
requirements_not_met_cunit:
	@echo
	@echo "WARNING:"
	@echo
	@echo "configure was unable to find CUnit which is required for unit testing."
	@echo "In order to enable unit testing, you must install CUnit and then re-run configure."
	@echo
