makefiles: make all, clean and distclean PHONY

Avoid a stat() call for each affected target and also potentially speed
up parallel builds.

From the GNU make manual[1]:

> Phony targets are also useful in conjunction with recursive
> invocations of make (see Recursive Use of make).  In this situation
> the makefile will often contain a variable which lists a number of
> sub-directories to be built.

[...]

> The implicit rule search (see Implicit Rules) is skipped for .PHONY
> targets.  This is why declaring a target as .PHONY is good for
> performance, even if you are not worried about the actual file
> existing.

Commands used to search, replace and cleanup:

    $ find -type f -name '*Makefile.in' -exec sed -i.bak \
      -e 's/^all:/.PHONY: all\nall:/' \
      -e 's/^clean:/.PHONY: clean\nclean:/' \
      -e 's/^distclean:/.PHONY: distclean\ndistclean:/' '{}' +
    $ find -type f -name '*Makefile.in.bak' -exec rm '{}' +

[1]: https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
This commit is contained in:
Kelvin M. Klann 2021-02-12 05:25:23 -03:00
parent 7e3888c7ff
commit 2465f9248e
23 changed files with 68 additions and 0 deletions

View file

@ -23,6 +23,7 @@ endif
COMPLETIONDIRS = src/zsh_completion src/bash_completion
.PHONY: all
all: all_items mydirs $(MAN_TARGET) filters
APPS = src/firecfg/firecfg src/firejail/firejail src/firemon/firemon src/profstats/profstats src/jailtest/jailtest
SBOX_APPS = src/fbuilder/fbuilder src/ftee/ftee
@ -72,6 +73,7 @@ seccomp.mdwx: src/fseccomp/fseccomp
seccomp.mdwx.32: src/fseccomp/fseccomp
src/fseccomp/fseccomp memory-deny-write-execute.32 seccomp.mdwx.32
.PHONY: clean
clean:
for dir in $$(dirname $(ALL_ITEMS)) $(MYDIRS); do \
$(MAKE) -C $$dir clean; \
@ -91,6 +93,7 @@ clean:
rm -f test/sysutils/firejail_t*
cd test/compile; ./compile.sh --clean; cd ../..
.PHONY: distclean
distclean: clean
for dir in $$(dirname $(ALL_ITEMS)) $(MYDIRS); do \
$(MAKE) -C $$dir distclean; \

View file

@ -1,3 +1,4 @@
.PHONY: all
all: firejail.bash_completion
include ../common.mk
@ -7,8 +8,10 @@ firejail.bash_completion: firejail.bash_completion.in
sed "s|_SYSCONFDIR_|$(sysconfdir)|" < $@.tmp > $@
rm $@.tmp
.PHONY: clean
clean:
rm -fr firejail.bash_completion
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fbuilder
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fbuilder: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fbuilder *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fcopy
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fcopy: $(OBJS) ../lib/common.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fcopy *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: firecfg
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
firecfg: $(OBJS) ../lib/common.o ../lib/firejail_user.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/firejail_user.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o firecfg *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: firejail
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
firejail: $(OBJS) ../lib/libnetlink.o ../lib/common.o ../lib/ldd_utils.o ../lib/firejail_user.o ../lib/errno.o ../lib/syscall.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/ldd_utils.o ../lib/firejail_user.o ../lib/errno.o ../lib/syscall.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o firejail *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: firemon
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
firemon: $(OBJS) ../lib/common.o ../lib/pid.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/pid.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o firemon *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fldd
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fldd: $(OBJS) ../lib/common.o ../lib/ldd_utils.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/ldd_utils.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fldd *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fnet
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fnet: $(OBJS) ../lib/common.o ../lib/libnetlink.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/libnetlink.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fnet *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fnetfilter
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fnetfilter: $(OBJS) ../lib/common.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fnetfilter *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fsec-optimize
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fsec-optimize: $(OBJS) ../lib/common.o ../lib/libnetlink.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/errno.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fsec-optimize *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fsec-print
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fsec-print: $(OBJS) ../lib/common.o ../lib/libnetlink.o ../lib/errno.o ../lib/syscall.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/errno.o ../lib/syscall.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fsec-print *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: fseccomp
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
fseccomp: $(OBJS) ../lib/common.o ../lib/errno.o ../lib/syscall.o
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/errno.o ../lib/syscall.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o fseccomp *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: ftee
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
ftee: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o ftee *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: jailtest
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
jailtest: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) ../lib/common.o ../lib/pid.o $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o jailtest *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,11 +1,14 @@
include ../common.mk
.PHONY: all
all: $(OBJS)
%.o : %.c $(H_FILE_LIST)
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@
.PHONY: clean
clean:; rm -fr $(OBJS) *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -11,6 +11,7 @@ BINOBJS = $(foreach file, $(OBJS), $file)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now
.PHONY: all
all: libpostexecseccomp.so
%.o : %.c $(H_FILE_LIST) ../include/seccomp.h ../include/rundefs.h
@ -19,7 +20,9 @@ all: libpostexecseccomp.so
libpostexecseccomp.so: $(OBJS)
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
.PHONY: clean
clean:; rm -fr $(OBJS) libpostexecseccomp.so *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -11,6 +11,7 @@ BINOBJS = $(foreach file, $(OBJS), $file)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now
.PHONY: all
all: libtrace.so
%.o : %.c $(H_FILE_LIST)
@ -19,7 +20,9 @@ all: libtrace.so
libtrace.so: $(OBJS)
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
.PHONY: clean
clean:; rm -fr $(OBJS) libtrace.so *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -11,6 +11,7 @@ BINOBJS = $(foreach file, $(OBJS), $file)
CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
LDFLAGS += -pie -fPIE -Wl,-z,relro -Wl,-z,now
.PHONY: all
all: libtracelog.so
%.o : %.c $(H_FILE_LIST) ../include/rundefs.h
@ -19,7 +20,9 @@ all: libtracelog.so
libtracelog.so: $(OBJS)
$(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
.PHONY: clean
clean:; rm -fr $(OBJS) libtracelog.so *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: firecfg.man firejail.man firejail-login.man firejail-users.man firejail-profile.man firemon.man jailtest.man
include ../common.mk
@ -5,7 +6,9 @@ include ../common.mk
%.man: %.txt
gawk -f ./preproc.awk -- $(MANFLAGS) < $< > $@
.PHONY: clean
clean:; rm -fr *.man
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: profstats
include ../common.mk
@ -8,7 +9,9 @@ include ../common.mk
profstats: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS)
.PHONY: clean
clean:; rm -fr *.o profstats *.gcov *.gcda *.gcno *.plist
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -1,3 +1,4 @@
.PHONY: all
all: _firejail
include ../common.mk
@ -7,8 +8,10 @@ _firejail: _firejail.in
sed "s|_SYSCONFDIR_|$(sysconfdir)|" < $@.tmp > $@
rm $@.tmp
.PHONY: clean
clean:
rm -fr _firejail
.PHONY: distclean
distclean: clean
rm -fr Makefile

View file

@ -5,8 +5,10 @@ $(TESTS):
cd $@ && ./$@.sh 2>&1 | tee $@.log
cd $@ && grep -a TESTING $@.log && grep -a -L "TESTING ERROR" $@.log
.PHONY: clean
clean:
for test in $(TESTS); do rm -f "$$test/$$test.log"; done
.PHONY: distclean
distclean: clean
rm -f Makefile