CVSROOT:        /cvs
Module name:    src
Changes by:     patr...@cvs.openbsd.org 2022/01/08 10:05:30

Modified files:
        share/mk       : bsd.dep.mk 

Log message:
Use ${.ALLSRC:M*.y} instead of ${.IMPSRC} as the input file for yacc,
to fix a bug where ${.IMPSRC} (aka $<) is used in a context where it
is not neccessarily defined by OpenBSD make.  This would sometime show
up trying to build libpcap with the following error message:

Using $< in a non-suffix rule context is a GNUmake idiom (<bsd.dep.mk>:47)

The issue is with the rule for the grammar.h file that is generated
by yacc from grammar.c. You can easily reproduce the bug with the
following steps:

- build libpcap from scratch: cd src/lib/libpcap && make clean all
- remove the generated grammar.h file: rm obj*/grammar.h
- build libpcap again (incremental build): make

In normal builds this does not trigger as grammar.h is implicitly
generated by the rule for grammar.c and when make checks for
dependencies it simply finds grammar.h uptodate. However, incremental
or parallel builds might decide to make grammar.h from grammar.y.

Now, why is this only a problem for grammar.h but not for grammar.c?
The answer to this question is burried deeply in OpenBSD's mk files.

The snippet in bsd.dep.mk that triggers the error is a single rule
statement that generates foo.c and foo.h from foo.y with a call to
yacc -d. The rule is generated with a loop, i.e. it is not a prefix
rule. However, a prefix rule context is required for the use of
${.IMPSRC} aka $<. For the .c file such a prefix rule is provided by
bsd.sys.mk and this rule is in scope when make evaluates the yacc rule.
However, for .h file generation from a .y file there is no such prefix
rule defined in any of the Makefiles. Even if it were the .h suffix is
missing from .SUFFIXES and the rule would not be considered.

The obvious way to fix this would be to use $f instead of ${.IMPSRC}.
However, this does not work as $f is then missing the path prefix and
yacc won't find it if an obj directory is used. This is probably the
reason for the use of ${.IMPSRC} in the first place.

Committing on behalf of ehrhardt@
"I like the diff" deraadt@
ok guenther@

Reply via email to