Beginning Linux Programming by Neil Matthew & Richard Stones

Beginning Linux Programming by Neil Matthew & Richard Stones

Author:Neil Matthew & Richard Stones
Language: eng
Format: mobi, epub
Publisher: Wiley Publishing, Inc.
Published: 2011-04-13T16:00:00+00:00


Multiple Targets

It’s often useful to make more than a single target file, or to collect several groups of commands into a single place. You can extend your makefile to do this. In the following example, you add a clean option that removes unwanted objects and an install option that moves the finished application to a different directory.

Try It Out Multiple Targets

Here’s the next version of the makefile, Makefile3:

all: myapp

# Which compiler

CC = gcc

# Where to install

INSTDIR = /usr/local/bin

# Where are include files kept

INCLUDE = .

# Options for development

CFLAGS = -g -Wall –ansi

# Options for release

# CFLAGS = -O -Wall –ansi

myapp: main.o 2.o 3.o

$(CC) -o myapp main.o 2.o 3.o

main.o: main.c a.h

$(CC) -I$(INCLUDE) $(CFLAGS) -c main.c

2.o: 2.c a.h b.h

$(CC) -I$(INCLUDE) $(CFLAGS) -c 2.c

3.o: 3.c b.h c.h

$(CC) -I$(INCLUDE) $(CFLAGS) -c 3.c

clean:

-rm main.o 2.o 3.o

install: myapp

@if [ -d $(INSTDIR) ]; \

then \

cp myapp $(INSTDIR);\

chmod a+x $(INSTDIR)/myapp;\

chmod og-w $(INSTDIR)/myapp;\

echo "Installed in $(INSTDIR)";\

else \

echo "Sorry, $(INSTDIR) does not exist";\

fi



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.