#	bsd.wml.mk - So  23 Jul 2000 10:34:03 CEST, Andreas Klemm
#	This file is for the apsfilter.org project
#
# $ApsCVS: www/mk/bsd.wml.mk,v 1.49 2002/11/30 12:29:45 andreas Exp $
#
# This include file "bsd.wml.mk" handles
# creating and installing of wml based html pages and pictures
#
# +++ variables +++
#
# HOSTNAME	the name of the host where apsfilter webpages are located
#
# ARCH		architecture of machine (uname -m)
#
# DOC		the translated html file(s), (default: index.html)
# HANDBOOK	handcraftet apsfilter handbook files
# IMG		the pictures with complete path
#		(all defined in Makefile)
# CGI		scripts for cgi-bin
# RAW		simply copy these files "raw" to $APSWWWDEST (robots.txt, ...)
#
# SITESOURCE	the wml source files and make framework
#
# WMLSTYLE	files on which the website depends
#
# APSCVS	apsfilter CVSROOT directory
# BACKUP_APSCVS	local mirror of CVSROOT directory, speeds up test make's
#
# STABLE_RELEASE  apsfilter stable release, default: 7.0.1
# STABLE_BRANCH   apsfilter-stable branch, default: RELENG_7
# CURRENT_RELEASE apsfilter-current release, default: current
# CURRENT_BRANCH  apsfilter-current branch, default: HEAD 
#
# APSDNSNAME	FQDN of our webserver, (default: www.apsfilter.org)
# APSWWWDEST	toplevel destination directory for webpages
# APSWWWOWN	owner of webpages and pics
# APSWWWGRP	group of webpages and pics
# APSWWWMODE	permissions of webpages and pics
#
# APSCGISRC	cgi scripts source directory, (default: cgi)
# APSCGIDEST	cgi scripts dest dir, (default: /var/www/${APSDNSNAME}/cgi-bin)
# APSCGIMODE	permissions of cgi scripts, (default: 555)
#		(all may be overwritten in /etc/make.conf)
#
# APSIMGSRC	images source directory for pics
# APSIMGDEST	toplevel destination directory for pics
#
# APSDOWNLOAD	apsfilter download directory
#		(all may be overwritten in /etc/make.conf)
# 64BITSSRC	source directory for 64Bits mp3 files
# 64BITS	list of mp3 files, remember: apsfilter rocks ;-)
# 64BITSDEST	mp3 destination directory
#
# SCRIPTS_ENV	hand over variables that scripts like make-release need
#
# HTMLVIEW	how to preview your webpages
#		(see install-target,
#		 may be overwritten in /etc/make.conf)
#
# Programs and commandline flags used by this macro file:
#
# CVS		path to CVS wrapper script (default: /var/apscvs/bin/cvs)
# LYNX		your favourite html previewer (default: /usr/local/bin/lynx)
# RM		location of the rm program (default: /bin/rm)
# WML		location of the wml program (default: /usr/local/bin/wml)
# WML_FLAGS	standard flags for the wml utility
#		(all may be overwritten in /etc/make.conf)
# INSTALL	install -C, to compary before copy
#
# +++ targets +++
#
#	all:
#		Convert wml files to html files
#		(see ${DOC}, ${WML}, ${WML_FLAGS}).
#
#	clean:
#		Clean src area, remove .html files
#
#	fixperms:
#		Make scripts executeable, if checkout eats up x bit
#
#	handbook:
#		Build -current and -stable handbook
#
#	install:
#		Install formatted output, .html files and pictures
#		(see ${DOC}, ${IMG}, ${CGI}, ${RAW}
#		${APSWWWDEST}, ${APSIMGSRC}, ${APSIMGDEST}
#		${APSWWWOWN}, ${APSWWWGRP}, ${APSWWWMODE}),
#		${APSCGIDEST}.
#
#	preview:
#		Preview formatted output using your favourite browser
#		(see ${HTMLVIEW}).
#
#	release:
#		update apsfilter download dir
#
#	touch:
#		force translation of support.wml, to update ml counters
#
#	upload:
#		upload certain binary files, that I don't want to
#		have in the CVS repository, for example our mpg3 files
#

HOSTNAME?=	www.apsfilter.org

.if !defined(ARCH)
ARCH!=		/usr/bin/uname -m
.endif

DOC?=		index.html

WMLSTYLE?=	.wmlrc

APSCVS?=	/var/apscvs/APSCVS
BACKUP_APSCVS?=	/home/andreas/sitebackup/apscvs/apscvs/APSCVS
STABLE_RELEASE?=	7.0.1
STABLE_BRANCH?=		RELENG_7
CURRENT_RELEASE?=	current
CURRENT_BRANCH?=	HEAD 

APSWWWOWN?=	andreas
APSWWWGRP?=	apsfilter
APSWWWMODE?=	664
APSDNSNAME?=	www.apsfilter.org
APSWWWDEST?=	/var/www/${APSDNSNAME}/htdocs

APSCGISRC?=	cgi
APSCGIMODE?=	555
APSCGIDEST?=	/var/www/${APSDNSNAME}/cgi-bin

APSIMGSRC?=	images
APSIMGDEST?=	${APSWWWDEST}/${APSIMGSRC}

64BITSSRC?=	64bits
64BITSDEST?=	${APSWWWDEST}/${64BITSSRC}

APSDOWNLOAD?=	${APSWWWDEST}/download

SCRIPTS_ENV=	APSWWWDEST=${APSWWWDEST} \
		APSWWWOWN=${APSWWWOWN} \
		APSWWWGRP=${APSWWWGRP} \
		APSWWWMODE=${APSWWWMODE} \
		APSDOWNLOAD=${APSDOWNLOAD} \
		CVS=${CVS} \
		APSCVS=${APSCVS} \
		STABLE_RELEASE=${STABLE_RELEASE} \
		STABLE_BRANCH=${STABLE_BRANCH} \
		CURRENT_RELEASE=${CURRENT_RELEASE} \
		CURRENT_BRANCH=${CURRENT_BRANCH}

CHMOD?=		/bin/chmod
CVS?=		/var/apscvs/bin/cvs
LYNX?=		/usr/local/bin/lynx
HTMLVIEW?=	${LYNX}
INSTALL=	/usr/bin/install -C
RM?=		/bin/rm
SETENV?=	/usr/bin/env
SH?=		/bin/sh
TOUCH?=		/usr/bin/touch
WML?=		/usr/local/bin/wml
WML_FLAGS?=	-DHOSTNAME=${HOSTNAME} -P wml/wml-import.pl

.SUFFIXES: .wml .html .css

.wml.html: ${WMLSTYLE}
	${WML} ${WML_FLAGS} < ${.IMPSRC} > ${.TARGET}

.wml.css: ${WMLSTYLE}
	${WML} ${WML_FLAGS} < ${.IMPSRC} > ${.TARGET}

.MAIN:	all

touch:
	@${TOUCH} support.wml

fixperms:
	@${CHMOD} +x ${SCRIPTS}

all:	fixperms touch ${DOC} handbook
	@rm -rf apsfilter

clean:
	${RM} -f ${DOC}
.if defined(DIRS_TO_CLEAN) && !empty(DIRS_TO_CLEAN)
.for dir in ${DIRS_TO_CLEAN}
	(${RM} -rf ${dir})
.endfor
.endif

_MKDEST:
.for _dir in ${APSWWWDEST} ${APSCGIDEST} ${APSIMGDEST} ${APSDOWNLOAD} \
		${64BITSDEST}
	@if ! test -d ${_dir}/; then \
		mkdir -p ${_dir}; \
		if ! test -d ${_dir}/; then \
			${ECHO} "Unable to create ${_dir}."; \
		exit 1; \
	fi; \
		${ECHO} "${_dir} created for ${.CURDIR}"; \
	fi
.endfor

handbook:
	@mkdir -p docs
	@echo ">>> creating handbook for -current..."
.if exists(${BACKUP_APSCVS})
	${CVS} -d ${BACKUP_APSCVS} -Q checkout -r ${CURRENT_BRANCH} -P apsfilter
.else
	${CVS} -d ${APSCVS} -Q checkout -r ${CURRENT_BRANCH} -P apsfilter
.endif
	@( cd apsfilter; ./configure ) > /dev/null 2>&1
	@mv apsfilter/doc/handbook.html docs/apsfilter-handbook-current.html
	@rm -rf apsfilter
	@echo ">>> creating handbook for -stable..."
.if exists(${BACKUP_APSCVS})
	${CVS} -d ${BACKUP_APSCVS} -Q checkout -r ${STABLE_BRANCH} -P apsfilter
.else
	${CVS} -d ${APSCVS} -Q checkout -r ${STABLE_BRANCH} -P apsfilter
.endif
	@( cd apsfilter; ./configure ) > /dev/null 2>&1
	@mv apsfilter/doc/handbook.html docs/apsfilter-handbook-stable.html
	@rm -rf apsfilter

install: _MKDEST all
.for _doc in ${DOC}
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSWWWMODE} \
		${_doc} ${APSWWWDEST}/${WWWDIR}
.endfor
.for _img in ${IMG}
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSWWWMODE} \
		${APSIMGSRC}/${_img} ${APSIMGDEST}
.endfor
.for _raw in ${RAW}
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSWWWMODE} \
		${_raw} ${APSWWWDEST}
.endfor
	tar cf - ${SITESOURCE} | ( cd ${APSWWWDEST}; tar xpf - )
.for _cgi in ${CGI}
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSCGIMODE} \
		${APSCGISRC}/${_cgi} ${APSCGIDEST}
.endfor
.for _img in ${64BITS}
	if [ ! -f ${64BITSDEST}/${_img} ]; then \
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSWWWMODE} \
		${64BITSSRC}/${_img} ${64BITSDEST}/${_img}; \
	fi
.endfor
.for _doc in ${HANDBOOK}
	@mkdir -p ${APSWWWDEST}/${WWWDIR}/docs
	${INSTALL} ${COPY} -o ${APSWWWOWN} -g ${APSWWWGRP} -m ${APSWWWMODE} \
		${_doc} ${APSWWWDEST}/${WWWDIR}/docs
.endfor

preview: all
.for _doc in ${DOC}
	${HTMLVIEW} ${_doc}
.endfor

upload:
	# unofficial 64bits stuff
	[ "`uname -n`" = "titan.klemm.apsfilter.org" ] \
	&& rsync -rtvc \
        -C \
        -e "ssh -c blowfish" \
	--include "*.mp3" \
        64bits \
        andreas@apsfilter.org:~/www/
	# bits pictures
	[ "`uname -n`" = "titan.klemm.apsfilter.org" ] \
	&& rsync -rtvc \
        -C \
        -e "ssh -c blowfish" \
        pics \
        andreas@apsfilter.org:~/www/
	# bits mp3 stuff
	[ "`uname -n`" = "titan.klemm.apsfilter.org" ] \
	&& rsync -rtvc \
        -C \
        -e "ssh -c blowfish" \
	--include "*.mp3" \
        bits \
        andreas@apsfilter.org:~/www/

release:
	${SETENV} ${SCRIPTS_ENV} ${SH} scripts/make-release
