Files
macports-guide/Makefile
T

104 lines
2.8 KiB
Makefile
Raw Normal View History

# $Id$
2015-09-15 16:58:39 +00:00
# Makefile to generate the MacPorts HTML guide pages.
2018-05-01 17:35:26 +02:00
# See README.md for the list of ports that need to be installed.
2008-10-18 12:04:29 +00:00
# If your MacPorts isn't installed in /opt/local you have to change PREFIX
# here.
2012-09-06 22:00:13 +00:00
UNAME := $(shell uname)
2008-10-18 12:04:29 +00:00
# Prefix of the MacPorts installation.
PREFIX = $(realpath $(realpath $(shell which port))/../..)
2012-09-06 22:00:13 +00:00
ifeq ($(UNAME), Linux)
PREFIX = /usr
endif
# Command abstraction variables.
MKDIR = /bin/mkdir
CP = /bin/cp
RM = /bin/rm
2008-10-18 12:04:29 +00:00
LN = /bin/ln
2012-09-06 22:00:13 +00:00
ifeq ($(UNAME), Linux)
SED = /bin/sed
2017-06-26 22:52:42 +02:00
REINPLACE = $(SED) -i -r
else
SED = /usr/bin/sed
REINPLACE = $(SED) -i '' -E
2012-09-06 22:00:13 +00:00
endif
TCLSH = /usr/bin/tclsh
2007-12-18 21:55:06 +00:00
XSLTPROC = $(PREFIX)/bin/xsltproc
XMLLINT = $(PREFIX)/bin/xmllint
DBLATEX = $(PREFIX)/bin/dblatex
2007-12-18 21:55:06 +00:00
# Data directories.
GUIDE = guide
# Source directories.
GUIDE_XML = $(GUIDE)/xml
# Result directories.
GUIDE_RESULT = $(GUIDE)/html
GUIDE_RESULT_DBLATEX = $(GUIDE)/dblatex
2008-10-18 12:04:29 +00:00
# Path to the DocBook XSL files.
GUIDE_XSL = $(GUIDE)/resources/single-page.xsl
GUIDE_XSL_CHUNK = $(GUIDE)/resources/chunk.xsl
2008-10-18 12:04:29 +00:00
# DocBook HTML stylesheet for the guide.
STYLESHEET = docbook.css
2023-11-04 17:42:12 +01:00
.PHONY: all clean guide guide-chunked guide-dblatex validate
all: guide guide-chunked
2018-03-28 07:29:08 +02:00
# Generate the HTML guide using DocBook from the XML sources
2018-05-01 17:51:52 +02:00
guide:
$(call xml2html,$(GUIDE_XML),$(GUIDE_RESULT),$(GUIDE_XSL))
2018-05-01 17:51:52 +02:00
guide-chunked::
$(call xml2html,$(GUIDE_XML),$(GUIDE_RESULT)/chunked,$(GUIDE_XSL_CHUNK))
# Rules to generate HTML from DocBook XML
2018-03-28 07:29:08 +02:00
define xml2html
$(MKDIR) -p $(2)
$(CP) $(GUIDE)/resources/$(STYLESHEET) $(2)/$(STYLESHEET)
$(CP) $(GUIDE)/resources/images/* $(2)/
$(CP) $(GUIDE)/resources/*.js $(2)/
2008-07-20 16:12:27 +00:00
$(XSLTPROC) --xinclude \
--output $(2)/index.html \
$(3) $(1)/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.
2017-06-26 22:52:42 +02:00
$(REINPLACE) \
2017-11-16 20:44:52 +01:00
's|(<h[0-9] [^>]*><a id="([^"]*)"></a>)([^<]*)(</h[0-9]>)|\1<a href="#\2">\3</a>\4|g' \
$(2)/index.html
endef
guide-chunked::
2018-03-28 07:29:08 +02:00
# Add the table of contents to every chunked HTML file.
# If someone knows a better way to do this please change it.
$(TCLSH) toc-for-chunked.tcl $(GUIDE_RESULT)/chunked
# Generate the guide as a PDF.
guide-dblatex: SUFFIX = pdf
guide-dblatex:
$(MKDIR) -p $(GUIDE_RESULT_DBLATEX)
$(DBLATEX) \
-P "latex.encoding=utf8" \
--fig-path="$(GUIDE)/resources/images" \
--type="$(SUFFIX)" \
--param='toc.section.depth=2' \
--param='doc.section.depth=3' \
--output="$(GUIDE_RESULT_DBLATEX)/macports-guide.$(SUFFIX)" \
$(GUIDE_XML)/guide.xml
2015-09-15 16:58:39 +00:00
# Remove all temporary files generated by guide:.
clean:
$(RM) -rf $(GUIDE_RESULT)
$(RM) -rf $(GUIDE_RESULT_DBLATEX)
$(RM) -f guide.tmp.xml
2008-10-18 12:04:29 +00:00
# Validate the XML files for the guide.
validate:
$(XMLLINT) --xinclude --loaddtd --postvalid --noout $(GUIDE_XML)/guide.xml