[PATCH 0/6] Assorted makefile cleanups
These are not directly apropose anything, but I encountered a number of minor uglies in the Makefiles while I was working on other stuff, so heres a bunch of cleanups. David Gibson (6): Makefile: Avoid using wildcard sources Makefile: Use $(BIN) and $(MANPAGES) variable to simplify several targets Makefile: Simplify pasta* targets with a pattern rule Makefile: Tweak $(RM) usage Makefile: Don't create extraneous -.s file Makefile: Spell prefix as PREFIX Makefile | 77 +++++++++++++++++++++++++++--------------------------- seccomp.sh | 5 ++-- 2 files changed, 41 insertions(+), 41 deletions(-) -- 2.36.1
The passt/pasta Makefile makes fairly heavy use of GNU make's $(wildcard)
function to locate the sources and headers to build. Using wildcards for
the things to compile is usually a bad idea though: if somehow you end up
with a .c or .h file in your tree you didn't expect it can misbuild in an
exceedingly confusing way. In particular this can sometimes happen if
switching between releases / branches where files have been added or
removed without 100% cleaning the tree.
It also makes life a bit complicated if building multiple different
binaries in the same tree: we already have some rather awkward
$(filter-out) constructions to avoid including qrap.c in the passt build.
Replace use of $(wildcard) with the more idiomatic approach of defining
variables listing all the relevant source files then using that throughout.
In the rule for seccomp.h there was also a bare "*.c" which caused make to
always rebuild that target. Fix that as well.
Similarly, seccomp.sh uses a wildcard to locate the sources, which is
unwise for the same reasons. Make it take the sources to examine on the
command line instead, and have the Makefile pass them in from the same
variables.
Signed-off-by: David Gibson
On Tue, 14 Jun 2022 15:12:21 +1000
David Gibson
The passt/pasta Makefile makes fairly heavy use of GNU make's $(wildcard) function to locate the sources and headers to build. Using wildcards for the things to compile is usually a bad idea though: if somehow you end up with a .c or .h file in your tree you didn't expect it can misbuild in an exceedingly confusing way. In particular this can sometimes happen if switching between releases / branches where files have been added or removed without 100% cleaning the tree.
Thanks for fixing this, I have to admit I hit this very issue all the time ;) -- Stefano
There are several places which explicitly list the various generated binaries, even though a $(BIN) variable already lists them. There are several more places that list all the manpage files, introduce a $(MANPAGES) variable to remove that repetition as well. Tweak the generation of pasta.1 as a link to passt.1 so it's not just made as a side effect of the pasta target. --- Makefile | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index f7ca3ef..88a3f47 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,8 @@ PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c icmp.c igmp.c \ QRAP_SRCS = qrap.c SRCS = $(PASST_SRCS) $(QRAP_SRCS) +MANPAGES = passt.1 pasta.1 qrap.1 + PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h icmp.h \ ndp.h netlink.h packet.h passt.h pasta.h pcap.h siphash.h \ tap.h tcp.h tcp_splice.h udp.h util.h @@ -83,13 +85,13 @@ endif prefix ?= /usr/local ifeq ($(TARGET_ARCH),X86_64) -all: passt passt.avx2 pasta pasta.avx2 qrap BIN := passt passt.avx2 pasta pasta.avx2 qrap else -all: passt pasta qrap BIN := passt pasta qrap endif +all: $(BIN) $(MANPAGES) + static: CFLAGS += -static -DGLIBC_NO_STATIC_NSS static: clean all @@ -110,6 +112,8 @@ pasta.avx2: passt.avx2 pasta: passt ln -s passt pasta + +pasta.1: passt.1 ln -s passt.1 pasta.1 qrap: $(QRAP_SRCS) passt.h @@ -123,28 +127,22 @@ valgrind: all .PHONY: clean clean: - -${RM} passt passt.avx2 *.o seccomp.h qrap pasta pasta.avx2 pasta.1 \ + -${RM} $(BIN) *.o seccomp.h pasta.1 \ passt.tar passt.tar.gz *.deb *.rpm -install: $(BIN) +install: $(BIN) $(MANPAGES) mkdir -p $(DESTDIR)$(prefix)/bin $(DESTDIR)$(prefix)/share/man/man1 cp -d $(BIN) $(DESTDIR)$(prefix)/bin - cp -d passt.1 pasta.1 qrap.1 $(DESTDIR)$(prefix)/share/man/man1 + cp -d $(MANPAGES) $(DESTDIR)$(prefix)/share/man/man1 uninstall: - -${RM} $(DESTDIR)$(prefix)/bin/passt - -${RM} $(DESTDIR)$(prefix)/bin/passt.avx2 - -${RM} $(DESTDIR)$(prefix)/bin/pasta - -${RM} $(DESTDIR)$(prefix)/bin/pasta.avx2 - -${RM} $(DESTDIR)$(prefix)/bin/qrap - -${RM} $(DESTDIR)$(prefix)/share/man/man1/passt.1 - -${RM} $(DESTDIR)$(prefix)/share/man/man1/pasta.1 - -${RM} $(DESTDIR)$(prefix)/share/man/man1/qrap.1 + -${RM} $(BIN:%=$(DESTDIR)$(prefix)/bin/%) + -${RM} $(MANPAGES:%=$(DESTDIR)$(prefix)/share/man/man1/%) pkgs: static tar cf passt.tar -P --xform 's//\/usr\/bin\//' $(BIN) tar rf passt.tar -P --xform 's//\/usr\/share\/man\/man1\//' \ - passt.1 pasta.1 qrap.1 + $(MANPAGES) gzip passt.tar EMAIL="sbrivio@redhat.com" fakeroot alien --to-deb \ --description="User-mode networking for VMs and namespaces" \ -- 2.36.1
On Tue, 14 Jun 2022 15:12:22 +1000
David Gibson
There are several places which explicitly list the various generated binaries, even though a $(BIN) variable already lists them. There are several more places that list all the manpage files, introduce a $(MANPAGES) variable to remove that repetition as well.
This also needs (sorry ;)) diff --git a/test/distro/debian b/test/distro/debian index f748dea..239e225 100644 --- a/test/distro/debian +++ b/test/distro/debian @@ -39,7 +39,7 @@ endef hostb ./passt -P __PIDFILE__ & sleep 1 host echo -hout GUEST_FILES ls -1 *.c *.h *.sh Makefile | tr '\n' ' '; echo +hout GUEST_FILES ls -1 *.c *.h *.sh passt.1 qrap.1 Makefile | tr '\n' ' '; echo test Debian GNU/Linux 8 (jessie), amd64 diff --git a/test/distro/fedora b/test/distro/fedora index 7a5eaef..013cb45 100644 --- a/test/distro/fedora +++ b/test/distro/fedora @@ -60,7 +60,7 @@ hostb ./passt -P __PIDFILE__ & sleep 1 host echo hout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | head -1 -hout GUEST_FILES ls -1 *.c *.h *.sh Makefile | tr '\n' ' '; echo +hout GUEST_FILES ls -1 *.c *.h *.sh passt.1 qrap.1 Makefile | tr '\n' ' '; echo test Fedora 26, x86_64 diff --git a/test/distro/opensuse b/test/distro/opensuse index 39f059a..3d71c42 100644 --- a/test/distro/opensuse +++ b/test/distro/opensuse @@ -39,7 +39,7 @@ hostb ./passt -P __PIDFILE__ & sleep 1 host echo hout DNS6 sed -n 's/^nameserver \([^:]*:\)\([^%]*\).*/\1\2/p' /etc/resolv.conf | head -1 -hout GUEST_FILES ls -1 *.c *.h *.sh Makefile | tr '\n' ' '; echo +hout GUEST_FILES ls -1 *.c *.h *.sh passt.1 qrap.1 Makefile | tr '\n' ' '; echo test OpenSUSE Leap 15.1 diff --git a/test/distro/ubuntu b/test/distro/ubuntu index c9a2b4d..c3d1630 100644 --- a/test/distro/ubuntu +++ b/test/distro/ubuntu @@ -38,7 +38,7 @@ endef hostb ./passt -P __PIDFILE__ & sleep 1 host echo -hout GUEST_FILES ls -1 *.c *.h *.sh Makefile | tr '\n' ' '; echo +hout GUEST_FILES ls -1 *.c *.h *.sh passt.1 qrap.1 Makefile | tr '\n' ' '; echo test Ubuntu 14.04.5 LTS (Trusty Tahr), amd64 ...added. -- Stefano
pasta, pasta.avx2 and pasta.1 are all generated as a link to the
corresponding passt file. We can consolidate the 3 rules for these targets
into a single pattern rule.
Signed-off-by: David Gibson
The use of rm commands in the clean and uninstall targets adds an explicit
leading - to ignore errors. However the built-in RM variable in make is
actually "rm -f" which already ignores errors, so the - isn't neccessary.
Also replace ${RM} with $(RM) which is the more conventional form in
Makefiles.
Signed-off-by: David Gibson
In order to probe availability of certain features the Makefile test
compiles a handful of tiny snippets, feeding those in from stdin. However
in one case - the one for -fstack-protector - it forgets to redirect the
output to stdout, meaning it creates a stray '-.s' file when make is
invoked (even make clean).
Signed-off-by: David Gibson
Makefile conventions (at least in the GNUish world) tend to control the
base install directory with the variable $(PREFIX) (all caps). The passt
Makefile has the same thing but in lower case $(prefix). Capitalize it to
match conventions.
Signed-off-by: David Gibson
On Tue, 14 Jun 2022 15:12:26 +1000
David Gibson
Makefile conventions (at least in the GNUish world) tend to control the base install directory with the variable $(PREFIX) (all caps). The passt Makefile has the same thing but in lower case $(prefix). Capitalize it to match conventions.
I've been wondering about this when I first added it to the Makefile, and I couldn't really find a rationale for it. From the documentation of GNU make: http://www.gnu.org/software/make/manual/make.html#Directory-Variables http://www.gnu.org/software/make/manual/make.html#DESTDIR prefix is (conventionally) lowercase, DESTDIR is uppercase, so I'd stick to that. I guess there's just some historic reason behind it. Some Makefiles of long-standing projects use prefix, some PREFIX. By the way, the rest of the series all look good to me (and is very appreciated!). -- Stefano
On Tue, Jun 14, 2022 at 04:45:05PM +0200, Stefano Brivio wrote:
On Tue, 14 Jun 2022 15:12:26 +1000 David Gibson
wrote: Makefile conventions (at least in the GNUish world) tend to control the base install directory with the variable $(PREFIX) (all caps). The passt Makefile has the same thing but in lower case $(prefix). Capitalize it to match conventions.
I've been wondering about this when I first added it to the Makefile, and I couldn't really find a rationale for it. From the documentation of GNU make:
http://www.gnu.org/software/make/manual/make.html#Directory-Variables http://www.gnu.org/software/make/manual/make.html#DESTDIR
prefix is (conventionally) lowercase, DESTDIR is uppercase, so I'd stick to that. I guess there's just some historic reason behind it. Some Makefiles of long-standing projects use prefix, some PREFIX.
Huh.. interesting. I guess the things I've looked at personally must have tended towards PREFIX. I'd assumed the GNU conventions specified that, but apparently not. Ok, let's drop this one.
By the way, the rest of the series all look good to me (and is very appreciated!).
-- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
On Tue, 14 Jun 2022 15:12:20 +1000
David Gibson
These are not directly apropose anything, but I encountered a number of minor uglies in the Makefiles while I was working on other stuff, so heres a bunch of cleanups.
David Gibson (6): Makefile: Avoid using wildcard sources Makefile: Use $(BIN) and $(MANPAGES) variable to simplify several targets Makefile: Simplify pasta* targets with a pattern rule Makefile: Tweak $(RM) usage Makefile: Don't create extraneous -.s file Makefile: Spell prefix as PREFIX
Makefile | 77 +++++++++++++++++++++++++++--------------------------- seccomp.sh | 5 ++-- 2 files changed, 41 insertions(+), 41 deletions(-)
Series applied, along with the previous ones, thanks! -- Stefano
participants (2)
-
David Gibson
-
Stefano Brivio