Using Sun WorkShop

Multiple Targets

Another form of concurrent file update occurs when the same rule is defined for multiple targets. An example is a yacc(1) program that builds both a program and a header for use with lex(1). When a rule builds several target files, it is important to specify them as a group using the + notation. This is especially so in the case of a parallel build.


y.tab.c y.tab.h: parser.y 
    $(YACC.y) parser.y

This rule is actually equivalent to the two rules:


y.tab.c: parser.y
	$(YACC.y) parser.y
y.tab.h: parser.y
	$(YACC.y) parser.y

The serial version of make builds the first rule to produce y.tab.c and then determines that y.tab.h is up-to-date and need not be built. When building in parallel, dmake checks y.tab.h before yacc has finished building y.tab.c and notices that y.tab.h does need to be built, it then starts another yacc in parallel with the first one. Since both yacc invocations are writing to the same files (y.tab.c and y.tab.h), these files are apt to be corrupted and incorrect. The correct rule uses the + construct to indicate that both targets are built simultaneously by the same rule. For example:


y.tab.c + y.tab.h: parser.y
	$(YACC.y) parser.y