.SUFFIXES: .i
.PHONY: clean default distclean distrib update install

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

SOURCES = fft_utils.i \
          fits.i \
          fmin.i \
          img.i \
          linop.i \
          mira.i \
          oifits.i \
          plot.i \
          rgl.i \
          utils.i \
          mira-demo.i mira-test1.i mira-test2.i

default:
	@echo "There is no default target.  Try one of:"
	@echo "    make update"
	@echo "    make clean"
	@echo "    make distclean"
	@echo "    make distrib [VERSION=###]"
#	@echo "    make install"

update: $(SOURCES)

clean:
	rm -f core *~

distclean: clean
	rm -rf old

fft_utils.i: /home/eric/yorick/fft_utils.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

fits.i: /home/eric/yorick/fits.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

fmin.i: /home/eric/yorick/fmin.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

img.i: /home/eric/yorick/img.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

linop.i: /home/eric/yorick/linop.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

optimpack.i: /home/eric/yorick/optimpack.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

plot.i: /home/eric/yorick/plot.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

#oifits.i: /home/eric/work/mira/oifits.i
#	test -e $@ && mv -f $@ $@.bak || true
#	cp -a $< $@

#rgl.i: /home/eric/yorick/rgl.i
#	test -e $@ && mv -f $@ $@.bak || true
#	cp -a $< $@

utils.i: /home/eric/yorick/utils.i
	test -e $@ && mv -f $@ $@.bak || true
	cp -a $< $@

DISTRIB_FILES = $(SOURCES) Makefile AUTHOR COPYING README NEWS
DISTRIB_SUBDIRS = data

distrib:
	@if test "x$(VERSION)" = "x"; then \
	  if test -f VERSION -a -r VERSION; then \
	    for version in `cat VERSION`; do break; done; \
	  fi; \
	  if test "x$$version" = "x"; then \
	    echo >&2 "error: bad VERSION file"; \
	    return 1; \
	  fi; \
	else \
	  version=$(VERSION); \
	fi; \
	pkgdir=mira-$$version; \
	archive=$$pkgdir.tar.bz2; \
	if test -e "$$pkgdir"; then \
	  echo >&2 "error: $$pkgdir already exists"; \
	  return 1; \
	fi; \
	if test -e "$$archive"; then \
	  echo >&2 "error: $$archive already exists"; \
	  return 1; \
	fi; \
	mkdir "$$pkgdir"; \
	for file in $(DISTRIB_FILES); do \
	  cp -a "$$file" "$$pkgdir/."; \
	done; \
	for dir in $(DISTRIB_SUBDIRS); do \
	  cp -a "$$dir" "$$pkgdir/$$dir"; \
	  (cd "$$pkgdir/$$dir/."; rm -f *~); \
	done; \
	rm -f "$$pkgdir/VERSION"; \
	echo "$$version" > "$$pkgdir/VERSION"; \
	tar cf - "$$pkgdir" | bzip2 -9 > "$$archive"; \
	rm -rf "$$pkgdir"; \
	echo "archive $$archive created"; \
	return 0

