Tim Ring
Tim Ring

Reputation: 1833

Circular file dependency dropped weirdness

I'm running a little utility from a make file (using GNU Make 3.81). The utility converts one type of file to another. For example the file 'thefile.x' gets converted to 'thefile.x.y'.

The target and make rule is:

%.x.y: %.x
    convertfile $< $@

all: file1.x.y file2.x.y

This actually works (the .x.y file is produced but I always get the message:

make: Circular thefile.x <- thefile.x.y dependency dropped.

This is just a minor issue as we don't want to see messages when everything is actually working.

Have looked at other 'circular dependency' Q&As and none of them seem to be the same problem I'm having. For other technical reasons I can't change the file naming conventions for this project.

After comment below I want to clarify what I'm doing and so reproduce the complete make file I'm using:

%.js.c: %.js
    js2c $< $@

all: test1.js.c test2.js.c

Here is output when I run it and it has stuff to do:

C:\work\timtest>make
make: Circular test1.js <- test1.js.c dependency dropped.
js2c test1.js test1.js.c
[RomFs] test1.js => test1.js.c
make: Circular test2.js <- test2.js.c dependency dropped.
js2c test2.js test2.js.c
[RomFs] test2.js => test2.js.c

Here is output when nothing to do:

make: Circular test1.js <- test1.js.c dependency dropped.
make: Circular test2.js <- test2.js.c dependency dropped.
make: Nothing to be done for `all'.

Upvotes: 0

Views: 273

Answers (1)

MadScientist
MadScientist

Reputation: 100856

You are seeing this because GNU make has a number of built-in rules. You can see a partial listing of them in the GNU make manual, or run make -p -f/dev/null to see a complete list.

One of these built-in rules tells make how to compile a program from a .c file. On POSIX systems programs don't have special suffixes, so this built-in rule says, basically:

%: %.c ; $(LINK.c) ...

So this rule tells make how to build any file foo from a file foo.c... this also means make can infer how to build a file foo.js from a file foo.js.c. Since you've also defined a rule for how to build foo.js.c from foo.js, that's a circular dependency and make evicts one of the rules (the built-in rule).

You need to prevent your .js files from being matched via match-anything patterns like the one above. There are two ways to do this as described in the manual. The one with the least side-effects is to add an empty pattern rule mentioning your new suffix, like this:

%.js:

That's it. Full details are available in the manual.

Upvotes: 1

Related Questions