#
#   the ultimate team organization software
#   ---------------------------------------
#
# Copyright 1999-2001 by Gero Kohnert
#
# Author: Gero Kohnert
#
# $Header: /cvsroot/tutos/tutos/Makefile,v 1.60.2.8 2003/10/13 16:08:50 gokohnert Exp $
# $Name:  $
#
#
# $Log: Makefile,v $
# Revision 1.60.2.8  2003/10/13 16:08:50  gokohnert
# updates
#
# Revision 1.60.2.7  2003/07/19 11:34:25  gokohnert
# fix missing ico file
#
# Revision 1.60.2.6  2003/07/18 05:29:04  gokohnert
# fix
#
# Revision 1.60.2.5  2003/06/14 10:22:52  gokohnert
# language stuff
#
# Revision 1.60.2.4  2003/05/30 13:18:54  tapoueh
# Merging work allowing to post new debian package.
#
# Revision 1.62  2003/05/30 13:18:02  tapoueh
# Minor debugs allowing to make the package.
#
# Revision 1.61  2003/05/30 12:39:37  tapoueh
# Scripts have to be world readable !
#
# Revision 1.60  2003/04/04 04:20:18  gokohnert
# cosmetics
#
# Revision 1.59  2003/03/23 22:11:13  gokohnert
# multiple fixes
#
# Revision 1.58  2003/02/10 04:59:13  gokohnert
# added missing picture
#
# Revision 1.57  2003/02/05 18:17:24  gokohnert
# moved README files to the modules/handlers directories
#
# Revision 1.56  2003/01/15 14:31:09  tapoueh
# Merge from the BRANCH-1-0, where the debian package development occurs.
# The log file bug fixed previously in the stable branch should have
# disapeared in the 1.1, thanks to Gero work.
#
# Note: we're in the process to be in debian main tree. Finally !
# The process should be 1 week long, then TUTOS will be accepted and
# deployed all over the world on each and every official debian mirror.
# And apt will know about tutos.
#
# Revision 1.55  2002/12/31 14:33:33  gokohnert
# cleanups for HTML
#
# Revision 1.54  2002/12/18 22:04:58  gokohnert
# fixes
#
# Revision 1.53  2002/12/16 20:40:23  gokohnert
# moved docmanagement to a new module
#
# Revision 1.52  2002/12/13 15:22:29  gokohnert
# fixes
#
# Revision 1.51  2002/12/10 18:17:42  gokohnert
# introduced new handler modules for fax/sms etc.
#
# Revision 1.50  2002/12/07 16:53:03  gokohnert
# new (moved) mailbox module
#
# Revision 1.49  2002/12/04 15:34:25  gokohnert
# using auth modules for authentification
#
# Revision 1.48  2002/11/27 17:54:56  gokohnert
# language updates
#
# Revision 1.47  2002/11/27 14:20:08  gokohnert
# Czech update
#
# Revision 1.46  2002/11/18 07:19:23  gokohnert
# more ldap
#
# Revision 1.45  2002/11/18 05:55:00  gokohnert
# sync with ldap feature
#
# Revision 1.44  2002/11/09 16:08:08  gokohnert
# moved ldap stuff to own dir
#
# Revision 1.43  2002/11/02 12:48:30  gokohnert
# modularized url management
#
# Revision 1.42  2002/10/13 20:34:22  gokohnert
# modularized installations
#
# Revision 1.41  2002/10/13 17:11:11  gokohnert
# additional changes (too many)
#
# Revision 1.40  2002/10/04 10:03:21  gokohnert
# css stuff (comments please)
#
# Revision 1.39  2002/10/01 08:59:55  tapoueh
# Merge with the stable branch.
#
# Revision 1.38  2002/09/30 20:16:33  gokohnert
# fix
#
# Revision 1.37  2002/09/29 20:26:06  gokohnert
# first checkin of a plam export module
# which allows the export of Appointments and Adresses formatted for inporting into palm pilots
#
# (not ready for reakl use)
#
# Revision 1.36  2002/09/27 09:12:27  gokohnert
# language updates
#
# Revision 1.35  2002/09/26 12:06:05  gokohnert
# new hungarian stuff
#
# Revision 1.34  2002/09/14 13:02:27  gokohnert
# menu / default focus / layout
#
# Revision 1.33  2002/08/28 19:41:54  gokohnert
# some module handling
#
# Revision 1.32  2002/08/25 11:53:03  gokohnert
# catalan support
#
# Revision 1.31  2002/08/21 16:04:12  gokohnert
# cleanup: moved langfiles holiday nameday and database interfaces to their own subdirs
#
# Revision 1.30  2002/08/15 13:14:23  gokohnert
# Started new layout engine mechanism for page creation:
# Pages that are displayed to the end user are now objects that extends a preloaded
# layout object. The type of the layout object is configurable and may change.
# So it will be possible to have classical layout (layout/classic_layout.pinc) or
# other layouts that for example may have the navigation somewhere else.
#
# Work will continue !
#
# Revision 1.29  2002/08/08 10:02:08  tapoueh
# Trying to be able to compile the documentation on a debian system.
# Paths are to differents, even filenames are not the same.
#
# It will end using autoconf/automake tools, but I do not have the time
# to learn and use that for now.
#
# Revision 1.28  2002/08/03 16:27:15  gokohnert
# some more fixes
#
# Revision 1.27  2002/07/26 11:55:13  tapoueh
# Make install will create config.ping and lang_custom.p3 with a
# introduction on how to use that files.
#
# Revision 1.26  2002/07/26 09:23:47  tapoueh
# Preparing release.
#
# Revision 1.25  2002/07/26 08:22:34  gokohnert
# release prepare
#
# Revision 1.24  2002/07/25 16:58:47  gokohnert
# release preps
#
# Revision 1.23  2002/07/25 12:29:59  gokohnert
# preparations for release
#
# Revision 1.22  2002/07/15 08:40:13  gokohnert
# update
#
# Revision 1.21  2002/07/08 20:24:26  gokohnert
# updates
#
# Revision 1.20  2002/07/07 10:55:53  gokohnert
# release preparations
#
# Revision 1.19  2002/07/02 19:15:40  gokohnert
# fixes to make pdf doku
#
# Revision 1.18  2002/07/01 11:58:38  gokohnert
# added theme nuke
#
# Revision 1.17  2002/07/01 11:41:05  tapoueh
# make install bugfix
#
# Revision 1.16  2002/06/29 13:27:17  gokohnert
# new book1pdf target for testing
#
# Revision 1.15  2002/06/27 17:33:38  gokohnert
# new (moved) invoice module
#
# Revision 1.14  2002/06/25 19:57:42  gokohnert
# fixed docbook pathes
#
# Revision 1.13  2002/06/25 19:27:47  gokohnert
# updates
#
# Revision 1.12  2002/06/21 14:23:18  gokohnert
# added dutch mailtemplates
#
# Revision 1.11  2002/06/20 10:48:19  gokohnert
# some more modularization
# new getAddLink functions in note,file,bug etc.
# infolist methods that can be called in ..._show scripts
#
# Revision 1.10  2002/06/17 12:59:00  tapoueh
# Added an 'install' file, working well for debian packaging... I don't know
# how well it fit with other systems.
# Now using the GNU Make tool and some of its functionalities as $(wildcard ).
#
# Revision 1.9  2002/06/12 21:04:20  gokohnert
# now working with register_globals set to Off
# other changes see mailing list and ChangeLog
#
# Revision 1.8  2002/06/05 18:56:19  gokohnert
# new spanish/nicaragua files
# email subjects are now in language files
# selection of country codes from iso_cntrycodes.p3
#
# Revision 1.7  2002/05/27 19:47:20  gokohnert
# new dutch module translation
#
# Revision 1.6  2002/05/26 18:25:59  gokohnert
# updates
#
# Revision 1.5  2002/05/22 17:59:50  gokohnert
# changes to enable the gantt stuff in existing environments (w/o caching)
#
# Revision 1.4  2002/05/03 13:54:59  gokohnert
# new password reminder feature
#
# Revision 1.3  2002/05/03 08:25:56  gokohnert
# feature permissions for teams
#
# Revision 1.2  2002/04/27 16:05:50  gokohnert
# namedays weekstart workdays in user profiles (run update.php \!)
#
# Revision 1.1  2002/04/12 14:54:14  gokohnert
# now use Makefile instead of Makefile.in
# Makefile.in,v $
#
#
#

# Primary Version
VERSION = 1.1
#
# The full Version is VERSION.DATE
#
DATE         = `date +%Y%m%d`
FULLVERSION  = $(VERSION).$(DATE)

# Standard Files
PHP =   $(PHP_TOP) \
	$(PHP_DB) \
	$(PHP_AUTH) \
	$(PHP_LOCAL) \
	$(PHP_GRP) \
	$(PHP_NOTE) \
	$(PHP_URL) \
	$(PHP_RES) \
	$(PHP_FILE) \
	$(PHP_WATCH) \
	$(PHP_INST) \
	$(PHP_INV) \
	$(PHP_LDAP) \
	$(PHP_MBOX) \
	$(PHP_LAYOUT)


PHP_TOP = $(wildcard php/*.php) \
	$(wildcard php/*.p3) \
	$(wildcard php/*.pinc)
PHP_DB = $(wildcard php/db/*.php) \
	$(wildcard php/db/*.p3) \
	$(wildcard php/db/*.pinc) 
PHP_LOCAL = $(wildcard php/localization/*.php) \
	$(wildcard php/localization/*.p3) \
	$(wildcard php/localization/*.pinc) 
PHP_AUTH = $(wildcard php/auth/*.php) \
	$(wildcard php/auth/*.p3) \
	$(wildcard php/auth/*.pinc) 

# CRM Groups Module
PHP_GRP = $(wildcard php/group/*.php) \
	$(wildcard php/group/*.p3) \
	$(wildcard php/group/*.pinc)

# LDAP Module
PHP_LDAP = $(wildcard php/ldap/*.php) \
        README.ldap \
	$(wildcard php/ldap/*.p3) \
	$(wildcard php/ldap/*.pinc)

# Mailbox Module
PHP_MBOX = $(wildcard php/mailbox/*.php) \
	$(wildcard php/mailbox/*.p3) \
	$(wildcard php/mailbox/*.pinc)

# Invoice Module
PHP_INV = $(wildcard php/invoice/*.php) \
	$(wildcard php/invoice/*.p3) \
	$(wildcard php/invoice/*.pinc)

# Note Module
PHP_NOTE = $(wildcard php/note/*.php) \
	$(wildcard php/note/*.p3) \
	$(wildcard php/note/*.pinc)

# URL Module
PHP_URL = $(wildcard php/url/*.php) \
	$(wildcard php/url/*.p3) \
	$(wildcard php/url/*.pinc)

# Docmanagement Module
PHP_FILE = $(wildcard php/file/*.php) \
	$(wildcard php/file/*.p3) \
	$(wildcard php/file/*.pinc)

# Resource Module
PHP_RES = $(wildcard php/resource/*.php) \
	$(wildcard php/resource/*.p3) \
	$(wildcard php/resource/*.pinc)

# Watchlist Module
PHP_WATCH = $(wildcard php/watchlist/*.php) \
	$(wildcard php/watchlist/*.p3) \
	$(wildcard php/watchlist/*.pinc)

# Installation Module
PHP_INST = $(wildcard php/installation/*.php) \
	$(wildcard php/installation/*.p3) \
	$(wildcard php/installation/*.pinc)

# Layout Engines
PHP_LAYOUT = $(wildcard php/layout/*.php) \
	$(wildcard php/layout/*.p3) \
	$(wildcard php/layout/*.pinc)

# Merge Module (nonstandard , need extra download)
PHP_MERGE = $(wildcard php/merge/*.php) \
        php/merge/README \
	$(wildcard php/merge/*.p3) \
	$(wildcard php/merge/*.pinc)

# Checklist Module (nonstandard , need extra download)
PHP_CHECKLIST = $(wildcard php/checklist/*.php) \
        php/checklist/README \
	$(wildcard php/checklist/*.p3) \
	$(wildcard php/checklist/*.pinc)

# Palm Module (nonstandard , need extra download)
PHP_PALM = $(wildcard php/palm/*.php) \
	$(wildcard php/palm/*.p3) \
	$(wildcard php/palm/*.pinc) \
	php/palm/README

# Ticker Module (nonstandard , need extra download)
PHP_TICKER = $(wildcard php/ticker/*.php) \
	$(wildcard php/ticker/*.p3) \
	$(wildcard php/ticker/*.pinc) \
	php/ticker/README

#
# Handler
#
# extra stuff (not part of distribution)
HDL_FAX =  $(wildcard php/fax/*.php) \
	html/faxheader \
	$(wildcard php/fax/*.p3) \
	$(wildcard php/fax/*.pinc) \
	php/fax/README

# extra stuff (not part of distribution)
HDL_MAP =  $(wildcard php/mapquest/*.php) \
	$(wildcard php/mapquest/*.p3) \
	$(wildcard php/mapquest/*.pinc) \
	php/mapquest/README

# extra stuff (not part of distribution)
HDL_SMS =  $(wildcard php/sms/*.php) \
	$(wildcard php/sms/*.p3) \
	$(wildcard php/sms/*.pinc) \
	php/sms/README

# extra stuff (not part of distribution)
HDL_CIA =  $(wildcard php/cia_factbook/*.php) \
	$(wildcard php/cia_factbook/*.p3) \
	$(wildcard php/cia_factbook/*.pinc) \
	php/cia_factbook/README

# extra stuff (not part of distribution)
HDL_WEATHER =  $(wildcard php/phpweather/*.php) \
	$(wildcard php/phpweather/*.p3) \
	$(wildcard php/phpweather/*.pinc) \
	php/phpweather/README


LANGFILES = \
	php/localization/de.p3 \
	php/localization/en.p3 \
	php/localization/en-us.p3 \
	php/localization/fr.p3 \
	php/localization/es.p3 \
	php/localization/es-mx.p3 \
	php/localization/es-ni.p3 \
	php/localization/it.p3 \
	php/localization/tw.p3 \
	php/localization/zh.p3 \
	php/localization/ru.p3 \
	php/localization/ko.p3 \
	php/localization/pl.p3 \
	php/localization/nl.p3 \
	php/localization/sv.p3 \
	php/localization/el.p3 \
	php/localization/pt.p3 \
	php/localization/pt-br.p3

HELP  =	html/help/.htaccess \
	$(wildcard html/help/*.html)

CSSFILES = html/red.css \
	html/blue.css \
	html/tutos.css \
	html/white.css

TOPFILES = \
	tutos.spec \
	tutos.spec.in \
	apache.conf \
	$(SCRIPTS) \
	ToDo \
	README \
	INSTALL \
	ChangeLog

SCRIPTS = \
	shellfunc.sh \
	scheme.sh \
	createdb.sh


THEMEBLUE   = \
	$(wildcard html/blue/*gif) \
	$(wildcard html/blue/*png)
THEMERED    = \
	$(wildcard html/red/*gif) \
	$(wildcard html/red/*png)

OTHERHP = \
	homepage/.htaccess \
	homepage/install.html \
	homepage/install_easy.html \
	homepage/install_hints.html \
	homepage/install_faq.html \
	homepage/mysql_setup.html

HTMLPICS = \
	$(wildcard html/*png) \
	$(wildcard html/*ico) \
	$(wildcard html/*gif)

TEMPLATES = \
	$(wildcard html/*.proto.*) \
	html/copyright.html

OTHERH= $(TEMPLATES) \
	$(THEMEBLUE) \
	$(THEMERED) \
	$(HTMLPICS)\
	$(wildcard html/*.gif)\
	html/motd.html \
	html/.htaccess

#
# Installation Guide is part of OTHER and distributed with all releases
#
HOMEP = homepage/index.html \
	homepage/about.html \
	homepage/require.html \
	homepage/database.html \
	homepage/source_php.html \
	homepage/object.html \
	homepage/docs.html \
	homepage/download.html \
	homepage/status.html \
	homepage/feedback.html \
	homepage/license.html \
	homepage/links.html \
	homepage/head0.html \
	homepage/head1.html \
	homepage/head2.html \
	homepage/foot1.html \
	homepage/installations.html \
	homepage/installations.png \
	homepage/address.html \
	homepage/address.png \
	homepage/bugtrack.html \
	homepage/bugtrack.png \
	homepage/bugstats.png \
	homepage/calendar.html \
	homepage/calendar.png \
	homepage/product.html \
	homepage/product.png \
	homepage/file.html \
	homepage/file.png \
	homepage/task.html \
	homepage/task.png \
	homepage/timetrack.html \
	homepage/timetrack.png \
	homepage/timetrack2.png \
	homepage/screens.html \
	homepage/tutos.css \
	homepage/gklc.html

#
# Documentation
#
#
# for development
#
DOCFILES_DEV= \
	documentation/.cvsignore \
	documentation/tutos.dsl \
	documentation/book-decl.sgml \
	documentation/tutos.sgml \
	documentation/tutos_user.sgml \
	documentation/tutos_admin.sgml \
	documentation/tutos_prog.sgml \
	$(wildcard documentation/tutos_user_*.sgml) \
	$(wildcard documentation/tutos_admin_*.sgml) \
	$(wildcard documentation/tutos_prog_*.sgml)

#
# for enduser
# (generated stuff will be handeld later)
DOCFILES= \
	$(wildcard documentation/user_manual/*.png) \
	$(wildcard documentation/admin_manual/*.png) \
	$(wildcard documentation/prog_manual/*.png) \

#
# Additional Files only for the developers
#
OTHERJ=	Makefile \
	.cvsignore \
	upload.sh \
	langdiff.sh \
	php/.cvsignore \
	apache.conf.in

#
# OTHER files are distributed with all release packages
#
OTHER =	${CSSFILES} \
	$(TOPFILES) \
	php/.htaccess \
	tutos.lsm \
	$(OTHERH) \
	$(OTHERHP)

#
# Extrafiles (not part of the release but we need to know about)
#
EXTRAFILES = \
	${THEMESQLI} \
	${THEMEVISUAL} \
	${THEMENUKE} \
	${LANG_HU} \
	${LANG_CS} \
	${LANG_JA} \
	${LANG_CA} \
	${LANG_ES-VE} \
	${PHP_MERGE} \
	${PHP_CHECKLIST} \
	${PHP_PALM} \
	${PHP_TICKER} \
	${HDL_CIA} \
	${HDL_MAP} \
	${HDL_FAX} \
	${HDL_SMS} \
	${HDL_WEATHER}

# Edited for Debian GNU/Linux.
DESTDIR =

#TARGETDIR    = /usr/local/tutos
REALPATH     = /usr/share/tutos
REPOSITORY   = /var/lib/tutos
TARGETDIR    = $(DESTDIR)$(REALPATH)
UPLOADDIR    = $(DESTDIR)$(REPOSITORY)

PERL         = $(shell which perl)
SED          = $(shell which sed)
CHMOD        = $(shell which chmod)
ECHO         = $(shell which echo)
RM           = $(shell which rm)
FIND         = $(shell which find)
XARG         = $(shell which xargs)
TOUCH        = $(shell which touch)

HOST         = $(shell which hostname)

.PHONY: all docs clean distclean tutos.spec apache.conf

.SUFFIXES: .sig .sgml .spec .conf

all: ${PHP} ${OTHERJ} ${HELP} ${LANGFILES}
	-@${CHMOD} 644 ${PHP} ${OTHERJ} ${HELP} ${LANGFILES}
	@${CHMOD} 755 . php  html homepage html/help
	@${CHMOD} 755 scheme.sh shellfunc.sh
	@${ECHO} "DONE"

apache.conf: apache.conf.in
	$(SED) \
		-e 's;%HOST%;${HOST};g' \
		-e 's;%PREFIX%;${REALPATH};g' < $< > $@
	@${CHMOD} 644 $@

tutos.spec: tutos.spec.in
	@${SED} \
		-e 's;%PREFIX%;${REALPATH};g' \
		-e "s;%VERSION%;${FULLVERSION};g" \
	< $< > $@
	@${CHMOD} 644 $@


# /usr/share/sgml/docbook/docbook-dsssl-stylesheets-1.64/html
# Creating the books
SGMLBASE     = /usr/share/sgml
JADE         = $(shell which jade)
JADEARGS3    = -t tex
JADEARGS2    = -V html-backend -ihtml -t sgml
JADEARGS     = -V html-index -ihtml -t sgml
CATALOGS     = -c ${SGMLBASE}/CATALOG.jade_dsl -c ${SGMLBASE}/CATALOG.docbook_4 -c ${SGMLBASE}/CATALOG.docbook-dsssl-stylesheets
#DSLFILE=${SGMLBASE}/docbook-toys/suse-both.dsl\#html
DSLFILE      = ../tutos.dsl\#html
STYLEVERSION = dsssl-stylesheets

COLLATEINDEX = ${SGMLBASE}/docbook/${STYLEVERSION}/bin/collateindex.pl
#COLLATEINDEX = $(shell which collateindex.pl)

book0: documentation/tutos.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${PERL} ${COLLATEINDEX} -x -N -o ../index.sgml);
	(cd documentation/$@; ${JADE} ${JADEARGS} ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/html -d ${DSLFILE}  ../tutos.sgml)
	(cd documentation/$@; ${PERL} ${SGMLBASE}/docbook/${STYLEVERSION}/bin/collateindex.pl -x -o ../index.sgml HTML.index);
	(cd documentation/$@; ${JADE} ${JADEARGS2} ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/html -d ${DSLFILE}  ../tutos.sgml)
	/bin/chmod 755 documentation/book0


book1: documentation/tutos_user.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS} ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/html -d ${DSLFILE}  ../book-decl.sgml ../tutos_user.sgml)
	/bin/chmod 755 documentation/$@

book1pdf: documentation/tutos_user.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS3}  -o $@.tex ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/print -d ../tutos.dsl\#print ../book-decl.sgml ../tutos_user.sgml;pdfjadetex $@.tex > $@.out;	pdfjadetex $@.tex > $@.out;pdfjadetex $@.tex > $@.out)

	/bin/chmod 755 documentation/$@

book2: documentation/tutos_admin.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS} ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/html -d ${DSLFILE}  ../book-decl.sgml ../tutos_admin.sgml)
	/bin/chmod 755 documentation/$@

book2pdf: documentation/tutos_admin.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS3}  -o $@.tex ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/print -d ../tutos.dsl\#print ../book-decl.sgml ../tutos_admin.sgml;pdfjadetex $@.tex > $@.out)

	/bin/chmod 755 documentation/$@

book3: documentation/tutos_prog.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS} ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/html -d ${DSLFILE}  ../book-decl.sgml ../tutos_prog.sgml)
	/bin/chmod 755 documentation/$@

book3pdf: documentation/tutos_prog.sgml
	@rm -rf documentation/$@
	@mkdir -p documentation/$@
	(cd documentation/$@; ${JADE} ${JADEARGS3}  -o $@.tex ${CATALOGS} -D ${SGMLBASE}/docbook/${STYLEVERSION}/print -d ../tutos.dsl\#print ../book-decl.sgml ../tutos_prog.sgml;pdfjadetex $@.tex > $@.out;pdfjadetex $@.tex > $@.out;pdfjadetex $@.tex > $@.out)

	/bin/chmod 755 documentation/$@

book: book0 book1 book2 book3


docs:
	@mkdir -p doc

clean:
	-@$(RM) -f l.* *.list
	-@$(FIND) . -type f -name "*~" | $(XARGS) $(RM) -f

distclean: clean
	-$(RM) config.log config.status config.cache apache.conf

#
# Update the config.pinc with the Release Date
#
updateconfig: php/config_default.pinc tutos.spec apache.conf
	cp php/config_default.pinc config.pinc.${DATE}
	@$(SED) \
		-e "s;tutos\[version\]=\"[0-9.]*\";tutos[version]=\"${FULLVERSION}\";g" \
		-e "s;tutos\[debug\]=[0-9]*;tutos[debug]=0;g" \
		-e "s;tutos\[demo\]=[0-9]*;tutos[demo]=0;g" \
	< config.pinc.${DATE} > php/config_default.pinc
	@$(CHMOD) 644 php/config_default.pinc
#
# create a backup file with all neccessary files
#
backup: ${PHP} ${LANGFILES} ${OTHER} ${OTHERJ} ${HOMEP} ${HELP} ${DOCFILES} ${DOCFILES_DEV} ${EXTRAFILES}
	tar cvjf tutos-all.tar.bz2 ${PHP} ${OTHER} ${OTHERJ} ${HOMEP} ${HELP} ${LANGFILES} ${DOCFILES} ${DOCFILES_DEV} ${EXTRAFILES} do-it

#
# PHP Release
#
php.list: ${PHP} ${LANGFILES} ${OTHER} ${HELP} ${DOCFILES} updateconfig book0
	@echo "# Make Filelist for php -> $@"
	@$(RM) -f $@ tmp.$@
	@$(TOUCH) tmp.$@
	@$(foreach d,${PHP} ${LANGFILES} ${OTHER} ${HELP} ${DOCFILES}, \
		echo tutos/$(d) >> tmp.$@; \
	)
	@cd .. ; ls -1 tutos/documentation/book0/* >> tutos/tmp.$@
	@cat tmp.$@ | grep -v "custom.p3" | grep -v "ja.p3" | grep -v "hu.p3" | grep -v "ca.p3"|  grep -v php/config.pinc | sort -u > $@

download-php: php.list additional
	@cd ..;tar -T tutos/php.list -cjf tutos/tutos-php-${FULLVERSION}.tar.bz2; cd tutos
	@cd ..;tar -T tutos/php.list -czf tutos/tutos-php-${FULLVERSION}.tar.gz; cd tutos 
	@cd ..;cat tutos/php.list | zip -@ tutos/tutos-php-${FULLVERSION}.zip; cd tutos
	@echo "# Packages created (PHP)"

upload-php: download-php
	./upload.sh php ${FULLVERSION}
	@echo "# upload-php to sourceforge finished"

#
# RPM Release
#
rpm-php: tutos.spec download-php
	cp tutos-php-${FULLVERSION}.tar.gz /usr/src/packages/SOURCES/tutos-php-${FULLVERSION}.tar.gz
	rpm -bb tutos.spec
	@echo "# created (RPM for PHP)"

#
# Check the CSS files for missing definitions
#
cssdiff: ${CSSFILES}
	cat html/tutos.css | egrep "{"  > css.tutos
	cat html/blue.css | egrep "{"  > css.blue
	cat html/red.css | egrep "{"  > css.red
	cat html/visual.css | egrep "{"  > css.visual
	cat html/sqli.css | egrep "{"  > css.sqli
	cat html/nuke.css | egrep "{"  > css.nuke
	cat html/white.css | egrep "{"  > css.white
	@echo "----------------------------------------"
	-diff css.tutos css.blue
	@echo "----------------------------------------"
	-diff css.tutos css.red
	@echo "----------------------------------------"
	-diff css.tutos css.visual
	@echo "----------------------------------------"
	-diff css.tutos css.sqli
	@echo "----------------------------------------"
	-diff css.tutos css.nuke
	@echo "----------------------------------------"
	-diff css.tutos css.white
	@echo "----------------------------------------"
	-@/bin/rm css.*

#
# Show the language differences (undefined fields in PHP language files)
#
langdiff: ${LANGFILES}
	@cd php/localization; ../../langdiff.sh
	@cd php/group; ../../langdiff.sh
	@cd php/resource; ../../langdiff.sh
	@cd php/note; ../../langdiff.sh
	@cd php/url; ../../langdiff.sh
	@cd php/file; ../../langdiff.sh
	@cd php/invoice; ../../langdiff.sh
	@cd php/installation; ../../langdiff.sh
	@cd php/ldap; ../../langdiff.sh
	@cd php/checklist; ../../langdiff.sh
	@cd php/merge; ../../langdiff.sh
	@cd php/ticker; ../../langdiff.sh
	@cd php/watchlist; ../../langdiff.sh

#
# put it all on zaphod == demo.tutos.org (this will only work for me !!!)
#
zaphod: ${PHP} ${LANGFILES} ${OTHER} ${HELP} zaphod.html updateconfig
	mkdir -p /net/zaphod/home/gero/src/tutos /net/zaphod/home/gero/src/tutos/html /net/zaphod/home/gero/src/tutos/homepage
	mkdir -p /net/zaphod/home/gero/src/tutos/php
	chmod 755 /net/zaphod/home/gero/src/tutos /net/zaphod/home/gero/src/tutos/html /net/zaphod/home/gero/src/tutos/homepage
	chmod 755 /net/zaphod/home/gero/src/tutos/html/visual /net/zaphod/home/gero/src/tutos/html/blue

	cp ChangeLog ToDo createdb.sh shellfunc.sh /net/zaphod/home/gero/src/tutos
	cp ${PHP} ${LANGFILES} /net/zaphod/home/gero/src/tutos/php
	cp html/*html html/*css html/*png html/*gif html/*ico /net/zaphod/home/gero/src/tutos/html
	cp ${HELP} /net/zaphod/home/gero/src/tutos/html/help
	cp homepage/.htaccess homepage/*html homepage/*png homepage/*css /net/zaphod/home/gero/src/tutos/homepage
	cp html/*.proto.* /net/zaphod/home/gero/src/tutos/html

	mkdir -p /net/zaphod/home/gero/src/tutos/documentation/
	mkdir -p /net/zaphod/home/gero/src/tutos/documentation/book0
	mkdir -p /net/zaphod/home/gero/src/tutos/documentation/user_manual
	mkdir -p /net/zaphod/home/gero/src/tutos/documentation/admin_manual
	chmod 755 /net/zaphod/home/gero/src/tutos/documentation
	chmod 755 /net/zaphod/home/gero/src/tutos/documentation/book0
	chmod 755 /net/zaphod/home/gero/src/tutos/documentation/user_manual
	chmod 755 /net/zaphod/home/gero/src/tutos/documentation/admin_manual
	cp documentation/book0/* /net/zaphod/home/gero/src/tutos/documentation/book0
	cp documentation/user_manual/*png /net/zaphod/home/gero/src/tutos/documentation/user_manual
	cp documentation/admin_manual/*png /net/zaphod/home/gero/src/tutos/documentation/admin_manual

	mkdir -p /net/zaphod/home/gero/src/tutos/php/localization
	mkdir -p /net/zaphod/home/gero/src/tutos/php/db
	mkdir -p /net/zaphod/home/gero/src/tutos/php/auth
	mkdir -p /net/zaphod/home/gero/src/tutos/php/merge
	mkdir -p /net/zaphod/home/gero/src/tutos/php/group
	mkdir -p /net/zaphod/home/gero/src/tutos/php/invoice
	mkdir -p /net/zaphod/home/gero/src/tutos/php/resource
	mkdir -p /net/zaphod/home/gero/src/tutos/php/file
	mkdir -p /net/zaphod/home/gero/src/tutos/php/ldap
	mkdir -p /net/zaphod/home/gero/src/tutos/php/note
	mkdir -p /net/zaphod/home/gero/src/tutos/php/watchlist
	mkdir -p /net/zaphod/home/gero/src/tutos/php/installation
	mkdir -p /net/zaphod/home/gero/src/tutos/html/visual
	mkdir -p /net/zaphod/home/gero/src/tutos/html/blue
	mkdir -p /net/zaphod/home/gero/src/tutos/html/red
	mkdir -p /net/zaphod/home/gero/src/tutos/html/help
	cp ${PHP_TOP} /net/zaphod/home/gero/src/tutos/php
	cp ${PHP_DB} /net/zaphod/home/gero/src/tutos/php/db
	cp ${PHP_AUTH} /net/zaphod/home/gero/src/tutos/php/auth
	cp ${PHP_LOCAL} /net/zaphod/home/gero/src/tutos/php/localization
	cp ${PHP_GRP} /net/zaphod/home/gero/src/tutos/php/group
	cp ${PHP_INV} /net/zaphod/home/gero/src/tutos/php/invoice
	cp ${PHP_NOTE} /net/zaphod/home/gero/src/tutos/php/note
	cp ${PHP_LDAP} /net/zaphod/home/gero/src/tutos/php/ldap
	cp ${PHP_MBOX} /net/zaphod/home/gero/src/tutos/php/mailbox
	cp ${PHP_URL} /net/zaphod/home/gero/src/tutos/php/url
	cp ${PHP_FILE} /net/zaphod/home/gero/src/tutos/php/file
	cp ${PHP_RES} /net/zaphod/home/gero/src/tutos/php/resource
	cp ${PHP_WATCH} /net/zaphod/home/gero/src/tutos/php/watchlist
	cp ${PHP_INST} /net/zaphod/home/gero/src/tutos/php/installation
	cp ${PHP_MERGE} /net/zaphod/home/gero/src/tutos/php/merge
	cp ${PHP_TICKER} /net/zaphod/home/gero/src/tutos/php/ticker
	cp ${PHP_CHECKLIST} /net/zaphod/home/gero/src/tutos/php/checklist
	cp ${PHP_PALM} /net/zaphod/home/gero/src/tutos/php/palm
	cp ${PHP_LAYOUT} /net/zaphod/home/gero/src/tutos/php/layout

	cp ${TEMPLATES} /net/zaphod/home/gero/src/tutos/html
	cp ${HTMLPICS} /net/zaphod/home/gero/src/tutos/html
	cp ${CSSFILES} /net/zaphod/home/gero/src/tutos/html
	cp ${THEMEBLUE} /net/zaphod/home/gero/src/tutos/html/blue
	cp ${THEMERED} /net/zaphod/home/gero/src/tutos/html/red
	cp ${TEHMEVISUAL} /net/zaphod/home/gero/src/tutos/html/visual
	cp ${HELP} /net/zaphod/home/gero/src/tutos/html/help

	cp zaphod.html /net/zaphod/home/gero/src/tutos/html/motd.html

# WARNING: I (Dimitri Fontaine <dfontaine@cvf.fr>) added this target
#          in order to be able to build a debian package !
install: clean apache.conf tutos.spec
	find php      -type d -exec mkdir -p $(TARGETDIR)/{} \;
	find html     -type d -exec mkdir -p $(TARGETDIR)/{} \;
	find homepage -type d -exec mkdir -p $(TARGETDIR)/{} \;

	# PHP files
	install -o www-data -m 664 $(PHP_TOP)    $(TARGETDIR)/php
	install -o www-data -m 664 $(PHP_DB)     $(TARGETDIR)/php/db
	install -o www-data -m 664 $(PHP_AUTH)   $(TARGETDIR)/php/auth
	install -o www-data -m 664 $(PHP_LOCAL)  $(TARGETDIR)/php/localization
	install -o www-data -m 664 $(PHP_GRP)    $(TARGETDIR)/php/group
	install -o www-data -m 664 $(PHP_INV)    $(TARGETDIR)/php/invoice
	install -o www-data -m 664 $(PHP_NOTE)   $(TARGETDIR)/php/note
	install -o www-data -m 664 $(PHP_LDAP)   $(TARGETDIR)/php/ldap
	install -o www-data -m 664 $(PHP_MBOX)   $(TARGETDIR)/php/mailbox
	install -o www-data -m 664 $(PHP_URL)    $(TARGETDIR)/php/url
	install -o www-data -m 664 $(PHP_RES)    $(TARGETDIR)/php/resource
	install -o www-data -m 664 $(PHP_FILE)   $(TARGETDIR)/php/file
	install -o www-data -m 664 $(PHP_WATCH)  $(TARGETDIR)/php/watchlist
	install -o www-data -m 664 $(PHP_INST)   $(TARGETDIR)/php/installation
	install -o www-data -m 664 $(PHP_MERGE)  $(TARGETDIR)/php/merge
	install -o www-data -m 664 $(PHP_TICKER) $(TARGETDIR)/php/ticker
	install -o www-data -m 664 $(PHP_PALM)   $(TARGETDIR)/php/palm
	install -o www-data -m 664 $(PHP_CHECKLIST) $(TARGETDIR)/php/checklist
	install -o www-data -m 664 $(PHP_LAYOUT) $(TARGETDIR)/php/layout
	install -o www-data -m 664 $(LANGFILES)  $(TARGETDIR)/php
	install -o www-data -m 664 php/.htaccess $(TARGETDIR)/php

	# HTML files
	install -o www-data -m 664 $(TEMPLATES)   $(TARGETDIR)/html
	install -o www-data -m 664 $(HTMLPICS)    $(TARGETDIR)/html
	install -o www-data -m 664 $(CSSFILES)    $(TARGETDIR)/html
	install -o www-data -m 664 html/.htaccess $(TARGETDIR)/html
	install -o www-data -m 664 $(THEMEBLUE)   $(TARGETDIR)/html/blue
	install -o www-data -m 664 $(THEMERED)    $(TARGETDIR)/html/red
	install -o www-data -m 664 $(THEMEVISUAL) $(TARGETDIR)/html/visual
	install -o www-data -m 664 $(HELP)        $(TARGETDIR)/html/help

	# HOMEDIR files
	install -o www-data -m 664 $(HOMEP)   $(TARGETDIR)/homepage
	install -o www-data -m 664 $(OTHERHP) $(TARGETDIR)/homepage

	# Top files
	install -o www-data -m 664 $(TOPFILES) $(TARGETDIR)
	(cd $(TARGETDIR) && chmod a+rx $(SCRIPTS))

	# care about config files
	mkdir -p $(DESTDIR)/etc/tutos
	cp $(TARGETDIR)/php/config_default.pinc $(DESTDIR)/etc/tutos
	cp $(TARGETDIR)/php/modules.pinc $(DESTDIR)/etc/tutos
	cp $(TARGETDIR)/apache.conf $(DESTDIR)/etc/tutos

	# Make a config.pinc in the tarball
	# it will be configured in the postinst process
	touch $(DESTDIR)/etc/tutos/config.pinc

	# Make an empty lang_custom.p3 in the tarball
	touch $(DESTDIR)/etc/tutos/lang_custom.p3
	echo "<?" >> $(DESTDIR)/etc/tutos/lang_custom
	echo " /* You can redefine specific categories here. */"\
	 >> $(DESTDIR)/etc/tutos/lang_custom.p3
	echo "?>" >> $(DESTDIR)/etc/tutos/lang_custom.p3

	# The upload dir
	mkdir -p $(UPLOADDIR)

	# care about documentation
	mkdir -p $(DESTDIR)/usr/share/doc/tutos
	install -m 664 $(DOCFILES) $(DESTDIR)/usr/share/doc/tutos
	install -m 664 README $(DESTDIR)/usr/share/doc/tutos
	install -m 664 INSTALL $(DESTDIR)/usr/share/doc/tutos/README.Install

#
# Packages & Handler that will not be part of the standard releases
#
#
additional: nuke.zip visual.zip sqli.zip \
	japanese.zip \
	catalan.zip \
	hungarian.zip \
	czech.zip \
	venezuela.zip \
	ticker.zip \
	merge.zip \
	checklist.zip \
	palm.zip \
	HDL_cia_factbook.zip \
	HDL_mapquest.zip \
	HDL_fax.zip \
	HDL_sms.zip \
	HDL_phpweather.zip
	@mv nuke.zip nuke-${FULLVERSION}.zip
	@mv visual.zip visual-${FULLVERSION}.zip
	@mv sqli.zip sqli-${FULLVERSION}.zip
	@mv japanese.zip japanese-${FULLVERSION}.zip
	@mv catalan.zip catalan-${FULLVERSION}.zip
	@mv hungarian.zip hungarian-${FULLVERSION}.zip
	@mv venezuela.zip venezuela-${FULLVERSION}.zip
	@mv czech.zip czech-${FULLVERSION}.zip
	@mv ticker.zip ticker-${FULLVERSION}.zip
	@mv merge.zip merge-${FULLVERSION}.zip
	@mv checklist.zip checklist-${FULLVERSION}.zip
	@mv palm.zip palm-${FULLVERSION}.zip
	@mv HDL_cia_factbook.zip HDL_cia_factbook-${FULLVERSION}.zip
	@mv HDL_mapquest.zip HDL_mapquest-${FULLVERSION}.zip
	@mv HDL_sms.zip HDL_sms-${FULLVERSION}.zip
	@mv HDL_phpweather.zip HDL_phpweather-${FULLVERSION}.zip
	@mv HDL_fax.zip HDL_fax-${FULLVERSION}.zip

THEMENUKE   = README.nuke \
	html/nuke.css \
	$(wildcard html/nuke/*gif)

nuke.zip: $(THEMENUKE)
	@echo "# Make Filelist for $@"
	@/bin/rm -f nuke.list
	@/usr/bin/touch nuke.list
	@$(foreach d,$(THEMENUKE), \
		echo tutos/$(d) >> nuke.list; \
	)
	cd ..;cat tutos/nuke.list | zip -@ tutos/$@
	rm nuke.list

THEMEVISUAL = README.visual \
	html/visual.css \
	$(wildcard html/visual/*gif)

visual.zip: $(THEMEVISUAL)
	@echo "# Make Filelist for $@"
	@/bin/rm -f visual.list
	@/usr/bin/touch visual.list
	@$(foreach d,$(THEMEVISUAL), \
		echo tutos/$(d) >> visual.list; \
	)
	cd ..;cat tutos/visual.list | zip -@ tutos/$@
	rm visual.list

THEMESQLI   = README.sqli \
	html/sqli.css \
	$(wildcard html/sqli/*gif)

sqli.zip: $(THEMESQLI)
	@echo "# Make Filelist for $@"
	@/bin/rm -f sqli.list
	@/usr/bin/touch sqli.list
	@$(foreach d,$(THEMESQLI), \
		echo tutos/$(d) >> sqli.list; \
	)
	cd ..;cat tutos/sqli.list | zip -@ tutos/$@
	rm sqli.list

LANG_JA = README.ja \
	$(wildcard php/*/ja.p3) \
	$(wildcard html/help/*_ja.html) \
        $(wildcard html/*.proto.ja)

japanese.zip: $(LANG_JA)
	@echo "# Make Filelist for $@"
	@/bin/rm -f ja.list
	@/usr/bin/touch ja.list
	@$(foreach d,$(LANG_JA), \
		echo tutos/$(d) >> ja.list; \
	)
	cd ..;cat tutos/ja.list | zip -@ tutos/$@
	rm ja.list

LANG_CA = README.ca \
	$(wildcard php/*/ca.p3) \
	$(wildcard html/help/*_ca.html) \
        $(wildcard html/*.proto.ca)

catalan.zip: $(LANG_CA)
	@echo "# Make Filelist for $@"
	@/bin/rm -f ca.list
	@/usr/bin/touch ca.list
	@$(foreach d,$(LANG_CA), \
		echo tutos/$(d) >> ca.list; \
	)
	cd ..;cat tutos/ca.list | zip -@ tutos/$@
	rm ca.list

LANG_ES-VE = README.es-ve \
	$(wildcard php/*/es-ve.p3) \
	php/localization/holiday_es_ve.pinc \
	$(wildcard html/help/*_es-ve.html) \
        $(wildcard html/*.proto.es-ve)

venezuela.zip: $(LANG_ES-VE)
	@echo "# Make Filelist for $@"
	@/bin/rm -f es-ve.list
	@/usr/bin/touch es-ve.list
	@$(foreach d,$(LANG_ES-VE), \
		echo tutos/$(d) >> es-ve.list; \
	)
	cd ..;cat tutos/es-ve.list | zip -@ tutos/$@
	rm es-ve.list

LANG_HU = README.hu \
	$(wildcard php/*/hu.p3) \
	$(wildcard html/help/*_hu.html) \
        $(wildcard html/*.proto.hu)

hungarian.zip: $(LANG_HU)
	@echo "# Make Filelist for $@"
	@/bin/rm -f hu.list
	@/usr/bin/touch hu.list
	@$(foreach d,$(LANG_HU), \
		echo tutos/$(d) >> hu.list; \
	)
	cd ..;cat tutos/hu.list | zip -@ tutos/$@
	rm hu.list

LANG_CS = README.cs \
	$(wildcard php/*/cs.p3) \
	$(wildcard html/help/*_cs.html) \
	$(wildcard html/*.proto.cs)

czech.zip: $(LANG_CS)
	@echo "# Make Filelist for $@"
	@/bin/rm -f cs.list
	@/usr/bin/touch cs.list
	@$(foreach d,$(LANG_CS), \
		echo tutos/$(d) >> cs.list; \
	)
	cd ..;cat tutos/cs.list | zip -@ tutos/$@
	rm cs.list

# Ticker Module
ticker.zip: $(PHP_TICKER)
	@echo "# Make Filelist for $@"
	@/bin/rm -f ticker.list
	@/usr/bin/touch ticker.list
	@$(foreach d,$(PHP_TICKER), \
		echo tutos/$(d) >> ticker.list; \
	)
	cd ..;cat tutos/ticker.list | zip -@ tutos/$@
	rm ticker.list

# Merge Module
merge.zip: $(PHP_MERGE)
	@echo "# Make Filelist for $@"
	@/bin/rm -f merge.list
	@/usr/bin/touch merge.list
	@$(foreach d,$(PHP_MERGE), \
		echo tutos/$(d) >> merge.list; \
	)
	cd ..;cat tutos/merge.list | zip -@ tutos/$@
	rm merge.list

# Checklist Module
checklist.zip: $(PHP_CHECKLIST)
	@echo "# Make Filelist for $@"
	@/bin/rm -f checklist.list
	@/usr/bin/touch checklist.list
	@$(foreach d,$(PHP_CHECKLIST), \
		echo tutos/$(d) >> checklist.list; \
	)
	cd ..;cat tutos/checklist.list | zip -@ tutos/$@
	rm checklist.list

# Palm Module
palm.zip: $(PHP_PALM)
	@echo "# Make Filelist for $@"
	@/bin/rm -f palm.list
	@/usr/bin/touch palm.list
	@$(foreach d,$(PHP_PALM), \
		echo tutos/$(d) >> palm.list; \
	)
	cd ..;cat tutos/palm.list | zip -@ tutos/$@
	rm palm.list

# Handler
HDL_cia_factbook.zip: $(HDL_CIA)
	@echo "# Make Filelist for $@"
	@/bin/rm -f cia.list
	@/usr/bin/touch cia.list
	@$(foreach d,$(HDL_CIA), \
		echo tutos/$(d) >> cia.list; \
	)
	cd ..;cat tutos/cia.list | zip -@ tutos/$@
	rm cia.list

HDL_mapquest.zip: $(HDL_MAP)
	@echo "# Make Filelist for $@"
	@/bin/rm -f map.list
	@/usr/bin/touch map.list
	@$(foreach d,$(HDL_MAP), \
		echo tutos/$(d) >> map.list; \
	)
	cd ..;cat tutos/map.list | zip -@ tutos/$@
	rm map.list

HDL_fax.zip: $(HDL_FAX)
	@echo "# Make Filelist for $@"
	@/bin/rm -f fax.list
	@/usr/bin/touch fax.list
	@$(foreach d,$(HDL_FAX), \
		echo tutos/$(d) >> fax.list; \
	)
	cd ..;cat tutos/fax.list | zip -@ tutos/$@
	rm fax.list

HDL_sms.zip: $(HDL_SMS)
	@echo "# Make Filelist for $@"
	@/bin/rm -f sms.list
	@/usr/bin/touch sms.list
	@$(foreach d,$(HDL_SMS), \
		echo tutos/$(d) >> sms.list; \
	)
	cd ..;cat tutos/sms.list | zip -@ tutos/$@
	rm sms.list

HDL_phpweather.zip: $(HDL_WEATHER)
	@echo "# Make Filelist for $@"
	@/bin/rm -f pw.list
	@/usr/bin/touch pw.list
	@$(foreach d,$(HDL_WEATHER), \
		echo tutos/$(d) >> pw.list; \
	)
	cd ..;cat tutos/pw.list | zip -@ tutos/$@
	rm pw.list


# EOF
