# To be included in other Makefile
-# TOP: relative path to BASEDIR
-ifndef TOP
-TOP=..
+# This Makefile converts all XML files found in the current directory
+# to HTML file under www directory and copies there the referenced
+# files such as images or hyperlinked files.
+
+ifndef BASEDIR
+BASEDIR := $(shell ( old_pwd="" ; while [ ! -e xsl/course.xsl ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
endif
-export TOP
+export BASEDIR
+
+# RELATIVEDIR: relative path from BASEDIR to the current directory
+RELATIVEDIR=$(patsubst $(BASEDIR)/%,%,$(shell pwd))
+
+# BACK_TO_BASE: relative path from the current directory to BASEDIR
+BACK_TO_BASE:=$(shell echo $(RELATIVEDIR)|sed -e 's/[^/]*/../g')
# Destination filename
ifndef FNAME
FNAME=index.html
endif
-# BASEDIR: absolute path calculated from TOP
-BASEDIR:=$(shell cd $(TOP); pwd)
-export BASEDIR
-
-RELATIVEDIR:=$(shell CUR=$$(pwd); cd $(TOP); RD=$${CUR\#$(BASEDIR)}; echo $${RD\#/})
TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR)
-export TARGETDIR
-
-ifndef HTML
-HTML:=$(FNAME)
-endif
-export SOURCE
+.PHONY: all clean local subdirs copy-links
-.PHONY: all clean local subdirs
+Q=$(if $(V),,@)
-all: local subdirs
+all: default
clean:
rm -rf $(TARGETDIR)/*
+ifdef SUBDIRS
subdirs:
$(Q)$(foreach d,$(SUBDIRS),$(MAKE) -C $(d) &&) true
-
-ifndef V
-Q=@
endif
-WWW_ROOT ?= $(TOP)
+WWW_ROOT ?= $(BACK_TO_BASE)
WWW_ROOT := $(WWW_ROOT:%/=%)
-DOCBOOK_REFS_CMD=xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/getlinks.xsl $(SOURCE)
-DOCBOOK_REFS=$(wildcard $(shell $(DOCBOOK_REFS_CMD)))
+ifndef XMLS
+XMLS := $(wildcard *.xml)
+endif
+htmls := $(XMLS:%.xml=%.html)
-local: $(addprefix $(TARGETDIR)/,$(HTML) $(DOCBOOK_REFS))
+default: subdirs
+default: $(htmls:%=$(TARGETDIR)/%)
-$(TARGETDIR)/$(HTML): $(SOURCE)
+$(TARGETDIR)/%.html: %.xml
$(Q)mkdir -p $(dir $@)
- $(Q)echo " XSLTPROC $<"
- $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/nst.xsl $< > "$@"
-# $(Q)$(MAKE) --no-print-directory $(addprefix $(TARGETDIR)/,$(DOCBOOK_REFS))
+ $(Q)echo " XSLTPROC $(notdir $@)"
+ $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/course.xsl $< > "$@"
+ $(Q)$(MAKE) --no-print-directory copy-links XML=$<
+
+links.mk: $(XML:%.xml=%.links)
+ $(Q)echo 'docbook_links = $(wildcard $(shell cat $^))' > $@
+
+ifeq ($(MAKECMDGOALS),copy-links)
+-include links.mk
+endif
+
+copy-links: $(docbook_links:%=$(TARGETDIR)/%)
+ $(Q)rm links.mk $(XML:%.xml=%.links)
+%.links: %.xml
+ $(Q)echo " XSLTPROC $@"
+ $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/getlinks.xsl $< > $@
# For copying other file from source (images, pfd, ...)
$(TARGETDIR)/%: %