# Makefile for psptools.
# Copyright (C) 1995 Yves Arrouye <Yves.Arrouye@imag.fr>

#### Start of system configuration section. ####

srcdir = @srcdir@
VPATH = @srcdir@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(INSTALL_GROUP) $(INSTALL_USER)
INSTALL_DATA = @INSTALL_DATA@
PERL = @PERL@
GZIP = @GZIP@
COMPRESS = @COMPRESS@

SHAR = @SHAR@
SED = @SED@
RM = rm -f

transform = @program_transform_name@
mancompress = 

prefix = @prefix@
exec_prefix = @exec_prefix@

# Directory in which to install scripts.
bindir = $(exec_prefix)/bin

# Directory in which to install library files.
perldir = @PERLLIB@

# Directory in which to install manual pages.
manprefix = $(prefix)/man
catprefix = $(manprefix)

#

dirbin = $(bindir)
prefixman = $(manprefix)

#### End of system configuration section. ####

SHELL = /bin/sh

PROGRAMS = psplpr npslpr mkppddir
MANPAGES = man/man1/psplpr.1 man/man1/npslpr.1 man/man1/mkppddir.1
PERLLIBS = lib/perl/ppd.pl lib/perl/printcap.pl lib/perl/printer.pl \
    lib/perl/psptools.pl

M4FILES = aclocal.m4
# Files that can be generated, but should be up to date for a distribution.
DISTDEP = Makefile configure.in
# Files to distribute.
DISTFILES = COPYRIGHT README INSTALL INSTALL.QUICK TODO ChangeLog \
        Makefile.in aclocal.m4 configure.in \
	src/psplpr.pl.in src/npslpr.pl.in src/mkppddir.pl.in \
	man/man1/psplpr.1.in man/man1/npslpr.1.in man/man1/mkppddir.1.in \
	lib/perl/ppd.pl.in lib/perl/printcap.pl.in lib/perl/printer.pl.in \
	    lib/perl/psptools.pl.in \
	configure install-sh mkinstalldirs

TARGETFILES = $(PROGRAMS) $(MANPAGES) $(PERLLIBS)
REMOVABLEFILES = $(TARGETFILES) src/psplpr.pl src/npslpr.pl src/mkppddir.pl \
	debian/postinst debian/prerm sedscript

all: psptools
debian: all debian/postinst debian/prerm

psptools: $(TARGETFILES)

src/psplpr.pl: src/psplpr.pl.in sedscript
	$(SED) -f sedscript src/psplpr.pl.in >$@
src/npslpr.pl: src/npslpr.pl.in sedscript
	$(SED) -f sedscript src/npslpr.pl.in >$@
src/mkppddir.pl: src/mkppddir.pl.in sedscript
	$(SED) -f sedscript src/mkppddir.pl.in >$@

man/man1/psplpr.1: man/man1/psplpr.1.in sedscript
	$(SED) -f sedscript man/man1/psplpr.1.in >$@
man/man1/npslpr.1: man/man1/npslpr.1.in sedscript
	$(SED) -f sedscript man/man1/npslpr.1.in >$@
man/man1/mkppddir.1: man/man1/mkppddir.1.in sedscript
	$(SED) -f sedscript man/man1/mkppddir.1.in >$@

lib/perl/printcap.pl: lib/perl/printcap.pl.in sedscript
	$(SED) -f sedscript lib/perl/printcap.pl.in >$@
lib/perl/printer.pl: lib/perl/printer.pl.in sedscript
	$(SED) -f sedscript lib/perl/printer.pl.in >$@
lib/perl/ppd.pl: lib/perl/ppd.pl.in sedscript
	$(SED) -f sedscript lib/perl/ppd.pl.in >$@
lib/perl/psptools.pl: lib/perl/psptools.pl.in sedscript
	$(SED) -f sedscript lib/perl/psptools.pl.in >$@

psplpr: src/psplpr.pl
	cp $? $@
	chmod +x $@

npslpr: src/npslpr.pl
	cp $? $@
	chmod +x $@

mkppddir: src/mkppddir.pl
	cp $? $@
	chmod +x $@

installdirs:
	$(SHELL) ${srcdir}/mkinstalldirs $(bindir) $(perldir) \
	    $(manprefix)/man1

install: all install-psptools
debian-install: debian install-psptools

install-psptools: installdirs install-man
	$(INSTALL_PROGRAM) psplpr $(bindir)/`echo psplpr|$(SED) '$(transform)'`; \
	$(INSTALL_PROGRAM) npslpr $(bindir)/`echo npslpr|$(SED) '$(transform)'`; \
	$(INSTALL_PROGRAM) mkppddir $(bindir)/`echo mkppddir|$(SED) '$(transform)'`; \
	for i in $(PERLLIBS); do \
	  $(INSTALL_DATA) $(srcdir)/$$i $(perldir); \
	done;

# Install manual pages. Try to see if there are already compres$(SED)
# manual pages in the destination directory. If this is the case, then
# compress the new manual pages too.

install-man:
	manpages="`ls $(manprefix)/man1`"; \
	for m in $(MANPAGES); do \
	  i=`basename $$m`; \
	  sect=`echo $$i | $(SED) 's/.*\.//'`; \
	  $(RM) $(manprefix)/man$$sect/$$i $(manprefix)/$$i.gz \
	      $(manprefix)/man$$sect/$$i.Z; \
	  $(INSTALL_DATA) $$m $(manprefix)/man$$sect; \
	  if test "$(mancompress)" = gzip -o "`echo \"$$manpages\"|$(SED) '/\.gz[ \t]*/!d'`" != "" \
	    -a "$(GZIP)" != ""; then \
	    $(RM) $(manprefix)/man$$sect/$$i.gz; \
	    $(GZIP) $(manprefix)/man$$sect/$$i; \
	  else \
	    if test "$(mancompress)" = compress -o "`echo \"$$manpages\"|$(SED) '/\.Z[ \t]*/!d'`" != "" \
	      -a "$(COMPRESS)" != ""; then \
	      $(RM) $(manprefix)/man$$sect/$$i.Z; \
	      $(COMPRESS) $(manprefix)/man$$sect/$$i; \
	    fi; \
	  fi; \
	done

uninstall: uninstall-man
	for p in $(PROGRAMS); do \
	  rm -f $(bindir)/`echo $$p|$(SED) '$(transform)'`; \
	done; \
	for i in ppd.pl printcap.pl printer.pl psptools.pl; do \
	  rm -f $(perldir)/$$i; \
	done; \
	if test "`ls $(perldir)`" = ""; then rm -rf $(perldir); fi \

uninstall-man:
	for m in $(MANPAGES); do \
	  f=`basename $$m`; \
	  for i in $f $f.gz $f.Z; do \
	    sect=`echo $$i | $(SED) 's/[^0-9]//g'`; \
	    if test -f $(manprefix)/man$$sect/$$i; then \
	        rm -f $(manprefix)/man$$sect/$$i; fi; \
	    if test -f $(catdir)/man$$sect/$$i; then \
	        rm -f $(catdir)/man$$sect/$$i; fi; \
	  done; \
	done

${srcdir}/configure: configure.in $(M4FILES)
	cd $(srcdir) && \
	rm -f configure && autoconf && chmod +x configure
Makefile: Makefile.in config.status
	./config.status
sedscript: sedscript.in config.status
	./config.status
config.status: configure
	./config.status --recheck

debian/postinst: debian/postinst.in Makefile
	$(SED) -e 's,%bindir%,$(dirbin),g' \
	    -e 's,%manprefix%,$(prefixman),g' debian/postinst.in >$@
debian/prerm: debian/prerm.in Makefile
	$(SED) -e 's,%bindir%,$(dirbin),g' debian/prerm.in >$@

maintainer-clean::
	@echo "This command is intended for maintainers to use;"
	@echo "rebuilding the deleted files requires autoconf"
	@echo "and copies of install-sh and mkinstalldirs."
	rm -f TAGS *.info* *~
	rm -f configure install-sh mkinstalldirs

clean mostlyclean distclean maintainer-clean::
	rm -f $(REMOVABLEFILES)

distclean maintainer-clean::
	rm -f Makefile config.status config.cache config.log
	rm -f configure.tmp

clean mostlyclean distclean maintainer-clean::
dist: $(DISTDEP)
	distname=`$(SED) -e '/^psptools_version=[^0-9]*/!d' \
	-e 's/[^0-9.]*\([0-9a-z.]*\).*/psptools-\1/' configure.in`; \
	rm -fr $$distname; \
	mkdir $$distname; \
	for file in $(DISTFILES); do \
	  2>/dev/null $(SHELL) ${srcdir}/mkinstalldirs \
	    `echo $$distname/$$file | $(SED) 's,/[^/]*$$,,'`; \
	  ln $$file $$distname/$$file \
	  || { echo copying $$file instead; cp -p $$file $$distname/$$file;}; \
	done; \
	chmod -R a+rX $$distname; \
	tar -chz -f $$distname.tar.gz $$distname; \
	rm -fr $$distname

shar: $(DISTDEP)
	distname=`$(SED) -e '/^psptools_version=[^0-9]*/!d' \
	-e 's/[^0-9.]*\([0-9a-z.]*\).*/psptools-\1/' configure.in`; \
	rm -fr $$distname; \
	mkdir $$distname; \
	for file in $(DISTFILES); do \
	  2>/dev/null $(SHELL) ${srcdir}/mkinstalldirs \
	    `echo $$distname/$$file | $(SED) 's,/[^/]*$$,,'`; \
	  ln $$file $$distname/$$file \
	  || { echo copying $$file instead; cp -p $$file $$distname/$$file;}; \
	done; \
	chmod -R a+rX $$distname; \
	$(SHAR) $(SHARFLAGS) -c -l 50 -a -n $$distname -o $$distname.shar \
	    $$distname; \
	rm -fr $$distname

