
# Makefile to install foomatic-db
# $Revision$

# PREFIX defaults to /usr/local for manually installed progs, so that they
# are not messed up on a system upgrade.
#
# `architecture independent', static data files i.e. perl libs go into
#   $(PREFIX)/share/foomatic
# (user) executables into $(PREFIX)/bin/
# system binaries go into $(PREFIX)/sbin
# configuration files into /etc/foomatic/*.
#
# The PERLPREFIX allows a seperate prefix for the Perl libraries. Use this
# when Perl libraries in /usr/local are not found.

# Variables

DEBUG=

prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
bindir=@bindir@
sbindir=@sbindir@
mandir=@mandir@
datadir=@datadir@
sysconfdir=@sysconfdir@

PREFIX=$(prefix)

# The location where to install the database
LIBDIR=$(datadir)/foomatic

# List of user-selected driver XMLs to install
DRIVERXMLS=@DRIVERXMLS@

# Variables for CUPS
CUPS_PPDS=@CUPS_PPDS@
PPDS_TO_CUPS=@PPDS_TO_CUPS@

# Variables for gzipping the custom PPD files
GZIP=@GZIP@
GZIP_PPDS=@GZIP_PPDS@

# This is mainly useful for building a binary foomatic package
DESTDIR=/

### Probably nothing to fiddle past here

# Files generated by the AC_OUTPUT call of "./configure"
AC_OUTPUT_FILES:=Makefile

# Masks for trash files which have to be removed before packaging Foomatic
TRASHFILES:="*~" "*\#*" ".??*" "*.rej"

all: build

# The install rule should check for kitloads and avoid stomping.  It doesn't
install: install-db

install-db:
	install -d $(DESTDIR)$(LIBDIR)
	install -d $(DESTDIR)$(LIBDIR)/db/source/printer
	install -d $(DESTDIR)$(LIBDIR)/db/source/driver
	install -d $(DESTDIR)$(LIBDIR)/db/source/opt
	install -d $(DESTDIR)$(LIBDIR)/db/source/PPD
	cp db/oldprinterids $(DESTDIR)$(LIBDIR)/db
	cp db/source/printer/*.xml $(DESTDIR)$(LIBDIR)/db/source/printer
	( cd db/source/driver/; \
	  for d in $(DRIVERXMLS); do \
	    cp $$d $(DESTDIR)$(LIBDIR)/db/source/driver; \
	  done )
	cp db/source/opt/*.xml $(DESTDIR)$(LIBDIR)/db/source/opt
	( cd db/source && tar cf - --exclude=.svn PPD ) | \
	  ( cd $(DESTDIR)$(LIBDIR)/db/source && tar xf -)
	if test $(GZIP) != GZIP_NOT_FOUND -a $(GZIP_PPDS) != no ; then \
	  GZIP='' find $(DESTDIR)$(LIBDIR)/db/source/PPD -name "*.ppd" -exec $(GZIP) "{}" \; ; \
	fi
	if test $(CUPS_PPDS) != CUPS_PPDS_NOT_FOUND -a $(PPDS_TO_CUPS) != no ; then \
	  install -d $(DESTDIR)$(CUPS_PPDS); \
	  ln -sf $(LIBDIR)/db/source/PPD $(DESTDIR)$(CUPS_PPDS)/foomatic-db-ppds; \
	fi

build:
	@echo "Nothing to compile/build, use \"make install\" to install the database."

clean: remove-trash

distclean: clean
	rm -f $(AC_OUTPUT_FILES) config.log config.status config.cache
	rm -rf autom*.cache confdefs.h

maintainer-clean: distclean
	rm -f configure aclocal.m4

# Uninstall an installed Foomatic
uninstall: uninstall-db

uninstall-db:
	rm -rf $(DESTDIR)$(LIBDIR)

# Various testing/debugging/etc targets
inplace: testing
testing: INPLACE = --inplace
testing:
	@echo "For using this database without system-wide installation, uncompress this"
	@echo "package inside the main directory of \"foomatic-db-engine\" or in the"
	@echo "directory where you have uncompressed \"foomatic-db-engine\"."
	@echo "Build \"foomatic-db-engine\" with \"make inplace\" and do the database"
	@echo "operations from within the main directory of \"foomatic-db-engine\"."

inplace-clean: testing_clean
testing-clean: clean

# Remove editor backup and temporary files
remove-trash:
	for m in $(TRASHFILES); do \
	  find . -name "$$m" -exec rm "{}" \; ; \
	done

# We need to export all Variables for makeDefaults and the scripts target to
# work.
.EXPORT_ALL_VARIABLES:

.PHONY: all build install install-db \
	inplace testing clean inplace-clean testing-clean distclean \
	maintainer-clean
