#
# Makefile -
#
#	Top-level Makefile for Yeti package and plugins.
#

# These values filled in by: yorick -batch make.i
Y_MAKEDIR=/usr/local/lib/yorick
Y_EXE=/usr/local/lib/yorick/bin/yorick
Y_EXE_PKGS=
Y_EXE_HOME=/usr/local/lib/yorick
Y_EXE_SITE=/usr/local/lib/yorick

# These values filled in by: ./configure [...]
YETI_PKGS = yeti yeti_fftw yeti_gsl yeti_regex yeti_tiff
YETI_VERSION_MAJOR = 6
YETI_VERSION_MINOR = 1
YETI_VERSION_MICRO = 6
YORICK_VERSION_MAJOR = 2
YORICK_VERSION_MINOR = 1
YORICK_VERSION_MICRO = 2

TMPDIR=/tmp

default: all

all: check
	@for dir in $(YETI_PKGS); do \
	  (cd $$dir; make); \
	done

check:
	@if test -z "$(YETI_PKGS)" -o ! -r config.h ; then \
	  echo "***************************************************************"; \
	  echo "  Before building Yeti, you must run the configuration script."; \
	  echo "  This is achieved by a command like:"; \
	  echo "      yorick -batch ./config.i [...]"; \
	  echo ""; \
	  echo "  See README file for detailled instructions.  For a summary"; \
	  echo "  of configuration options, you can also try:"; \
	  echo "      yorick -batch ./config.i --help"; \
	  echo "***************************************************************"; \
	  false; \
	else \
	  true; \
	fi

install: check
	@for dir in $(YETI_PKGS); do \
	  (cd $$dir; make $@); \
	done
	@for src in AUTHORS COPYING NEWS README VERSION; do \
	  dst=$(Y_EXE_SITE)/doc/Yeti-$$src; \
	  cp $$src $$dst; \
	  chmod 644 $$dst; \
	done

clean: check
	rm -f *~ *.tmp
	@for dir in $(YETI_PKGS); do \
	  (cd $$dir; make $@); \
	done

distrib:
	@version=`cat VERSION`; \
	target=yeti-$${version}; \
	tmpdir=$(TMPDIR)/$${target}; \
	archive=$${tmpdir}.tar.gz; \
	if test -d $${tmpdir}; then \
	  echo "directory $${tmpdir} already exists"; \
	  false; \
	else \
	  olddir=`pwd`; \
	  rm -rf $${tmpdir}; \
	  cp -a . $${tmpdir}; \
	  cd $${tmpdir}; \
	  test -r config.h || touch config.h; \
	  make clean YETI_PKGS="yeti yeti_fftw yeti_regex yeti_tiff"; \
	  rm -f config.h; \
	  rm -rf devel */RCS; \
	  cd ..; \
	  tar cf - $${target} | gzip -9 > $${archive}; \
	  cd $${olddir}; \
	  rm -rf $${tmpdir}; \
	  echo "archive is: $${archive}"; \
	fi
