550
◾
Linux with Operating System Concepts
ignore errors that
may occur during compilation, -k to continue to work as much as pos-
sible even if errors arise, and –I
dir
to specify an include directory. If there are include state-
ments, this directory is searched in place of the current directory. As with the configure
step, the make step may take seconds or minutes and will
result in numerous messages
being displayed.
Most makefiles are written in parts. These parts may include the compilation section,
an installation section, a clean-up section, and a tar section. To run the compilation sec-
tion,
just issue the
make
command by itself. To perform the installation separately (which
is usually required), use the command
make
install
. If you have already attempted
to compile and/or install the software and it failed, before trying again,
issue
make
clean
. Finally, if you want to take the files and wrap them up (or back up) in a tar file, use
make
tar
. The command
make
all
should perform a
make
clean
,
make
, and
make
install
all in one. Not all makefiles will have all of these sections and you can find out
which sections are available in the
README
file.
Here, we examine the components of a typical
makefile
, albeit a very simple one.
Interspersed
between the lines of the
makefile
file are explanations of the script’s code.
CC
=
gcc
FLAGS
=
-Wall
LIBS
=
-lcrypt
LIBM
=
-lm
The above lines define several compilation variables.
gcc
is the GNUs C/C
++
compiler.
This will be the command that the makefile eventually issues to compile the source code.
–Wall
is a popular option for the compiler, which enables all warnings. LIBS and LIBM
define library options.
INSTALL_PREFIX
=
/usr/local
BIN_DIR
=
/bin
MAN_DIR
=
/man/man1
BIN_DIR_D
=
/sbin
These variables define installation directories. The BIN_DIR_D is used to store the dae-
mon version of the program assuming that you want to create both a normal executable
and a daemon.
PROGRAM_NAME
=
. . .
SOURCES
=
. . .
HEADERS
=
. . .
OBJECTS
=
. . .
These four variables define the names of the files to be used by gcc.
Specifically,
PROGRAM_NAME is the English description of the program and will be the name of the
compiled file. SOURCES are the C/C
++
source code files (.c or.cpp). HEADERS lists one or
Software Installation and Maintenance
◾
551
more header files (.h). Finally, OBJECTS are files that store already-compiled C/C
++
code.
These are known as object files (.o). The object files are often used as libraries, containing
the compiled code of commonly referenced functions.
In
this case, let us assume that we have the following definitions for SOURCES and
OBJECTS, respectively:
SOURCES
=
file1.cpp file2.cpp file3.cpp
OBJECTS
=
file4.o file5.o file6.o
Continuing with our makefile, we reach the portion that actually performs the
operation(s) desired.
all:
Do'stlaringiz bilan baham: