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