MODULE_big = tiny
OBJS       = tiny.o
DATA_built = tiny.sql tiny.source int8.source int24.source int8.c.in int24.c.in tiny.c
EXTRA_CLEAN = 

SHLIB_LINK = $(BE_DLLLIBS)

ifdef NO_PGXS
subdir = src/tutorial
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/src/makefiles/pgxs.mk
else
PGXS = $(shell pg_config --pgxs)
include $(PGXS)
endif

int8.source: int.source.in
	sed -e "s:<TYPE>:INT8:g" \
	    -e "s:<Type>:Int8:g" \
	    -e "s:<type>:int8:g" \
	    -e "s:<UPTYPE>:INT16:g" \
	    -e "s:<Uptype>:Int16:g" \
	    -e "s:<uptype>:int16:g" \
		-e "s:<PG_GETARG_TYPE>:PG_GETARG_INT8:g" \
		-e "s:<PG_RETURN_TYPE>:PG_RETURN_INT8:g" \
		-e "s:<PG_RETURN_UPTYPE>:PG_RETURN_INT16:g" \
		-e "s:<DatumGetUpType>:DatumGetInt16:g" \
		-e "s:<NAME>:INT1:g" \
		-e "s:<Name>:Int1:g" \
		-e "s:<name>:int1:g" \
		-e "s:<UPNAME>:INT2:g" \
		-e "s:<Upname>:Int2:g" \
		-e "s:<upname>:int2:g" \
		-e "s:<TYPE_MAX>:INT8_MAX:g" \
		-e "s:<TYPE_MIN>:INT8_MIN:g" \
		-e "s:<internallength>:1:g" \
		-e "s:<alignment>:char:g" \
	< int.source.in > int8.source

int8.c.in: tiny.h int.c.in
	sed -e "s:<TYPE>:INT8:g" \
	    -e "s:<Type>:Int8:g" \
	    -e "s:<type>:int8:g" \
	    -e "s:<UPTYPE>:INT16:g" \
	    -e "s:<Uptype>:Int16:g" \
	    -e "s:<uptype>:int16:g" \
		-e "s:<PG_GETARG_TYPE>:PG_GETARG_INT8:g" \
		-e "s:<PG_RETURN_TYPE>:PG_RETURN_INT8:g" \
		-e "s:<PG_RETURN_UPTYPE>:PG_RETURN_INT16:g" \
		-e "s:<DatumGetUpType>:DatumGetInt16:g" \
		-e "s:<NAME>:INT1:g" \
		-e "s:<Name>:Int1:g" \
		-e "s:<name>:int1:g" \
		-e "s:<UPNAME>:INT2:g" \
		-e "s:<Upname>:Int2:g" \
		-e "s:<upname>:int2:g" \
		-e "s:<TYPE_MAX>:INT8_MAX:g" \
		-e "s:<TYPE_MIN>:INT8_MIN:g" \
		-e "s:<tofloat4>:i2tof:g" \
		-e "s:<fromfloat4>:ftoi2:g" \
		-e "s:<tofloat8>:i2tod:g" \
		-e "s:<fromfloat8>:dtoi2:g" \
	< int.c.in > int8.c.in

int24.source: int.source.in
	sed -e "s:<TYPE>:INT24:g" \
	    -e "s:<Type>:Int24:g" \
	    -e "s:<type>:int24:g" \
	    -e "s:<UPTYPE>:INT32:g" \
	    -e "s:<Uptype>:Int32:g" \
	    -e "s:<uptype>:int32:g" \
		-e "s:<PG_GETARG_TYPE>:PG_GETARG_INT24:g" \
		-e "s:<PG_RETURN_TYPE>:PG_RETURN_INT24:g" \
		-e "s:<PG_RETURN_UPTYPE>:PG_RETURN_INT32:g" \
		-e "s:<DatumGetUpType>:DatumGetInt32:g" \
		-e "s:<NAME>:INT3:g" \
		-e "s:<Name>:Int3:g" \
		-e "s:<name>:int3:g" \
		-e "s:<UPNAME>:INT4:g" \
		-e "s:<Upname>:Int4:g" \
		-e "s:<upname>:int4:g" \
		-e "s:<TYPE_MAX>:INT24_MAX:g" \
		-e "s:<TYPE_MIN>:INT24_MIN:g" \
		-e "s:<internallength>:3:g" \
		-e "s:<alignment>:char:g" \
	< int.source.in > int24.source

int24.c.in: tiny.h int.c.in
	sed -e "s:<TYPE>:INT24:g" \
	    -e "s:<Type>:Int24:g" \
	    -e "s:<type>:int24:g" \
	    -e "s:<UPTYPE>:INT32:g" \
	    -e "s:<Uptype>:Int32:g" \
	    -e "s:<uptype>:int32:g" \
		-e "s:<PG_GETARG_TYPE>:PG_GETARG_INT24:g" \
		-e "s:<PG_RETURN_TYPE>:PG_RETURN_INT24:g" \
		-e "s:<PG_RETURN_UPTYPE>:PG_RETURN_INT32:g" \
		-e "s:<DatumGetUpType>:DatumGetInt32:g" \
		-e "s:<NAME>:INT3:g" \
		-e "s:<Name>:Int3:g" \
		-e "s:<name>:int3:g" \
		-e "s:<UPNAME>:INT4:g" \
		-e "s:<Upname>:Int4:g" \
		-e "s:<upname>:int4:g" \
		-e "s:<TYPE_MAX>:INT24_MAX:g" \
		-e "s:<TYPE_MIN>:INT24_MIN:g" \
		-e "s:<tofloat4>:i4tof:g" \
		-e "s:<fromfloat4>:ftoi4:g" \
		-e "s:<tofloat8>:i4tod:g" \
		-e "s:<fromfloat8>:dtoi4:g" \
	< int.c.in > int24.c.in

tiny.c: tiny.c.in int8.c.in int24.c.in
	rm -f $@; \
	cat tiny.c.in int8.c.in int24.c.in > tiny.c

tiny.source: int8.source int24.source
	rm -f $@; \
	cat int8.source int24.source > tiny.source

%.sql: %.source
	rm -f $@; \
	C=`pwd`; \
	sed -e "s:_OBJWD_:$$C:g" < $< > $@

