
all: mkoutdir build

ifeq "$(ROOT)" "/users/www/www"
    OUTDIR = /var/www-csc/$(RELDIR)
else
    OUTDIR = $(ROOT)/build/$(RELDIR)
endif
OUTPUTS = $(addprefix $(OUTDIR),$(FILES))

.PHONY: force mkoutdir build clean

mkoutdir:
	mkdir -p $(OUTDIR)

build: $(OUTPUTS)

clean:
ifeq "$(ROOT)" "/users/www/www"
	rm -rf $(OUTDIR)/*
else
	rm -rf $(OUTDIR)
endif

XSLTARGS=g_date="`date -I`" g_time="`date +%H:%M:%S`" g_outdir="$(OUTDIR)" \
	g_datetime="`date --rfc-3339=seconds`" g_pwd="`pwd`" g_root="$(ROOT)"
XSLTPROC = $(ROOT)/scripts/xsltproc.py

$(OUTDIR)%.html: %.xml $(ROOT)/csc.dtd $(ROOT)/xsl/*.xsl directory.xml $(ROOT)/menu.xml
	$(XSLTPROC) $< $(ROOT)/xsl/html.xsl $@ $(XSLTARGS)

$(OUTDIR)%.atom: %.xml xsl/atom.xsl
	$(XSLTPROC) $< $(ROOT)/xsl/atom.xsl $@ $(XSLTARGS)

$(OUTDIR)%.ics: %.xml
	$(XSLTPROC) $< $(ROOT)/xsl/ics.xsl $@ $(XSLTARGS)

$(OUTDIR)%.html: %.html
	cp -f $< $@
$(OUTDIR)%.cgi: %.cgi
	cp -f $< $@
$(OUTDIR).htaccess:
	cp -f .htaccess $@
$(OUTDIR)%.ico: %.ico
	cp -f $< $@
$(OUTDIR)%.css: %.css
	cp -f $< $@
$(OUTDIR)%.gif: %.gif
	cp -f $< $@
$(OUTDIR)%.png: %.png
	cp -f $< $@
$(OUTDIR)%.swf: %.swf
	cp -f $< $@
$(OUTDIR)%.js: %.js
	cp -f $< $@
$(OUTDIR)%.txt: %.txt
	cp -f $< $@
$(OUTDIR)%.der: %.der
	cp -f $< $@
$(OUTDIR)%.pem: %.pem
	cp -f $< $@
