112Chapter4 • Using GNU make
###################################################
# Makefile created to demonstrate use of the make
# utility in the "Linux Development Platform" book.
#
# Author: Rafeeq Ur Rehman
# rr@conformix.net
###################################################
# Variable definition
OBJS = ftp.o common.o
HDRS = ftp.h common.h
CFLAGS = -g -O2
TARGETS = ftp
CC = gcc
# Default Target
ftp: $(OBJS) $(HDRS)
$(CC) $(OBJS) -o ftp
ftp.o: ftp.c $(HDRS)
$(CC) $(CFLAGS) -c ftp.c
common.o: common.c common.h
$(CC) $(CFLAGS) -c common.c
clean:
rm -f $(TARGETS) $(OBJS)
This makefile has initial comments that show information about the file. After that, vari-
ables are defined. The rule to build default target is listed next. This rule has two dependencies
which are defined by variables
$(OBJS)
and
$(HDRS)
. Rules to build the object files are
listed after the default rule. The last rule,
clean
, is used to remove files created during the
make
process so that the directory contains only the initial source code files when you invoked
this rule for the first time. This rule has no dependency, so the
rm
command is guaranteed to be
executed.
When building the default target
ftp
,
make
checks the dependencies. For this it expands
two variables
$(OBJS)
and
$(HDRS)
. After expansion,
make
finds out that the target is
dependent upon the following four files.
1.
ftp.o
2.
ftp.h
3.
common.o
4.
common.h
Next Page >>
<< Previous Page
Back to the Table of Contents