]> rtime.felk.cvut.cz Git - edu/xsl.git/blob - Makefile
Fixed when called from symlinked directory
[edu/xsl.git] / Makefile
1 # To be included in other Makefile
2
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.
6
7 ifndef BASEDIR
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 ) )
9 endif
10 export BASEDIR
11
12 # RELATIVEDIR: relative path from BASEDIR to the current directory
13 RELATIVEDIR=$(patsubst /%,%,$(patsubst $(BASEDIR)%,%,$(shell pwd -L)))
14
15 # BACK_TO_BASE: relative path from the current directory to BASEDIR
16 BACK_TO_BASE:=$(shell echo $(RELATIVEDIR)|sed -e 's/[^/]\+/../g')
17 ifeq ($(BACK_TO_BASE),)
18 BACK_TO_BASE=.
19 endif
20
21 # $(info BASEDIR=$(BASEDIR))
22 # $(info RELATIVEDIR=$(RELATIVEDIR))
23 # $(info BACK_TO_BASE=$(BACK_TO_BASE))
24
25 TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR)
26
27 .PHONY: all clean local subdirs copy-links
28
29 Q=$(if $(V),,@)
30
31 all: default
32
33 clean:
34         rm -rf $(TARGETDIR)/*
35
36 ifdef SUBDIRS
37 subdirs:
38         $(Q)$(foreach d,$(SUBDIRS),$(MAKE) -C $(d) &&) true
39 endif
40
41
42 WWW_ROOT ?= $(BACK_TO_BASE)
43 WWW_ROOT := $(WWW_ROOT:%/=%)
44
45 ifndef XMLS
46 XMLS := $(wildcard *.xml)
47 endif
48 htmls := $(if $(word 2,$(XMLS)),$(XMLS:%.xml=%.html),index.html)
49
50 default: subdirs
51 default: $(htmls:%=$(TARGETDIR)/%)
52 default: copy-links
53
54 ifeq ($(words $(XMLS)),1)
55 $(TARGETDIR)/$(htmls): $(XMLS)
56 else
57 $(TARGETDIR)/%.html: %.xml
58 endif
59         $(Q)mkdir -p $(dir $@)
60         $(Q)echo "  XSLTPROC $(RELATIVEDIR:%=%/)$(notdir $@)"
61         $(Q)xsltproc --stringparam www.root "$(WWW_ROOT)" $(XSLTPROCFLAGS) $(BASEDIR)/xsl/course.xsl $< > "$@"
62 ifdef SHOW_HTML_PATH
63         $(Q)echo "$@"           # Used by XXE macro to display the compiled page
64 endif
65
66
67 links.mk: $(XMLS:%.xml=%.links)
68         $(Q)echo 'docbook_links = $(sort $(wildcard $(shell cat $^)))' > $@
69
70 -include links.mk
71
72 copy-links: $(docbook_links:%=$(TARGETDIR)/%)
73         $(Q)rm links.mk $(XMLS:%.xml=%.links)
74
75 %.links: %.xml
76 #       $(Q)echo "  XSLTPROC $@"
77         $(Q)xsltproc --stringparam www.root "$(WWW_ROOT)" $(XSLTPROCFLAGS) $(BASEDIR)/xsl/getlinks.xsl $< > $@
78
79 # For copying other file from source (images, pfd, ...)
80 $(TARGETDIR)/%: %
81         $(Q)mkdir -p $(dir $@);\
82             if [ ! -d "$<" ]; then \
83                 echo "  CP       $<";\
84                 cp $< $@; \
85             fi