#=============================================================================
#
#    rules.doc
#
#    Additional rules for processing documentation written in DocBook/SGML
#
#=============================================================================
#####COPYRIGHTBEGIN####
#                                                                          
# -------------------------------------------                              
# The contents of this file are subject to the Red Hat eCos Public License 
# Version 1.1 (the "License"); you may not use this file except in         
# compliance with the License.  You may obtain a copy of the License at    
# http://www.redhat.com/                                                   
#                                                                          
# Software distributed under the License is distributed on an "AS IS"      
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the 
# License for the specific language governing rights and limitations under 
# the License.                                                             
#                                                                          
# The Original Code is eCos - Embedded Configurable Operating System,      
# released September 30, 1998.                                             
#                                                                          
# The Initial Developer of the Original Code is Red Hat.                   
# Portions created by Red Hat are                                          
# Copyright (C) 2001 Red Hat, Inc.                             
# All Rights Reserved.                                                     
# -------------------------------------------                              
#                                                                          
#####COPYRIGHTEND####
#=============================================================================
#####DESCRIPTIONBEGIN####
#
# Author(s):     bartv
# Date:          2001-01-11
# Purpose:       Rules for processing documentation
# Description:
#     Each package's doc directory's makefile should define the
#     following variables:
#       TOPLEVEL   - of the component repository
#       MAIN_SGML  - documentation entry point
#       OTHER_SGML - any other .sgml files accessed from main
#       PICTURES   - referenced by the SGML files
#####DESCRIPTIONEND####
#=============================================================================

.PHONY: default check html pdf clean

# Locations of the stylesheets and other SGML support files
CATALOG          := /usr/lib/sgml/CATALOG
MAIN_STYLESHEETS := /usr/lib/sgml/stylesheets/nwalsh-modular
ECOS_STYLESHEET  := $(TOPLEVEL)/pkgconf/stylesheet.dsl
FIXHTML          := $(TOPLEVEL)/pkgconf/fixhtml.tcl

# The files that will be generated:
ifeq (,$(MAIN_HTML))
 MAIN_HTML        := $(subst .sgml,.html,$(MAIN_SGML))
endif
ifeq (,$(MAIN_PDF))
 MAIN_PDF         := $(subst .sgml,.pdf,$(MAIN_SGML))
endif

# Rules for generating pictures
GIFS := $(foreach x,$(PICTURES),$(x).gif)
EPS  := $(foreach x,$(PICTURES),$(x).eps)

%.gif: %.fig
	convert -crop 0x0 $< $@

%.eps: %.fig
	convert -crop 0x0 $< $@

default: check

# Validating an sgml document can be achieved with 
check: $(MAIN_SGML) $(OTHER_SGML) $(GIFS) $(EPS)
	nsgmls -vs -c $(CATALOG) $<

# Generating HTML from the SGML. In practice multiple .html files may
# be generated, but for the purposes of dependency analysis the others
# can be ignored.
html: $(MAIN_HTML)

$(MAIN_HTML): $(MAIN_SGML) $(OTHER_SGML) $(GIFS) $(ECOS_STYLESHEET) $(FIXHTML)
	jade -t sgml -i html -d $(ECOS_STYLESHEET)#html $<
	tclsh $(FIXHTML)

# PDF files can be generated in a similar fashion.
pdf: $(MAIN_PDF)

$(MAIN_PDF):  $(MAIN_SGML) $(OTHER_SGML) $(EPS) $(ECOS_STYLESHEET)
	jade -o $(subst .sgml,.tex,$(MAIN_SGML)) -t tex -V tex-backend -d $(ECOS_STYLESHEET)#print $<
	pdfjadetex $(subst .sgml,.tex,$(MAIN_SGML))
	pdfjadetex $(subst .sgml,.tex,$(MAIN_SGML))
	pdfjadetex $(subst .sgml,.tex,$(MAIN_SGML))

#$(MAIN_PDF):  $(MAIN_SGML) $(OTHER_SGML) $(EPS) $(ECOS_STYLESHEET)
#	jade -o $(subst .sgml,.tex,$(MAIN_SGML)) -t tex -V tex-backend -d $(ECOS_STYLESHEET)#print $<
#	jadetex $(subst .sgml,.tex,$(MAIN_SGML))
#	jadetex $(subst .sgml,.tex,$(MAIN_SGML))
#	jadetex $(subst .sgml,.tex,$(MAIN_SGML))
#	dvips -o $(subst .sgml,.ps,$(MAIN_SGML)) $(subst .sgml,.dvi,$(MAIN_SGML))
#	ps2pdf $(subst .sgml,.ps,$(MAIN_SGML)) $(subst .sgml,.pdf,$(MAIN_SGML))

# Clean. For now assume that all .html, .gif etc files are generated
clean:
	rm -rf *.html *.tex *.dvi *.aux *.log *.ps *.pdf *.gif *.eps

