]> rtime.felk.cvut.cz Git - edu/xsl.git/blob - Makefile
f614bf6669821838dd45e23f91c8bd60bb586627
[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 $(BASEDIR)/%,%,$(shell pwd))
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
18 # Destination filename
19 ifndef FNAME
20 FNAME=index.html
21 endif
22
23 TARGETDIR:=$(BASEDIR)/www/$(RELATIVEDIR)
24
25 .PHONY: all clean local subdirs copy-links
26
27 Q=$(if $(V),,@)
28
29 all: default
30
31 clean:
32         rm -rf $(TARGETDIR)/*
33
34 ifdef SUBDIRS
35 subdirs:
36         $(Q)$(foreach d,$(SUBDIRS),$(MAKE) -C $(d) &&) true
37 endif
38
39
40 WWW_ROOT ?= $(BACK_TO_BASE)
41 WWW_ROOT := $(WWW_ROOT:%/=%)
42
43 ifndef XMLS
44 XMLS := $(wildcard *.xml)
45 endif
46 htmls := $(XMLS:%.xml=%.html)
47
48 default: subdirs
49 default: $(htmls:%=$(TARGETDIR)/%)
50
51 $(TARGETDIR)/%.html: %.xml
52         $(Q)mkdir -p $(dir $@)
53         $(Q)echo "  XSLTPROC $(notdir $@)"
54         $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/course.xsl $< > "$@"
55         $(Q)$(MAKE) --no-print-directory copy-links XML=$<
56
57 links.mk: $(XML:%.xml=%.links)
58         $(Q)echo 'docbook_links = $(wildcard $(shell cat $^))' > $@
59
60 ifeq ($(MAKECMDGOALS),copy-links)
61 -include links.mk
62 endif
63
64 copy-links: $(docbook_links:%=$(TARGETDIR)/%)
65         $(Q)rm links.mk $(XML:%.xml=%.links)
66
67 %.links: %.xml
68         $(Q)echo "  XSLTPROC $@"
69         $(Q)xsltproc --stringparam www.root $(WWW_ROOT) $(XSLTPROCFLAGS) $(BASEDIR)/xsl/getlinks.xsl $< > $@
70
71 # For copying other file from source (images, pfd, ...)
72 $(TARGETDIR)/%: %
73         $(Q)mkdir -p $(dir $@);\
74             if [ ! -d "$<" ]; then \
75                 echo "  CP       $<";\
76                 cp $< $@; \
77             fi