Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

makefile % pattern and circular references

232 views
Skip to first unread message

James Harris

unread,
Mar 12, 2019, 2:13:10 PM3/12/19
to
Any idea why the following reports a circular reference? I guess it must
be the slightly unusual name in a pattern but I cannot work out why this
should happen.

I've stripped it back to a bare minimum and the directory contains only
two files:

fibaa.nasm
makefile

The makefile has only two lines:

%.nasm.o: %.nasm
nasm -f elf $^ -o $@

When I run

make fibaa.nasm.o -n

it reports

make: Circular fibaa.nasm <- fibaa.nasm.o dependency dropped.
nasm -f elf fibaa.nasm -o fibaa.nasm.o


So where does the circular reference come from? I guess it's something
to do with having the target object file include the .nasm part but I
cannot see why it thinks it should create fibaa.nasm given that the file
exists in the directory.

Is there a crafty implicit rule I should be aware of? Or am I missing
something obvious?


--
James Harris

Kaz Kylheku

unread,
Mar 12, 2019, 2:30:31 PM3/12/19
to
On 2019-03-12, James Harris <james.h...@gmail.com> wrote:
> Is there a crafty implicit rule I should be aware of?

You can list GNU Make's internal database with "make -p". (This will pull
in your Makefile too, if there is one.) It shows the implicit rules.

one of them is the prog.o -> prog rule:

%: %.o
# commands to execute (built-in):
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@

Here, % can match the fibaa.nasm stem.

You can invoke make without built-in rules using "make -r";
if the problem goes away, that tends to also confirm that it's coming
from an internal rule.

William Ahern

unread,
Mar 12, 2019, 5:00:11 PM3/12/19
to
Also can clear the default suffix list inline with `.SUFFIXES:`.

James Harris

unread,
Mar 12, 2019, 5:05:20 PM3/12/19
to
Thanks for that. I followed up on it to look for a way to configure the
makefile to ensure the implicit rules were suppressed and found a
suggestion to use the following.

# Cancel implicit rules
.SUFFIXES:

I'm not sure if it's the best way but it seems to do the job.


--
James Harris

James Harris

unread,
Mar 12, 2019, 5:11:22 PM3/12/19
to
Thanks, yes, found that a bit below
https://www.gnu.org/software/make/manual/make.html#Canceling-Rules.

--
James Harris

Kaz Kylheku

unread,
Mar 12, 2019, 6:41:49 PM3/12/19
to
Probably the best way is not to tack .o onto .nasm.

If NASM objects must be distinguished from other objects, use another
suffix like .no or .nasm-o, .nasmo or whatever.

Jorgen Grahn

unread,
Mar 13, 2019, 2:20:05 AM3/13/19
to
On Tue, 2019-03-12, Kaz Kylheku wrote:
> On 2019-03-12, James Harris <james.h...@gmail.com> wrote:
>> # Cancel implicit rules
>> .SUFFIXES:
>>
>> I'm not sure if it's the best way but it seems to do the job.
>
> Probably the best way is not to tack .o onto .nasm.

Yeah, he's producing foo.o from foo, which confuses me as a human
reader, for the same reason it confuses make (with its default rules).

> If NASM objects must be distinguished from other objects, use another
> suffix like .no or .nasm-o, .nasmo or whatever.

Or place them all in a subdirectory, or something.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
0 new messages