make -j together with bison
I'm having a weird parallel build problem. My makefile looks something like this (not the actual Makefile, just to illustrate the point, so don't hate):
parser.c parser.h : parser.y lexer.c : lexer.l parser.h app : lexer.o parser.o
Because both the parser.c and parser.h file both depend on parser.y, bison eventually gets invoked twice, once on behalf of lexer.c (which includes parser.h and therefore depends on it), and once on behalf of app (which depends on parser.o, which depends on parser.c).
When I make with -d to see the debugging output, I see that bison get invoked twice in two different threads, relatively close together. I'm worried that when all the stars are aligned just right, I could have a race condition and corrupt bison output. I tried a few things with the dependencies in an attempt to force them to be serial, but I just starting getting stranger and stranger make behaviour.
So, the million dollar question is this: Is there a more sane way around the fact that when a program like bison actually outputs two files, satisfying two dependencies, and therefore when built with -j might be invoked from two different unsynced threads?
You should use a pattern rule; in pattern rules multiple targets mean that one invocation of the recipe generates both targets:
%.c %.h : %.y ...