Working with Multiple Makefiles and Directories129
During the process of building all targets, you can see how
make
enters and leaves each
directory and builds targets in each directory.
4.4.7Cleaning Everything
The cleaning process is done the same way as we built all targets. Output of this process is
shown below. Again you can see that
make
enters each directory, runs the
make clean
com-
mand and then leaves the directory. The
clean
rule in makefiles present in each subdirectory is
used to remove files.
[root@conformix make]# make clean
rm -f *~
for i in common-dir ftp-dir tftp-dir dns-dir ; do \
( cd $i ; make clean) ; \
done
make[1]: Entering directory `/root/make/common-dir'
rm -f common.o libcommon.a *~
make[1]: Leaving directory `/root/make/common-dir'
make[1]: Entering directory `/root/make/ftp-dir'
Deleting files ...
rm -f ftp ftp.o *~
make[1]: Leaving directory `/root/make/ftp-dir'
make[1]: Entering directory `/root/make/tftp-dir'
Deleting files ...
rm -f tftp tftp.o *~
make[1]: Leaving directory `/root/make/tftp-dir'
make[1]: Entering directory `/root/make/dns-dir'
Deleting files ...
rm -f dnsresolver dnsresolver.o *~
make[1]: Leaving directory `/root/make/dns-dir'
[root@conformix make]#
The
make clean
command finishes its operation after going through all subdirectories.
4.4.8Making Individual Targets
Instead of using a single big makefile, you can also build individual targets using smaller
makefiles. While building only one target,
make
will go into only that directory and build that
target. The following output shows the output of the
make
command when you build only the
ftp target.
[root@conformix make]# make ftp
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'
[root@conformix make]#