## onShore Timesheet Makefile
##
## $Id: Makefile,v 1.53 2001/08/31 06:08:25 adam Exp $
##
## Configuration
##
##
## BEGIN LOCAL CONFIGURATION HERE
##
# Perl include path
PERLINC		:= /usr/lib/perl5/site_perl
# application root directory, a CGI directory
APPROOT		:= /home/httpd/html/timesheet
# The *relative* url to application
TIMESHEET_URL	:= /onshore-timesheet
# where to put the application's images
IMAGE_DIR	:= $(APPROOT)/images
# The *relative* url for images
IMAGE_URL	:= $(TIMESHEET_URL)/images
# application library path
LIBDIR		:= $(APPROOT)/lib 
# application configuration directory
CONFDIR		:= $(APPROOT)/etc
# configuration file
CONFFILE	:= onshore-timesheet.conf
# application logging dir -- FIXME: not used
LOGDIR		:= /var/log
# where to put utility scripts
UTILDIR		:= /usr/local/sbin
# database (Currently, only "postgres" supported)
DATABASE	:= postgres
# database unix user account
DBOWNER		:= postgres
# database to create
DBNAME		:= timesheet 
# create a guest account? set to "no" if you don't want a guest account enabled
GUEST_ACCOUNT	:= yes
# SQL interpreter; include here any args for special ports, etc
SQL_INTERPRETER	:= psql
# WWW unix user account (becomes owner of password file and .htaccess file,
#  owns database tables). 
WWWUSER		:= nobody
# installed file ownership (besides .htpasswd & .htaccess)
APPOWNER	:= root
# file groupship 
APPGROUP	:= root 
# application adminstrator name
ADMIN_FIRST	:= Timesheet
ADMIN_MIDDLE	:= Default
ADMIN_LAST	:= Administrator
ADMIN_MAIL	:= admin@localhost
# hostname -- FIXME: not used
HOST		:= `hostname`
# where to install the Apache user passwd file
PASSFILE	:= /etc/onshore-timesheet.passwd
# download user
DOWNLOAD_USER	:= billing
# export log path
EXPORT_LOG	:= /var/log/onshore-timesheet-export.log
# database address
DBADDR		:= localhost:5432
# export directory
EXPORT_DIR	:= /var/lib/onshore-timesheet/export
# directory for backups
BACKUP_DIR	:= /var/lib/onshore-timesheet/backup
# temporary installation prefix, used by the package building scripts
INSTPREFIX	:= ''
##
## END LOCAL CONFIGURATION
##

##
## YOU SHOULD NOT HAVE TO GO BEYOND THIS POINT
##
VERSION	:= 2.3
SRCDIR	:= $(shell pwd)
TOPDIR	:= $(shell basename $(SRCDIR))
# only needed for dist
CVS2CL	:= cvs2cl
#

.PHONY: install
install:	install-db install-timesheet config-timesheet done-notice

.PHONY: upgrade
upgrade:	install-timesheet config-timesheet done-notice

.PHONY: install-timesheet
install-timesheet: 
	install/install-timesheet -libdir   $(LIBDIR)  \
				  -approot  $(APPROOT) \
				  -imagedir $(IMAGE_DIR) \
				  -utildir  $(UTILDIR) \
				  -perlinc  $(PERLINC) \
	 			  -wwwuser  $(WWWUSER) \
				  -appowner $(APPOWNER) \
				  -appgroup $(APPGROUP) \
				  -config   $(CONFDIR)/$(CONFFILE) \
				  -logdir   $(LOGDIR) \
				  -instprefix $(INSTPREFIX) \
			          -create_guest $(GUEST_ACCOUNT) \
				  -htpasswd $(PASSFILE) \

.PHONY: config-timesheet
config-timesheet:
	install/config-timesheet -url		$(TIMESHEET_URL) \
				 -image_url	$(IMAGE_URL) \
				 -export_dir    $(EXPORT_DIR) \
				 -backup_dir	$(BACKUP_DIR) \
				 -dbaddr        $(DBADDR) \
				 -sqldb         $(DBNAME) \
				 -passfile      $(PASSFILE) \
				 -download_user $(DOWNLOAD_USER) \
				 -confdir       $(CONFDIR) \
				 -conffile      $(CONFFILE) \
				 -export_log    $(EXPORT_LOG) \
				 -instprefix    $(INSTPREFIX) 

.PHONY: install-db
install-db: 
	su  $(DBOWNER) -c 'install/install-db -db $(DATABASE) \
			   -dbowner $(DBOWNER) \
			   -dbuser $(WWWUSER) \
			   -sql_interpreter $(SQL_INTERPRETER) \
			   -sql_directory `pwd`/db \
			   -admin_last $(ADMIN_LAST) \
			   -admin_first $(ADMIN_FIRST) \
			   -admin_middle $(ADMIN_MIDDLE) \
		  	   -admin_mail $(ADMIN_MAIL) \
			   -dbname $(DBNAME) \
			   -create_guest $(GUEST_ACCOUNT)'

.PHONY: install-debian-files
install-debian-files:
	$(MAKE) APPROOT=/var/www/timesheet CONFDIR=/etc \
	WWWUSER=wwwdata \
	PERLINC=/usr/local/lib/site_perl install-timesheet

.PHONY: install-debian
install-debian:
	$(MAKE) APPROOT=/var/www/timesheet CONFDIR=/etc \
	WWWUSER=wwwdata \
	PERLINC=/usr/local/lib/site_perl install

.PHONY: doc
doc:
	$(MAKE) -C doc

.PHONY: clean
clean: 	
	rm -f `find . -name '*.bak' -o -name '*~' -o -name '.#*' -o -name 'core'`
	$(MAKE) -C doc $@

.PHONY: distclean
distclean: clean
	$(MAKE) -C doc $@

.PHONY: destroy
destroy:
	su  $(DBOWNER) -c 'install/destroy-db -db $(DATABASE) \
			   -dbowner $(DBOWNER) \
			   -dbuser $(WWWUSER) \
			   -sql_interpreter $(SQL_INTERPRETER) \
			   -dbname $(DBNAME)'

.PHONY: nuke
nuke:  destroy
	rm -rf $(APPROOT)

.PHONY: done-notice
done-notice: 
	cat install/done-notice

.PHONY: dist
dist:	
	$(CVS2CL) -r
	cvs ci -m "update for next release" ChangeLog
	$(MAKE) doc
	@echo tagging with release tag 'upstream_version_$(shell echo $(VERSION) | tr . _)'
	cvs -q rtag -d upstream_version_`echo $(VERSION) | tr . _` onshore-timesheet
	cvs -q tag -F upstream_version_`echo $(VERSION) | tr . _`
	@echo "now build the Debian package (cvs-buildpackage)"
