srcdir = @srcdir@
VPATH  = @srcdir@

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

OBJS= \
	Pextlib.o \
	adv-flock.o \
	curl.o \
	filemap.o \
	fs-traverse.o \
	md5cmd.o \
	mktemp.o \
	pipe.o \
	readdir.o \
	readline.o \
	realpath.o \
	rmd160cmd.o \
	setmode.o \
	sha1cmd.o \
	sha256cmd.o \
	strsed.o \
	system.o \
	tracelib.o \
	tty.o \
	uid.o \
	vercomp.o \
	xinstall.o
ifeq (@TRACEMODE_SUPPORT@,1)
OBJS+=sip_copy_proc.o
endif

ifneq ($(HAVE_GETDELIM),yes)
COMPAT_OBJS+= ../compat/getdelim.o
endif
ifneq ($(HAVE_GETLINE),yes)
COMPAT_OBJS+= ../compat/getline.o
endif
ifneq ($(HAVE_STRLCAT),yes)
COMPAT_OBJS+= ../compat/strlcat.o
endif

CPPFLAGS+= -I$(srcdir)/../compat
LIBS+= $(COMPAT_OBJS)

SHLIB_NAME= Pextlib${SHLIB_SUFFIX}
INSTALLDIR= ${TCL_PACKAGE_PATH}/pextlib1.0

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

# tracelib.o has an additional dependency
tracelib.o: ../darwintracelib1.0/sandbox_actions.h

CPPFLAGS := ${SQLITE3_CPPFLAGS} ${CPPFLAGS}
CFLAGS+= ${CURL_CFLAGS} ${MD5_CFLAGS} ${READLINE_CFLAGS}
LIBS+= ${CURL_LIBS} ${MD5_LIBS} ${READLINE_LIBS}
ifeq (darwin,@OS_PLATFORM@)
LIBS+= ../registry2.0/registry${SHLIB_SUFFIX}
SHLIB_LDFLAGS+= -install_name ${INSTALLDIR}/${SHLIB_NAME}
${SHLIB_NAME}: ../registry2.0/registry${SHLIB_SUFFIX}
endif

.PHONY: test codesign

test:: ${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/checksums.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/curl.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/filemap.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/fs-traverse.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/symlink.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/system.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/unsetenv.tcl ./${SHLIB_NAME}
	${TCLSH} $(srcdir)/tests/vercomp.tcl ./${SHLIB_NAME}

distclean::
	rm -f Makefile

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