]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/bmake/mk/yacc.mk
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / bmake / mk / yacc.mk
1 # $Id: yacc.mk,v 1.6 2011/06/10 22:45:46 sjg Exp $
2
3 #
4 #       @(#) Copyright (c) 1999-2011, Simon J. Gerraty
5 #
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
11 #       left intact. 
12 #      
13 #       Please send copies of changes and bug-fixes to:
14 #       sjg@crufty.net
15 #
16
17 # this file contains rules to DTRT when SRCS contains foo.y or foo.c
18 # when only a foo.y exists.
19
20 YACC?= yacc
21 YFLAGS?= -v -t
22 RM?= rm
23
24 YACC.y?= ${YACC} ${YFLAGS}
25
26 .if ${YACC.y:M-d} == "" || defined(NO_RENAME_Y_TAB_H)
27
28 .y.c:
29         ${YACC.y} ${.IMPSRC}
30         [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}
31         ${RM} -f y.tab.[!h]
32
33 .else
34
35 # the touch of the .c is to ensure it is newer than .h (paranoia)
36 .y.h:
37         ${YACC.y} ${.IMPSRC}
38         [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET:T:R}.c
39         [ ! -s y.tab.h ] || cmp -s y.tab.h ${.TARGET:T:R}.h \
40                 || mv y.tab.h ${.TARGET:T:R}.h
41         touch ${.TARGET:T:R}.c
42         ${RM} -f y.tab.*
43
44 # Normally the .y.h rule does the work - to avoid races.
45 # If for any reason the .c is lost but the .h remains,
46 # regenerate the .c
47 .y.c:   ${.TARGET:T:R}.h
48         [ -s ${.TARGET} ] || { \
49                 ${YACC.y} ${.IMPSRC} && \
50                 { [ ! -s y.tab.c ] || mv y.tab.c ${.TARGET}; \
51                 ${RM} y.tab.*; }; }
52 .endif
53
54 beforedepend:   ${SRCS:T:M*.y:S/.y/.c/g}
55
56 CLEANFILES+= ${SRCS:T:M*.y:S/.y/.[ch]/g}
57 CLEANFILES+= y.tab.[ch]