TITLE:		Printing on LFS
LFS VERSION:	any
AUTHOR:		Wolfgang Arendt <wolare@gmx.de>

SYNOPSIS:
	This hint describes, how to set up basic printing.  We are
	assuming local networking is enabled, sections 9.1 through 9.6
	of the book.
 
HINT:

Table of contents

     * Introduction
     * About this hint
     * Packages
     * Prerequisites
     * Hardware
     * Kernel
     * Users and groups:
     * apsfilter
     * Building gdbm
     * Building LPRng
     * Building Ghostscript
     * Building psutils
     * Installing a2ps
     * Building apsfilter
     * Sources and disclaimer
     * Contributions
     * Further information

Introduction

   We will build LPRng with gdbm support. It will run as user lp, member
   of the daemon group. In this example, the GID of the group daemon is 5
   and so is the UID of the user lp. Please modify all commands to fit
   your environment. All components will install their configuration into
   the /etc directory. Moreover we will install Ghostscript as printer
   driver, assisted by a2ps, the "any to Postscript" converter, apsfilter
   and psutils.

About this hint

   This hint is a merge of the following documents:

   printing.txt
          by Fabio Fracassi <f.fracassi@gmx.net>

   print.txt
          by ktb <x.y.f@home.com>

   ghostscript.txt
          by Wolfgang Arendt <wolare@gmx.de>

   printing2.txt
          by Wolfgang Arendt <wolare@gmx.de>

Packages

   The basic printing system consists of the following packages:

   gdbm-1.8.0.tar.gz
          ftp://ftp.gnu.org/gnu/gdbm/

   LPRng-3.8.4.tgz
          ftp://ftp.lprng.com/pub/LPRng/LPRng/

   psutils-p17.tar.gz
          ftp://ftp.dcs.ed.ac.uk/pub/ajcd/

   a2ps-4.13:a2ps-4.13
          ftp://ftp.enst.fr/pub/unix/a2ps/

   apsfilter-7.1.1.tar.gz
          http://www.apsfilter.org/download/

   ghostscript-7.00.tar.gz
          ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/

   Standard fonts for ghostscript
          ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/fonts/ghostscript-fonts-std-6.0.tar.gz

   Optional fonts for ghostscript
          ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/fonts/ghostscript-fonts-other-6.0.tar.gz

Prerequisites

  Hardware

   You need a supported printer. Check:

   http://www.linuxprinting.org/printer_list.cgi

   for a list of supported hardware.

  Kernel

   You need a kernel with support for the interface, your printer is
   connected to and printing support in general.

   To check, whether this is the case, try the following:

   For a local printer on the first parallel port try:
  echo "bla\\f" > /dev/lp0

   The printer should react in any way (to be more precisely: it should
   print one page with the word "bla" on it).

   For a networked printer try pinging the IP number of the printer.

   If one of those worked, you are ready to install the software.

   If the printer did not respond make sure it is connected to the
   computer correctly i.e., check cables, make sure the network is
   working correctly and that there is kernel support for the printer.

   You can check, whether your kernel supports the parallel port, by
   running

  cat /usr/src/linux/.config | grep CONFIG_PARPORT

   You can check, whether you have printing support in the kernel, by
   running:

  cat /usr/src/linux/.config | grep CONFIG_PRINTER

  Users and groups:

   The printer daemon should not run as user root for security reasons.
   Check, whether you have a user named "lp", that is member of the group
   "daemon". If you do not, create such user, by running

  groupadd -g 5 daemon

  useradd -u 5 -d /var/spool/lp -s /bin/sh -g daemon lp

  apsfilter

   In order to build apsfilter, it is necessary, that you have an
   executable file named "sendmail" in your path. This does not need to
   be a real mail transfer agent, since apsfilter does not really use it,
   except for acquiring the apsfilter's author's mail address.

   You might get along, by creating a faked sendmail, like

  touch /usr/bin/sendmail &&
  chmod 750 /usr/bin/sendmail

   but consider installing a real MTA. If you want an easy solution for a
   dial-up system, consider Masqmail, which is quite easy to set up. Find
   Masqmail here: http://www.innominate.org/~oku/masqmail/

   (please consider, sending the apsfilter's author an email
   nevertheless).

Building gdbm

   The gdbm database library helps speed up large print jobs.

   LPRng does not compile unless you have "gdbm" installed. You may
   choose, not to install it, and to skip this section. In that case, you
   will have to use "--disable-gdbm" as a "configure" option, when
   compiling LPRng.

   For more information see:
     * http://www.astart.com/lprng/LPRng-HOWTO.html
     * http://www.gnu.org/software/gdbm/gdbm.html

   The configure script does not seem to recognize the "--prefix=..."
   option correctly, so we will manually make an adjustment to the
   Makefile.

   Enter:

./configure &&
ed Makefile <<EOF
/^prefix/s#/local##
.
w
EOF
make &&
make install

Building LPRng

   LPRng seems to behave in an unpredictable way, if you use optimization
   higher than O2. You may try to compile it with your usual compiler
   flags. But if this fails, try "-O2"

   Build LPRng with the following commands:

./configure --prefix=/usr \
  --sysconfdir=/etc \
  --with-userid=lp \
  --with-groupid=daemon &&
make &&
make install

   Instead of using the start stop script, that comes with LPRng, create
   such a file from the /etc/init.d/template file.

Building Ghostscript

   Extract the package and change to the top-level-directory of the
   distribution. If you use version 5.10 you will find all the source
   files in that directory. Users of version 6.5 and higher will find
   subdirectories there, containing the sources, libraries etc.

   If you can not find a file named unix-gcc.mak in your present
   directory (which should be gs<VERSION>), then copy it there from the
   src subdirectory.

   Stay in the same directory and extract the zlib-package. This creates
   a directory named zlib-1.1.3. Rename this directory to zlib (or make a
   symlink).

   Extract jpegsrc.v6b.tar.gz and rename the jpeg-6b directory to jpeg
   (or make a symlink).

   Extract libpng-1.2.1.tar.gz and move the libpng-1.2.1-directory to
   libpng (or - guess, what - make a symlink).

   Create the file changes.sed, containing the following lines:
  s|XINCLUDE=-I/usr/local/X/include|XINCLUDE=-I/usr/X11R6/include|
  s|XLIBDIRS=-L/usr/X11/lib|XLIBDIRS=-L/usr/X11R6/lib|
  s|jpeg-6a|jpeg|
  s|prefix = /usr/local|prefix = /usr|
  w Makefile

   Now create the Makefile, by running the following command:

  sed -n -f changes.sed unix-gcc.mak

   Now, you should be ready to compile the whole thing. Just run:

  make &&
  make install

   If the compilation fails with error messages, containing something
   about zdevcal.c, then append the line

  #include <time.h>

   to the file src/time_.h and try again. (This might have to do with
   glibc-2.2.... but I am not sure about it).

   Finally extract the fonts to the /usr/share/ghostscript directory. The
   directory structure should look somewhat like this:

  /usr/share/ghostscript
  /usr/share/ghostscript/gs7.00
  /usr/share/ghostscript/fonts

  Notes:

   If you have zlib and libpng installed, you might choose, to use shared
   versions of the libpng and zlib libraries. In that case, please edit
   the Makefile, before running "make":

   Change SHARE_LIBPNG=0 to SHARE_LIBPNG=1.

   Change SHARE_ZLIB=0 to SHARE_ZLIB=1.

   Make sure you have the paths to your X libs and X*.h files accessible
   to the build process. With a default X install they should be in
   /usr/X11R6/lib and /usr/X11R6/include/X11.

   Make sure, that the following two lines to are in your
   /etc/ld.so.conf:

/usr/X11R6/lib
/usr/X11R6/include/X11

   and run

  ldconfig

   It is possible, to build ghostscript, without having X installed. In
   that case, edit the Makefile and comment out all the lines, that refer
   to X.

Building psutils

   Installing psutils is optional. If you do not install the package, you
   will get a warning, when you install a2ps. For more information see:
   http://www.dcs.ed.ac.uk/home/ajcd/psutils/

   The following command will install psutils. It is configured for paper
   size a4. If you need another media type, then you need to change the
   line beginning with PAPER= in the Makefile.

cp Makefile.unix Makefile &&
ed Makefile <<EOF
/^BINDIR/s#/local##
/^INCLUDEDIR/s#/local##
/^PERL/s#/local##
/^MANDIR/s#/local##
.
w
EOF
make &&
make install

Installing a2ps

   a2ps is the "Any (graphics format) to Postscript" converter.

   Compile a2ps by entering:

./configure --prefix=/usr \
  --sysconfdir=/etc \
  --enable-shared &&
make &&
make install

Building apsfilter

   Apsfilter a filter that runs ghostscript and creates /etc/printcap.

   Compile apsfilter by entering

./configure --prefix=/usr \
  --sysconfdir=/etc &&
make &&
make install

   The last thing, that you have to do is, to configure apsfilter using
   /usr/share/apsfilter/SETUP

   You will be asked a series of questions about printer type, which
   driver to install, paper size, network connection etc.

Sources and disclaimer

   We certainly do not consider ourselves experts at print installations.
   This document should give you a good start though. We welcome any
   comments.

Contributions

   02 May 2002. Yoon Soo <yoonsoo@web.de> added:

   I have an addition which may be interesting for your lfs-hint about
   printing.

   It deals with ghostscript-6.51 :

   If you already have installed zlib and libpng (as described in the
   blfs book) you can skip the copy of these sources into the ghostscript
   tree (for jpeg it is strongly recommended to have this statically
   linked).

cp Makefile Makefile.bak
sed "60 s/\/usr\/local/\/usr/" Makefile.bak |
sed "65 s/\/man/\/share\/man/" |
sed "s/SHARE_LIBPNG=0/SHARE_LIBPNG=1/" |
sed "s/SHARE_ZLIB=0/SHARE_ZLIB=1/" |
sed "263 s/-I/-I\/usr/" > Makefile
make
make install

Further information:

     * http://www.linuxdoc.org/HOWTO/Printing-HOWTO/index.html
     * http://www.linuxprinting.org/printer_list.cgi
