
# Makefile to install foomatic-db-nonfree
# $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. XML files 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)

# Foomatic database location for a regular installation
LIBDIR=@LIBDIR@

# Foomatic database location for a "make inplace" installation
LOCAL_LIBDIR=@LOCAL_LIBDIR@

BINDIR=$(bindir)
SBINDIR=$(sbindir)
MANDIR=$(mandir)
ETCDIR=$(sysconfdir)/foomatic

## Settings for Perl
# Where to find the perl binary
PERL=@PERL@

# 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)
	tar cf - db | ( cd $(DESTDIR)$(LIBDIR) && tar xf -)

build:
#	Nothing to build

clean:
#	Remove data from local database
	if [ -f inplace-stamp ]; then \
	  rm -f inplace-stamp; \
	  PWD=`pwd`; \
	  for file in `find db -type f -print`; do \
	    if [ -r ${PWD}/$(LOCAL_LIBDIR)/$$file ] && \
		diff -q $$file ${PWD}/$(LOCAL_LIBDIR)/$$file 2>/dev/null; then\
	      rm -f ${PWD}/$(LOCAL_LIBDIR)/$$file; \
	      olddir=`echo $$file | perl -p -e 's:^(.*?)/?[^/]+$$:$$1:' 2> /dev/null`; \
              while [ -n "$$olddir" ] && rmdir ${PWD}/$(LOCAL_LIBDIR)/$$olddir 2>/dev/null; do \
                olddir=`echo $$olddir | perl -p -e 's:^(.*?)/?[^/]+$$:$$1:' 2> /dev/null`; \
              done; \
	    fi; \
	  done; \
	fi

distclean: clean remove-trash
	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:
	for file in `find db -type f -print`; do \
	  if [ -r ${DESTDIR}$(LIBDIR)/$$file ] && \
	     diff -q $$file ${DESTDIR}$(LIBDIR)/$$file 2>/dev/null; then\
	    rm -f ${DESTDIR}$(LIBDIR)/$$file; \
	    olddir=`echo $$file | perl -p -e 's:^(.*?)/?[^/]+$$:$$1:' 2> /dev/null`; \
            while [ -n "$$olddir" ] && rmdir ${DESTDIR}$(LIBDIR)/$$olddir 2>/dev/null; do \
              olddir=`echo $$olddir | perl -p -e 's:^(.*?)/?[^/]+$$:$$1:' 2> /dev/null`; \
            done; \
	  fi; \
	done; \

# Various testing/debugging/etc targets
inplace: testing
testing:
	touch inplace-stamp
#	Insert data into a local database
	if [ -d $(LOCAL_LIBDIR) ]; then \
	  tar cf - db |(cd $(LOCAL_LIBDIR); tar xf -); \
	  chmod -R a+rX $(LOCAL_LIBDIR); \
	fi

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 \
	man inplace testing clean inplace-clean testing-clean distclean \
	maintainer-clean
