freebsd-skq/contrib/bmake/mk/yacc.mk
Simon J. Gerraty 2c3632d14f Update to bmake-20200902
Lots of code refactoring, simplification and cleanup.
Lots of new unit-tests providing much higher code coverage.
All courtesy of rillig at netbsd.

Other significant changes:

o new read-only variable .SHELL which provides the path of the shell
  used to run scripts (as defined by  the .SHELL target).

o variable parsing detects more errors.

o new debug option -dl: LINT mode, does the equivalent of := for all
  variable assignments so that file and line number are reported for
  variable parse errors.
2020-09-05 19:29:42 +00:00

58 lines
1.4 KiB
Makefile

# $Id: yacc.mk,v 1.7 2020/08/19 17:51:53 sjg Exp $
#
# @(#) Copyright (c) 1999-2011, Simon J. Gerraty
#
# This file is provided in the hope that it will
# be of use. There is absolutely NO WARRANTY.
# Permission to copy, redistribute or otherwise
# use this file is hereby granted provided that
# the above copyright notice and this notice are
# left intact.
#
# Please send copies of changes and bug-fixes to:
# sjg@crufty.net
#
# this file contains rules to DTRT when SRCS contains foo.y or foo.c
# when only a foo.y exists.
YACC?= yacc
YFLAGS?= -v -t
RM?= rm
YACC.y?= ${YACC} ${YFLAGS}
.if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H)
.y.c:
${YACC.y} ${.IMPSRC}
[ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}
${RM} -f y.tab.[!h]
.else
# the touch of the .c is to ensure it is newer than .h (paranoia)
.y.h:
${YACC.y} ${.IMPSRC}
[ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c
[ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \
|| mv y.tab.h ${.TARGET:T:R}.h
touch ${.TARGET:T:R}.c
${RM} -f y.tab.*
# Normally the .y.h rule does the work - to avoid races.
# If for any reason the .c is lost but the .h remains,
# regenerate the .c
.y.c: ${.TARGET:T:R}.h
[ -s ${.TARGET} ] || { \
${YACC.y} ${.IMPSRC} && \
{ [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \
${RM} y.tab.*; }; }
.endif
beforedepend: ${SRCS:T:M*.y:S/.y/.c/g}
CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g}
CLEANFILES+= y.tab.[ch]