#
# rsync files in this dir with install locations on various machines
#
# Larry Solheim Jul,2013

# Determine kernel type and machine name
MACH_TYPE := $(shell uname -s|tr '[A-Z]' '[a-z]')
MACH_NAME := $(word 1,$(subst ., ,$(shell uname -n|awk -F'.' '{print $1}' -)))

# Determine dns domain name
# The requires a properly configured resolv.conf
DOMAIN := $(subst int.cmc.,cmc.,$(word 2,$(shell grep -E 'search|domain' /etc/resolv.conf)))

# Determine location, typically either cccma or cmc
LOCATION := $(word 1,$(subst ., ,$(DOMAIN)))
ifndef LOCATION
  $(error Unable to determine a value for LOCATION.)
endif

# INSTALL_BIN and INSTALL_LIB name the directories on the remote machine
# into which the files will be installed via rsync
# INSTALL_BIN := '$$CCRNSRC/cccjob_dir/cccmake/bin'
# INSTALL_LIB := '$$CCRNSRC/cccjob_dir/cccmake/lib'
INSTALL_BIN := '~acrnsrc/cccjob_dir/cccmake/bin'
INSTALL_LIB := '~acrnsrc/cccjob_dir/cccmake/lib'

# A list of file to be copied to the remote bin dir
BINFILES := cccmf up2cpp up2patch build_system_cache_files

all: sync

.PHONY: debug
debug:
	@echo DOMAIN = $(DOMAIN)
	@echo LOCATION = $(LOCATION)
	@echo INSTALL_BIN = $(INSTALL_BIN)
	@echo INSTALL_LIB = $(INSTALL_LIB)

sync:
ifeq ($(LOCATION), cccma)
	@# the remote machine will always be joule in this case
	rsync -Cav --chmod=Dg+rx,Fg+r,g+X $(BINFILES) joule:$(INSTALL_BIN)
	rsync -Cav --chmod=Dg+rx,Fg+r,g+X $(BINFILES) lxwrk2:$(INSTALL_BIN)
else
	@echo "rsync is only allowed when originating in Victoria"
endif
