SHELL = /bin/sh

SUBDIRS = bin dat doc etc examples images tcl ups

#=============================================================================

default:
	@echo Please invoke this makefile using sdssmake. >&2
	@exit 1

install:
	@echo ""
	@echo "Make sure the current sxQT directories under"
	@echo ""
	@echo "     `pwd`"
	@echo ""
	@echo "have the latest versions of the files.  These will be copied to the"
	@echo "the destination during the install of sxQT."
	@echo ""
	@if [ "$(SDSSQT_DIR)" = "" ]; then \
		echo "The destination directory has not been specified.  Set the environment"   >&2; \
		echo "variable SDSSQT_DIR"                                                         >&2; \
		echo ""; \
		exit 1; \
	fi
	@if [ ! -d $(SDSSQT_DIR) ]; then \
		echo $(SDSSQT_DIR) "doesn't exist; making it"; \
		mkdir $(SDSSQT_DIR); \
	fi
	@:
	@: Check the inode number for . and $(SDSSQT_DIR) to find out if two
	@: directories are the same\; they may have different names due to
	@: symbolic links and automounters
	@:
	@if [ `ls -id $(SDSSQT_DIR) | awk '{print $$1}'` = \
                                `ls -id . | awk '{print $$1}'` ]; then \
	   echo "The destination directory is the same as the current directory."          >&2; \
	   echo "Aborting the installation." >&2; \
	   echo ""; \
	   exit 1; \
        fi

	@echo "You will be installing in"
	@echo ""
	@echo "   SDSSQT_DIR = $(SDSSQT_DIR)"
	@echo ""
	@echo "I'll give you 2 seconds to think about it (control-C to abort) ..."
	@for pos in 2 1; do \
	   echo "                           " | sed -e 's/ /'$$pos'/'$$pos; \
	   sleep 1; \
	done
	@echo "... and we're off... unprotecting files and directories for deletion ...and deleting"
	@chmod 777 $(SDSSQT_DIR)
	@(cd $(SDSSQT_DIR); find . -perm -400 -exec chmod 777 {} \;)
	-@/bin/rm -rf $(SDSSQT_DIR)
	@mkdir $(SDSSQT_DIR)
	@cp Makefile README branches $(SDSSQT_DIR)
	@for f in $(SUBDIRS); do \
	      (mkdir $(SDSSQT_DIR)/$$f; cd $$f; echo In $$f; $(MAKE) install ); \
	done

tags :
	@ rm -f TAGS
	$$SDSSTOOLS_DIR/bin/tcl_tags -a -f TAGS tcl/*.tcl

clean:
	@echo In .
	- /bin/rm -f *~ .*~ *.bak *.orig *.old .\#* \#*\#
	@for f in $(SUBDIRS); do \
		(cd $$f ; echo In $$f; $(MAKE) clean); \
	done
