################################################################################
# Makefile for the Kubuntu Documentation
#
# Copyright (C) 2009 Richard A. Johnson <nixternal@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 3 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, see <http://www.gnu.org/licenses/>.
#
################################################################################

MAKECMD=make

# Language code for documents
LN=C

# XSL Processor
XSLTPROC=/usr/bin/xsltproc

# Stylesheets
CHUNKXSL=libs/kubuntu-chunk.xsl
NONCHUNKXSL=libs/kubuntu-nonchunk.xsl
CHUNKONLINEXSL=libs/kubuntu-chunk-online.xsl

# Output/build directory
BUILD=build
KBASE=$(BUILD)/kubuntu

################
## Make Targets
################

# Style
style:

	mkdir -p $(KBASE)/images
	mkdir -p $(KBASE)/common
	cp images/* $(KBASE)/images/
	cp libs/kubuntu.css $(KBASE)/common/

# All Kubuntu Documentation
all: common style desktopfiles

	for doc in `ls docs/`; do \
		for lang in `ls docs/$$doc`; do \
		    xsltproc -o $(KBASE)/docs/$$doc/$$lang/index.html $(CHUNKXSL) \
		    docs/$$doc/$$lang/$$doc.xml; done; done

# Common - ccbysa and contributors
common: clean

	mkdir -p $(KBASE)/docs
	xsltproc -o $(KBASE)/docs/contributors.html $(NONCHUNKXSL) \
	    common/contributors.xml
	xsltproc -o $(KBASE)/docs/license.html $(NONCHUNKXSL) \
	    common/ccbysa.xml

desktopfiles:
	mkdir -p $(KBASE)/data
	intltool-merge -d data/about/po/ data/about/about.desktop.in build/kubuntu/data/about.desktop
	cp build/kubuntu/data/about.desktop build/kubuntu/data/about.desktop.tobemoved
	intltool-merge -d data/directory/po/ data/directory/directory.desktop.in build/kubuntu/data/.directory
	intltool-merge -d data/kubuntu-docs/po/ data/kubuntu-docs/kubuntu-docs.desktop.in build/kubuntu/data/kubuntu-docs.desktop
	intltool-merge -d data/welcome/po/ data/welcome/welcome.desktop.in build/kubuntu/data/a_welcome.desktop

# Web - build docs for use on the web
web: common style

	cp -r /usr/share/doc/kde4/HTML/en/common/* $(KBASE)/common/
	for doc in `ls docs/`; do \
	    cp docs/$$doc/$(LN)/$$doc.xml docs/$$doc/$(LN)/$$doc.xml.orig; \
	    sed -i 's/help\:\/kubuntu\//\.\.\/\.\.\//g' docs/$$doc/$(LN)/$$doc.xml; \
	    xsltproc -o $(KBASE)/$$doc/$(LN)/index.html $(CHUNKONLINEXSL) \
	    docs/$$doc/$(LN)/$$doc.xml; \
	    mv docs/$$doc/$(LN)/$$doc.xml.orig docs/$$doc/$(LN)/$$doc.xml; done

# Clean the build directory
clean:

	rm -rf $(BUILD)
