
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

SHLIB_NAME= registry${SHLIB_SUFFIX}
INSTALLDIR= ${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 (darwin,@OS_PLATFORM@)
SHLIB_LDFLAGS+= -install_name @loader_path/../registry2.0/${SHLIB_NAME}
endif

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

.PHONY: test codesign

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}" "${DESTDIR}${INSTALLDIR}"
	$(INSTALL)    -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "${SHLIB_NAME}" "${DESTDIR}${INSTALLDIR}"
	$(SILENT) set -x; for file in ${SRCS}; do \
		$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "$(srcdir)/$$file" "${DESTDIR}${INSTALLDIR}/$$file"; \
	done
	$(SILENT) set -x; for file in ${SRCS_AUTOCONF}; do \
		$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 "$$file" "${DESTDIR}${INSTALLDIR}/$$file"; \
	done
	$(INSTALL) -o "${DSTUSR}" -g "${DSTGRP}" -m 444 pkgIndex.tcl "${DESTDIR}${INSTALLDIR}"

codesign:: $(SHLIB_NAME)
	../codesign.sh $?
