home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / Software-Building < prev    next >
Text File  |  1998-10-14  |  35KB  |  1,057 lines

  1.   Building and Installing Software Packages for Linux
  2.   Mendel Leo Cooper <mailto:thegrendel@theriver.com>
  3.   http://personal.riverusers.com/~thegrendel/
  4.   v1.62, 19 August 1998
  5.  
  6.   This is a comprehensive guide to building and installing"generic" UNIX
  7.   software distributions under Linux. Additionally, there is some cover¡
  8.   age of packages targeted specifically for Linux.
  9.   ______________________________________________________________________
  10.  
  11.   Table of Contents
  12.  
  13.  
  14.   1. Introduction
  15.  
  16.   2. Unpacking the Files
  17.  
  18.   3. Using Make
  19.  
  20.   4. Prepackaged Binaries
  21.  
  22.   5. Termcap and Terminfo Issues
  23.  
  24.   6. Backward Compatibility With a.out Binaries
  25.  
  26.      6.1 An Example
  27.  
  28.   7. Troubleshooting
  29.  
  30.      7.1 Link Errors
  31.      7.2 Other Problems
  32.      7.3 Tweaking and fine tuning
  33.      7.4 Where to go for more help
  34.  
  35.   8. Final Steps
  36.  
  37.   9. First Example: Xscrabble
  38.  
  39.   10. Second Example: Xloadimage
  40.  
  41.   11. Third Example: Fortune
  42.  
  43.   12. Where to Find Source Archives
  44.  
  45.   13. Final Words
  46.  
  47.   14. References and Further Reading
  48.  
  49.  
  50.  
  51.   ______________________________________________________________________
  52.  
  53.   1.  Introduction
  54.  
  55.   Many software packages for the various flavors of UNIX, including
  56.   Linux, are distributed as compressed archives of source files.  The
  57.   same package may be "built" to run on different target machines, and
  58.   this saves the author of the software from having to produce multiple
  59.   distributions. A single distribution of a software package may thus
  60.   end up running, in various incarnations, on an Intel box, a DEC Alpha,
  61.   a RISC workstation, or even a mainframe.  Unfortunately, this puts the
  62.   responsibility of actually "building" and installing the software on
  63.   the end user, the de facto "system administrator", the fellow sitting
  64.   at the keyboard --  you.  Take heart, though, the process is not
  65.   nearly as terrifying or mysterious as it seems, as this guide will
  66.   demonstrate.
  67.   2.  Unpacking the Files
  68.  
  69.   You have downloaded or otherwise acquired a software package.  Most
  70.   likely it is archived (tarred) and compressed (gzipped), in .tar.gz or
  71.   .tgz form (familiarly known as a 'tar ball'). First copy it to a
  72.   working directory. Then untar and gunzip it. The appropriate command
  73.   for this is tar xzvf filename, where filename is the name of the
  74.   software file, of course.  The de-archiving process will usually
  75.   install the appropriate files in subdirectories it will create.  Note
  76.   that if the package name has a .Z suffix, then the above procedure
  77.   will serve just as well, though running uncompress, followed by a tar
  78.   xvf also works.
  79.  
  80.   This method of unpacking 'tar balls' is equivalent to either of the
  81.   following:
  82.  
  83.   ╖  gzip -cd filename | tar xvf -
  84.  
  85.   ╖  gunzip -c filename | tar xvf -
  86.  
  87.   Source files in the new bzip2 (.bz2) format can be unarchived by a
  88.   bzip2 -cd filename | tar xvf -, or, more simply by a tar xyvf
  89.   filename, assuming that gzip has been appropriately patched (refer to
  90.   the Bzip2 HOWTO <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/mini/Bzip>
  91.   for details).
  92.  
  93.   [Many thanks to R. Brock Lynn for corrections and updates on the above
  94.   information.]
  95.  
  96.  
  97.  
  98.   Sometimes the archived file must be untarred and installed from the
  99.   user's home directory, or perhaps in a certain other directory, as
  100.   specified in the package's config info.  Should you get an error
  101.   message attempting to untar it, this may be the reason. Read the
  102.   package docs, especially the README and/or Install files, if present,
  103.   and edit the config files and/or Makefiles as necessary, consistent
  104.   with the installation instructions. Note that you would not ordinarily
  105.   alter the Imake file, since this could have unforseen consequences.
  106.   Some software packages permit automating this process by running make
  107.   install to emplace the binaries in the appropriate system areas.
  108.  
  109.   Occasionally, you may need to update or incorporate bug fixes into the
  110.   unarchived source files using a patch or diff file that lists the
  111.   changes.  The doc files and/or README file will inform you should this
  112.   be the case. The normal syntax for invoking Larry Wall's powerful
  113.   patch utility is patch < patchfile.
  114.  
  115.   You may now proceed to the build stage of the process.
  116.  
  117.  
  118.  
  119.  
  120.  
  121.   3.  Using Make
  122.  
  123.   The Makefile is the key to the build process. In its simplest form, a
  124.   Makefile is a script for compiling or building the "binaries", the
  125.   executable portions of a package. The Makefile can also provide a
  126.   means of updating a software package without having to recompile every
  127.   single source file in it, but that is a different story (or a
  128.   different article).
  129.  
  130.   At some point, the Makefile launches cc or gcc. This is actually a
  131.   preprocessor, a C (or C++) compiler, and a linker, invoked in that
  132.   order.  This process converts the source into the binaries, the actual
  133.   executables.
  134.  
  135.   Invoking make usually involves just typing make. This generally builds
  136.   all the necessary executable files for the package in question.
  137.   However, make can also do other tasks, such as installing the files in
  138.   their proper directories (make install) and removing stale object
  139.   files (make clean).  Running make -n permits previewing the build
  140.   process, as it prints out all the commands that would be triggered by
  141.   a make, without actually executing them.
  142.  
  143.  
  144.   Only the simplest software uses a generic Makefile. More complex
  145.   installations require tailoring the Makefile according to the location
  146.   of libraries, include files, and resources on your particular machine.
  147.   This is especially the case when the build needs the X11 libraries to
  148.   install. Imake and xmkmf accomplish this task.
  149.  
  150.   An Imakefile is, to quote the man page, a "template" Makefile. The
  151.   imake utility constructs a Makefile appropriate for your system from
  152.   the Imakefile. In almost all cases, however, you would run xmkmf, a
  153.   shell script that invokes imake, a front end for it.  Check the README
  154.   or INSTALL file included in the software archive for specific
  155.   instructions.  Read the imake and xmkmf man pages for a more detailed
  156.   analysis of the procedure..
  157.  
  158.   Be aware that xmkmf and make may need to be invoked as root,
  159.   especially when doing a make install to move the binaries over to the
  160.   /usr/bin or /usr/local/bin directories.  Using make as an ordinary
  161.   user without root privileges will likely result in write access denied
  162.   error messages because you lack write permission to system
  163.   directories. Check also that the binaries created have the proper
  164.   execute permissions for you and any other appropriate users.
  165.  
  166.   Invoking xmkmf uses the Imake file to build a new Makefile appropriate
  167.   for your system. You would normally invoke xmkmf with the -a argument,
  168.   to automatically do a make Makefiles, make includes, and make depend.
  169.   This sets the variables and defines the library locations for the
  170.   compiler and linker.  Sometimes, there will be no Imake file, instead
  171.   there will be an INSTALL or configure script that will accomplish this
  172.   purpose. Note that if you run configure, it should be invoked as
  173.   ./configure to ensure that the correct configure script in the current
  174.   directory is called. In most cases, the README file included with the
  175.   distribution will explain the install procedure.
  176.  
  177.   It is usually a good idea to visually inspect the Makefile that xmkmf
  178.   or one of the install scripts builds. The Makefile will normally be
  179.   correct for your system, but you may occasionally be required to
  180.   "tweak" it or correct errors manually.
  181.  
  182.  
  183.   Your general installation procedure will therefore be:
  184.  
  185.   ╖  Read the README file and other applicable docs.
  186.  
  187.   ╖  Run xmkmf -a, or the INSTALL or configure script.
  188.  
  189.   ╖  Check the Makefile.
  190.  
  191.   ╖  If necessary, run make clean, make Makefiles, make includes, and
  192.      make depend.
  193.  
  194.   ╖  Run make.
  195.  
  196.   ╖  Check file permissions.
  197.  
  198.  
  199.   ╖  If necessary, run make install.
  200.  
  201.  
  202.  
  203.   4.  Prepackaged Binaries
  204.  
  205.  
  206.  
  207.   Manually building and installing packages from source is apparently so
  208.   daunting a task for some Linux users that they have embraced the
  209.   popular rpm and deb package formats. While it may be the case that an
  210.   rpm install normally runs as smoothly and as fast as a software
  211.   install in a certain other notorious operating system, some thought
  212.   should certainly be given to the disadvantages of self-installing,
  213.   prepackaged binaries.
  214.  
  215.   First, be aware that software packages are normally released first as
  216.   later. So, if you wish to keep up with all the 'bleeding edge'
  217.   software, you might not wish to wait for an rpm or deb to appear. Some
  218.   less popular packages may never be rpm'ed.
  219.  
  220.   Installing an rpm package is not necessarily a no-brainer.  If there
  221.   is a dependency conflict, an rpm install will fail. Likewise, should
  222.   the rpm require a different version of libraries than the ones present
  223.   on your system, the install may not work, even if you create symbolic
  224.   links to the missing libraries from the ones in place.  You must
  225.   install rpm's and deb's as root, in order to have the necessary write
  226.   permissions, and this opens a potentially serious security hole, as
  227.   you may inadvertently clobber system binaries and libraries, or even
  228.   install a Trojan horse that might wreak havoc upon your system.
  229.  
  230.   It is important to obtain rpm and deb packages from a "trusted
  231.   source". In any case, you should run a 'signature check' on the
  232.   package, rpm --checksig packagename.rpm, before installing.  Running
  233.   an rpm --verify packagename.rpm is likewise highly recommended. For
  234.   the truly paranoid (and, in this case there is much to be said for
  235.   paranoia), there are the unrpm and rpmunpack utilities available from
  236.   the Sunsite utils/package directory
  237.   <ftp://sunsite.unc.edu/pub/Linux/utils/package> for unpacking and
  238.   checking the individual components of the packages.
  239.  
  240.   The martian
  241.   <http://www.people.cornell.edu/pages/rc42/program/martian.html> and
  242.   alien <http://kitenet.net/programs/alien/> programs allow conversion
  243.   between the rpm, deb, and tar.gz package format. This makes these
  244.   packages accessible to all Linux distributions.
  245.  
  246.   In their most simple form, the commands rpm -i packagename.rpm and
  247.   dpkg --install packagename.deb automatically unpack and install the
  248.   software.  Exercise caution, though, since using these commands
  249.   blindly may be dangerous to your system's health!
  250.  
  251.   Note that the above warnings also apply, though to a lesser extent, to
  252.   Slackware's pkgtool installation utility. All "automatic" software
  253.   installations require caution.
  254.  
  255.   Carefully read the man pages for the rpm and dpkg commands, and refer
  256.   to the RPM HOWTO <ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/RPM-
  257.   HOWTO>, TFUG's Quick Guide to Red Hat's Package Manager
  258.   <http://www.tfug.org/helpdesk/linux/rpm.html>, and The Debian Package
  259.   Management Tools <http://www.debian.org/doc/FAQ/debian-faq-7.html> for
  260.   more detailed information.
  261.  
  262.  
  263.  
  264.  
  265.   5.  Termcap and Terminfo Issues
  266.  
  267.  
  268.  
  269.   According to its man page, "terminfo is a data base describing
  270.   terminals, used by screen-oriented programs...".  It defines a generic
  271.   set of control sequences (escape codes) used to display text on
  272.   terminals, and makes possible support for different terminal hardware
  273.   without the need for special drivers.  The terminfo database has
  274.   largely supplanted the older termcap one. This is usually of no
  275.   concern for program installation except when dealing with a package
  276.   that requires termcap.
  277.  
  278.   Most Linux distributions now use terminfo, but still retain the older
  279.   termcap libraries for compatibility with legacy applications.
  280.   Sometimes there is a special compatibility package that needs to be
  281.   installed to facilitate use of termcap linked binaries.  Very
  282.   occasionally, an #define termcap statement might need to be commented
  283.   out of a source file.  Check the appropriate docs for your particular
  284.   distribution for information on this.
  285.  
  286.  
  287.  
  288.  
  289.   6.  Backward Compatibility With a.out Binaries
  290.  
  291.  
  292.   In a very few cases, it is necessary to use a.out binaries, either
  293.   because the source code is not available or because it is not possible
  294.   to build new ELF binaries from the source for some reason.
  295.  
  296.   As it happens, ELF installations almost always have a complete set of
  297.   a.out libraries in the /usr/i486-linuxaout/lib directory.
  298.   Theoretically, a.out binaries should be able to find these libraries
  299.   at runtime, but this may not always be the case.
  300.  
  301.   Note that the kernel should have a.out support built into it, either
  302.   directly or as a loadable module. It may be necessary to rebuild the
  303.   kernel to enable this. Moreover, some Linux distributions require
  304.   installation of a special compatibility package, such as Debian's
  305.   xcompat for executing a.out X applications.
  306.  
  307.  
  308.   6.1.  An Example
  309.  
  310.  
  311.   Jerry Smith wrote a very handy rolodex program some years back. It
  312.   uses the Motif libraries, but fortunately is available as a statically
  313.   linked binary in a.out format. Unfortunately, the source refuses to
  314.   rebuild using the lesstif libraries. Even more unfortunately, the
  315.   a.out binary bombs on an ELF system with the following error message.
  316.  
  317.  
  318.        xrolodex: can't load library '//lib/libX11.so.3'
  319.                No such library
  320.  
  321.  
  322.  
  323.  
  324.   As it happens, there is such a library, in /usr/i486-linuxaout/lib,
  325.   but xrolodex is unable to locate it at run time. The simple solution
  326.   is to provide a symbolic link in the /lib directory:
  327.  
  328.   ln -s /usr/i486-linuxaout/lib/X11.so.3.1.0 libX11.so.3
  329.  
  330.  
  331.   It turns out to be necessary to provide similar links for the
  332.   libXt.so.3 and libc.so.4 libraries. This needs to be done as root, of
  333.   course. Note that you should make absolutely certain you will not
  334.   overwrite or cause version number conflicts with pre-existing
  335.   libraries.  Fortunately, the new ELF libraries have higher version
  336.   numbers than the older a.out ones, to anticipate and forestall just
  337.   such problems.
  338.  
  339.   After creating the three links, xrolodex runs fine.
  340.  
  341.   The xrolodex program may be obtained from Spectro
  342.   <http://www.spectro.com/xrolodex.html>.
  343.  
  344.  
  345.  
  346.  
  347.   7.  Troubleshooting
  348.  
  349.  
  350.   If xmkmf and/or make succeeded without errors, you may proceed to the
  351.   ``next section''.  However, in "real life", few things work right the
  352.   first time.  This is when your resourcefulness is put to the test.
  353.  
  354.  
  355.   7.1.  Link Errors
  356.  
  357.  
  358.   ╖  Suppose make fails with a Link error: -lX11: No such file or
  359.      directory, even after xmkmf has been invoked. This may mean that
  360.      the Imake file was not set up properly. Check the first part of the
  361.      Makefile for lines such as:
  362.  
  363.  
  364.  
  365.        LIB=            -L/usr/X11/lib
  366.        INCLUDE=        -I/usr/X11/include/X11
  367.        LIBS=           -lX11 -lc -lm
  368.  
  369.  
  370.  
  371.  
  372.  
  373.   The -L and -I switches tell the compiler and linker where to look for
  374.   the library and include files, respectively. In this example, the X11
  375.   libraries should be in the /usr/X11/lib directory, and the X11 include
  376.   files should be in the /usr/X11/include/X11 directory. If this is
  377.   incorrect for your machine, make the necessary changes to the Makefile
  378.   and try the make again.
  379.  
  380.  
  381.   ╖  Undefined references to math library functions, such as the
  382.      following:
  383.  
  384.  
  385.                 /tmp/cca011551.o(.text+0x11): undefined reference to `cos'
  386.  
  387.  
  388.  
  389.  
  390.   The fix for this is to explicitly link in the math library, by adding
  391.   an -lm to the LIB or LIBS flags in the Makefile (see previous exam¡
  392.   ple).
  393.  
  394.  
  395.   ╖  In a very few cases, running ldconfig as root may be the solution:
  396.  
  397.      # /etc/ldconfig -n /lib will update the shared library symbolic
  398.      links. This should not be necessary under normal circumstances.
  399.  
  400.  
  401.   ╖  Yet another thing to try if xmkmf fails is the following script:
  402.  
  403.  
  404.                 make -DUseInstalled -I/usr/X386/lib/X11/config
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.   ╖  Sometimes the source needs the older release X11R5 libraries to
  414.      build.  If you have the R5 libs in /usr/X11R6/lib (you were given
  415.      the option of having them when first installing Linux), then you
  416.      need only ensure that you have the links that the software needs to
  417.      build.  The R5 libs are named libX11.so.3.1.0, libXaw.so.3.1.0, and
  418.      libXt.so.3.1.0. You generally need links, such as libX11.so.3 ->
  419.      libX11.so.3.1.0. Possibly the software will also need a link of the
  420.      form libX11.so -> libX11.so.3.1.0.  Of course, to create a
  421.      "missing" link, use the command ln -s libX11.so.3.1.0 libX11.so, as
  422.      root.
  423.  
  424.  
  425.  
  426.   ╖  Some packages will require you to install updated versions of one
  427.      or more libraries. For example, the StarOffice suite from
  428.      StarDivision GmbH is notorious for needing a libc version 5.4.4 or
  429.      greater.  As root, you would need to copy one or more libraries to
  430.      the appropriate directories, remove the old libraries, then reset
  431.      the symbolic links.
  432.  
  433.      Caution: Exercise extreme care in this, as you can render your
  434.      system nonfunctional if you screw up.
  435.  
  436.      You can usually find updated libraries at Sunsite
  437.      <ftp://sunsite.unc.edu/pub/Linux>.
  438.  
  439.  
  440.   7.2.  Other Problems
  441.  
  442.  
  443.  
  444.   ╖  An installed Perl or shell script gives you a No such file or
  445.      directory error message. In this case, check the file permissions
  446.      to make sure the file is executable and check the file header to
  447.      ascertain whether the shell or program invoked by the script is in
  448.      the place specified.  For example, the scrip may begin with:
  449.  
  450.  
  451.        #!/usr/local/bin/perl
  452.  
  453.  
  454.  
  455.  
  456.   If Perl is in fact installed in your /usr/bin directory instead of the
  457.   /usr/local/bin one, then the script will not run.  There are two meth¡
  458.   ods of correcting this. The script file header may be changed to
  459.   #!/usr/bin/perl, or a symbolic link to the correct directory may be
  460.   added, ln -s /usr/bin/perl /usr/local/bin/perl.
  461.  
  462.  
  463.   ╖  Some X11 software requires the Motif libraries to build.  The
  464.      standard Linux distributions do not have the Motif libraries
  465.      installed, and at present Motif costs an extra $100-$200 (though
  466.      the freeware Lesstif <http://www.lesstif.org/> also works in many
  467.      cases). If you need Motif to build a certain package, but lack the
  468.      Motif libraries, it may be possible to obtain statically linked
  469.      binaries. Static linking incorporates the library routines in the
  470.      binaries themselves.  This results in much larger binary files, but
  471.      the code will run on systems lacking the libraries.
  472.  
  473.  
  474.  
  475.   ╖  Running a configure script creates a strange Makefile, one
  476.      seemingly unrelated to the package you are attempting to build.
  477.      This means the wrong configure ran, one found somewhere else in
  478.      your path. Always invoke configure as ./configure to prevent this.
  479.  
  480.  
  481.  
  482.   ╖  Linux distributions are in the process of changing over to the
  483.      newer libc 6 (glibc 2) from libc 5. Precompiled binaries that
  484.      worked with the older library may bomb if you have upgraded your
  485.      library. The solution is to either recompile the applications from
  486.      the source or to obtain newer precompiled binaries.  If you are in
  487.      the process of upgrading your system to libc 6 and are experiencing
  488.      problems, refer to Eric Green's Glibc 2 HOWTO.
  489.  
  490.  
  491.   ╖  Sometimes it is necessary to remove the -ansi option from the
  492.      compile flags in the Makefile. This enables gcc's extra, non-ANSI
  493.      features, and allows building packages that require these
  494.      extensions. (Thanks to Sebastien Blondeel for pointing this out.)
  495.  
  496.  
  497.   ╖  Some programs require having setuid root, in order to run with root
  498.      privileges. The command to implement this is chmod u+s filename, as
  499.      root (note that the program must already be owned by root). This
  500.      has the effect of setting the setuid bit in the file permissions.
  501.      This issue comes up when the program accesses the system hardware,
  502.      such as a modem or CD ROM drive, or when the SVGA libs are invoked
  503.      from console mode, as in one particularly notorious emulation
  504.      package. If a program works when run by root, but gives access
  505.      denied error messages to an ordinary user, suspect this as the
  506.      cause.
  507.  
  508.  
  509.  
  510.      Warning: A program with setuid as root may pose a security risk to
  511.      your system. The program runs with root privileges and thus has the
  512.      potential for doing significant damage. Make certain that you know
  513.      what the program does, by looking at the source if possible, before
  514.      setting the setuid bit.
  515.  
  516.  
  517.  
  518.  
  519.   7.3.  Tweaking and fine tuning
  520.  
  521.  
  522.   You may wish to examine the Makefile to make certain that the best
  523.   compilation options for your system are invoked. For example, setting
  524.   the -O2 flag chooses the highest level of optimization and the -fomit-
  525.   frame-pointer flag results in a smaller binary (though debugging will
  526.   then be disabled). Do not play around with this unless you know what
  527.   you are doing, and in any case, not until after a trial build works.
  528.  
  529.   7.4.  Where to go for more help
  530.  
  531.  
  532.   In my experience, perhaps 25% of applications build "right out of the
  533.   box". Another 50% or so can be "persuaded" to build with an effort
  534.   ranging from trivial to herculean. That still means a significant
  535.   number of packages will not build no matter what. Even then, the Intel
  536.   ELF and/or a.out binaries for these might possibly be found at Sunsite
  537.   <ftp://sunsite.unc.edu> or the TSX-11 archive <ftp://tsx-11.mit.edu>.
  538.   Red Hat <http://redhat.com> and Debian <http://www.debian.org> have
  539.   extensive archives of prepackaged binaries of most of the popular
  540.   Linux software.  Perhaps the author of the software can supply the
  541.   binaries compiled for your particular flavor of machine.
  542.  
  543.  
  544.   Note that if you obtain precompiled binaries, you will need to check
  545.   for compatibility with your system:
  546.  
  547.   ╖  The binaries must run on your hardware (i.e., Intel x86).
  548.  
  549.   ╖  The binaries must be compatible with your kernel (i.e., a.out or
  550.      ELF).
  551.  
  552.   ╖  Your libraries must be up to date.
  553.  
  554.   ╖  Your system must have the appropriate installation utility (rpm or
  555.      deb).
  556.  
  557.   If all else fails, you may find help in the appropriate newsgroups,
  558.   such as comp.os.linux.x or comp.os.linux.development.
  559.  
  560.   If nothing at all works, at least you gave it your best effort, and
  561.   you learned a lot.
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.   8.  Final Steps
  570.  
  571.   Read the software package documentation to determine whether certain
  572.   environmental variables need setting (in .bashrc or .cshrc) and if the
  573.   .Xdefaults and .Xresources files need customizing.
  574.  
  575.   There may be an applications default file, usually named Xfoo.ad in
  576.   the original Xfoo distribution. If so, edit the Xfoo.ad file to
  577.   customize it for your machine, then rename (mv) it Xfoo and install it
  578.   in the /usr/lib/X11/app-defaults directory, as root.  Failure to do
  579.   this may cause the software to behave strangely or even refuse to run.
  580.  
  581.   Most software packages come with one or more preformatted man pages.
  582.   As root, copy the Xfoo.man file to the appropriate /usr/man,
  583.   /usr/local/man, or /usr/X11R6/man directory (man1 - man9), and rename
  584.   it accordingly.  For example, if Xfoo.man ends up in /usr/man/man4, it
  585.   should be renamed Xfoo.4 (mv Xfoo.man Xfoo.4).  By convention, user
  586.   commands go in man1, games in man6, and administration packages in
  587.   man8 (see the man docs for more details).  Of course, you may deviate
  588.   from this on your own system, if you like.
  589.  
  590.   Some packages will not install the binaries in the appropriate system
  591.   directories, that is, they are missing the install option in the
  592.   Makefile. Should this be the case, you can install the binaries
  593.   manually by copying the binaries to the appropriate system directory,
  594.   /usr/local/bin or /usr/X11R6/bin, as root, of course.
  595.   Note that some or all of the above procedures should, in most cases,
  596.   be handled automatically by a make install, and possibly a make
  597.   install.man or make install_man. If so, the README or INSTALL doc file
  598.   will specify this.
  599.  
  600.  
  601.  
  602.   9.  First Example: Xscrabble
  603.  
  604.   Matt Chapman's Xscrabble seemed like a program that would be
  605.   interesting to have, since I happen to be an avid ScrabbleTM player. I
  606.   downloaded it, uncompressed it,  and built it following the procedure
  607.   in the README file:
  608.  
  609.  
  610.             xmkmf
  611.             make Makefiles
  612.             make includes
  613.             make
  614.  
  615.  
  616.  
  617.  
  618.   Of course it did not work...
  619.  
  620.  
  621.  
  622.        gcc -o xscrab -O2 -O -L/usr/X11R6/lib
  623.        init.o xinit.o misc.o moves.o cmove.o main.o xutils.o mess.o popup.o
  624.        widgets.o display.o user.o CircPerc.o
  625.        -lXaw -lXmu -lXExExt -lXext -lX11 -lXt -lSM -lICE -lXExExt -lXext -lX11
  626.        -lXpm -L../Xc -lXc
  627.  
  628.        BarGraf.o(.text+0xe7): undefined reference to `XtAddConverter'
  629.        BarGraf.o(.text+0x29a): undefined reference to `XSetClipMask'
  630.        BarGraf.o(.text+0x2ff): undefined reference to `XSetClipRectangles'
  631.        BarGraf.o(.text+0x375): undefined reference to `XDrawString'
  632.        BarGraf.o(.text+0x3e7): undefined reference to `XDrawLine'
  633.        etc.
  634.        etc.
  635.        etc...
  636.  
  637.  
  638.  
  639.  
  640.   I enquired about this in the comp.os.linux.x newsgroup, and someone
  641.   kindly pointed out that apparently the Xt, Xaw, Xmu, and X11 libs were
  642.   not being found at the link stage. Hmmm...
  643.  
  644.   There were two main Makefiles, and the one in the src directory caught
  645.   my interest. One line in the Makefile defined LOCAL_LIBS as:
  646.   LOCAL_LIBS = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) Here were
  647.   references to the libs not being found by the linker.
  648.  
  649.   Looking for the next reference to LOCAL_LIBS, I saw on line 495 of
  650.   that Makefile:
  651.  
  652.  
  653.              $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LOCAL_LIBS) $(LDLIBS)
  654.        $(EXTRA_LOAD_FLAGS)
  655.  
  656.  
  657.  
  658.  
  659.   Now what were these LDLIBS?
  660.  
  661.         LDLIBS = $(LDPOSTLIB) $(THREADS_LIBS) $(SYS_LIBRARIES)
  662.   $(EXTRA_LIBRARIES)
  663.  
  664.  
  665.  
  666.  
  667.   The SYS_LIBRARIES were:
  668.  
  669.  
  670.         SYS_LIBRARIES = -lXpm -L../Xc -lXc
  671.  
  672.  
  673.  
  674.  
  675.   Yes! Here were the missing libraries.
  676.  
  677.   Possibly the linker needed to see the LDLIBS before the LOCAL_LIBS...
  678.   So, the first thing to try was to modify the Makefile by transposing
  679.   the $(LOCAL_LIBS) and $(LDLIBS) on line 495, so it would now read:
  680.  
  681.  
  682.                $(CCLINK) -o $@ $(LDOPTIONS) $(OBJS) $(LDLIBS) $(LOCAL_LIBS)
  683.        $(EXTRA_LOAD_FLAGS)                          ^^^^^^^^^^^^^^^^^^^^^^^
  684.  
  685.  
  686.  
  687.  
  688.   I tried running make again with the above change, and lo and behold,
  689.   it worked this time. Of course,  Xscrabble still needed some fine
  690.   tuning and twiddling, such as renaming the dictionary and commenting
  691.   out some assert statements in one of the source files, but since then
  692.   it has provided me with many hours of pleasure.
  693.  
  694.  
  695.  
  696.   [Note that a newer version of Xscrabble is now available in rpm
  697.   format, and this installs without problems.]
  698.  
  699.  
  700.  
  701.  
  702.   You may e-mail Matt Chapman <mailto:matt@belgarath.demon.co.uk>, and
  703.   download Xscrabble from his home page
  704.   <http://www.belgarath.demon.co.uk/programs/index.html>.
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.               Scrabble is a registered trademark of the Milton Bradley Co., Inc.
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.   10.  Second Example: Xloadimage
  721.  
  722.   This example poses an easier problem. The xloadimage program seemed a
  723.   useful addition to my set of graphic tools.  I copied the xloadi41.gz
  724.   file directly from the source directory on the CD included with the
  725.   excellent ``X User Tools'' book, by Mui and Quercia. As expected, tar
  726.   xzvf unarchives the files.  The make, however, produces a nasty-
  727.   looking error and terminates.
  728.  
  729.  
  730.  
  731.        gcc -c -O -fstrength-reduce -finline-functions -fforce-mem
  732.        -fforce-addr -DSYSV  -I/usr/X11R6/include
  733.        -DSYSPATHFILE=\"/usr/lib/X11/Xloadimage\" mcidas.c
  734.  
  735.        In file included from /usr/include/stdlib.h:32,
  736.                         from image.h:23,
  737.                         from xloadimage.h:15,
  738.                         from mcidas.c:7:
  739.        /usr/lib/gcc-lib/i486-linux/2.6.3/include/stddef.h:215:
  740.        conflicting types for `wchar_t'
  741.        /usr/X11R6/include/X11/Xlib.h:74: previous declaration of
  742.        `wchar_t'
  743.        make[1]: *** [mcidas.o] Error 1
  744.        make[1]: Leaving directory
  745.        `/home/thegrendel/tst/xloadimage.4.1'
  746.        make: *** [default] Error 2
  747.  
  748.  
  749.  
  750.  
  751.   The error message contains the essential clue.
  752.  
  753.   Looking at the file image.h, line 23...
  754.  
  755.  
  756.               #include <stdlib.h>
  757.  
  758.  
  759.  
  760.  
  761.   Aha, somewhere in the source for xloadimage, wchar_t has been
  762.   redefined from what was specified in the standard include file,
  763.   stdlib.h. Let us first try commenting out line 23 in image.h, as
  764.   perhaps the stdlib.h include is not, after all, necessary.
  765.  
  766.   At this point, the build proceeds without any fatal errors. The
  767.   xloadimage package functions correctly now.
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.   11.  Third Example: Fortune
  775.  
  776.   This final example requires some knowledge of C programming. The
  777.   majority of UNIX/Linux software is written in C, and learning at least
  778.   a little bit of C would certainly be an asset for anyone serious about
  779.   software installation.
  780.  
  781.   The notorious fortune program displays up a humorous saying, a
  782.   "fortune cookie", every time Linux boots up. Unfortunately (pun
  783.   intended), attempting to build fortune on a Red Hat distribution with
  784.   a 2.0.30 kernel generates fatal errors.
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.   ~/fortune# make all
  794.  
  795.  
  796.   gcc -O2 -Wall -fomit-frame-pointer -pipe   -c fortune.c -o
  797.   fortune.o
  798.   fortune.c: In function `add_dir':
  799.   fortune.c:551: structure has no member named `d_namlen'
  800.   fortune.c:553: structure has no member named `d_namlen'
  801.   make[1]: *** [fortune.o] Error 1
  802.   make[1]: Leaving directory `/home/thegrendel/for/fortune/fortune'
  803.   make: *** [fortune-bin] Error 2
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.   Looking at fortune.c, the pertinent lines are these.
  812.  
  813.  
  814.  
  815.           if (dirent->d_namlen == 0)
  816.                    continue;
  817.                name = copy(dirent->d_name, dirent->d_namlen);
  818.  
  819.  
  820.  
  821.  
  822.   We need to find the structure dirent, but it is not declared in the
  823.   fortune.c file, nor does a grep dirent show it in any of the other
  824.   source files. However, at the top of fortune.c, there is the following
  825.   line.
  826.  
  827.  
  828.  
  829.        #include <dirent.h>
  830.  
  831.  
  832.  
  833.  
  834.   This appears to be a system library include file, therefore, the
  835.   logical place to look for dirent.h is in /usr/include.  Indeed, there
  836.   does exist a dirent.h file in /usr/include, but that file does not
  837.   contain the declaration of the dirent structure.  There is, however, a
  838.   reference to another dirent.h file.
  839.  
  840.  
  841.  
  842.        #include <linux/dirent.h>
  843.  
  844.  
  845.  
  846.  
  847.  
  848.   At last, going to /usr/include/linux/dirent.h, we find the structure
  849.   declaration we need.
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.   struct dirent {
  860.           long            d_ino;
  861.           __kernel_off_t  d_off;
  862.           unsigned short  d_reclen;
  863.           char            d_name[256]; /* We must not include
  864.   limits.h! */
  865.   };
  866.  
  867.  
  868.  
  869.  
  870.   Sure enough, the structure declaration contains no d_namelen, but
  871.   there are a couple of "candidates" for its equivalent. The most likely
  872.   of these is d_reclen, since this structure member probably represents
  873.   the length of something and it is a short integer.  The other
  874.   possibility, d_ino, could be an inode number, judging by its name and
  875.   type. As a matter of fact, we are probably dealing with a "directory
  876.   entry" structure, and these elements represent attributes of a file,
  877.   its name, inode, and length (in blocks).  This would seem to validate
  878.   our guess.
  879.  
  880.   Let us edit the file fortune.c, and change the two d_namelen
  881.   references in lines 551 and 553 to d_reclen.  Try a make all again.
  882.   Success. It builds without errors. We can now get our "cheap thrills"
  883.   from fortune.
  884.  
  885.  
  886.   12.  Where to Find Source Archives
  887.  
  888.   Now that you are eager to use your newly acquired knowledge to add
  889.   utilities and other goodies to your system, you may find them online
  890.   at the Linux Applications and Utilities Page
  891.   <http://www.redhat.com/linux-info/linux-app-list/linapps.html>, or on
  892.   one of the very reasonably priced CD ROM archives by Red Hat
  893.   <http://www.redhat.com/>, InfoMagic <mailto:orders@infomagic.com>,
  894.   Linux Systems Labs <http://www.lsl.com>, Cheap Bytes
  895.   <http://www.cheapbytes.com>, and others.
  896.  
  897.   A comprehensive repository of source code is the comp sources UNIX
  898.   archive <ftp://ftp.vix.com/pub/usenet/comp.sources.unix/>.
  899.  
  900.   Much UNIX source code is posted on the alt.sources newsgroup. If you
  901.   are looking for particular source code packages, you may post on the
  902.   related alt.sources.wanted newsgroup.  Another good place to check is
  903.   the comp.os.linux.announce newsgroup.  To get on the Unix sources
  904.   <mailto:unix-sources@pa.dec.com> mailing list, send a subscribe
  905.   message there.
  906.  
  907.   Archives for the alt.sources newsgroup are at the following ftp sites:
  908.  
  909.  
  910.   ╖  ftp.sterling.com/usenet/alt.sources/
  911.      <ftp://ftp.sterling.com/usenet/alt.sources/>
  912.  
  913.   ╖  wuarchive.wustl.edu/usenet/alt.sources/articles
  914.      <ftp://wuarchive.wustl.edu/usenet/alt.sources/articles>
  915.  
  916.   ╖  src.doc.ic.ac.uk/usenet/alt.sources/articles
  917.      <ftp://src.doc.ic.ac.uk/usenet/alt.sources/articles>
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.   13.  Final Words
  926.  
  927.   To sum up, persistence makes all the difference  (and a high
  928.   frustration threshold certainly helps). As in all endeavors, learning
  929.   from mistakes is critically important.  Each misstep, every failure
  930.   contributes to the body of knowledge that will lead to mastery of the
  931.   art of building software.
  932.  
  933.  
  934.  
  935.   14.  References and Further Reading
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.   BORLAND C++ TOOLS AND UTILITIES GUIDE, Borland International, 1992,
  992.   pp. 9-42.
  993.   [One of the manuals distributed with Borland C++, ver. 3.1. Gives
  994.   a fairly good intro to make syntax and concepts, using Borland's
  995.   crippled implementation for DOS.]
  996.  
  997.   DuBois, Paul: SOFTWARE PORTABILITY WITH IMAKE, O'Reilly and Associates,
  998.   1996, ISBN 1-56592-226-3.
  999.   [This is reputed to be the definitive imake reference, though I did not
  1000.   have it available when writing this article.]
  1001.  
  1002.   Frisch, Aeleen: ESSENTIAL SYSTEM ADMINISTRATION, O'Reilly and
  1003.   Associates, 1995, ISBN 1-56592-127-5.
  1004.   [This otherwise excellent sys admin handbook has only sketchy coverage
  1005.   of software building.]
  1006.  
  1007.   Lehey, Greg: PORTING UNIX SOFTWARE, O'Reilly and Associates, 1995, ISBN
  1008.   1-56592-126-7.
  1009.  
  1010.   Mui, Linda and Valerie Quercia: X USER TOOLS, O'Reilly and Associates,
  1011.   1994, ISBN 1-56592-019-8, pp. 734-760.
  1012.  
  1013.   Oram, Andrew and Steve Talbott: MANAGING PROJECTS WITH MAKE, O'Reilly
  1014.   and Associates, 1991, ISBN 0-937175-90-0.
  1015.  
  1016.   Peek, Jerry and Tim O'Reilly and Mike Loukides: UNIX POWER TOOLS,
  1017.   O'Reilly and Associates / Random House, 1997, ISBN 1-56592-260-3.
  1018.   [A wonderful source of ideas, and tons of utilities you may end up
  1019.   building from the source code, using the methods discussed in
  1020.   this article.]
  1021.  
  1022.   Stallman, Richard M. and Roland McGrath: GNU MAKE, Free Software
  1023.   Foundation, 1995, ISBN 1-882114-78-7.
  1024.   [Required reading.]
  1025.  
  1026.   Welsh, Matt and Lar Kaufman: RUNNING LINUX, O'Reilly and Associates,
  1027.   1996, ISBN 1-56592-151-8.
  1028.   [Still the best overall Linux reference, though lacking in depth
  1029.   in some areas.]
  1030.  
  1031.  
  1032.  
  1033.   The BZIP2 HOWTO, by David Fetter.
  1034.  
  1035.   The Glibc2 HOWTO, by Eric Green
  1036.  
  1037.   The LINUX ELF HOWTO, by Daniel Barlow.
  1038.  
  1039.   The RPM HOWTO, by Donnie Barnes.
  1040.  
  1041.   [These HOWTOs are available in HTML format from the LDP site,
  1042.   http://sunsite.unc.edu/LDP/linux.html.]
  1043.  
  1044.  
  1045.  
  1046.   The man pages for dpkg, gcc, gzip, imake, ldconfig, make, patch, rpm, tar,
  1047.   termcap, terminfo, and xmkmf.
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.