~canonical-training/ubuntu-desktop-course/ubuntu-desktop-course-beta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# See the README file for instructions on:
# * Making a docbook book or a docbook article
# * Customizing the docbook
# * localizing it (translations and images)
# * Building it
# * etc.

# This is quite a hack, a patch that integrates the call of the 
# top level Makefile is welcome.

ifeq ($(CURDIR)x,x)
	CURDIR = $(shell pwd)
endif

include $(TYPE).Makefile
HTMLXSL = $(CURDIR)/lib/ubuntu-html-chunk-cust-en.xsl
DIRTARGETS = $(addsuffix stamp,$(wildcard */))
HTMLTARGETS = $(addsuffix .html,$(basename $(wildcard *.xml))) 
PDFTARGETS = $(addsuffix .pdf,$(basename $(wildcard *.xml))) 


LINGUAS=$(shell if test -r lib/LINGUAS; then grep -v "^\#" lib/LINGUAS; fi)


export XSLTPROC = /usr/bin/xsltproc
export FOP = /usr/bin/fop
XSL ?= $(CURDIR)/lib/html.xsl
XML2PO = /usr/bin/xml2po
XMLLINT = /usr/bin/xmllint
BASENAME = /usr/bin/basename
DIRNAME = /usr/bin/dirname
MSGMERGE = /usr/bin/msgmerge
#BLOCALIZED=build/localizedxml/$(LANG)
export BXML=build/xml/$(LANG)
BHTML=build/html/$(LANG)
BHTMLSITE=build/html-site/$(LANG)
export BPDF=build/pdf/$(LANG)

all:
	@echo "See the README file for usage instructions."

%/stamp: %/
	@$(MAKE) CURDIR=$(CURDIR) XSL=$(XSL) -f $(CURDIR)/Makefile -C $<

localize: localize-images localize-xml

localize-xml: 
	@echo "Localizingin $(BXML)"
#	@mkdir -p $(BXML)
	@for doc in $(SHIPPEDDOCS) ; do \
		doc_name=`basename $$doc .xml`; \
		dir_name=`dirname "$$doc"`; \
#		echo "dir_name: $$dir_name"; \
#		echo "Translating: $$dir_name/$$doc_name." ; \
#		for lang in $(LINGUAS) ; do \
		po_file=$$dir_name/po/$(LANG).po ; \
# ubuntu-desktop-course specific: \
# need to transform for student or teach guide: \
		echo "Generating $(BXML)/$$doc_name.phase0.xml with lib/$(GUIDE).xsl from $$dir_name/$$doc_name.xml." ; \
		$(XSLTPROC) --xinclude --stringparam language $(LANG) -o $(BXML)/$$doc_name.phase0.xml lib/$(GUIDE).xsl $$dir_name/$$doc_name.xml ; \
		if [ $$doc_name = $(DOC) ] ; then \
# phase1: if current DOC is article or book, we need to xinclude transform it and set language \
			echo "Generating $(BXML)/$$doc_name.phase1.xml file with xsl." ; \
			$(XSLTPROC) --xinclude --stringparam language $(LANG) -o $(BXML)/$$doc_name.phase1.xml lib/book.xsl $(BXML)/$$doc_name.phase0.xml ; \
		else \
			echo "Copying  $(BXML)/$$doc_name.phase0.xml to $(BXML)/$$doc_name.$(LANG).xml." ; \
			cp  $(BXML)/$$doc_name.phase0.xml $(BXML)/$$doc_name.phase1.xml ; \
		fi ; \
		if test -f $$po_file ; then \
# phase2: use po to translate or mv untranslated phase1 to lang-specific xml \
			echo "Using $$po_file"; \
			$(XML2PO) -p $$po_file -o $(BXML)/$$doc_name.xml $(BXML)/$$doc_name.phase1.xml ; \
		else \
			echo "$$po_file not found."; \
# Using untranslated $$dir_name/$$doc_name.xml." ; \
			mv $(BXML)/$$doc_name.phase1.xml $(BXML)/$$doc_name.xml ; \
		fi ; \
#		done ; \
#		echo "$(BXML)/$$doc_name.phase1.xml"; \
		if test -f $(BXML)/$$doc_name.phase0.xml ; then \
			rm $(BXML)/$$doc_name.phase0.xml; \
		fi ; \
		if test -f $(BXML)/$$doc_name.phase1.xml ; then \
			rm $(BXML)/$$doc_name.phase1.xml; \
		fi ; \
		if test -f $(BXML)/$$doc_name.phase2.xml ; then \
			rm $(BXML)/$$doc_name.phase2.xml; \
		fi ; \
	done

localize-images:
	@echo "Creating $(BXML)"
	@mkdir -p $(BXML)
	@for chapter in $(CONTENTDIRS); do \
			echo "Copying $$chapter/images to $(BXML)"; \
			cp -R $$chapter/images/ $(BXML); \
		if test -d $$chapter/images-$(LANG) ; then \
			echo "Copying $$chapter/images-$(LANG)/* to $(BXML)/images."; \
			cp $$chapter/images-$(LANG)/* $(BXML)/images; \
		fi; \
	done

html: localize
	@echo "Creating $(BHTML)"
	@mkdir -p $(BHTML)
	@cp -r $(BXML)/images $(BHTML)
	@cp lib/html-images/* $(BHTML)/images
	@$(XSLTPROC) --xinclude -o $(BHTML)/index-phase1.html ./lib/xinclude.xsl $(BXML)/$(DOC).xml
	@$(XSLTPROC) --stringparam toc.max.depth 2 --stringparam chunk.quietly 2 --stringparam html.stylesheet style.css -o $(BHTML)/index-phase2.html /usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl $(BHTML)/index-phase1.html
	@$(XSLTPROC) --html -o $(BHTML)/index.html ./lib/css.xsl $(BHTML)/index-phase2.html
	@cp ./lib/style.css ./lib/css.xsl $(BHTML)/ 
	@rm  $(BHTML)/*phase*

html-site: localize
	@echo "Creating $(BHTMLSITE)"
	@mkdir -p $(BHTMLSITE)
	@cp -r $(BXML)/images $(BHTMLSITE)
	@$(XSLTPROC) --xinclude -o $(BHTMLSITE)/index-phase1.html ./lib/xinclude.xsl $(BXML)/$(DOC).xml
	@$(XSLTPROC) --xinclude -o $(BHTMLSITE)/index.html $(HTMLXSL) $(BHTMLSITE)/index-phase1.html
	@rm  $(BHTMLSITE)/*phase*

pdf-target:
	@echo "Creating $(BPDF)"
	@mkdir -p $(BPDF)
	@cp lib/pdf.Makefile $(BPDF)/Makefile   
	@$(MAKE) -C $(BPDF)

pdf: localize pdf-target
    
xml-target:
	@echo "Creating build/xml/$(LANG)"
	@mkdir -p build/xml/$(LANG)
	

xml: localize
# xml-target

# This target creates the POT templates and updates pos
update-po: $(SHIPPEDDOCS)
	@for doc in $(SHIPPEDDOCS) ; do \
		doc_name_stripped=`basename $$doc .xml`; \
		dir_name=`dirname $$doc`; \
		pot_name="`$(BASENAME) $$doc_name_stripped.pot| tr A-Z a-z`"; \
#		echo "doc: $$doc"; \
#		echo "dir_name: $$dir_name"; \
#		echo "pot_name: $$pot_name"; \
		$(XSLTPROC) --xinclude -o $$dir_name/xinclude.xml ./lib/xinclude.xsl $$doc; \
		$(XML2PO) -e -o $$dir_name/po/$$pot_name $$dir_name/xinclude.xml; \
		rm $$dir_name/xinclude.xml; \
		for lingua in $(LINGUAS) ; do \
			if [ "$$lingua" != "en" ] ; then \
				$(MSGMERGE) -U $$dir_name/po/$$lingua.po $$dir_name/po/$$pot_name; \
			fi; \
		done; \
	done

linguas: 
	@for lingua in $(LINGUAS) ; do \
    	LANG:=lingua ; \
    	echo "LANG: $(LANG)"; \
	done

clean:
	@rm -f *.html *.pdf tmp-*.xml */tmp-*.xml */*.html */*.pdf */po/*.pot */*fo *.mo */*.mo .xml2po.mo
	@rm -rf build

#.PHONY: $(DIRTARGETS)