1 # $Id: yacc.mk,v 1.8 2022/06/22 04:51:06 sjg Exp $
4 # @(#) Copyright (c) 1999-2011, Simon J. Gerraty
6 # This file is provided in the hope that it will
7 # be of use. There is absolutely NO WARRANTY.
8 # Permission to copy, redistribute or otherwise
9 # use this file is hereby granted provided that
10 # the above copyright notice and this notice are
13 # Please send copies of changes and bug-fixes to:
17 # this file contains rules to DTRT when SRCS contains foo.y or foo.c
18 # when only a foo.y exists.
24 YACC.y?= ${YACC} ${YFLAGS}
26 # first deal with explicit *.y in SRCS
27 .for y in ${SRCS:M*.y}
28 .if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H)
29 .ORDER: ${y:T:R}.c y.tab.h
31 ${y:T:R}.c y.tab.h: $y
33 [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}
36 .ORDER: ${y:T:R}.c ${y:T:R}.h
38 ${y:T:R}.c ${y:T:R}.h: $y
40 [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c
41 [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \
42 || mv y.tab.h ${.TARGET:T:R}.h
47 .if ${SRCS:M*.y} == ""
48 .if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H)
52 [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}
57 # the touch of the .c is to ensure it is newer than .h (paranoia)
60 [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c
61 [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \
62 || mv y.tab.h ${.TARGET:T:R}.h
63 touch ${.TARGET:T:R}.c
66 # Normally the .y.h rule does the work - to avoid races.
67 # If for any reason the .c is lost but the .h remains,
69 .y.c: ${.TARGET:T:R}.h
70 [ -s ${.TARGET} ] || { \
71 ${YACC.y} ${.IMPSRC} && \
72 { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \
77 beforedepend: ${SRCS:T:M*.y:S/.y/.c/g}
79 CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g}
80 CLEANFILES+= y.tab.[ch]