old-www/LDP/LG/issue97/smith.html

126 lines
6.7 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><base href="http://www.linuxgazette.com/" />
<title>
configure; make; make install - Linux Gazette </title>
</head>
<body>
<!-- node: "configure; make; make install" -->
<table cellpadding="0" cellspacing="0" style="border 0px; width: 100%;">
<tr><td colspan="2"><img src="themes/lg/images/drop.gif" alt="" title="" /> &nbsp; <b>configure; make; make install</b></td></tr>
<tr style="vertical-align: bottom;"><td colspan="2" style="background-color: #000000; width: 100%;"><img src="themes/lg/images/pixel.gif" width="1" height="1" alt="" title="" /></td></tr>
<tr><td><div style="color: #7c7c7c;"><small>Submitted by <a href="http://www.linuxgazette.com/user/view/395" title="View user profile.">Willy</a> on Saturday, November 22, 2003 - 12:55</small></div></td><td style="text-align: right; vertical-align: top;"></td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2"><p>Over and over I have heard people say that you just use the usual
configure, make, make install sequence to get a program running.
Unfortunately, most people using computers today have never used a
compiler or written a line of program code.
With the advent of graphical user interfaces and applications builders,
there are lots of serious programmers who have never done this.
<p>
What you have are three steps, each of which will use a whole host of
programs to get a new program up and running.
Running configure is relatively new compared with the use of make.
But, each step has a very distinct purpose.
I am going to explain the second and third steps first, then come back
to configure.
<p>
The make utility is embedded in UNIX history.
It is designed to decrease a programmer's need to remember things.
I guess that is actually the nice way of saying it decreases a
programmer's need to document.
In any case, the idea is that if you establish a set of rules to create
a program in a format make understands, you don't have to remember them
again.
<p>
To make this even easier, the make utility has a set of built-in rules
so you only need to tell it what new things it needs to know to build
your particular utility.
For example, if you typed in <code>make love</code>, make would first
look for some new rules from you. If you didn't supply it any then it
would look at its built-in rules.
One of those built-in rules tells make that it can run the linker (ld)
on a program name ending in .o to produce the executable program.
<p>
So, make would look for a file named love.o.
But, it wouldn't stop there.
Even if it found the .o file, it has some other rules
that tell it to make sure the .o file is up to date.
In other words, newer than the source program.
The most common source program on Linux systems is written in C and
its file name ends in .c.
<p>
If make finds the .c file (love.c in our example) as well as the .o
file, it would check their timestamps to make sure the .o was newer.
If it was not newer or did not exist, it would use another built-in
rule to build a new .o from the .c (using the C compiler).
This same type of situation exists for other programming languages.
The end result, in any case, is that when make is done, assuming it can
find the right pieces, the executable program will be built and up to
date.
<p>
The old UNIX joke, by the way, is what early versions of make said when
it could not find the necessary files. In the example above, if there
was no love.o, love.c or any other source format, the program would
have said:<br>
<code>make: don't know how to make love. Stop.</code>
<p>
Getting back to the task at hand, the default file for additional rules
in Makefile in the current directory.
If you have some source files for a program and there is a Makefile
file there, take a look. It is just text.
The lines that have a word followed by a colon are targets. That is,
these are words you can type following the make command name to do
various things.
If you just type make with no target, the first target will be
executed.
<p>
What you will likely see at the beginning of most Makefile files are
what look like some assignment statements. That is, lines with a couple
of fields with an equal sign between them.
Surprise, that is what they are.
They set internal variables in make.
Common things to set are the location of the C compiler (yes, there is
a default), version numbers of the program and such.
<p>
This now beings up back to configure. On different systems, the C
compiler might be in a different place, you might be using ZSH instead
of BASH as your shell, the program might need to know your host name,
it might use a dbm library and need to know if the system had gdbm or
ndbm and a whole bunch of other things.
You used to do this configuring by editing Makefile. Another pain for
the programmer and it also meant that any time you wanted to install
software on a new system you needed to do a complete inventory of what
was where.
<p>
As more and more software became available and more and more
POSIX-compliant platforms appeared, this got harder and harder.
This is where configure comes in.
It is a shell script (generally written by GNU Autoconf) that goes up
and looks for software and even tries various things to see what works.
It then takes its instructions from Makefile.in and builds Makefile
(and possibly some other files) that work on the current system.
<p>
Background work done, let me put the pieces together.
<ul>
<li> You run configure (you usually have to type <code>./configure</code> as most people don't have the current directory in their search path). This builds a new Makefile.
<li> Type <code>make</code> This builds the program. That is, make would be executed, it would look for the first target in Makefile and do what the instructions said. The expected end result would be to build an executable program.
<li> Now, as root, type <code>make install</code>. This again invokes make, make finds the target install in Makefile and files the directions to install the program.
</ul>
<p>
This is a very simplified explanation but, in most cases, this is what
you need to know. With most programs, there will be a file named
INSTALL that contains installation instructions that will fill you in
on other considerations. For example, it is common to supply some
options to the configure command to change the final location of the
executable program. There are also other make targets such as clean
that remove unneeded files after an install and, in some cases test
which allows you to test the software between the make and make install
steps.</p></td></tr>
</table>
</body>
</html>