Re: [dev] Special target ".POSIX" in Makefiles

From: Markus Wichmann <>
Date: Mon, 3 Jan 2022 11:16:48 +0100

On Sat, Jan 01, 2022 at 08:09:38PM +0100, Mattias Andre wrote:
> CC = c99
> # Required as POSIX doesn't mandate that it is defined by default
> OBJ =\
> alpha.o\
> beta.o\
> gamma.o
> LINUX_AMD64_OBJ = $(OBJ:.o=.linux-amd64-o)
> OPENBSD_AMD64_OBJ = $(OBJ:.o=.openbsd-amd64-o)
> all: myproj-linux-amd64 myproj-openbsd-amd64
> myproj-linux-amd64: $(LINUX_AMD64_OBJ)
> myproj-openbsd-amd64: $(OPENBSD_AMD64_OBJ)
> .c.linux-amd64-o:
> $(CC) -c -o $_AT_ $< $(CFLAGS_LINUX_AMD64) $(CPPFLAGS_LINUX_AMD64)
> .c.openbsd-amd64-o:
> .SUFFIXES: .c .linux-amd64-o .openbsd-amd64-o
> # NB! Cannot use .linux-amd64.o and .openbsd-amd64.o
> # as POSIX requires a dot at the beginning but
> # forbids any additional dot

OK, that is one way. I do wonder how you would handle configurable
dependencies. I have always been partial to the Linux Kconfig way of
doing it, but it requires +=:

obj-y = alpha.o beta.o gamma.o
obj-$(CONFIG_FOO) += foo.o
obj-$(CONFIG_BAR) += bar.o
obj-$(CONFIG_BAZ) += baz.o

dir.o: $(obj-y)
        ld -r -o $_AT_ $^

With your scheme, this one in particular would blow up due to
combinatorics (need a list for none, FOO, BAR, BAZ, FOO+BAR, FOO+BAZ,
BAR+BAZ, and FOO+BAR+BAZ. Now imagine this for the hundreds of options
Linux has)

But with the advent of ninja (yes, I know this list's opinion of C++ and
Google in particular, but you cannot deny that Ninja is FAST), I have
come around to the idea of configure scripts creating makefiles (or
similar). And then you can generate makefiles in as complicated a manner
as you like.

Indeed, if the makefile is generated, there is little need for suffix
rules at all. You can just make direct rules for everything. Repetition
is no problem if the code generating the Makefile is readable. And then
you can even build with make -r, because you don't need the default
database, either. And -r saves time in some implementations.

Received on Mon Jan 03 2022 - 11:16:48 CET

This archive was generated by hypermail 2.3.0 : Mon Jan 03 2022 - 11:24:07 CET