#--*- Makefile -*--

TRUNK    ?= ^/trunk
BRANCHES ?= ^/branches

.PHONY: release major minor patch

VFILE = .version

VERSION := $(shell grep -v "^\#" ${VFILE})

all tests test: lib/Version.slib

lib/Version.slib: lib/Version.sin ${VFILE}
	sed 's/@VERSION@/${VERSION}/' $< > $@

release:
	svn ci
	svn cp ${TRUNK} ${BRANCHES}/release/v${VERSION} \
	   -m "Preparing version ${VERSION} for release in the release branch."
	${MAKE} minor

major:
	awk -F. '/^#/{print} !/^#/{print $$1+1 "." $$2 ($$3 ? ".":"") $$3}' \
		${VFILE} > ${VFILE}.$$$$; \
	mv -f ${VFILE}.$$$$ ${VFILE}

minor:
	awk -F. '/^#/{print} !/^#/{print $$1 "." $$2+1 ($$3 ? ".":"") $$3}' \
		${VFILE} > ${VFILE}.$$$$; \
	mv -f ${VFILE}.$$$$ ${VFILE}

patch:
	awk -F. '/^#/{print} !/^#/{print $$1 "." $$2 "." $$3+1}' \
		${VFILE} > ${VFILE}.$$$$; \
	mv -f ${VFILE}.$$$$ ${VFILE}
