]> rtime.felk.cvut.cz Git - edu/xsl.git/blobdiff - Makefile
Fixed when called from symlinked directory
[edu/xsl.git] / Makefile
index 3634e838adf87767a9810f4f55647973386b0933..cc75c19f36e88cb277148654646017c1a5e934b4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,59 +1,80 @@
 # To be included in other Makefile
 
-# TOP: relative path to BASEDIR
-ifndef TOP
-TOP=..
-endif
-export 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.
 
-# Destination filename
-ifndef FNAME
-FNAME=index.html
+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
-
-# 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
+# RELATIVEDIR: relative path from BASEDIR to the current directory
+RELATIVEDIR=$(patsubst /%,%,$(patsubst $(BASEDIR)%,%,$(shell pwd -L)))
 
-ifndef HTML
-HTML:=$(FNAME)
+# 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
 
-export SOURCE
+# $(info BASEDIR=$(BASEDIR))
+# $(info RELATIVEDIR=$(RELATIVEDIR))
+# $(info BACK_TO_BASE=$(BACK_TO_BASE))
 
-.PHONY: all clean local subdirs
+TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR)
 
-all: local subdirs
+.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
-
-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 := $(if $(word 2,$(XMLS)),$(XMLS:%.xml=%.html),index.html)
 
-local: $(addprefix $(TARGETDIR)/,$(HTML) $(DOCBOOK_REFS))
+default: subdirs
+default: $(htmls:%=$(TARGETDIR)/%)
+default: copy-links
 
-$(TARGETDIR)/$(HTML): $(SOURCE)
+ifeq ($(words $(XMLS)),1)
+$(TARGETDIR)/$(htmls): $(XMLS)
+else
+$(TARGETDIR)/%.html: %.xml
+endif
        $(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 $(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)/%: %