# this works on Linux2
# PATH=/usr/local/bin:/usr/local/pgsql/bin/
# -d maruska -d maruska

include pg.mk

PSQL=psql
#/usr/local/pgsql/bin/psql

# html *.t.html.{en,it,ru}
templates:=$(wildcard *.t)

products:=$(subst .t,, $(templates))


all:  $(SEDFILE) $(products) new
	ls -l $(products)

# default value
#PGHOST=linux2

SEDFILE=ricerche.sed

$(SEDFILE): FORCE
	$(PSQL) -A -t -q -f ricerche.sql > $@
        # questo lo aggiunge !!!
	cat meeting/2006/ricerche.sed >> $@
	chgrp html $@
	chmod 660  $@

FORCE:



$(products):%: %.t $(SEDFILE)
	mkdir -p products/
	sed -f $(SEDFILE)  $< > products/$@
	mkdir -p static/
	[ -e $@ ] && mv -v $@ static/   || true
	install -g html -m 664  products/$@  .
	rm products/$@


new:
	# fixme:  This needs a TRAP to remove that file!
	$(PSQL) -c "delete from ticket_best;"
	for lingua in it fr en ru ;\
	do \
	wget.scm -l $${lingua} -f index.html.$${lingua}; \
	chmod o+r index.html.$${lingua} ;\
	done

#	wget "http://$${lingua}.ruska.dyndns.org/cgi/kahua/index/index?static=1"  -O index.html.$${lingua}.1 && mv -v index.html.$${lingua}.1 index.html.$${lingua} && chgrp html index.html.$${lingua} && chmod g+w index.html.$${lingua};\
	rm -fv index.html.$${lingua}.1; \



#	wget 'http://ru.maruska.dyndns.org/cgi/kahua/index/index?static=1'  -O index.html.ru.1 && mv -v index.html.ru.1 index.html.ru
#	wget 'http://en.maruska.dyndns.org/cgi/kahua/index/index?static=1'  -O index.html.en.1 && mv -v index.html.en.1 index.html.en



# .PHONY:	ricerche.sql
#force

