## Process this file with automake to produce Makefile.in
##

AUTOMAKE_OPTIONS = no-dependencies

distdir = ${PACKAGE_NAME}-${PACKAGE_VERSION}
memelibdir = ${libdir}/${PACKAGE_NAME}-${PACKAGE_VERSION}
memelibexecdir = ${libexecdir}/${PACKAGE_NAME}-${PACKAGE_VERSION}
memedatadir = $(DESTDIR)${datadir}/${PACKAGE_NAME}-${PACKAGE_VERSION}

SUBDIRS = src scripts tests doc etc website

SEDSPEC = \
  -e 's%@catalina.home@%$(CATALINA_HOME)%' \
  -e 's%@catalina.base@%$(CATALINA_BASE)%' \
  -e 's%@version@%$(VERSION)%' \
  -e 's%@site.url@%${URL}%' \
  -e 's%@site.services@%$(OPAL_URL)%' \
  -e 's%@site.DN@%$(OPAL_DN)%' \
  -e 's%@site.contact@%$(CONTACT)%' \
  -e 's%@developer.contact@%$(DEV_CONTACT)%' \
  -e 's%@expiry@%${EXPIRY}%' \
  -e 's%@bin.dir@%$(bindir)%' \
  -e 's%@etc.dir@%$(sysconfdir)%' \
  -e 's%@lib.dir@%$(memelibdir)%' \
  -e 's%@libexec.dir@%$(memelibexecdir)%' \
  -e 's%@db.dir@%$(MEME_DB)%' \
  -e 's%@sendmail@%$(SENDMAIL)%' \
  -e 's%@MYHOME@%$(top_srcdir)%' \
  -e 's%@quota@%$(QUOTA)%' \
  -e 's%@drmaa_queue@%$(DRMAA_QUEUE)%' \
  -e 's%@drmaa_queue_short@%$(DRMAA_QUEUE_SHORT)%' 

# load the list of website files into the variable WEBSITE_FILES
# this should be generated by the bootstrap but can be regenerated by the command:
# ant generate-web-file-list
include website.mk

# Set the archive revision and date to refer to the changeset tagged as
# the original release or the current changeset if there is no such older tag.
ARCHIVE_DATE:
	git log -1 --format=%cd > $(top_srcdir)/ARCHIVE_DATE

ARCHIVE_REVISION:
	git rev-parse HEAD > $(top_srcdir)/ARCHIVE_REVISION

MemeSuite.properties: MemeSuite.properties.in Makefile
	$(SED) $(SEDSPEC) $< > $@

build.xml: build.xml.in Makefile
	$(SED) $(SEDSPEC) $< > $@

dbdir:
	mkdir -p $(DESTDIR)$(MEME_DB)

all-local:
if WEB
	$(ANT) compile
endif

install-data-local:
if WEB
	mkdir -p $(DEST_DIR)$(MEME_LOGS)
	chmod a+w $(DEST_DIR)$(MEME_LOGS)
endif

distclean-local: clean-local
clean-local: clean-ac
if WEB
	if [ -f build.xml ]; then $(ANT) clean; fi
	rm -f build.xml MemeSuite.properties
endif

clean-ac:
	rm -rf autom4te.cache

test:
	$(MAKE) check

install-data-hook: dbdir
if WEB
	$(ANT) install
endif

#dist-hook:

rmd160=$(shell openssl dgst -rmd160 $(DIST_ARCHIVES) | sed -e 's/^.*= //')
sha256=$(shell openssl dgst -sha256 $(DIST_ARCHIVES) | sed -e 's/^.*= //')
filesize=$(shell stat -f %z $(DIST_ARCHIVES))

Portfile: etc/Portfile.in $(DIST_ARCHIVES)
	echo ${rmd160}
	echo ${sha256}
	echo ${filesize}
	sed -e 's/@SHA256@/$(sha256)/' \
	    -e 's/@RMD160@/$(rmd160)/' \
	    -e 's/@FILESIZE@/$(filesize)/' \
	    -e 's/@ARCHIVE@/$(DIST_ARCHIVES)/' < etc/Portfile.in > Portfile
	@mkdir -p ~/ports/science/memesuite
	@cp Portfile ~/ports/science/memesuite
	@portindex -f  -o ~/ports ~/ports


BUILT_SOURCES = ARCHIVE_REVISION ARCHIVE_DATE 

if WEBSITE
BUILT_SOURCES += MemeSuite.properties build.xml
endif

EXTRA_DIST = ARCHIVE_REVISION ARCHIVE_DATE build.xml.in MemeSuite.properties.in website.mk $(WEBSITE_FILES)

AM_DISTCHECK_CONFIGURE_FLAGS= --enable-build-libxml2 --enable-build-libxslt 

