On Thu, 2024-12-19 at 12:17 -0600, Eric Blake wrote:
> Currently GNU make does not conform to the required .c.o inference
> rule because it adds a -o option.

Technically, make's built-in recipe for .c.o is:

  $(COMPILE.c) $(OUTPUT_OPTION) $<

where OUTPUT_OPTION is set to "-o $@" if GNU Make's configure-time
check determined that cc supports the -o option, and empty otherwise.

This has always been hinky because obviously just because the cc that
configure discovered at build time supports (or not) -o, doesn't mean
that whatever C compiler you end up using in your makefile does too (or
doesn't either).  But, it works (probably because there hasn't been a C
compiler that _didn't_ handle -o for decades).

Note, your example is wrong because the POSIXLY_CORRECT environment
variable doesn't control whether make is supposed to run in POSIX mode
or not (that would be completely unworkable, if the setting/unsetting
an environment variable changed the way make interpreted the current
makefile!)

You have to set the .POSIX: special target in your makefile if you want
it to have POSIX syntax; something like:

$ touch foo.c
$ echo '.POSIX:' | make -f- -n foo.o

Unfortunately this gives the same result.  There is actually code in
GNU Make to reset OUTPUT_OPTION to empty if POSIX is specified... but
it's commented out.  I apparently added it, and commented it out, back
in 2006 and the explanation 2006 me gave makes no sense to 2024 me, so
one of us is dumb :).

In the abstract I would not have a problem with uncommenting this code,
assuming I can come to grips with why I commented it out before.


> What's worse, the addition of a -o rule causes interesting effects;
> $< contains a name with a /, the presence or absence of .o changes
> which directory the compiler would put its outpt in, which in turn
> influences where make should look for any existing .o file to check
> for timestamps before deciding if compilation is needed.

I don't understand this, and I didn't really understand the part of the
but report either.

If someone could provide more details about exactly what the problem is
I'd be interested to learn.


Thanks Eric!

Reply via email to