NAME=Marshall
MAJOR_VERSION=0.6
MINOR_VERSION=1
RELEASE_TAG=
VERSION=${MAJOR_VERSION}.${MINOR_VERSION}${RELEASE_TAG}
PACKAGE_NAME=${NAME}-${VERSION}

PYTHON="/usr/bin/python"
TMPDIR=~/tmp

CURDIR=$(shell pwd)
BASE_DIR=$(shell dirname ${CURDIR})
INSTANCE_HOME=~/src/instance/pd11
PACKAGES=${NAME}
BASE_URL=https://www.enfoldsystems.com/Products/Open/Downloads
TEST_OPTS=--keepbytecode -v -p --libdir Products/${NAME}

RM=rm -f
RMRF=rm -rf
FIND=find
XARGS=xargs
CD=cd
LN=ln -sfn
CP=cp
TAR=tar
ZIP=zip
MKDIR=mkdir -p
MV=mv

.PHONY : clean test reindent reindent_clean sdist
.PHONY : default

# default:     The default step (invoked when make is called without a target)
default: quickclean test

clean :
	find . \( -name '*~' -o -name '*.py[co]' -o -name '*.bak' -o -name '\.#*' \) -exec rm {} \; -print

quickclean :
	find . \( -name '*~' -o -name '*.bak' -o -name '\.#*' \) -exec rm {} \; -print

reindent :
	~/src/reindent.py -r -v .

test :
	cd ${INSTANCE_HOME} && ./bin/zopectl test ${TEST_OPTS}

# sdist:       Create a source distribution file (implies clean).
#
sdist: reindent clean sdist_tgz
	${CD} ${TMPDIR} && \
	${TAR} -zxf ${BASE_DIR}/${PACKAGE_NAME}.tgz && \
	${ZIP} -r ${PACKAGE_NAME}.zip ${PACKAGE_NAME}
	${RMRF} ${TMPDIR}/${PACKAGE_NAME}
	${MV} ${TMPDIR}/${PACKAGE_NAME}.zip ${BASE_DIR}

# sdist_tgz:   Create a tgz archive file as a source distribution.
#
sdist_tgz:
	echo -n "${MAJOR_VERSION}.${MINOR_VERSION}${RELEASE_TAG}" >\
          ${CURDIR}/version.txt
	${MKDIR} ${TMPDIR}/${PACKAGE_NAME}
	${CD} ${TMPDIR}/${PACKAGE_NAME} && \
          for package in ${PACKAGES}; do ${LN} ${BASE_DIR}/$$package .; done && \
          ${CD} ${TMPDIR} && ${TAR} \
           --exclude=${PACKAGE_NAME}.tgz \
           --exclude=CVS \
           --exclude=.svn \
           --exclude=.cvsignore \
           --exclude=makefile \
           --exclude=Makefile \
           --exclude=*.pyc \
           --exclude=*.pyo \
           --exclude=TAGS \
           --exclude=*~ \
           --exclude=.#* \
	-zhcf ${BASE_DIR}/${PACKAGE_NAME}.tgz ${PACKAGE_NAME}
	${RMRF} ${TMPDIR}/${PACKAGE_NAME}


mail :
	mutt -nx -s 'New $(NAME) Release $(VERSION)' \
	-a $(BASE_DIR)/${PACKAGE_NAME}.tgz \
	-a $(BASE_DIR)/$(PACKAGE_NAME).zip \
	-i version.txt $(TO) < .

upload :
	curl -n -T $(BASE_DIR)/${PACKAGE_NAME}.tgz ${BASE_URL}/${PACKAGE_NAME}.tgz
#	curl -n -T $(BASE_DIR)/$(PACKAGE_NAME).zip ${BASE_URL}/${PACKAGE_NAME}.zip
