mirror of https://github.com/tLDP/LDP
Complete make basics + explain info in the reference links
This commit is contained in:
parent
28d0e6f1ec
commit
27d8516f24
|
@ -2,9 +2,10 @@
|
|||
|
||||
<!--
|
||||
|
||||
The version history of this document, along with the comments are at the
|
||||
end of the file. Last modification history is ...
|
||||
The version history of this document, along with the comments is at the
|
||||
end of the file.
|
||||
|
||||
Last modification info:
|
||||
$Id$
|
||||
|
||||
-->
|
||||
|
@ -155,7 +156,8 @@ $Id$
|
|||
&autoconf;, &automake; &libtool; etc. It also tries to provide an
|
||||
explanation as to to how these tools work. To be able to follow
|
||||
the explanations given in here, the reader is expected to be
|
||||
familiar with the basics of programming.
|
||||
familiar with Unix like operating systems and the basics of
|
||||
programming.
|
||||
|
||||
</para>
|
||||
|
||||
|
@ -175,7 +177,7 @@ $Id$
|
|||
http://www.tldp.org/HOWTO/GNU-Build-System-HOWTO/</ulink>. The
|
||||
latest in-progress version of this document is available at the
|
||||
<ulink
|
||||
url="http://www.pratapgarh.com/appaji/interests/freedom-sw/gbsh.html">
|
||||
url="http://www.appaji.net/interests/freedom-sw/gbsh.html">
|
||||
GNU-Build-System HOWTO home page</ulink>.
|
||||
|
||||
</para>
|
||||
|
@ -193,7 +195,12 @@ $Id$
|
|||
This document, the <emphasis>GNU-Build-System HOWTO</emphasis>, is
|
||||
distributed under the terms of the <citetitle>GNU General Public
|
||||
License</citetitle>. The word <emphasis>Program</emphasis> in the
|
||||
license is to be interpreted as <emphasis>document</emphasis>.
|
||||
license is to be interpreted as <emphasis>document</emphasis>. The
|
||||
term <emphasis>source code</emphasis> refers to the DocBook/XML
|
||||
format of this document and the term <emphasis>object
|
||||
code</emphasis> refers to one, many or all the other formats that
|
||||
this document is available in, after conversion from the
|
||||
<emphasis>source code</emphasis>.
|
||||
|
||||
</para>
|
||||
|
||||
|
@ -259,8 +266,7 @@ $Id$
|
|||
a developer in each stage of the configure, compile and distribute
|
||||
process. Projects using the suite of the GBS are recognizable by
|
||||
the ease with which they are installed. The ubiquitous
|
||||
"<command>./configure && make && make install</command>" does the
|
||||
trick.
|
||||
<command>./configure && make && make install</command> does it all.
|
||||
|
||||
</para>
|
||||
|
||||
|
@ -270,10 +276,10 @@ $Id$
|
|||
how to use them. Though the treatment would not be in depth, it
|
||||
should help you understand the files that these tools operate on.
|
||||
The aim is to take the reader step by step, through the stages
|
||||
turning a set of source files of a "project" to conform to the
|
||||
"<command>./configure && make && make install</command>" mantra. We
|
||||
will work through each of these components using a <literal>Hello
|
||||
World!</literal> styled example.
|
||||
turning a set of source files of a <quote>project</quote> to conform
|
||||
to the <command>./configure && make && make install</command>
|
||||
mantra. We will work through each of these components using a
|
||||
<literal>Hello World!</literal> styled example.
|
||||
|
||||
</para>
|
||||
|
||||
|
@ -299,10 +305,10 @@ $Id$
|
|||
&make; is a utility for automatic compilation of a project's
|
||||
source code. It is used in projects to find out if the files
|
||||
(typically C sources) that a certain <quote>target</quote>
|
||||
(typically object files and executables) depends on have
|
||||
depends on (typically object files and executables) have
|
||||
changed, and re-generates the target. It makes compiling only
|
||||
the necessary files of a big project as simple as typing
|
||||
"&make;", when a few of them have been modified. The input to
|
||||
&make;, when a few of them have been modified. The input to
|
||||
the &make; utility is a &makefile;.
|
||||
|
||||
</para>
|
||||
|
@ -315,7 +321,9 @@ $Id$
|
|||
|
||||
<para>
|
||||
|
||||
A very minimal &makefile; would look like:
|
||||
A very minimal &makefile; to &make; a program called
|
||||
<filename>foo</filename> from a C program
|
||||
<filename>foo.c</filename> would look like:
|
||||
|
||||
</para>
|
||||
|
||||
|
@ -332,19 +340,27 @@ foo: foo.c
|
|||
|
||||
The target in this &makefile; is <filename>foo</filename> and it
|
||||
depends on the <filename>foo.c</filename> dependency. The
|
||||
second line tells make how to build the target in case the
|
||||
dependency changes.
|
||||
second line (command) tells make how to build the target in case
|
||||
the dependency changes. The command should be on its own line
|
||||
with a <TAB> character (and <emphasis>not</emphasis>
|
||||
spaces) before it.
|
||||
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
||||
Creating the <filename>foo</filename> executable can then be
|
||||
done by issuing a <command>make foo</command> command in the
|
||||
directory where the above &makefile; is present.
|
||||
The <filename>foo</filename> executable can then be created by
|
||||
issuing a <command>make foo</command> command in the directory
|
||||
where the above &makefile; is present.
|
||||
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
&cmdline; <userinput>make</userinput>
|
||||
gcc -o foo foo.c
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
||||
<para>
|
||||
|
||||
A slightly more useful example would be:
|
||||
|
@ -354,16 +370,19 @@ foo: foo.c
|
|||
<screen>
|
||||
&cmdline; <userinput>cat Makefile</userinput>
|
||||
|
||||
default: hw
|
||||
all: hw
|
||||
|
||||
hw: hello.o world.o
|
||||
gcc -o hw hello.o world.o -lm
|
||||
hw: main.o hello.o world.o
|
||||
gcc main.o hello.o world.o -o hw
|
||||
|
||||
world.o: world.c hello.h world.h
|
||||
gcc -Wall -c hello.c
|
||||
|
||||
hello.o: hello.c hello.h
|
||||
gcc -c hello.c
|
||||
gcc -Wall -c hello.c
|
||||
|
||||
world.o: world.c world.h
|
||||
gcc -c world.c
|
||||
gcc -Wall -c world.c
|
||||
|
||||
clean:
|
||||
rm -f hw hello.o world.o
|
||||
|
@ -373,33 +392,79 @@ clean:
|
|||
|
||||
<para>
|
||||
|
||||
The target in this &makefile; (which is the first target that
|
||||
appears in the &makefile;) is <literal>default</literal>.
|
||||
<literal>default</literal> depends on <literal>hw</literal>
|
||||
which in-turn depends on <filename>hello.o</filename> and
|
||||
<filename>world.o</filename>. These can be <quote>made</quote>
|
||||
using the rules that have been specified for them. For example,
|
||||
<filename>hello.o</filename> is created using the command
|
||||
<command>gcc -c hello.c</command> whenever
|
||||
<filename>hello.c</filename> or <filename>hello.h</filename> are
|
||||
modified.
|
||||
The default target in this &makefile; (which is the first target
|
||||
that appears in the &makefile;) is <literal>all</literal>.
|
||||
<literal>all</literal> depends on <literal>hw</literal> which
|
||||
in-turn depends on <filename>main.o</filename>,
|
||||
<filename>hello.o</filename> and <filename>world.o</filename>.
|
||||
These can be <quote>made</quote> using the rules that have been
|
||||
specified for them. For example, <filename>hello.o</filename>
|
||||
is created using the command <command>gcc -Wall -c
|
||||
hello.c</command> whenever <filename>hello.c</filename> or
|
||||
<filename>hello.h</filename> are modified.
|
||||
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
&cmdline; <userinput>make</userinput>
|
||||
gcc -Wall -c main.c
|
||||
gcc -Wall -c hello.c
|
||||
gcc -Wall -c world.c
|
||||
gcc main.o hello.o world.o -o hw
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
||||
<para>
|
||||
|
||||
The other target <literal>clean</literal> can be invoked
|
||||
explicitly to remove the target files that have been generated.
|
||||
Another invocation of &make; (or <command>make all</command>)
|
||||
does nothing.
|
||||
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
&cmdline; <userinput>make all</userinput>
|
||||
make: Nothing to be done for `all'.
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
||||
<para>
|
||||
|
||||
However, if one of the files is changed (say
|
||||
<filename>hello.h</filename>), &make; will figure out the right
|
||||
files to be re-compiled (based on the dependencies in the
|
||||
&makefile;) and generate a new <filename>hw</filename>.
|
||||
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
&cmdline; <userinput>touch hello.c</userinput>
|
||||
&cmdline; <userinput>make all</userinput>
|
||||
gcc -Wall -c main.c
|
||||
gcc -Wall -c hello.c
|
||||
gcc main.o hello.o world.o -o hw
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
||||
<para>
|
||||
|
||||
The other target in the &makefile;, <literal>clean</literal>,
|
||||
can be invoked explicitly to remove the target files that have
|
||||
been generated.
|
||||
|
||||
</para>
|
||||
|
||||
<screen>
|
||||
&cmdline; <userinput>make clean</userinput>
|
||||
rm -f hw hello.o world.o
|
||||
|
||||
rm -f hw main.o hello.o world.o
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
||||
</sect3>
|
||||
|
||||
<sect3 id="make-variables">
|
||||
|
||||
<title>Variables in &makefile;s</title>
|
||||
|
||||
<para>
|
||||
|
||||
A &makefile; can also be written using variables and wild-cards
|
||||
|
@ -412,21 +477,25 @@ rm -f hw hello.o world.o
|
|||
&cmdline; <userinput>cat Makefile</userinput>
|
||||
|
||||
TARGET = hw
|
||||
OBJS = hello.o world.o
|
||||
OBJS = main.o hello.o world.o
|
||||
CC = gcc
|
||||
CCOPTS = -c
|
||||
LOPTS = -lm
|
||||
CCOPTS = -Wall -c
|
||||
RM = rm
|
||||
RMOPTS = -f
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) -o $@ $(OBJS) $(LOPTS)
|
||||
$(CC) $(OBJS) -o $(TARGET)
|
||||
|
||||
main.o: main.c hello.h world.h
|
||||
$(CC) $(CCOPTS) $<
|
||||
|
||||
%.o: %.c %.h
|
||||
$(CC) $(CCOPTS) $<
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) $(OBJS)
|
||||
$(RM) $(RMOPTS) $(TARGET) $(OBJS)
|
||||
|
||||
&cmdline;
|
||||
</screen>
|
||||
|
@ -442,7 +511,8 @@ clean:
|
|||
<para>
|
||||
|
||||
In general, one source file would depend on more than one
|
||||
header file and the dependency rule is not as simple as
|
||||
header file (like the <filename>main.o</filename>
|
||||
dependency) and the dependency rule is not as simple as
|
||||
this. It is infact difficult to keep track of dependencies
|
||||
on header files and their dependencies with nested includes.
|
||||
There are ways of handling this (see the manual page of
|
||||
|
@ -467,10 +537,10 @@ clean:
|
|||
|
||||
<para>
|
||||
|
||||
GNU &make; provides several other useful features like the VPATH
|
||||
directive to locate the source files that are not co-located
|
||||
with the &makefile;, facility for sophisticated wildcards, etc.
|
||||
These are described in the <link
|
||||
GNU &make; provides several other useful features like the
|
||||
<literal>VPATH</literal> directive to locate the source files
|
||||
that are not co-located with the &makefile;, facility for
|
||||
sophisticated wildcards, etc. These are described in the <link
|
||||
linkend="resources"><citetitle>official GNU &make;
|
||||
manual</citetitle></link>.
|
||||
|
||||
|
@ -484,7 +554,7 @@ clean:
|
|||
|
||||
<para>
|
||||
|
||||
A &makefile; that goes with software packages, and follows the
|
||||
A &makefile; that goes with software packages that follow the
|
||||
GNU &makefile; conventions has a few standard targets and
|
||||
provides useful and commonly used functionality like:
|
||||
|
||||
|
@ -535,6 +605,15 @@ clean:
|
|||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
|
||||
<literal>install</literal>: installs the compiled binaries,
|
||||
manual pages, documents at their appropriate location.
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
|
||||
|
@ -649,7 +728,7 @@ clean:
|
|||
|
||||
<sect1 id="real-example">
|
||||
|
||||
<title>Back to the real world</title>
|
||||
<title>The real world</title>
|
||||
|
||||
<para>
|
||||
|
||||
|
@ -782,10 +861,42 @@ clean:
|
|||
|
||||
<sect2 id="distro-install">
|
||||
|
||||
<title>From GNU/Linux distribution packages</title>
|
||||
<title>From distribution packages</title>
|
||||
|
||||
<para></para>
|
||||
|
||||
<sect3 id="fedora-install">
|
||||
|
||||
<title>Fedora</title>
|
||||
|
||||
<para></para>
|
||||
|
||||
</sect3>
|
||||
|
||||
<sect3 id="suse-install">
|
||||
|
||||
<title>SuSE</title>
|
||||
|
||||
<para></para>
|
||||
|
||||
</sect3>
|
||||
|
||||
<sect3 id="debian-install">
|
||||
|
||||
<title>Debian</title>
|
||||
|
||||
<para></para>
|
||||
|
||||
</sect3>
|
||||
|
||||
<sect3 id="mandrake-install">
|
||||
|
||||
<title>Mandrake</title>
|
||||
|
||||
<para></para>
|
||||
|
||||
</sect3>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="source-install">
|
||||
|
@ -926,10 +1037,11 @@ clean:
|
|||
<listitem>
|
||||
<para>
|
||||
|
||||
<ulink url="http://www.mv.com/ipusers/vanzandt/">autoproject:
|
||||
</ulink> In the authors words, <quote>autoproject - a script to
|
||||
start a programming project using &autoconf;, &automake;, and
|
||||
optionally a command line parser generator</quote>
|
||||
<ulink
|
||||
url="http://www.mv.com/ipusers/vanzandt/">autoproject:</ulink>
|
||||
In the authors words, <quote>autoproject - a script to start a
|
||||
programming project using &autoconf;, &automake;, and optionally
|
||||
a command line parser generator</quote>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -950,8 +1062,11 @@ clean:
|
|||
<para>
|
||||
|
||||
The official GNU &make; manual <ulink
|
||||
url="&gnu;manual/make/index.html">
|
||||
http://www.gnu.org/manual/make/index.html</ulink>
|
||||
url="&gnu;software/make/manual/index.html">
|
||||
http://www.gnu.org/software/make/manual/index.html</ulink>. You
|
||||
are encouraged to explore and write more complex rules, commands
|
||||
in the rules, conditional parts, transformation of text in
|
||||
&makefile;s etc., all of which are detailed in the manual.
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -960,8 +1075,11 @@ clean:
|
|||
<para>
|
||||
|
||||
The official &autoconf; manual <ulink
|
||||
url="&gnu;manual/autoconf/index.html">
|
||||
http://www.gnu.org/manual/autoconf/index.html</ulink>
|
||||
url="&gnu;software/autoconf/manual/autoconf-2.57/autoconf.html">
|
||||
http://www.gnu.org/software/autoconf/manual/autoconf-2.57/autoconf.html</ulink>.
|
||||
Take a look at the documentation of existing tests and learn how
|
||||
to write new &autoconf; macros and tests. The indices of the
|
||||
manual are great for reference.
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -969,9 +1087,12 @@ clean:
|
|||
<listitem>
|
||||
<para>
|
||||
|
||||
The official &automake; manual <ulink
|
||||
url="&gnu;manual/automake/index.html">
|
||||
http://www.gnu.org/manual/automake/index.html</ulink>
|
||||
Manuals of &automake; <ulink
|
||||
url="&gnu;software/automake/manual/index.html">
|
||||
http://www.gnu.org/software/automake/manual/index.html</ulink>.
|
||||
A few examples, alternative approaches to handling
|
||||
sub-directories, how various targets work, support for test
|
||||
suites etc.
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -980,8 +1101,8 @@ clean:
|
|||
<para>
|
||||
|
||||
The official &libtool; manual <ulink
|
||||
url="&gnu;manual/libtool/index.html">
|
||||
http://www.gnu.org/manual/libtool/index.html</ulink>
|
||||
url="&gnu;software/libtool/manual.html">
|
||||
http://www.gnu.org/software/libtool/manual.html</ulink>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -989,8 +1110,9 @@ clean:
|
|||
<listitem>
|
||||
<para>
|
||||
|
||||
The official &m4; manual <ulink url="&gnu;manual/m4/index.html">
|
||||
http://www.gnu.org/manual/m4/index.html</ulink>
|
||||
Yet another language to pick up. The &m4; manual with lots of
|
||||
examples is at <ulink url="&gnu;software/m4/manual/index.html">
|
||||
http://www.gnu.org/software/m4/manual/index.html</ulink>
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -1774,6 +1896,9 @@ clean:
|
|||
<!--
|
||||
|
||||
$Log$
|
||||
Revision 1.11 2003/11/20 20:48:49 appaji
|
||||
Finally, a neat structure to add the meat
|
||||
|
||||
Revision 1.10 2003/11/20 18:36:44 appaji
|
||||
Lots of minor changes, add about section
|
||||
|
||||
|
|
Loading…
Reference in New Issue