# To be included in other Makefile # 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 BASEDIR # RELATIVEDIR: relative path from BASEDIR to the current directory RELATIVEDIR=$(patsubst /%,%,$(patsubst $(BASEDIR)%,%,$(shell pwd -L))) # BACK_TO_BASE: relative path from the current directory to BASEDIR BACK_TO_BASE:=$(shell echo $(RELATIVEDIR)|sed -e 's/[^/]\+/../g') ifeq ($(BACK_TO_BASE),) BACK_TO_BASE=. endif # $(info BASEDIR=$(BASEDIR)) # $(info RELATIVEDIR=$(RELATIVEDIR)) # $(info BACK_TO_BASE=$(BACK_TO_BASE)) TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR) .PHONY: all clean local subdirs copy-links Q=$(if $(V),,@) all: default clean: rm -rf $(TARGETDIR)/* ifdef SUBDIRS subdirs: $(Q)$(foreach d,$(SUBDIRS),$(MAKE) -C $(d) &&) true endif WWW_ROOT ?= $(BACK_TO_BASE) WWW_ROOT := $(WWW_ROOT:%/=%) ifndef XMLS XMLS := $(wildcard *.xml) endif htmls := $(if $(word 2,$(XMLS)),$(XMLS:%.xml=%.html),index.html) default: subdirs default: $(htmls:%=$(TARGETDIR)/%) default: copy-links ifeq ($(words $(XMLS)),1) $(TARGETDIR)/$(htmls): $(XMLS) else $(TARGETDIR)/%.html: %.xml endif $(Q)mkdir -p $(dir $@) $(Q)echo " XSLTPROC $(RELATIVEDIR:%=%/)$(notdir $@)" $(Q)xsltproc --stringparam www.root "$(WWW_ROOT)" $(XSLTPROCFLAGS) $(BASEDIR)/xsl/course.xsl $< > "$@" ifdef SHOW_HTML_PATH $(Q)echo "$@" # Used by XXE macro to display the compiled page endif links.mk: $(XMLS:%.xml=%.links) $(Q)echo 'docbook_links = $(sort $(wildcard $(shell cat $^)))' > $@ -include links.mk copy-links: $(docbook_links:%=$(TARGETDIR)/%) $(Q)rm links.mk $(XMLS:%.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)/%: % $(Q)mkdir -p $(dir $@);\ if [ ! -d "$<" ]; then \ echo " CP $<";\ cp $< $@; \ fi