The make Rules113
Now
make
also finds out that there are other rules to build
ftp.o
and
common.o
files.
If these two files are not up-to-date,
make
rebuilds these object files using corresponding rules.
For example, if
common.c
file has been changed since
make
built
common.o
last time,
make
will rebuild it. After checking dependencies,
make
will build
ftp
if any of the dependency is
newer than the ftp file or ftp file does not exist.
If you want to remove the target file and the object files, you can use the
make clean
command that invokes the
clean
rule. This rule has no dependency so the
rm
command will
always execute, removing the ftp and any object files.
4.2.3Another Example of Makefile
The following Makefile is a little bit bigger and is used to build three targets. These are as
follows:
1.
The
ftp server
2.
The
tftp server
3.
The
dnsresolver
Before going into detail of how it is done, let us look at the Makefile itself. It is listed
below.
###################################################
# Makefile created to demonstrate use of the make
# utility in the "Linux Development Platform" book.
#
# Author: Rafeeq Ur Rehman
# rr@conformix.com
###################################################
# Variable definition
SRCS = ftp.c tftp.c dnsresolver.c common.c
OBJS = ftp.o tftp.o dnsresolver.o common.o
FTPOBJS = ftp.o common.o
FTPHDRS = ftp.h common.h
TFTPOBJS = tftp.o common.o
TFTPHDRS = tftp.h common.h
DNSRESOLVEROBJS = dnsresolver.o common.o
DNSRESOLVERHDRS = dnsresolver.h common.h
CC = gcc
CFLAGS = -g -O2
LDFLAGS = -static
TARGETS = ftp tftp dnsresolver
INSTALLDIR = /root
# Default Target