#################################################################################
# Makefile for the Kubuntu Documentation
# Copyright (C) 2005-2006 Ubuntu Documentation Project (ubuntu-doc@lists.ubuntu.com)
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#    On Debian based systems a copy of the GPL can be found
#    at /usr/share/common-licenses/GPL
#
#################################################################################

MAKECMD=make

# XSL Processors
XSLTPROC=/usr/bin/xsltproc

current_distro=$(shell test -e /etc/debian_version && echo "debian")

# NWalsh Docbook XSL's
ifeq ($(current_distro), debian)
# Ubuntu
NWDBXSL=/usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl

# Debian and Ubuntu also need an explicit location for the XML catalog files
#export XML_CATALOG_FILES = /usr/share/xml/docbook/schema/dtd/4.3/catalog.xml
#else
# SuSE
#NWDBXSL=/usr/share/xml/docbook/stylesheet/nwalsh/current/html/docbook.xsl
endif

# Stylesheets for building HTML and PDF
KUBUNTUXSL=libs/kubuntu-chunk.xsl
INDEXXSL=libs/index-table.xsl

# Makes an Image list text file
MKIMGLST=../libs/imagelist.xsl

# Collected and Write Status
wOS=../libs/writeOwnerStatus.xsl

BUILDDIR=../build/

# Base kde directories for output from processor
KBASE=$(BUILDDIR)kubuntu/

# all is for the kubuntu package and for the nightly builds for doc.ubuntu.com
all: clean style tbh

# Style
style:
	# copy style sheet to build directory
	mkdir $(KBASE)common/
	mkdir -p $(KBASE)images/admon/
	mkdir $(KBASE)images/C/
	mkdir $(KBASE)images/callouts/
	mkdir $(KBASE)images/navig/
	mkdir $(KBASE)images/index
	cp libs/*.css $(KBASE)common/
	cp /usr/share/doc/kde/HTML/en/common/*png $(KBASE)common/
	cp images/admon/*.png $(KBASE)images/admon/
	cp images/C/*.png $(KBASE)images/C/
	cp images/callouts/*.png $(KBASE)images/callouts/
	cp images/navig/*.png $(KBASE)images/navig/
	cp images/index/*.png $(KBASE)images/index/

# Topic Based Help
tbh:

	# ABOUT KUBUNTU
	for cc in `cat about-kubuntu/lang`; do \
	xsltproc --stringparam generate.toc "no" \
	--param chunk.first.sections 0 --xinclude -o \
	$(KBASE)about-kubuntu/$$cc/index.html $(KUBUNTUXSL) \
	about-kubuntu/$$cc/about-kubuntu.xml; done

	# ADD APPLICATIONS
	for cc in `cat add-applications/lang`; do \
	xsltproc --xinclude -o $(KBASE)add-applications/$$cc/index.html \
	$(KUBUNTUXSL) add-applications/$$cc/add-applications.xml; done

	# BASIC CONCEPTS
	for cc in `cat basic-concepts/lang`; do \
	xsltproc --xinclude -o $(KBASE)basic-concepts/$$cc/index.html \
	$(KUBUNTUXSL) basic-concepts/$$cc/basic-concepts.xml; done

	# CONFIG DESKTOP
	for cc in `cat config-desktop/lang`; do \
	xsltproc --xinclude -o $(KBASE)config-desktop/$$cc/index.html \
	$(KUBUNTUXSL) config-desktop/$$cc/config-desktop.xml; done

	# FILES AND DOCS
	for cc in `cat files-and-docs/lang`; do \
	xsltproc --xinclude -o $(KBASE)files-and-docs/$$cc/index.html \
	$(KUBUNTUXSL) files-and-docs/$$cc/files-and-docs.xml; done

	# GAMES
	for cc in `cat games/lang`; do \
	xsltproc --xinclude -o $(KBASE)games/$$cc/index.html \
	$(KUBUNTUXSL) games/$$cc/games.xml; done

	# GETTING HELP
	for cc in `cat getting-help/lang`; do \
	xsltproc --xinclude -o $(KBASE)getting-help/$$cc/index.html \
	$(KUBUNTUXSL) getting-help/$$cc/getting-help.xml; done

	# HARDWARE
	for cc in `cat hardware/lang`; do \
	xsltproc --xinclude -o $(KBASE)hardware/$$cc/index.html \
	$(KUBUNTUXSL) hardware/$$cc/hardware.xml; done

	# INDEX
	for cc in `cat index/lang`; do \
	xsltproc --xinclude -o $(KBASE)index/$$cc/index.html \
	$(INDEXXSL) index/$$cc/index.xml; done

	# INTERNET
	for cc in `cat internet/lang`; do \
	xsltproc --xinclude -o $(KBASE)internet/$$cc/index.html \
	$(KUBUNTUXSL) internet/$$cc/internet.xml; done

	# KEEPING SAFE
	for cc in `cat keeping-safe/lang`; do \
	xsltproc --xinclude -o $(KBASE)keeping-safe/$$cc/index.html \
	$(KUBUNTUXSL) keeping-safe/$$cc/keeping-safe.xml; done

	# MUSIC, VIDEO, AND PHOTOS (MULTIMEDIA)
	for cc in `cat musicvideophotos/lang`; do \
	xsltproc --xinclude -o $(KBASE)musicvideophotos/$$cc/index.html \
	$(KUBUNTUXSL) musicvideophotos/$$cc/musicvideophotos.xml; done

	# NETWORK
	for cc in `cat network/lang`; do \
	xsltproc --xinclude -o $(KBASE)network/$$cc/index.html \
	$(KUBUNTUXSL) network/$$cc/network.xml; done

	# NEW TO KUBUNTU
	for cc in `cat newtokubuntu/lang`; do \
	xsltproc --xinclude -o $(KBASE)newtokubuntu/$$cc/index.html \
	$(KUBUNTUXSL) newtokubuntu/$$cc/newtokubuntu.xml; done

	# OFFICE
	for cc in `cat office/lang`; do \
	xsltproc --xinclude -o $(KBASE)office/$$cc/index.html \
	$(KUBUNTUXSL) office/$$cc/office.xml; done

	# PRINTING AND SCANNING
	for cc in `cat printing/lang`; do \
	xsltproc --xinclude -o $(KBASE)printing/$$cc/index.html \
	$(KUBUNTUXSL) printing/$$cc/printing.xml; done

	# PROGRAMMING (GENERAL)
	for cc in `cat programming/lang`; do \
	xsltproc --xinclude -o $(KBASE)programming/$$cc/index.html \
	$(KUBUNTUXSL) programming/$$cc/programming.xml; done

	# SYSTEM SETTINGS
	for cc in `cat system-settings/lang`; do \
	xsltproc --xinclude -o $(KBASE)system-settings/$$cc/index.html \
	$(KUBUNTUXSL) system-settings/$$cc/system-settings.xml; done

# Cleanup
clean:

	rm -rf $(KBASE)*
