1*6eef5f0cSAntonio Huete Jimenez# $Id: yacc.mk,v 1.8 2022/06/22 04:51:06 sjg Exp $ 25f1e34d9SAlexandre Perrin 35f1e34d9SAlexandre Perrin# 45f1e34d9SAlexandre Perrin# @(#) Copyright (c) 1999-2011, Simon J. Gerraty 55f1e34d9SAlexandre Perrin# 65f1e34d9SAlexandre Perrin# This file is provided in the hope that it will 75f1e34d9SAlexandre Perrin# be of use. There is absolutely NO WARRANTY. 85f1e34d9SAlexandre Perrin# Permission to copy, redistribute or otherwise 95f1e34d9SAlexandre Perrin# use this file is hereby granted provided that 105f1e34d9SAlexandre Perrin# the above copyright notice and this notice are 115f1e34d9SAlexandre Perrin# left intact. 125f1e34d9SAlexandre Perrin# 135f1e34d9SAlexandre Perrin# Please send copies of changes and bug-fixes to: 145f1e34d9SAlexandre Perrin# sjg@crufty.net 155f1e34d9SAlexandre Perrin# 165f1e34d9SAlexandre Perrin 175f1e34d9SAlexandre Perrin# this file contains rules to DTRT when SRCS contains foo.y or foo.c 185f1e34d9SAlexandre Perrin# when only a foo.y exists. 195f1e34d9SAlexandre Perrin 205f1e34d9SAlexandre PerrinYACC?= yacc 215f1e34d9SAlexandre PerrinYFLAGS?= -v -t 225f1e34d9SAlexandre PerrinRM?= rm 235f1e34d9SAlexandre Perrin 245f1e34d9SAlexandre PerrinYACC.y?= ${YACC} ${YFLAGS} 255f1e34d9SAlexandre Perrin 26*6eef5f0cSAntonio Huete Jimenez# first deal with explicit *.y in SRCS 27*6eef5f0cSAntonio Huete Jimenez.for y in ${SRCS:M*.y} 28*6eef5f0cSAntonio Huete Jimenez.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) 29*6eef5f0cSAntonio Huete Jimenez.ORDER: ${y:T:R}.c y.tab.h 30*6eef5f0cSAntonio Huete Jimenezy.tab.h: .NOMETA 31*6eef5f0cSAntonio Huete Jimenez${y:T:R}.c y.tab.h: $y 32*6eef5f0cSAntonio Huete Jimenez ${YACC.y} ${.IMPSRC} 33*6eef5f0cSAntonio Huete Jimenez [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} 34*6eef5f0cSAntonio Huete Jimenez ${RM} -f y.tab.[!h] 35*6eef5f0cSAntonio Huete Jimenez.else 36*6eef5f0cSAntonio Huete Jimenez.ORDER: ${y:T:R}.c ${y:T:R}.h 37*6eef5f0cSAntonio Huete Jimenez${y:T:R}.h: .NOMETA 38*6eef5f0cSAntonio Huete Jimenez${y:T:R}.c ${y:T:R}.h: $y 39*6eef5f0cSAntonio Huete Jimenez ${YACC.y} ${.IMPSRC} 40*6eef5f0cSAntonio Huete Jimenez [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c 41*6eef5f0cSAntonio Huete Jimenez [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ 42*6eef5f0cSAntonio Huete Jimenez || mv y.tab.h ${.TARGET:T:R}.h 43*6eef5f0cSAntonio Huete Jimenez ${RM} -f y.tab.* 44*6eef5f0cSAntonio Huete Jimenez.endif 45*6eef5f0cSAntonio Huete Jimenez.endfor 46*6eef5f0cSAntonio Huete Jimenez 47*6eef5f0cSAntonio Huete Jimenez.if ${SRCS:M*.y} == "" 485f1e34d9SAlexandre Perrin.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H) 495f1e34d9SAlexandre Perrin 505f1e34d9SAlexandre Perrin.y.c: 515f1e34d9SAlexandre Perrin ${YACC.y} ${.IMPSRC} 525f1e34d9SAlexandre Perrin [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET} 535f1e34d9SAlexandre Perrin ${RM} -f y.tab.[!h] 545f1e34d9SAlexandre Perrin 555f1e34d9SAlexandre Perrin.else 565f1e34d9SAlexandre Perrin 575f1e34d9SAlexandre Perrin# the touch of the .c is to ensure it is newer than .h (paranoia) 585f1e34d9SAlexandre Perrin.y.h: 595f1e34d9SAlexandre Perrin ${YACC.y} ${.IMPSRC} 605f1e34d9SAlexandre Perrin [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c 615f1e34d9SAlexandre Perrin [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \ 625f1e34d9SAlexandre Perrin || mv y.tab.h ${.TARGET:T:R}.h 635f1e34d9SAlexandre Perrin touch ${.TARGET:T:R}.c 645f1e34d9SAlexandre Perrin ${RM} -f y.tab.* 655f1e34d9SAlexandre Perrin 665f1e34d9SAlexandre Perrin# Normally the .y.h rule does the work - to avoid races. 675f1e34d9SAlexandre Perrin# If for any reason the .c is lost but the .h remains, 685f1e34d9SAlexandre Perrin# regenerate the .c 695f1e34d9SAlexandre Perrin.y.c: ${.TARGET:T:R}.h 705f1e34d9SAlexandre Perrin [ -s ${.TARGET} ] || { \ 715f1e34d9SAlexandre Perrin ${YACC.y} ${.IMPSRC} && \ 725f1e34d9SAlexandre Perrin { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \ 735f1e34d9SAlexandre Perrin ${RM} y.tab.*; }; } 745f1e34d9SAlexandre Perrin.endif 75*6eef5f0cSAntonio Huete Jimenez.endif 765f1e34d9SAlexandre Perrin 775f1e34d9SAlexandre Perrinbeforedepend: ${SRCS:T:M*.y:S/.y/.c/g} 785f1e34d9SAlexandre Perrin 795f1e34d9SAlexandre PerrinCLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g} 805f1e34d9SAlexandre PerrinCLEANFILES+= y.tab.[ch] 81*6eef5f0cSAntonio Huete Jimenez 82