SHELL=/bin/sh

# Load in machine-specific environment settings from environment_config.make.
# This include file MUST be created and MUST define the following variables:
#
# SURVEYOR_ROOT: /path/to/phpsurveyor/installation
# SURVEYOR_USER: the user that owns the phpSurveyor directory
# SURVEYOR_PORT: appropriate HTTP port
# SURVEYOR_ADMIN_EMAIL: administrator email address (quote "@" with \)
# SURVEYOR_ADMIN_NAME: administrator real name
#
include environment_config.make


BINDIR:=$(EPRINTSSTATS)/scripts

GENERATED_FILES:=config.php apache.conf

CONFIG_SUBS:=SURVEYOR_ROOT SURVEYOR_PORT SURVEYOR_ADMIN_EMAIL SURVEYOR_ADMIN_NAME


.PHONY: deploy stats


deploy: $(GENERATED_FILES)
	@announce "Copying files..."
	@sudo -u $(SURVEYOR_USER) rsync --verbose --cvs-exclude --exclude=Makefile \
		--exclude='*.make' --exclude='*_src.*' \
		--recursive --times . $(SURVEYOR_ROOT)


config.php: config_src.php environment_config.make
	@announce "Generating $@"
	perl -p $(foreach SUB,$(CONFIG_SUBS),-e "s|##$(SUB)##|$($(SUB))|g;") $< > $@

apache.conf: apache_src.conf environment_config.make
	@announce "Generating $@"
	perl -p $(foreach SUB,$(CONFIG_SUBS),-e "s|##$(SUB)##|$($(SUB))|g;") $< > $@


debug:
	@echo "SURVEYOR_ROOT = [$(SURVEYOR_ROOT)]"
