SHELL = /bin/sh

#=============================================================================
#
#  EXECUTABLE    --- Name of the executable
#  INSTALL_DIR   --- Root directory into which the product is to be installed.
#  INSTALL_FILES --- Names of the files to be installed.
#  CLEAN_FILES   --- Names of specific files to be deleted when the directory
#                    is cleaned.  Files matching one of a default set of file
#                    name templates will be deleted automatically
#                    (i.e., *~ core *.bak *.orig *.old .#* #*# *.o).  This
#                    variable is for declaring additional files to delete which
#                    don't match any of the file name templates.
#  SCRIPTS       --- Test scripts to run.
#
#  For example, for the product "mySch":
#     EXECUTABLE    = mySch
#     INSTALL_DIR   = $(MYSCH_DIR)
#     INSTALL_FILES = *.tcl
#     CLEAN_FILES   = 
#     SCRIPTS       = tst_1.tcl tst_2.tcl
#
#=============================================================================

EXECUTABLE	= target
INSTALL_DIR	= $(TARGET_INSTALL_DIR)
INSTALL_FILES	= *.tcl Makefile
CLEAN_FILES	= tmp* tsObj-000109-1-0-0101.fit tsObjOut-000109-1-0-0101.fit \
		  tsObj-000109-1-0-0102.fit tsObjOut-000109-1-0-0102.fit \
		  diagAccept.out summary.html usno.gif \
		  tsObjOut-000000-0-0-0000.fit 
SCRIPTS		= tst_io.tcl tst_calib.tcl tst_target.tcl tst_quasar.tcl \
                  tst_stars.tcl tst_serendipity.tcl tst_rosat.tcl tst_galaxy.tcl

#=============================================================================
#
# You should not have to edit any of the rest of this file, if all you are
# doing is building one class library and one executable, and some supporting
# TCL scripts.
#
#=============================================================================

#===========================================================================
# STANDARD TARGETS
#===========================================================================

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

all : scripts

install :
	@if [ "$(INSTALL_DIR)" = "" ]; then \
		echo You have not specified a destination directory >&2; \
		exit 1; \
	fi     
	@ rm -rf $(INSTALL_DIR)/test
	@ mkdir $(INSTALL_DIR)/test
	@if [ "$(INSTALL_FILES)" != "" ]; then \
		cp $(INSTALL_FILES) $(INSTALL_DIR)/test; \
		chmod 644 $(INSTALL_DIR)/test/*; \
	fi

clean :
	rm -f $(CLEAN_FILES) *~ core *.bak *.orig *.old quasarsAccept* quasarsReject* .#* #*#

#===========================================================================
# ADDITIONAL TARGETS
#===========================================================================

scripts: $(SCRIPTS)
	@rm -f .failed~; \
	if [ "$(SCRIPTS)" != "" ]; then \
		for f in $(SCRIPTS); do \
			echo Running ../bin/$(EXECUTABLE) -noTk -file $$f; \
			if ../bin/$(EXECUTABLE) -noTk -file $$f 2>&1; then \
				echo Passed all tests >&2; \
			else \
				echo Failed some tests: >&2; touch .failed~; \
			fi | sed -n -e 's/^TEST-ERR: */   /p' ; \
		done; \
	fi; \
	if [ -f .failed~ ]; then \
		echo; echo "Failed to pass tests" >&2; exit 1; \
	fi
	@ rm -f .failed~
