# Makefile to update the HTML files in this directory. May be run from
# cron or by hand. Some useful targets:
#
#   make (or: make all) - rebuild all HTML, RSS and Atom files
#   make foo.html - for any foo, rebuild just that file
#   make foo.atom - for any foo, rebuild just that file
#
# foo.html is generated from foo.tmpl, which is itself an HTML file,
# but may contain inclusions (handled with hxincl). Some of these
# inclusions are themselves generated by extracting information from
# other HTML files or from Atom feeds. Different methods are used for
# building those inclusions. In general, there are the following kinds
# of files:
#
#   .html - HTML file to serve on-line, typically generated
#   .tmpl - template to generate a .html file from, typically hand-made
#   .inc - HTML fragment for inclusion in other files, typically hand-made
#   .gen - HTML fragment for inclusion in other files, typically generated
#   .rss - RSS file, typically generated from a .html file
#   .atom - Atom file, typically generated from a .html file
#   .stored - local copy of a remote file
#   .trans1 - a set of <link> elements pointing to translations, generated
#   .trans2 - a set of <a> elements pointing to translations, generated
#   .trans3 - a feedback form (only on non-English pages), generated
#   .trans4 - a set of <a> elements pointing to translations, generated
#   .var (typically .foo.var) - database of translations of foo.html
#   .php3 - members.*.php3 uses PHP to get a current list of WG members
#
# Some of the .gen files:
#
#   news.*.gen - HTML fragment with most recent news items from several pages
#   wgnews.gen - HTML fragment with the most recent CSS blog entries
#   roadmap.gen - HTML fragment with the table of publications
#
# Localization:
#
# The AWK programs are localized with GNU gettext. Translations of
# boilerplate text are in the directories XXX/LC_MESSAGES/ for each
# locale XXX. Unfortunately, this requires the corresponding locale to
# be installed on the machine that runs gawk. Under Debian, install
# localizations with: dpkg-reconfigure locales
#
# To extract localizable strings from the AWK scripts, use:
# gawk --gen-po -f foo.awk >foo.po
#
# To do:
#
# As of March 2009, the feedback form is still disabled, for lack of a
# backend to process the submissions.
#
# (For a tiny gain in speed, this Makefile can be run with make -R -r
# because it doesn't need the built-in compiler rules.)
#
# Created: 28 November 2008
# Author: Bert Bos <bert@w3.org>

# All the files to generate:
#
TARGETS = Disclosures.de.html Disclosures.en.html Group.en.php3	    \
Overview.be.html Overview.en.html Overview.fr.html Overview.nl.html \
Overview.pl.html Overview.ru.html Overview.tg.html Overview.uk.html \
current-work.de.html current-work.en.html current-work.ru.html	    \
current-work.uk.html learning.be.html learning.en.html		    \
learning.fr.html learning.ru.html members.be.php3 members.de.php3   \
members.en.php3 members.nl.php3 members.ru.php3 read.en.html	    \
read.ru.html read.uk.html software.af.html software.ca.html	    \
software.de.html software.en.html software.es.html software.hu.html \
software.ru.html software.uk.html software.uz.html specs.de.html    \
specs.en.html specs.ru.html specs.uk.html translating.en.html	    \
translating.ru.html

FEEDS = current-work.atom current-work.rss learning.atom learning.rss \
Overview.atom Overview.rss software.atom software.rss

COMMITS = $(TARGETS) $(FEEDS)

all: $(TARGETS) $(FEEDS) daily-color.css subdirs

subdirs:; $(foreach f,$(wildcard */Makefile),$(MAKE) -C $(dir $(f));)

# The Overview.* files depend on some news files, in addition to the
# various other files that all HTML file depend on (see
# Makefile.common)
#
$(foreach lang,$(subst .,,$(suffix $(basename $(TARGETS)))),\
$(eval Overview.$(lang).html: news.$(lang).gen wgnews.gen roadmap.gen))

news.%.gen: learning.%.html software.%.html current-work.%.html\
		learning.en.html software.en.html current-work.en.html\
		sort.awk news.awk
	@echo "* Extracting recent news         	-> $@"
	@(hxnormalize -x learning.$*.html |\
	  hxcopy -i learning -o Overview; \
	 hxnormalize -x current-work.$*.html |\
	  hxcopy -i current-work -o Overview;\
	 hxnormalize -x software.$*.html |\
	  hxcopy -i software -o Overview; \
	 hxnormalize -x learning.en.html |\
	  hxcopy -i learning -o Overview; \
	 hxnormalize -x current-work.en.html |\
	  hxcopy -i current-work -o Overview;\
	 hxnormalize -x software.en.html |\
	  hxcopy -i software -o Overview) |\
	hxpipe | LC_ALL=$(LOCALE_$*) gawk -f sort.awk -f news.awk | hxunpipe >$@

wgnews.gen: blog.stored blognews.awk
	@echo "* Extracting blog items          	-> $@"
	@hxpipe $< | LC_ALL=$(DEFAULT) gawk -f blognews.awk >$@

roadmap.gen: current-work.en.html
	@echo "* Extracting roadmap             	-> $@"
	@echo "<table class=status lang=en>" >$@
	@hxnormalize -x $< | hxcopy -i current-work -o Overview |\
	 hxselect table.status tbody:first-child >>$@
	@hxnormalize -x $< | hxcopy -i current-work -o Overview |\
	 hxselect table.status tbody:first-child + tbody >>$@
	@echo "</table>" >>$@

# Get the blog no more than once per hour. And if the online version
# hasn't chnaged, don't change the time stamp.
#
blog.stored: blog.retrieved
	@echo "* Checking if blog entries changed	-> $@"
	@cmp -s $< $@ || cp $< $@

blog.retrieved: always
	@if [ ! -f $@ ] || [ `find $@ -mmin +60` ]; then \
	 echo "* Retrieving blog entries        	-> $@"; \
	 curl --silent http://www.w3.org/blog/CSS?tempskin=_atom >$@; \
	fi

# A bit of fun: change the color hue if it hasn't changed in 23 hours
# (Used in combination with by floatspan-n.css.)
#
daily-color.css: always
	@if [ ! -f $@ ]; then \
	 echo "* Creating background color      	-> $@"; \
	 echo 'body {background-color: hsl('`date +%j`',95%,17%)}' >$@; \
	elif [ `find $@ -mmin +1380` ]; then \
	 echo "* Updating background color      	-> $@"; \
	 echo 'body {background-color: hsl('`date +%j`',95%,17%)}' >$@; \
	fi

very-clean::
	@rm $(FEEDS) blog.stored blog.retrieved

include Makefile.common

.PHONY: all subdirs always

