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

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

#---------------------------------------------------------- configuration flags

# These values filled in by: yorick -batch config.i
YETI_PKGS = yeti yeti_fftw yeti_gsl yeti_regex yeti_tiff
YETI_VERSION_MAJOR = 6
YETI_VERSION_MINOR = 3
YETI_VERSION_MICRO = 2
YETI_VERSION_SUFFIX = ""
YORICK_VERSION_MAJOR = 2
YORICK_VERSION_MINOR = 2
YORICK_VERSION_MICRO = 0
YORICK_VERSION_SUFFIX = "x"

SUBDIRS = $(YETI_PKGS) doc

TMPDIR=/tmp

DISTRIB_PKGS = yeti yeti_fftw yeti_gsl yeti_regex yeti_tiff
DISTRIB_DIRS = doc $(DISTRIB_PKGS)
DISTRIB_FILES = AUTHORS LICENSE NEWS README VERSION \
	Makefile Makefile.in configure config.h.in config.i

#------------------------------------------------------------------------------

default: all

all: check
	@for dir in $(SUBDIRS); 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 $(SUBDIRS); do \
	  (cd $$dir; make $@); \
	done
#	@for src in AUTHORS COPYING NEWS README VERSION; do \
#	  dst=$(Y_EXE_SITE)/doc/$$src.yeti; \
#	  cp -pf $$src $$dst; \
#	  chmod 644 $$dst; \
#	done

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

distclean: clean
	rm -f config.h Makefile

distrib:
	@version=`cat VERSION`; \
	target="yeti-$${version}"; \
	tmpdir="$(TMPDIR)/$${target}"; \
	archive="$${tmpdir}.tar.bz2"; \
	if test -d "$${tmpdir}"; then \
	  echo "directory $${tmpdir} already exists"; \
	  false; \
	else \
	  olddir=`pwd`; \
	  mkdir -p "$${tmpdir}"; \
	  for file in $(DISTRIB_FILES); do \
	    cp -a "$${file}" "$${tmpdir}/$${file}"; \
	  done; \
	  for dir in $(DISTRIB_DIRS); do \
	    cp -a "$${dir}" "$${tmpdir}/$${dir}"; \
	  done; \
	  cd "$${tmpdir}"; \
	  touch config.h; \
	  make clean YETI_PKGS="$(DISTRIB_PKGS)"; \
	  rm -f config.h; \
	  rm -rf */RCS */*~; \
	  cd "$(TMPDIR)"; \
	  tar cf - "$${target}" | bzip2 -9 > "$${archive}"; \
	  cd "$${olddir}"; \
	  rm -rf "$${tmpdir}"; \
	  echo "archive is: $${archive}"; \
	fi
