
srcdir = @srcdir@
VPATH  = @srcdir@

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

SRCS_AUTOCONF = registry_autoconf.tcl
SRCS = registry.tcl registry_util.tcl receipt_flat.tcl receipt_sqlite.tcl portimage.tcl portuninstall.tcl
OBJS = registry.o util.o \
	entry.o entryobj.o \
	file.o fileobj.o \
	portgroup.o portgroupobj.o
	#graph.o graphobj.o

SHLIB_NAME= registry${SHLIB_SUFFIX}
INSTALLDIR= ${DESTDIR}${TCL_PACKAGE_PATH}/registry2.0

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

CPPFLAGS+=-D_XOPEN_SOURCE=600

pkgIndex.tcl: $(SRCS) $(SRCS_AUTOCONF)

CFLAGS+=	${SQLITE3_CFLAGS}
LIBS+=	${SQLITE3_LIBS} ../cregistry/cregistry.a
ifeq ($(shell uname), Darwin)
SHLIB_LDFLAGS+= -install_name @loader_path/../registry2.0/${SHLIB_NAME}
endif

${SHLIB_NAME}: ../cregistry/cregistry.a

.PHONY: test

test:: ${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/entry.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/depends.tcl ./${SHLIB_NAME}

distclean:: clean
	rm -f registry_autoconf.tcl
	rm -f Makefile

install:: all $(SHLIB_NAME)
	$(INSTALL) -d -o "${DSTUSR}" -g "${DSTGRP}" -m "${DSTMODE}" "${INSTALLDIR}"
	$(INSTALL)    -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "${SHLIB_NAME}" "${INSTALLDIR}"
	$(SILENT) set -x; for file in ${SRCS}; do \
		$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "$(srcdir)/$$file" "${INSTALLDIR}/$$file"; \
	done
	$(SILENT) set -x; for file in ${SRCS_AUTOCONF}; do \
		$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "$$file" "${INSTALLDIR}/$$file"; \
	done
	$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 pkgIndex.tcl "${INSTALLDIR}"
