Real goals with PHONY dependencies

Trying to find an elegant method to solve some complex dependencies. There is something like the following in my Makefile:

.PHONY: FOO FOO: foo foo: build foo .PHONY: BAR BAR: bar bar: FOO build bar 

The idea here is that I want to abstract real files (foo, bar) with fake targets (FOO BAR). Of course, in my real Makefile this is more complicated, so abstraction is important. The problem here, however, is to make the fake target FOO a dependency for the bar, then Make always tries to rebuild the panel, even if both foo and bar are updated. This is apparently because it always treats FOO as deprecated. But this behavior is not entirely correct.

So it seems that I have only 3 options: 1) Make the panel directly dependent on foo. In my real Makefile, this is more complicated and tries to specify real files, since dependencies are highly undesirable. 2) Use variables in addition to all phonons. This makes the whole Makefile more complex. 3) Remove foo / Foo as a bar dependency and add recursive make from FOO as part of the rule in the line. This is a very bad form.

Is there an even more elegant solution that I don't know about?

Thanks.

+4
source share
2 answers

GNU make an answer to this situation of dependency for order only . This allows you to secure ordering goals without having an β€œoutdated” relationship. From your question, this seems to be what you are looking for.

Thus, your snapshot from the makefile will look like this:

 .PHONY: FOO FOO: foo foo: build foo .PHONY: BAR BAR: bar bar: | FOO build bar 

This will always allow foo to be created before the line, but it will not indicate that when updating foo this bar should be built. foo will only be created when make BAR is called, and foo files do not exist.

+1
source

Do you think variables are what you need and can really help readability. They allow us to make the drum file properly depend on the foo file, and not on your user-friendly purpose .PHONY:

 foo.file = horrendously/long/path/to/the/real/foo.file bar.file = horrendously/long/path/to/the/real/bar.file .PHONY: FOO FOO: $(foo.file) $(foo.file): touch $@ .PHONY: BAR BAR: $(bar.file) $(bar.file): $(foo.file) touch $@ 

And here we go:

 $ make BAR touch horrendously/long/path/to/the/real/foo.file touch horrendously/long/path/to/the/real/bar.file $ make BAR make: Nothing to be done for `BAR'. 
0
source

Source: https://habr.com/ru/post/1501011/


All Articles