VERSION=0.1.5
NAME=latex_make

FILES_LIST=\
  $(shell cvs log -R 2>/dev/null |sed -e 's|.*/LatexMake/||' -e 's/,v$$//')

SUB_DIR=$(NAME)-$(VERSION)
ARCHIVE=$(NAME)-$(VERSION).tar.gz
TARGET_HOST=aluf
REMOTE_DIR=public_html/latex_make
TARGET_DIR=$(TARGET_HOST):$(REMOTE_DIR)

RM=rm -f
CP=cp
MKDIR=mkdir
TAR=tar
SCP=scp
SSH=ssh
DIRNAME=dirname

# a target to print the value of some variable:
test-print:
	@echo $(FILES_LIST)

# pack: crate a tar archive from the CVS
pack: $(ARCHIVE)

$(ARCHIVE): $(FILES_LIST)
	$(RM) -r $(SUB_DIR)
	$(MKDIR) $(SUB_DIR)
	for file in $(FILES_LIST); do         \
	  dir=`$(DIRNAME) $${file}`;          \
	  mkdir -p $(SUB_DIR)/$${dir};        \
	  $(CP) $${file} $(SUB_DIR)/$${file}; \
	done
	$(TAR) -cvzf $(ARCHIVE) $(SUB_DIR)
	
# publish: copy the current version to a remote server
# Does not attempt to handle cleaning of the previous version
publish: $(ARCHIVE)
	$(SCP) $(ARCHIVE) $(TARGET_DIR)
	$(SSH) $(TARGET_HOST) 'cd $(REMOTE_DIR); gzip -d <$(ARCHIVE)|tar xvf -'
