###############################################################################
# Sloan Digital Sky Survey (SDSS)
# N. Padmanabhan, D. Schlegel, D. Finkbeiner, R. H. Lupton, C. P. Loomis
###############################################################################

SHELL = /bin/sh

VERSION="`env EUPS_DIR=. PYTHONPATH=python bin/eups --version 2>&1 | awk '/Version/ {print $$3}'`"
#
# Set by configure
#
prefix = /Users/runner/miniforge3/conda-bld/eups_1753249737050/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/eups
EUPS_PATH = /Users/runner/miniforge3/conda-bld/eups_1753249737050/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/share/eups
EUPS_DIR = /Users/runner/miniforge3/conda-bld/eups_1753249737050/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/eups
SETUP_ALIASES = 
EUPS_PYTHON = /Users/runner/miniforge3/conda-bld/eups_1753249737050/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/bin/python
EUPS_DB = $(patsubst %,%/ups_db, $(subst :, ,$(EUPS_PATH)))
#
export prefix EUPS_PATH EUPS_DIR SETUP_ALIASES EUPS_PYTHON
#
SUBDIRS = bin etc python site ups lib doc

.PHONY : all show install clean test tests

all : show
	@ echo
	@ echo Please use \"make install\" if you want to install eups

install : show
	@:
	@: Check the inode number for . and $(EUPS_DIR) to find out if two
	@: directories are the same\; they may have different names due to
	@: symbolic links and automounters
	@:
	@if [ -d "$(EUPS_DIR)" ]; then \
	    if [ `ls -id "$(EUPS_DIR)" | awk '{print $$1}'` = `ls -id . | awk '{print $$1}'` ]; then \
		echo "The destination directory is the same" \
			"as the current directory; aborting." >&2; \
		echo ""; \
		exit 1; \
	   fi; \
	fi

	@:
	@: Delete the contents of $EUPS_DIR, if exists, keeping only the 'site' subdirectory
	@:
	@ if [ -d "$(EUPS_DIR)" ]; then \
	        chmod -R u+w "$(EUPS_DIR)"/* ; \
	        for f in "$(EUPS_DIR)"/*; do \
		    if [ -d "$$f" ] && [ `basename "$$f"` != "site" ]; then \
			rm -r "$$f"; \
		    fi; \
		done; \
	else \
		mkdir -p "$(EUPS_DIR)"; \
	fi

	@:
	@: Create EUPS database directories for each entry on EUPS_PATH
	@:
	@if [ "$(EUPS_PATH)" = "" ]; then \
		echo You have not specified EUPS_PATH >&2; \
		exit 1; \
	fi
	@ for d in "$(shell perl -e 'foreach $$d (split(":","$(EUPS_PATH)")) { print "$$d\n"}')"; do \
		if [ ! -d "$$d" ]; then \
			mkdir -p "$$d"; \
		fi; \
	done
	@ for db in "$(EUPS_DB)"; do \
		if [ -d "$$db" ]; then \
			echo "EUPS database $$db already exists"; \
		else \
			mkdir -p "$$db"; \
		fi; \
	done

	@:
	@: Run make in each subdirectory
	@:
	@ for f in $(SUBDIRS); do \
		(\
		   if [ ! -d "$(EUPS_DIR)"/$$f ]; then mkdir "$(EUPS_DIR)"/$$f; fi; \
		   cd $$f ; \
		   echo In $$f; $(MAKE) $(MFLAGS) install \
                ); \
	done
	- cp Makefile README  Release_Notes gpl.txt "$(EUPS_DIR)"

	echo $(VERSION) > "$(EUPS_DIR)/git.version"
	@echo "Remember to source $(EUPS_DIR)/bin/setups.{c,z,}sh"
declare :
	@vers="$(VERSION)"; \
	eups declare --root $(EUPS_DIR) eups $$vers && \
	echo eups declare --root $(EUPS_DIR) eups $$vers
show : git.version
	@echo "Eups will use                               /Users/runner/miniforge3/conda-bld/eups_1753249737050/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/bin/python"
	@echo "You will be installing ups in \$$EUPS_DIR   = $(EUPS_DIR)"
	@echo "Eups will look for products in \$$EUPS_PATH = $(EUPS_PATH)"
	@echo "Your EUPS database[s] will be               $(EUPS_DB)"
	@echo "Your EUPS version is                        $(VERSION)"
	@ \
	EUPS_DB_DIR=`echo "$(EUPS_PATH)" | sed -e 's/:.*//'`; \
	if [ -d "$$EUPS_DB_DIR/site" ]; then \
		echo "Your site configuration files are:"; \
		for f in "$$EUPS_DB_DIR"/site/*[a-z]; do \
		    if [ -n "`echo $$f | grep -v Makefile`" ]; then \
		        echo "   $$f"; \
		    fi; \
		done; \
	else \
		echo "Your site configuration files will be in    $$EUPS_DB_DIR/site"; \
	fi
git.version :
	# Save the git version in case we have a copy of the source without a .git directory
	@ env EUPS_DIR=. PYTHONPATH=python \
		"$(EUPS_PYTHON)" -S -c "import eups.utils; print eups.utils.version()" > git.version
#
# Rebuild configure; almost no-one should need to do this
#
configure : configure.ac
	@ echo "Rebuilding ./configure"
	autoconf
#
# Run tests
#
tests : test
test :
	@ echo "Running tests"
	"$(EUPS_PYTHON)" -Wd tests/testAll.py
	@ echo "Running server tests (requires network)"
	"$(EUPS_PYTHON)" tests/testServerAll.py
clean :
	- /bin/rm -f *~ core
	@ for f in $(SUBDIRS); do \
		(cd $$f ; echo In $$f; $(MAKE) $(MFLAGS) clean ); \
	done

TAGS:
	find . -type f -name '*.py' | xargs etags
