srcdir = @srcdir@
VPATH  = @srcdir@

include ../../Mk/macports.autoconf.mk

OBJS= 		libmachista.o hashmap.o machista_wrap.o
SHLIB_NAME= machista${SHLIB_SUFFIX}
INSTALLDIR=	${DESTDIR}${TCL_PACKAGE_PATH}/machista1.0

SWIG         = @SWIG@
SWIG_FLAGS   = -tcl8 -pkgversion 1.0 -namespace
SWIG_LDFLAGS = -ltcl

SWIG_IFACE = machista.i
SWIG_SRCS  = ${SWIG_IFACE:%.i=%_wrap.c}
SWIG_OBJS  = ${SWIG_SRCS:%.c=%.o}

TESTS = ./tests/libmachista-test

include $(srcdir)/../../Mk/macports.tea.mk

CFLAGS+= -fPIC

${SWIG_SRCS}:: ${SWIG_IFACE}
ifdef SWIG
	${SWIG} ${SWIG_FLAGS} $<
else
	@echo "Building ${SWIG_SRCS} requires swig, which you apparently did not have installed when configuring MacPorts." >&2
	@echo "Please install swig and re-run configure" >&2
	@echo "To use this SWIG, run configure as follows:" >&2
	@echo "    SWIG=/opt/swig/bin/swig ./configure --your-usual-config-flags" >&2
	@echo "If you checked out from svn you can also run svn revert in base/src/machista1.0 to get rid of this error" >&2
	@exit 1
endif

${SWIG_OBJS}:: ${SWIG_SRCS}

${PKG_INDEX}:: ${SWIG_SHLIB}
	$(SILENT) ../pkg_mkindex.sh $< || ( rm -rf $@ && exit 1 )

clean::
	rm -f ${SWIG_OBJS} ${PKG_INDEX}
	rm -f ${TESTS}
	rm -rf ${TESTS:%=%.dSYM}

distclean::
	rm -f Makefile

test:: ${TESTS}
	${TESTS}

tests/libmachista-test: tests/libmachista-test.c libmachista.h libmachista.o hashmap.o
	$(CC) $(CFLAGS) -D_POSIX_SOURCE -o $@ -I. $< libmachista.o hashmap.o

