# $Id: Makefile 38345 2008-07-16 15:51:17Z simon@macports.org $ # Makefile to generate the macports html guide and the man pages. # The ports 'docbook-xsl', 'docbook-xml' and 'libxslt' have to be installed. # If your macports isn't installed in /opt/local you have to change PREFIX # here. # Prefix of the macports installation. PREFIX = /opt/local # Command abstraction variables. MKDIR = /bin/mkdir CP = /bin/cp RM = /bin/rm SED = /usr/bin/sed TCLSH = /usr/bin/tclsh XSLTPROC = $(PREFIX)/bin/xsltproc XMLLINT = $(PREFIX)/bin/xmllint # Data directories. GUIDE = guide MAN = man # Source directories. GUIDE-SRC = $(GUIDE)/xml MAN-SRC = $(MAN)/xml # Result directories. GUIDE-RESULT = $(GUIDE)/html GUIDE-RESULT-CHUNK = $(GUIDE-RESULT)/chunked MAN-RESULT = $(MAN)/man/ # Man temporary directory. MAN-TMP = $(MAN)/tmp # Path to the docbook xsl files. DOCBOOK = $(PREFIX)/share/xsl/docbook-xsl GUIDE-XSL = $(DOCBOOK)/xhtml/profile-docbook.xsl GUIDE-XSL-CHUNK = $(DOCBOOK)/xhtml/chunk.xsl MAN-XSL = $(MAN)/resources/macports.xsl # Docbook html stylesheet for the guide. STYLESHEET = docbook.css # Additional parameters for the guide. STRINGPARAMS = --stringparam html.stylesheet $(STYLESHEET) \ --stringparam section.autolabel 1 \ --stringparam toc.section.depth 1 \ --stringparam generate.toc "book toc" \ --stringparam section.label.includes.component.label 1 \ --stringparam profile.condition "noman" # Additional parameters for the chunked guide. STRINGPARAMS-CHUNK = --stringparam chunk.section.depth 0 .PHONY: all guide man clean validate all: guide man # Generate the html guide using DocBook from the xml sources in $(GUIDE-SRC). guide: $(MKDIR) -p $(GUIDE-RESULT) $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT)/$(STYLESHEET) $(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT)/ $(XSLTPROC) --xinclude $(STRINGPARAMS) \ --output $(GUIDE-RESULT)/index.html \ $(GUIDE-XSL) $(GUIDE-SRC)/guide.xml # Convert all sections (h1-h9) to a link so it's easy to link to them. # If someone knows a better way to do this please change it. $(SED) -i "" -E \ 's|(]*>)([^<]*)()|\1\3\4|g' \ $(GUIDE-RESULT)/index.html # Generate the chunked html guide with one section per file. guide-chunked: $(MKDIR) -p $(GUIDE-RESULT-CHUNK) $(CP) $(GUIDE)/resources/$(STYLESHEET) $(GUIDE-RESULT-CHUNK)/$(STYLESHEET) $(CP) $(GUIDE)/resources/images/* $(GUIDE-RESULT-CHUNK)/ $(XSLTPROC) --xinclude $(STRINGPARAMS) $(STRINGPARAMS-CHUNK) \ --output $(GUIDE-RESULT-CHUNK)/index.html \ $(GUIDE-XSL-CHUNK) $(GUIDE-SRC)/guide.xml # Convert all sections (h1-h9) to a link so it's easy to link to them. # If someone knows a better way to do this please change it. $(SED) -i "" -E \ 's|(]*>)([^<]*)()|\1\3\4|g' \ $(GUIDE-RESULT-CHUNK)/*.html # Add the table of contents to every junked html file. # If someone knows a better way to do this please change it. $(TCLSH) toc-for-chunked.tcl $(GUIDE-RESULT-CHUNK) # Generate the man pages using DocBook from the xml source in $(MAN-SRC). # The portfile-*.xml and portgroup-*.xml files in $(GUIDE-SRC) are copied to # $(MAN-TMP) and modified (section -> refsection) so they can be used as man # xml source files and then xincluded in the real man xml files in $(MAN-SRC). man: $(MAN-XSL) $(MKDIR) -p $(MAN-RESULT) $(MKDIR) -p $(MAN-TMP) $(CP) $(GUIDE-SRC)/portfile-*.xml $(MAN-TMP) $(CP) $(GUIDE-SRC)/portgroup-*.xml $(MAN-TMP) $(SED) -i "" 's|||g' $(MAN-TMP)/* $(XSLTPROC) --xinclude --output $(MAN-RESULT) $(MAN-XSL) \ $(MAN-SRC)/port.1.xml \ $(MAN-SRC)/portfile.7.xml \ $(MAN-SRC)/portgroup.7.xml \ $(MAN-SRC)/porthier.7.xml $(RM) -r $(MAN-TMP) # Create XSL from template for man pages. $(MAN-XSL): $(SED) 's:@PREFIX@:$(PREFIX):' $@.in > $@ # Remove all temporary files generated by guide: and man:. clean: $(RM) -rf $(GUIDE-RESULT) $(RM) -rf $(MAN-RESULT) $(RM) -rf $(MAN-TMP) $(RM) -rf $(MAN-XSL) $(RM) -f guide.tmp.xml # Validate the xml files for the guide. # These two steps are necessary as otherwise xmllint complains about missing # ids. validate: $(XMLLINT) --xinclude $(GUIDE-SRC)/guide.xml > guide.tmp.xml $(XMLLINT) --loaddtd --valid --noout guide.tmp.xml