128Chapter4 • Using GNU make
# Default Target
dnsresolver: $(SRCS) $(HDRS)
$(CC) $(CFLAGS) $(INCLUDES) dnsresolver.c
$(CC) $(LDFLAGS) $(COMMON) $(OBJS) -lcommon -o dnsresolver
install:
cp dnsresolver $(INSTALLDIR)
clean:
@echo "Deleting files ..."
rm -f dnsresolver $(OBJS) *~
4.4.6Building Everything
After going through these makefiles, you are ready to build the targets. Go to the top
directory and run the
make
command from there. It will read the makefile in the top directory
and will try to build all targets. A typical output of this action is as follows:
[root@conformix make]# make
#######################################
### BUILDING ALL TARGETS ###
#######################################
for i in common-dir ftp-dir tftp-dir dns-dir ; do \
( cd $i ; make ) ; \
done
make[1]: Entering directory `/root/make/common-dir'
gcc -g -O2 -c common.c
ar -cr libcommon.a common.o
ranlib libcommon.a
make[1]: Leaving directory `/root/make/common-dir'
make[1]: Entering directory `/root/make/ftp-dir'
gcc -g -O2 -c -I../common-dir ftp.c
gcc -static -L../common-dir ftp.o -lcommon -o ftp
make[1]: Leaving directory `/root/make/ftp-dir'
make[1]: Entering directory `/root/make/tftp-dir'
gcc -g -O2 -c -I../common-dir tftp.c
gcc -static -L../common-dir tftp.o -lcommon -o tftp
make[1]: Leaving directory `/root/make/tftp-dir'
make[1]: Entering directory `/root/make/dns-dir'
gcc -g -O2 -c -I../common-dir dnsresolver.c
gcc -static -L../common-dir dnsresolver.o -lcommon -o
dnsresolver
make[1]: Leaving directory `/root/make/dns-dir'
[root@conformix make]#