01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CH04.fm Page 111 Monday, October 7, 2002 8:54 PM<br />

<strong>The</strong> make Rules 111<br />

Comm<strong>and</strong> Echoing<br />

By default all comm<strong>and</strong>s in the makefile are echoed to st<strong>and</strong>ard output as these are executed.<br />

This provides information about the activity of make as it is going through the makefile.<br />

However you can suppress the comm<strong>and</strong> echo by starting comm<strong>and</strong>s with the character @.<br />

This is especially useful in printing information from within the makefile using the echo<br />

comm<strong>and</strong>. For example, you can create a makefile that prints information before it starts executing.<br />

A typical rule in the makefile that displays information about the object before executing<br />

any other comm<strong>and</strong> follows. It displays a line showing that make is going to build FTP:<br />

ftp: $(SRCS) $(HDRS)<br />

@echo "Building FTP"<br />

@$(CC) $(CFLAGS) $(INCLUDES) ftp.c<br />

@$(CC) $(LDFLAGS) $(COMMON) $(OBJS) -lcommon -o ftp<br />

When make reads this file, it displays the following output:<br />

[root@conformix ftp-dir]# make ftp<br />

Building FTP<br />

[root@conformix ftp-dir]#<br />

If you don’t insert the @ characters in this file, the result will be as follows. You can easily<br />

find the difference between this <strong>and</strong> the earlier output of the make comm<strong>and</strong>.<br />

[root@conformix ftp-dir]# make ftp<br />

echo "Building FTP"<br />

Building FTP<br />

gcc -g -O2 -c -I../common-dir ftp.c<br />

gcc -static -L../common-dir ftp.o -lcommon -o ftp<br />

[root@conformix ftp-dir]#<br />

N O T E <strong>The</strong>re are other ways to suppress the comm<strong>and</strong><br />

echo. One of these is the use of –s or –silent flag on the<br />

comm<strong>and</strong> line. However the most common method is the use of<br />

the @ character.<br />

Rules with no Dependencies<br />

Many rules are used with no dependencies. <strong>The</strong>se rules are used to execute comm<strong>and</strong>s<br />

without looking into any dependencies. Comm<strong>and</strong>s in these rules are guaranteed to be executed.<br />

4.2.2 A Basic Makefile<br />

Let us start with a simple makefile shown below. This makefile is used to build ftp,<br />

which is the default target.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!