1 # To be included in other Makefile
3 # This Makefile converts all XML files found in the current directory
4 # to HTML file under www directory and copies there the referenced
5 # files such as images or hyperlinked files.
8 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 ) )
12 # RELATIVEDIR: relative path from BASEDIR to the current directory
13 RELATIVEDIR=$(patsubst /%,%,$(patsubst $(BASEDIR)%,%,$(shell pwd)))
15 # BACK_TO_BASE: relative path from the current directory to BASEDIR
16 BACK_TO_BASE:=$(shell echo $(RELATIVEDIR)|sed -e 's/[^/]\+/../g')
18 # $(info BASEDIR=$(BASEDIR))
19 # $(info RELATIVEDIR=$(RELATIVEDIR))
20 # $(info BACK_TO_BASE=$(BACK_TO_BASE))
22 TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR)
24 .PHONY: all clean local subdirs copy-links
35 $(Q)$(foreach d,$(SUBDIRS),$(MAKE) -C $(d) &&) true
39 WWW_ROOT ?= $(BACK_TO_BASE)
40 WWW_ROOT := $(WWW_ROOT:%/=%)
43 XMLS := $(wildcard *.xml)
45 htmls := $(if $(word 2,$(XMLS)),$(XMLS:%.xml=%.html),index.html)
48 default: $(htmls:%=$(TARGETDIR)/%)
50 ifeq ($(words $(XMLS)),1)
51 $(TARGETDIR)/$(htmls): $(XMLS)
53 $(TARGETDIR)/%.html: %.xml
55 $(Q)mkdir -p $(dir $@)
56 $(Q)echo " XSLTPROC $(RELATIVEDIR:%=%/)$(notdir $@)"
57 $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/course.xsl $< > "$@"
58 $(Q)$(MAKE) --no-print-directory copy-links XML=$<
60 links.mk: $(XML:%.xml=%.links)
61 $(Q)echo 'docbook_links = $(wildcard $(shell cat $^))' > $@
63 ifeq ($(MAKECMDGOALS),copy-links)
67 copy-links: $(docbook_links:%=$(TARGETDIR)/%)
68 $(Q)rm links.mk $(XML:%.xml=%.links)
71 $(Q)echo " XSLTPROC $@"
72 $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/getlinks.xsl $< > $@
74 # For copying other file from source (images, pfd, ...)
76 $(Q)mkdir -p $(dir $@);\
77 if [ ! -d "$<" ]; then \