# Makefile to build the txt and html files for the
# doc-debian package

LANGUAGE = english
# Adjust this (or create a symlink) to the location of your webml copy (if you have one)
# If this directory does not exist the 'update' call will not be able to run, read
# the README-build file to know how to set it up
WEBWML   = ~/debian/www/webwml/$(LANGUAGE)

WMLFILES= \
bug-log-access.wml          bug-maint-mailcontrol.wml constitution.1.0.wml   \
bug-log-mailserver.wml      bug-reporting.wml         \
bug-mailserver-refcard.wml  constitution.wml          social-contract.wml    \
bug-maint-info.wml          constitution.1.1.wml      social-contract.1.0.wml \
constitution.1.2.wml        social-contract.wml 	  constitution.1.3.wml

# These are the automatic files we can generate:
TXTFILES = $(subst .wml,.txt,$(WMLFILES))
HTMLFILES = $(subst .wml,.html,$(WMLFILES))
GENERATED_FILES = $(TXTFILES) $(HTMLFILES)
# Mailing lists does not have an associated wml file, so we add it separately
# to keep GENERATED_FILES to be just those that are built with the Makefile

all: $(TXTFILES)

wml: $(WMLFILES)

update: 
	 @$(MAKE) wml

clean:
	-rm -f $(GENERATED_FILES)

realclean: clean
	-rm -f $(WMLFILES)

%.html: %.wml
	wml -q $< >$@

%.txt: %.html
	lynx -dump -nolist $< >$@

# These rules are conditioned to the existence of $(WEBWML)
# so that the package can be built regardless of its existence
# Warning: hack
webwmlexists := $(shell ls -d $(WEBWML) 2>/dev/null)

ifneq "$(webwmlexists)" ""
bug-log-access.wml: $(WEBWML)/Bugs/Access.wml
	cat $<  |grep -v ^# >$@
bug-log-mailserver.wml: $(WEBWML)/Bugs/server-request.wml
	cat $<  |grep -v ^# >$@
bug-mailserver-refcard.wml: $(WEBWML)/Bugs/server-refcard.wml
	cat $<  |grep -v ^# >$@
bug-maint-info.wml: $(WEBWML)/Bugs/Developer.wml
	cat $<  |grep -v ^# >$@
bug-maint-mailcontrol.wml: $(WEBWML)/Bugs/server-control.wml
	cat $<  |grep -v ^# >$@
bug-reporting.wml: $(WEBWML)/Bugs/Reporting.wml
	cat $<  |grep -v ^# >$@
constitution.wml: $(WEBWML)/devel/constitution.wml
	cat $<  | perl -pe 's/<toc-add-entry /<h2><toc-add-entry /; s/toc-add-entry>/toc-add-entry><\/h2>/' | grep -v ^# >$@
constitution.1.3.wml: $(WEBWML)/devel/constitution.1.3.wml
	cat $<  |grep -v ^# >$@
constitution.1.2.wml: $(WEBWML)/devel/constitution.1.2.wml
	cat $<  |grep -v ^# >$@
constitution.1.1.wml: $(WEBWML)/devel/constitution.1.1.wml
	cat $<  |grep -v ^# >$@
constitution.1.0.wml: $(WEBWML)/devel/constitution.1.0.wml
	cat $<  |grep -v ^# >$@
mailing-lists.wml:  $(WEBWML)/MailingLists/subscribe.wml
	cat $<  |grep -v ^# >$@
social-contract.wml:  $(WEBWML)/social_contract.wml
	cat $<  |grep -v ^# >$@
social-contract.1.0.wml:  $(WEBWML)/social_contract.1.0.wml
	cat $<  |grep -v ^# >$@

mailing-lists.txt: $(WEBWML)/MailingLists/mailing-lists.txt
	cp $< $@

## the Makefile in $(WEBWML)/MailingLists needs internet access!
$(WEBWML)/MailingLists/mailing-lists.txt:
	cd $(WEBWML)/MailingLists && $(MAKE) mailing-lists.txt
else
%.wml:
	@echo "ERROR: Cannot find $(WEBWML) to regenerate the sources. Please read the TODO."
endif

# Not in Debian's website, therefore kept in our own SVN:
# source-unpack.txt
# debian-manifesto
