On So, 2013-02-02 at 00:22 +0100, Sebastian Pipping wrote: > On 01.02.2013 16:18, Matěj Týč wrote: > > ... > > > > Consider a server process that can execute commands and that can load > > (huge) data into cache to spped the execution up. Loading the data is a > > make task and a target file cache-foo is created to expose that the data > > has been succesfully loaded into the server cache. Then cache-foo is an > > order-only dependency of foo1, foo2 and foo3 targets that take advantage > > of it (rules to make them call the server process that uses the foo > > cache). Therefore those targets are not made before setting the cache up > > and also the cache is loaded once, not concurently even if like -j4 is > > used as a make argument. > > > > As you might guess, if I have a target 'bar' that depends on 'foo1' and > > 'foo2', then even if 'foo1' and 'foo2' exist, if 'cache-foo' is missing, > > it is remade and data are loaded into the cache without being of any > > use, which is quite annoying. In other words, the whole server might > > have to start, load the cache and then do nothing. > > This is what I understand to be our current Makefile: > > bar_deps = foo1 foo2 > > bar: $(bar_deps) > > $(bar_deps): | cache-foo > > %: > touch $@
Yes, this is basically correct, great! > Now you want that cache-foo is not built if all of $(bar_deps) exist. > We can achieve that by only adding cache-foo as a dependency, if former > is not the case. So let's replace the line > > $(bar_deps): | cache-foo > > by > > $(bar_deps): | $(if $(call any_file_missing,$(bar_deps)),cache-foo,) > The first function here would be enough for me, BUT... (see below) BTW. it is a pity one can't write $(call file_missing,$@) > > using two custom functions: > > # $(call file_missing,file_1) > # returns: > # true (actually $(file_1)) if the file is missing > # false (empty string) if the file exists > define file_missing > $(if $(wildcard $1),,$1) > endef > > ... > > I hereby put that into the public domain. > > > This session confirms it working: > > $ touch foo1 foo2 bar > > $ make > make: `bar' is up to date. # cache-foo not built! > > $ rm foo1 > > $ make > touch cache-foo # cache-foo built, since foo1 is missing > touch foo1 > touch bar > > I'm curious, if that helps. Thank you for your quick help, your example indeed works, but it has one weakness. Consider a case when eg. 'foo1' depends on 'baz' and suddenly 'baz' is updated, so 'foo1' should be updated, too. However, the old 'foo1' is still there, so the 'file_missing' function assumes that nothing has to be done => cache-foo is not needed, which is not true. Since I generate the makefile using some M4sugar macros, I don't mind having to write some extra stuff; however now the workaround path seems to complicate quite a lot... Thank you, Matej > > Best, > > > > Sebastian _______________________________________________ Bug-make mailing list Bug-make@gnu.org https://lists.gnu.org/mailman/listinfo/bug-make