phony: dist
MAJOR_VERSION := $(shell grep MAJOR_VERSION src/stan/version.hpp | sed -e 's/.*\"\([^]]*\)\".*/\1/g')
MINOR_VERSION := $(shell grep MINOR_VERSION src/stan/version.hpp | sed -e 's/.*\"\([^]]*\)\".*/\1/g')
PATCH_VERSION := $(shell grep PATCH_VERSION src/stan/version.hpp | sed -e 's/.*\"\([^]]*\)\".*/\1/g')
VERSION_STRING := $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)

dist: clean-all 
	@echo ''
	@echo 'Building distribution tarball for version: ' $(VERSION_STRING)
	@echo stan-src-$(VERSION_STRING) > .fname
	@-rm -rf stan-src-$(VERSION_STRING) stan-src-$(VERSION_STRING).tgz
	@echo ''
	@echo '- making documentation' 
	$(MAKE) doxygen manual > /dev/null
	$(MAKE) clean-manual
	@echo ''
	@echo '- making directory: stan-src-$(VERSION_STRING)'
	@mkdir stan-src-$(VERSION_STRING)
	@echo ''
	@echo '- copying files (takes a few minutes)'
	rsync -avz --exclude "*~" --exclude ".fname" --exclude ".git*" --exclude stan-src-$(VERSION_STRING) --exclude "*.tgz" ./ stan-src-$(VERSION_STRING) > /dev/null
	@echo ''
	@echo '- creating the tarball'
	tar --gzip --create --dereference --mode=755 --file=stan-src-$(VERSION_STRING).tgz stan-src-$(VERSION_STRING)
	@echo ''
	@echo '- cleanup'
	-rm -rf stan-src-$(VERSION_STRING) .fname
