# Makefile for GLFS Book generation.
# By Tushar Teredesai <tushar@linuxfromscratch.org>
# 2006-01-31
# $LastChangedBy: jgnew $
# $Date: 2006-03-15 10:14:43 -0600 (Wed, 15 Mar 2006) $
# Adjust these to suit your installation
OUTPUTDIR = $(HOME)/public_html/glfs-book
DUMPDIR= $(HOME)/glfs-commands
INSTALL = install
JADE = openjade
DOCBOOK = /usr/share/sgml/docbook/dsssl-stylesheets-1.78
BASEDIR= $(HOME)/public_html/glfs-book-xsl/
TEXBASEDIR= $(HOME)/public_html/glfs-book-tex/
NOCHUNKS_OUTPUT=GLFS-BOOK.html
SRCDIR = $(PWD)

all: glfs

glfs:
	@if [ -z $(BASEDIR) ]; then \
		echo "Envar BASEDIR is not set!" ; \
		exit 1 ; \
	fi
	@echo "Generating XHTML Version of GLFS Book with xsltproc..."
	@echo "  BASEDIR = $(BASEDIR)"
	@$(INSTALL) -d $(BASEDIR)
	xsltproc --xinclude --nonet -stringparam base.dir $(BASEDIR) \
	  stylesheets/glfs-chunked.xsl index.xml
	if [ ! -e $(BASEDIR)stylesheets ]; then \
	  mkdir -p $(BASEDIR)stylesheets; \
	fi;
	cp stylesheets/*.css $(BASEDIR)stylesheets
	if [ ! -e $(BASEDIR)images ]; then \
	  mkdir -p $(BASEDIR)images; \
	fi;
	cp images/*.png $(BASEDIR)/images
	cd $(BASEDIR); sed -i -e "s@../stylesheets@stylesheets@g" *.html
	cd $(BASEDIR); sed -i -e "s@../images@images@g" *.html

	for filename in `find $(BASEDIR) -name "*.html"`; do \
	  tidy -config tidy.conf $$filename; \
	  true; \
	  sh obfuscate.sh $$filename; \
	  sed -i -e "s@text/html@application/xhtml+xml@g" $$filename; \
	done;

nochunks:
	@echo "Generating nochunks version of GLFS..."
	xsltproc --xinclude --nonet -stringparam profile.condition html \
        --output $(BASEDIR)/$(NOCHUNKS_OUTPUT) \
        stylesheets/glfs-nochunks.xsl index.xml

	tidy -config tidy.conf $(BASEDIR)/$(NOCHUNKS_OUTPUT) || true

	sh obfuscate.sh $(BASEDIR)/$(NOCHUNKS_OUTPUT)

	sed -i -e "s@text/html@application/xhtml+xml@g"  \
          $(BASEDIR)/$(NOCHUNKS_OUTPUT)

pdf:
	xsltproc --xinclude --nonet --stringparam profile.condition pdf \
             --output glfs-pdf.xml stylesheets/glfs-profile.xsl index.xml 
	xsltproc --xinclude --nonet --output glfs.fo \
	         stylesheets/glfs-pdf.xsl glfs-pdf.xml
	sed -i -e "s/inherit/all/" glfs.fo
	fop.sh glfs.fo glfs.pdf
	$(INSTALL) -d $(BASEDIR)pdf
	rm glfs.fo
	mv glfs.pdf $(BASEDIR)pdf

tex:
	@if [ -z $(TEXBASEDIR) ]; then \
       echo "Envar TEXBASEDIR is not set!" ; \
       exit 1 ; \
    fi
	@echo "Generating TeX Version of GLFS Book with xsltproc..."
	@echo "  TEXBASEDIR = $(TEXBASEDIR)"
	@$(INSTALL) -d $(TEXBASEDIR)
# Using profiles in book source to exclude parts of the book from TeX
# i.e., Changelog
	xsltproc --nonet --output $(TEXBASEDIR)index.xml \
    	--stringparam "profile.role" "book" \
	http://docbook.sourceforge.net/release/xsl/current/profiling/profile.xsl \
	    index.xml
	@cd $(TEXBASEDIR) && xsltproc --nonet -o glfs-book.tex \
	    $(SRCDIR)/stylesheets/glfs-tex.xsl index.xml

dump-commands:
	xsltproc --xinclude --nonet --output $(DUMPDIR)/ \
	   stylesheets/dump-commands.xsl index.xml

validate:
	xmllint --noout --nonet --xinclude --postvalid index.xml

validate-pdf:
	xsltproc --xinclude --nonet --stringparam profile.condition pdf \
             --output glfs-pdf.xml stylesheets/glfs-profile.xsl index.xml 
	xmllint --noout --nonet --postvalid glfs-pdf.xml

glfs-patch-list:
	@echo "Generating glfs-patch-list..."
	xsltproc --xinclude --nonet \
             --output glfs-patch-list stylesheets/patcheslist.xsl index.xml
	sed -e "s|^.*/||" glfs-patch-list > glfs-patches
	sort glfs-patches > glfs-patch-list
	rm glfs-patches

.PHONY : glfs-patch-list
