# Zope2 build and install Makefile.

# We do as much as possible in Python in order to avoid needing to
# learn autoconf or some other awful thing. ;-)

NAME=Zope
MAJOR_VERSION=<<ZOPE_MAJOR_VERSION>>
MINOR_VERSION=<<ZOPE_MINOR_VERSION>>
RELEASE_TAG=<<VERSION_RELEASE_TAG>>
PACKAGE_NAME=${NAME}-${MAJOR_VERSION}.${MINOR_VERSION}-${RELEASE_TAG}

PYTHON="<<PYTHON>>"
ZPKG=zpkg
TMPDIR=/tmp
PREFIX=<<PREFIX>>
BASE_DIR=<<BASE_DIR>>
DISTUTILS_OPTS=<<DISTUTILS_OPTS>>
INSTALL_FLAGS=<<INSTALL_FLAGS>>
TESTOPTS=-v
BUILD_FLAGS=-i

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

.PHONY : clean install instance untestinst testinst build
.PHONY : default

# default:     The default step (invoked when make is called without a target)
default: build
	@echo
	@echo Zope built.  Next, do \'make install\' \(or \'make instance\'
	@echo to run a Zope instance directly from the build directory\).
	@echo

# build:
build:
	${PYTHON} "${BASE_DIR}/setup.py" \
           ${DISTUTILS_OPTS} build_ext ${BUILD_FLAGS}

# install:     Install a software home.
install: version_txt
	${PYTHON} "${BASE_DIR}/setup.py" ${DISTUTILS_OPTS} \
	   build_ext ${BUILD_FLAGS} \
	   install --skip-build --home="${PREFIX}" ${INSTALL_FLAGS}
	[ -f ${PREFIX}/bin/python ] || ${LN} ${PYTHON} ${PREFIX}/bin/python
	@echo
	@echo Zope binaries installed successfully.
	@echo Now run \'${PREFIX}/bin/mkzopeinstance.py\'

# inplace:     Do an in-place build
inplace: build

# instance:    Do an inplace build and create an instance home in the resulting
#              software home.
instance: build
	${PYTHON} "${BASE_DIR}/utilities/mkzopeinstance.py" ${MKZ_FLAGS} \
           --dir="${BASE_DIR}" 

# uninstance:  Remove the instance files made by make instance (w/ prejudice)
uninstance:
	${RMRF} "${BASE_DIR}/bin"
	${RMRF} "${BASE_DIR}/etc"
	${RMRF} "${BASE_DIR}/import"
	${RMRF} "${BASE_DIR}/log"
	${RMRF} "${BASE_DIR}/var"
	${RMRF} "${BASE_DIR}/Products"

# testinst:    Perform an inplace build and create an instance home in the
#              resulting software home without asking questions.  Useful when
#              performing automated testing.
testinst: MKZ_FLAGS=--user=admin:admin
testinst: instance

# test:        Do an inplace build and run the Zope test suite.
test: inplace
	${PYTHON} "${BASE_DIR}/test.py" ${TESTOPTS}

# clean:       Delete the build files and any binaries/bytecode files in
#              the source directory for good measure.
clean:
	${FIND} "${BASE_DIR}" \
         -name '*.py[co]' -o -name '*.so' -o -name '*.o' | ${XARGS} ${RM}

# version_txt: create a version file in lib/python/version.txt
version_txt:
	printf "Zope ${MAJOR_VERSION}.${MINOR_VERSION}-${RELEASE_TAG}" >\
          "${BASE_DIR}/lib/python/version.txt"

# Building a source distribution requires that zpkg be available:
sdist:
	${ZPKG} -C ${BASE_DIR}/releases/Zope2.cfg

# clobber:     Make the source tree 'pristine' again.
clobber: clean uninstance

# distclean:     Make the source tree *really* 'pristine' again.
distclean: clobber
	${RM} makefile Makefile
	${RMRF} build-base
