# bgrot - A program to keep your background interesting
# This is the Makefile for bgrot
# See the file LICENSE for license information
# Written by Matthew Fuller <fullermd@over-yonder.net>

# OK, first: config stuff

# BINDIR: Where the programs are
BINDIR = /usr/local/bin

# CONFDIR: Where the system-wide config goes
CONFDIR = /usr/local/etc

# DIRMODE: Permission bits for directories
# FILEMODE: Permission bits for files
# Make sure you don't knock everyone off being able to use it now...
DIRMODE = 755
FILEMODE = 755

# BINOWN and BINGRP: Ownership for binary files
BINOWN = bin
BINGRP = bin

# MANDIR: Where is your manpage base?
MANDIR = /usr/local/man

# OK, that's about it for user stuff
# Touch the rest of this file at your own risk
INSTALLFILES =	background.sh bgrandom.pl bgrotman.pl createlist.sh \
				masterlistgen.sh

# Meat
build: setconfdir createconfig

all: build

info:
	@echo Usage:
	@echo Type \'make\' to build the files for installation
	@echo Type \'make install\' to install
	@echo Type \'make buildlist\' to build the image list
	@echo NOTE: to build the list manually, ensure that ${BINDIR} is
	@echo in your path and type \'createlist\.sh\',
	@echo or type \'${BINDIR}/createlist\.sh\'

help: info

install:
	@echo Installing...
.if !exists(${BINDIR})
	-mkdir -m ${DIRMODE} ${BINDIR}
.endif
	@echo Installing files...
	-install -o ${BINOWN} -g ${BINGRP} -m ${FILEMODE} -c ${INSTALLFILES} ${BINDIR}
	-install -o ${BINOWN} -g ${BINGRP} -m ${FILEMODE} -c bgrot.conf ${CONFDIR}
	@echo Compressing manpage...
	@gzip -c bgrot.1 > bgrot.1.gz
	@echo Installing manpage...
	-install -o ${BINOWN} -g ${BINGRP} -m ${FILEMODE} -c bgrot.1.gz ${MANDIR}/man1
	@echo Installation completed
	@echo Read the file README for usage information

buildlist:
	@echo Building image list...
	@echo To do this manually, ensure that ${BINDIR} is in your path
	@echo and type \'createlist\.sh\', or type \'${BINDIR}/createlist\.sh\'
	@/bin/sh ${BINDIR}/createlist.sh

setconfdir:
	@echo Setting config directory...
	@chmod u+x setconfdir.pl
	@echo ${CONFDIR} | ./setconfdir.pl

createconfig:
	@echo Creating config file and intitializing settings...
	@chmod u+x createconfig.pl
	@echo ${BINDIR} | ./createconfig.pl

manpage:
	@echo Compressing manpage...
	@gzip -c bgrot.1 > bgrot.1.gz
	@echo Installing manpage...
	-install -o ${BINOWN} -g ${BINGRP} -m ${FILEMODE} -c bgrot.1.gz ${MANDIR}/man1

uninstall:
	@echo Uninstalling scripts...
	@for entry in ${INSTALLFILES}; do \
		rm -f ${BINDIR}/$${entry}; \
	done
	@echo Uninstalling configuration...
	@rm -f ${CONFDIR}/bgrot.conf
	@echo Uninstalling manpage...
	@rm -f ${MANDIR}/man1/bgrot.1.gz
	@echo Done.
