# -*-makefile-*-
# JLdL 18May10.
#
# This makefile closes the "quotas-config" package, as an "all" arch
# _ package; the main part of its structure is meant to install
# _ everything within the debian/package subdirectory.

# Edited for Debian GNU/Linux.
DESTDIR = 

# The name of the package this makefile is meant for.
NAME = quotas-config

# Where the configuration file goes.
ETC = $(DESTDIR)/etc

# Where the cron-job file goes.
CRON = $(DESTDIR)/etc/cron.daily

# Where the cron-job snippet file goes.
SNIP = $(DESTDIR)/etc/cron.d

# Where the quota data files go.
DAT = $(DESTDIR)/etc/quotas

# Where the user executables go.
CBIN = $(DESTDIR)/usr/bin

# Where the root executables go.
SBIN = $(DESTDIR)/usr/sbin

# Where the server library goes.
SLIB = $(DESTDIR)/usr/lib/$(NAME)

# Where the volatile snap and log files go.
VLIB = $(DESTDIR)/var/lib/$(NAME)

# Where the man pages go.
MANS = $(DESTDIR)/usr/share/man

# Where the additional documentation goes.
DOCS = $(DESTDIR)/usr/share/doc/$(NAME)

# The configuration file.
CONFFILES = \
quotas.conf

# The cron-job file.
CRONFILES = \
cron.daily/quotas-config

# The cron-job snippet file.
CRONSNIPS = \
cron.d/quotas-config

# The example quota data files.
QUOTFILES = \
examples/tmp.user \
examples/tmp.group \
examples/var.user \
examples/var.group \
examples/temp.user \
examples/temp.group \
examples/home.user \
examples/home.group \
examples/bckp_home.user \
examples/bckp_home.group

# The user executables.
CBINFILES = \
clean-backup \
clean-backup-by-subdir

# The root executables.
SBINFILES = \
edit-fs-quotas \
edit-quotas \
fix-bckp-quotas \
fix-quotas \
update-bckp-quotas \
update-quotas \
multi-fix-quotas \
multi-update-quotas \
clean-user-backups

# The library files.
SLIBFILES = \
clean-backup.sub \
lock \
myrror-user \
myrror-user.local \
myrror-user-do-the-backup.sub \
myrror-user-lock-the-account.sub \
myrror-user-lock-the-account.local \
myrror-user-lock.en \
myrror-user-lock.pt \
myrror-user-mail-over-quota.sub \
myrror-user-mail.en.1 \
myrror-user-mail.pt.1 \
myrror-user-mail.en.2 \
myrror-user-mail.pt.2

# The user man page.
MAN1FILES = \
clean-backup.1.gz

# The file man pages.
MAN5FILES = \
quotas.conf.5.gz

# The description man pages.
MAN7FILES = \
quotas-config.7.gz

# The root man pages.
MAN8FILES = \
edit-fs-quotas.8.gz \
edit-quotas.8.gz \
fix-bckp-quotas.8.gz \
fix-quotas.8.gz \
update-bckp-quotas.8.gz \
update-quotas.8.gz \
multi-fix-quotas.8.gz \
multi-update-quotas.8.gz \
clean-user-backups.8.gz

# Extra documentation files and directories.
DOCSFILES = \
debian/README.Debian \
README.clean-backup \
README.myrror-user

# The date is used as a version number.
#THEDATE = $(shell date +%Y%m%d)
THEDATE = $(shell date +%y%m%d)

# Define the host from which the package is to be distributed.
DHOST = fmasft

# Define the distribution site within the host.
DSITE = /sft/debian-cluster

# Define the distribution directory within the site.
DIR = $(DSITE)/dists/stable/main

# Define the location of the package just compiled.
LOC = /local/src

# Do not do anything by default, just print a help message.
default:
	@echo "Nothing to do: no actual compilation is needed."
	@echo "The most useful targets are:"
	@echo "  'package' to make the package;"
	@echo "  'distribute' to install on the distribution site;"
	@echo "  'veryclean' to really clean it all up."
	@echo "Other internal targets are:"
	@echo "  'clean' to clean this directory;"
	@echo "  'cleandebfiles' to remove the Debian files;"
	@echo "  'cleandebpacks' to remove the Debian package(s)."

# Install files on the server.
install: $(MAN1FILES) $(MAN5FILES) $(MAN7FILES) $(MAN8FILES)
	@echo Installing the configuration file in $(ETC)/
	@mkdir -p $(ETC)/
	@cp -pf $(CONFFILES) $(ETC)/
	@echo Installing the example quota data files in $(DAT)/examples/
	@mkdir -p $(DAT)/examples/
	@cp -pf $(QUOTFILES) $(DAT)/examples/
	@echo Installing the cron-job file in $(CRON)/
	@mkdir -p $(CRON)/
	@cp -pf $(CRONFILES) $(CRON)/
	@echo Installing the cron-job snippet file in $(SNIP)/
	@mkdir -p $(SNIP)/
	@cp -pf $(CRONSNIPS) $(SNIP)/
	@echo Installing user executables in $(CBIN)/
	@mkdir -p $(CBIN)/
	@cp -dpf $(CBINFILES) $(CBIN)/
	@echo Installing root executables in $(SBIN)/
	@mkdir -p $(SBIN)/
	@cp -pf $(SBINFILES) $(SBIN)/
	@echo Installing the library files in $(SLIB)/
	@mkdir -p $(SLIB)/
	@cp -pf $(SLIBFILES) $(SLIB)/
	@echo Installing man pages in $(MANS)/man1/
	@mkdir -p $(MANS)/man1/
	@cp -pf $(MAN1FILES) $(MANS)/man1/
	@echo Installing man pages in $(MANS)/man5/
	@mkdir -p $(MANS)/man5/
	@cp -pf $(MAN5FILES) $(MANS)/man5/
	@echo Installing man pages in $(MANS)/man7/
	@mkdir -p $(MANS)/man7/
	@cp -pf $(MAN7FILES) $(MANS)/man7/
	@echo Installing man pages in $(MANS)/man8/
	@mkdir -p $(MANS)/man8/
	@cp -pf $(MAN8FILES) $(MANS)/man8/
	@echo Installing additional documentation in $(DOCS)/
	@mkdir -p $(DOCS)/
	@cp -af $(DOCSFILES) $(DOCS)/
	@echo Creating the snap and log file directory $(VLIB)/
	@mkdir -p $(VLIB)/

# Make the package.
package:
	dpkg-buildpackage -kE92A1F5C

# Install the package in the distribution site.
distribute:
# Fix the ownership of the files.
	chown root:root $(LOC)/$(NAME)_*.dsc
	chown root:root $(LOC)/$(NAME)_*.tar.gz
	chown root:root $(LOC)/$(NAME)_*.deb
# Copy remotely and backwards because of authorization issues.
	ssh $(DHOST) "cp -pf $(LOC)/$(NAME)_*.dsc $(DIR)/source/"
	ssh $(DHOST) "cp -pf $(LOC)/$(NAME)_*.tar.gz $(DIR)/source/"
	ssh $(DHOST) "cp -pf $(LOC)/$(NAME)_*_all.deb $(DIR)/binary-all/"
# Refresh the site remotely because of authorization issues.
	ssh $(DHOST) "cd $(DSITE) ; ./MakePackagesFiles"

# Clean up this directory.
clean:
	rm -f *~ *.gz

# Clean up the Debian package files.
cleandebfiles:
	rm -f build-stamp configure-stamp
	rm -rf debian/$(NAME)/

# Clean the packages and related files.
cleandebpacks:
	rm -f ../$(NAME)_*.dsc
	rm -f ../$(NAME)_*.tar.gz
	rm -f ../$(NAME)_*.changes
	rm -f ../$(NAME)_*_all.deb

# Really clean it all up.
veryclean: clean cleandebfiles cleandebpacks

# A pattern rule to make compressed versions of files.
%.gz: %
	@echo Compressing file $<
	@cat $< | sed -e 's|YYYYMMDD|$(THEDATE)|g' | gzip -c9 - > $@

