# ---------------------------------------------------------------------------
#    Makefile for KOSHER DILL - Disk space management utility
# ---------------------------------------------------------------------------

BINDIR 		= @KOSHERDILL_PROGRAM@
LIBDIR 		= @KOSHERDILL_LIBRARY@
WISH 		= @BLT_WISH@

template 	= $(srcdir)/kosherdill.tmpl
script 		= kosherdill
INSTALL 	= @INSTALL@
INSTALL_DATA 	= @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
SHELL 		= /bin/sh
RM 		= rm -f
srcdir		= @srcdir@

all: kosherdill-build

install: kosherdill-install install-dirs install-library install-help
	$(INSTALL_PROGRAM) $(script) $(BINDIR)	
	@echo '== install complete =='

kosherdill-build: $(template)
	$(RM) $(script)
	sed -e "s#%install-dir%#`pwd`#" -e "s#%blt-program%#$(WISH)#" \
		$(template) > $(script)
	chmod 755 $(script)

kosherdill-install: $(template)
	$(RM) $(script)
	sed -e "s#%install-dir%#$(LIBDIR)#" \
		-e "s#%blt-program%#$(WISH)#" $(template) > $(script)
	chmod 755 $(script)

install-help:
	@set -x; for i in $(srcdir)/Help/[A-Z][a-z]* ; do \
	    $(INSTALL_DATA) $$i $(LIBDIR)/Help ; \
	done

install-library:
	@set -x; for i in $(srcdir)/scripts/*tcl* ; do \
	    $(INSTALL_DATA) $$i $(LIBDIR)/scripts ; \
	done

install-dirs:
	@for i in $(LIBDIR) $(LIBDIR)/scripts $(LIBDIR)/Help $(BINDIR) ; do \
	    if test ! -d $$i ; then \
		mkdir $$i ; \
	    fi ; \
	done

clean:
	$(RM) $(script) *\~ "#"*	

realclean: clean
	$(RM) config.status Makefile
