Skip to content

Commit

Permalink
makefiles: make all, clean and distclean PHONY
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kmk3 committed Mar 1, 2021
1 parent 7e3888c commit 2465f92
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; \
Expand All @@ -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; \
Expand Down
3 changes: 3 additions & 0 deletions src/bash_completion/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: firejail.bash_completion

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fbuilder/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fbuilder

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fcopy/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fcopy

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/firecfg/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: firecfg

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/firejail/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: firejail

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/firemon/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: firemon

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fldd/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fldd

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fnet/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fnet

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fnetfilter/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fnetfilter

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fsec-optimize/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fsec-optimize

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fsec-print/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fsec-print

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/fseccomp/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: fseccomp

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/ftee/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: ftee

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/jailtest/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: jailtest

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/lib/Makefile.in
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/libpostexecseccomp/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/libtrace/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/libtracelog/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/man/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
.PHONY: all
all: firecfg.man firejail.man firejail-login.man firejail-users.man firejail-profile.man firemon.man jailtest.man

include ../common.mk

%.man: %.txt
gawk -f ./preproc.awk -- $(MANFLAGS) < $< > $@

.PHONY: clean
clean:; rm -fr *.man

.PHONY: distclean
distclean: clean
rm -fr Makefile
3 changes: 3 additions & 0 deletions src/profstats/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: profstats

include ../common.mk
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/zsh_completion/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all
all: _firejail

include ../common.mk
Expand All @@ -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
2 changes: 2 additions & 0 deletions test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2465f92

Please sign in to comment.