7

I was answering another question -- Dependency ordering error for multi-job make on SO, and I posted the following makefile. The OP replied back saying if -j wasn't specified on the command line, it wouldn't build the dir1/out/file.bar target... Perplexed, I verified that it works with -j2 but not with -j1. I've looked it over, and I'm not seeing what I missed. I thought I'd post it here in case someone knows, as I'm very curious...

$(shell mkdir dir1 >& /dev/null; touch dir1/file.foo; \
        mkdir dir2 >& /dev/null; touch dir2/file.foo)


OUTDIRS = dir1/out dir2/out
OUTPUTS = dir1/out/file.bar dir2/out/file.bar

.DEFAULT_GOAL := all

$(OUTPUTS) : | $(OUTDIRS)

$(OUTDIRS) :
        @echo "making $@"
        sleep 1
        mkdir -p $@
        @echo "done making $@"


%.bar : ../%.foo
        @echo "copying $< to $@"
        @cp $< $@

all : outputs
        @echo "done $@"

outputs : $(OUTPUTS)
        @echo "created all output files"

clean :
        @rm -rf dir1 dir2

I am running make 3.81, and OP was using 3.82. I tried running with make -d -j1 -r, and I get the following snippet:

     Finished prerequisites of target file `dir1/out/file.bar'.
    Must remake target `dir1/out/file.bar'.
    Successfully remade target file `dir1/out/file.bar'.
    Considering target file `dir2/out/file.bar'.
     File `dir2/out/file.bar' does not exist.
      Considering target file `dir2/out/../file.foo'.
       Finished prerequisites of target file `dir2/out/../file.foo'.
      No need to remake target `dir2/out/../file.foo'.
      Pruning file `dir1/out'.
      Pruning file `dir2/out'.
     Finished prerequisites of target file `dir2/out/file.bar'.
    Must remake target `dir2/out/file.bar'.
copying dir2/out/../file.foo to dir2/out/file.bar
    Successfully remade target file `dir2/out/file.bar'.

It seems to think it remade dir1/out/file.bar, but it didn't run any targets/recipes to do so... I'm wondering what I missed...

blackghost
  • 1,730
  • 11
  • 24
  • 1
    I suspect this is a known bug. – Beta Jun 13 '17 at 17:46
  • Having a similar issue, I agree a bug. How to work around? – Samuel Dec 11 '20 at 00:35
  • I worked around by adding a dummy file that depends on the missing file, for example: obj/makebug: obj/missingfile @touch obj/makebug – Samuel Dec 11 '20 at 01:22
  • There are two rules to make the ".bar" files. Try putting a print under the $(OUTPUTS) rule and see if it's being called. If so, I'd delete that and move the directory dependency onto the individual .bar rules. Let me know if that is or isn't it, I'm curious. – RMiller Dec 21 '21 at 14:13

0 Answers0