126Chapter4 • Using GNU make
install:
cp $(LIBCOMMON) $(INSTALLDIR)
clean:
rm -f $(OBJS) $(LIBCOMMON) *~
This makefile builds an archive library file
libcommon.a
, which is the default target.
Note that this makefile can also be used as a standalone in this directory so that if someone is
working only on the library part of the project, he/she can use this makefile to test only the com-
pilation and library building process. This is useful because each developer can stay in his/her
own directory without building all parts of the project from the main makefile in the top direc-
tory.
4.4.3Makefile in the ftp-dir Directory
The makefile in the
ftp-dir
directory builds the
ftp
target. It compiles and then stati-
cally links the object files using the library we built in
common-dir
directory. This makefile is
shown below.
# Variable definition
SRCS = ftp.c
OBJS = ftp.o
HDRS = ftp.h
CC = gcc
CFLAGS = -g -O2 -c
INCLUDES = -I../common-dir
LDFLAGS = -static -L$(LIBSDIR)
LIBSDIR = ../common-dir
INSTALLDIR = /root
# Default Target
ftp: $(SRCS) $(HDRS)
$(CC) $(CFLAGS) $(INCLUDES) ftp.c
$(CC) $(LDFLAGS) $(COMMON) $(OBJS) -lcommon -o ftp
install:
cp ftp $(INSTALLDIR)
clean:
@echo "Deleting files ..."
rm -f ftp $(OBJS) *~
Next Page >>
<< Previous Page
Back to the Table of Contents