SHELL=/bin/sh

PKG=Yenta

top_distdir=$(PKG)
srcdir=@srcdir@

ACSUBDIRS=@subdirs@
EXPACSUBDIRS=App/C/Savant App/C/Scheme
OTHERSUBDIRS=App/Scheme Distribution Internal Statistics
SUBDIRS=$(ACSUBDIRS) $(OTHERSUBDIRS)
DISTFILES=COPYING Makefile.in configure configure.in install-sh \
	missing mkinstalldirs

default: all

all install uninstall clean distclean mostlyclean realclean pure::
	for x in $(ACSUBDIRS); do \
		(cd $$x; $(MAKE) $(MFLAGS) $@) \
	done

clean::
	rm -f core

distclean::
	rm -f config.cache config.log config.status

realclean:: distclean
	rm -f TAGS
	for subdir in $(OTHERSUBDIRS); do \
		rm -f $subdir/TAGS; \
	done

dist $(PKG).tar.gz: distdir
	-chmod -R a+r $(PKG)
	GZIP=--best tar chozf $(PKG).tar.gz $(PKG)
	rm -rf $(PKG)

distdir $(PKG):
	rm -rf $(PKG)
	mkdir $(PKG)
	-chmod 777 $(PKG)
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  test -f $(PKG)/$$file \
	  || ln $$d/$$file $(PKG)/$$file 2> /dev/null \
	  || cp -p $$d/$$file $(PKG)/$$file;	\
	done
	for subdir in $(ACSUBDIRS); do		\
	  test -d $(PKG)/$$subdir		\
	  || ./mkinstalldirs $(PKG)/$$subdir	\
	  || exit 1;				\
	  chmod 777 $(PKG)/$$subdir;		\
	  d=`echo $$subdir | sed -e 's:[^/]*:..:g'`; \
	  (cd $$subdir && $(MAKE) top_distdir=$$d/$(PKG)/$$subdir distdir=$$d/$(PKG)/$$subdir distdir) \
	    || exit 1; \
	done
	for subdir in $(OTHERSUBDIRS); do	\
	  test -d $(PKG)/$$subdir		\
	  || ./mkinstalldirs $(PKG)/$$subdir	\
	  || exit 1;				\
	  chmod 777 $(PKG)/$$subdir;		\
	done
	find $(OTHERSUBDIRS) -name CVS -prune -o -print | cpio -dplmv $(PKG)

crippled-dist crippled-$(PKG).tar.gz: crippled-distdir
	-chmod -R a+r $(PKG)
	GZIP=--best tar chozf $(PKG).tar.gz $(PKG)
	rm -rf $(PKG)

crippled-distdir crippled-$(PKG):
	rm -rf $(PKG)
	mkdir $(PKG)
	-chmod 777 $(PKG)
	@for file in $(DISTFILES); do \
	  d=$(srcdir); \
	  test -f $(PKG)/$$file \
	  || ln $$d/$$file $(PKG)/$$file 2> /dev/null \
	  || cp -p $$d/$$file $(PKG)/$$file;	\
	done
	for subdir in $(EXPACSUBDIRS); do		\
	  test -d $(PKG)/$$subdir		\
	  || ./mkinstalldirs $(PKG)/$$subdir	\
	  || exit 1;				\
	  chmod 777 $(PKG)/$$subdir;		\
	  d=`echo $$subdir | sed -e 's:[^/]*:..:g'`; \
	  (cd $$subdir && $(MAKE) top_distdir=$$d/$(PKG)/$$subdir distdir=$$d/$(PKG)/$$subdir distdir) \
	    || exit 1; \
	done
	for subdir in $(OTHERSUBDIRS); do	\
	  test -d $(PKG)/$$subdir		\
	  || ./mkinstalldirs $(PKG)/$$subdir	\
	  || exit 1;				\
	  chmod 777 $(PKG)/$$subdir;		\
	done
	find $(OTHERSUBDIRS) -name CVS -prune -o -print | cpio -dplmv $(PKG)


tags-recursive:
	for subdir in $(ACSUBDIRS); do \
		(cd $$subdir && $(MAKE) $(MFLAGS) tags); \
	done
	for subdir in $(OTHERSUBDIRS); do \
		(cd $$subdir && find * -name '*.scm' -print | xargs -r etags);\
	done

tags TAGS: tags-recursive
	tags=; \
	here=`pwd`; \
	list='$(SUBDIRS)'; for subdir in $$list; do \
	  test -f $$subdir/TAGS && tags="$$tags -i $$here/$$subdir/TAGS"; \
	done; \
	test -n "$$tags" && (cd $(srcdir) && etags $$tags -o $$here/TAGS)
