1*c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 2*c59c3bf3SSimon J. Gerraty# 3*c59c3bf3SSimon J. Gerraty# $Id: yacc.mk,v 1.9 2024/02/17 17:26:57 sjg Exp $ 43cbdda60SSimon J. Gerraty 53cbdda60SSimon J. Gerraty# 63cbdda60SSimon J. Gerraty# @(#) Copyright (c) 1999-2011, Simon J. Gerraty 73cbdda60SSimon J. Gerraty# 83cbdda60SSimon J. Gerraty# This file is provided in the hope that it will 93cbdda60SSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 103cbdda60SSimon J. Gerraty# Permission to copy, redistribute or otherwise 113cbdda60SSimon J. Gerraty# use this file is hereby granted provided that 123cbdda60SSimon J. Gerraty# the above copyright notice and this notice are 133cbdda60SSimon J. Gerraty# left intact. 143cbdda60SSimon J. Gerraty# 153cbdda60SSimon J. Gerraty# Please send copies of changes and bug-fixes to: 163cbdda60SSimon J. Gerraty# sjg@crufty.net 173cbdda60SSimon J. Gerraty# 183cbdda60SSimon J. Gerraty 193cbdda60SSimon J. Gerraty# this file contains rules to DTRT when SRCS contains foo.y or foo.c 203cbdda60SSimon J. Gerraty# when only a foo.y exists. 213cbdda60SSimon J. Gerraty 223cbdda60SSimon J. GerratyYACC?= yacc 233cbdda60SSimon J. GerratyYFLAGS?= -v -t 243cbdda60SSimon J. GerratyRM?= rm 253cbdda60SSimon J. Gerraty 263cbdda60SSimon J. GerratyYACC.y?= ${YACC} ${YFLAGS} 273cbdda60SSimon J. Gerraty 28954401e6SSimon J. Gerraty# first deal with explicit *.y in SRCS 29954401e6SSimon J. Gerraty.for y in ${SRCS:M*.y} 30954401e6SSimon J. Gerraty.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) 31954401e6SSimon J. Gerraty.ORDER: ${y:T:R}.c y.tab.h 32954401e6SSimon J. Gerratyy.tab.h: .NOMETA 33954401e6SSimon J. Gerraty${y:T:R}.c y.tab.h: $y 34954401e6SSimon J. Gerraty ${YACC.y} ${.IMPSRC} 35954401e6SSimon J. Gerraty [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} 36954401e6SSimon J. Gerraty ${RM} -f y.tab.[!h] 37954401e6SSimon J. Gerraty.else 38954401e6SSimon J. Gerraty.ORDER: ${y:T:R}.c ${y:T:R}.h 39954401e6SSimon J. Gerraty${y:T:R}.h: .NOMETA 40954401e6SSimon J. Gerraty${y:T:R}.c ${y:T:R}.h: $y 41954401e6SSimon J. Gerraty ${YACC.y} ${.IMPSRC} 42954401e6SSimon J. Gerraty [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c 43954401e6SSimon J. Gerraty [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ 44954401e6SSimon J. Gerraty || mv y.tab.h ${.TARGET:T:R}.h 45954401e6SSimon J. Gerraty ${RM} -f y.tab.* 46954401e6SSimon J. Gerraty.endif 47954401e6SSimon J. Gerraty.endfor 48954401e6SSimon J. Gerraty 49954401e6SSimon J. Gerraty.if ${SRCS:M*.y} == "" 503cbdda60SSimon J. Gerraty.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) 513cbdda60SSimon J. Gerraty 523cbdda60SSimon J. Gerraty.y.c: 533cbdda60SSimon J. Gerraty ${YACC.y} ${.IMPSRC} 543cbdda60SSimon J. Gerraty [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} 553cbdda60SSimon J. Gerraty ${RM} -f y.tab.[!h] 563cbdda60SSimon J. Gerraty 573cbdda60SSimon J. Gerraty.else 583cbdda60SSimon J. Gerraty 593cbdda60SSimon J. Gerraty# the touch of the .c is to ensure it is newer than .h (paranoia) 603cbdda60SSimon J. Gerraty.y.h: 613cbdda60SSimon J. Gerraty ${YACC.y} ${.IMPSRC} 623cbdda60SSimon J. Gerraty [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c 633cbdda60SSimon J. Gerraty [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ 643cbdda60SSimon J. Gerraty || mv y.tab.h ${.TARGET:T:R}.h 653cbdda60SSimon J. Gerraty touch ${.TARGET:T:R}.c 663cbdda60SSimon J. Gerraty ${RM} -f y.tab.* 673cbdda60SSimon J. Gerraty 683cbdda60SSimon J. Gerraty# Normally the .y.h rule does the work - to avoid races. 693cbdda60SSimon J. Gerraty# If for any reason the .c is lost but the .h remains, 703cbdda60SSimon J. Gerraty# regenerate the .c 713cbdda60SSimon J. Gerraty.y.c: ${.TARGET:T:R}.h 723cbdda60SSimon J. Gerraty [ -s ${.TARGET} ] || { \ 733cbdda60SSimon J. Gerraty ${YACC.y} ${.IMPSRC} && \ 743cbdda60SSimon J. Gerraty { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \ 753cbdda60SSimon J. Gerraty ${RM} y.tab.*; }; } 763cbdda60SSimon J. Gerraty.endif 77954401e6SSimon J. Gerraty.endif 783cbdda60SSimon J. Gerraty 793cbdda60SSimon J. Gerratybeforedepend: ${SRCS:T:M*.y:S/.y/.c/g} 803cbdda60SSimon J. Gerraty 813cbdda60SSimon J. GerratyCLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g} 823cbdda60SSimon J. GerratyCLEANFILES+= y.tab.[ch] 83954401e6SSimon J. Gerraty 84