1 | # $Id: yacc.kmk 3284 2019-01-05 01:40:31Z bird $
|
---|
2 | ## @file
|
---|
3 | # yacc/bison unit.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (c) 2008-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
|
---|
8 | #
|
---|
9 | # This file is part of kBuild.
|
---|
10 | #
|
---|
11 | # kBuild is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # kBuild is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with kBuild; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
24 | #
|
---|
25 | #
|
---|
26 | # As a special exception you are granted permission to include this file, via
|
---|
27 | # the kmk include directive, as you wish without this in itself causing the
|
---|
28 | # resulting makefile, program or whatever to be covered by the GPL license.
|
---|
29 | # This exception does not however invalidate any other reasons why the makefile,
|
---|
30 | # program, whatever should not be covered the GPL.
|
---|
31 | #
|
---|
32 | #
|
---|
33 |
|
---|
34 | ifdef UNIT_yacc
|
---|
35 | $(error kBuild: The yacc unit was included twice!)
|
---|
36 | endif
|
---|
37 | UNIT_yacc = yacc
|
---|
38 |
|
---|
39 | # Add our target properties.
|
---|
40 | PROPS_TOOLS += YACCTOOL
|
---|
41 | PROPS_SINGLE += YACCTOOL
|
---|
42 | PROPS_ACCUMULATE_R += YACCFLAGS
|
---|
43 |
|
---|
44 | # Add ourselves to the default source handlers.
|
---|
45 | KBUILD_SRC_HANDLERS += \
|
---|
46 | .y:def_src_handler_yacc_y \
|
---|
47 | .ypp:def_src_handler_yacc_ypp \
|
---|
48 | .y++:def_src_handler_yacc_ypp
|
---|
49 |
|
---|
50 |
|
---|
51 | ## wrapper the compile command dependency check.
|
---|
52 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
53 | _DEP_YACC_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_YACC_CMDS_PREV_),$$(commands $(out)),FORCE)
|
---|
54 | else
|
---|
55 | _DEP_YACC_CMDS =
|
---|
56 | endif
|
---|
57 |
|
---|
58 |
|
---|
59 | ##
|
---|
60 | # Generates the rules for running flex on a specific source file.
|
---|
61 | #
|
---|
62 | # @param $(obj) The object file.
|
---|
63 | # @param lots more
|
---|
64 | define def_yacc_rule
|
---|
65 | $(out) + $(output_extra) +| $(output_maybe) : \
|
---|
66 | $(deps) \
|
---|
67 | $(value _DEP_YACC_CMDS) \
|
---|
68 | | \
|
---|
69 | $(orderdeps)
|
---|
70 | %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
|
---|
71 | $$(QUIET)$$(RM) -f -- $(dep) $(out) $(output_extra) $(output_maybe)
|
---|
72 |
|
---|
73 | $(cmds)
|
---|
74 |
|
---|
75 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
76 | %$$(QUIET2)$$(APPEND) '$(dep)'
|
---|
77 | %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_YACC_CMDS_PREV_'
|
---|
78 | %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
|
---|
79 | %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
|
---|
80 | endif
|
---|
81 |
|
---|
82 | # update globals and target properties.
|
---|
83 | _OUT_FILES += $(out) $(output_extra) $(output_maybe)
|
---|
84 | $(target)_GEN_SOURCES_ += $(out)
|
---|
85 | $(target)_2_INTERMEDIATES += $(intermediates)
|
---|
86 |
|
---|
87 | endef # def_yacc_rule
|
---|
88 |
|
---|
89 |
|
---|
90 | ##
|
---|
91 | # Handler for .y files listed in the SOURCES properties.
|
---|
92 | #
|
---|
93 | # .y files are transformed into .c (and maybe .h) files that then gets
|
---|
94 | # compiled by the C compiler.
|
---|
95 | #
|
---|
96 | # @param target The target file.
|
---|
97 | # @param source The source file.
|
---|
98 | # @param lots more
|
---|
99 | # @returns quite a bit.
|
---|
100 | #
|
---|
101 | define def_src_handler_yacc_y
|
---|
102 | # Figure out all the props.
|
---|
103 | local type := YACC
|
---|
104 | local tmp := $(kb-src-tool tool)
|
---|
105 | ifeq ($(tool),)
|
---|
106 | $(error kBuild: $(target) / $(sources) does not a (yacc) tool defined!)
|
---|
107 | endif
|
---|
108 | ifndef TOOL_$(tool)_YACC_CMDS
|
---|
109 | $(error kBuild: TOOL_$(tool)_YACC_CMDS isn't defined! target=$(target) source=$(source) )
|
---|
110 | endif
|
---|
111 | local out := $(kb-obj-base outbase).c
|
---|
112 | local tmp := $(kb-src-prop YACCFLAGS,flags,left-to-right,)
|
---|
113 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
---|
114 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
---|
115 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
---|
116 |
|
---|
117 | # Adjust paths if we got a default path.
|
---|
118 | ifneq ($(defpath),)
|
---|
119 | local source := $(abspathex $(source),$(defpath))
|
---|
120 | endif
|
---|
121 |
|
---|
122 | # dependency file.
|
---|
123 | local dep := $(out)$(SUFF_DEP)
|
---|
124 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
125 | _DEPFILES_INCLUDED += $(dep)
|
---|
126 | $(eval includedep $(dep))
|
---|
127 | endif
|
---|
128 |
|
---|
129 | # Call the tool.
|
---|
130 | local cmds := $(TOOL_$(tool)_YACC_CMDS)
|
---|
131 | local output_extra := $(TOOL_$(tool)_YACC_OUTPUT)
|
---|
132 | local output_maybe := $(TOOL_$(tool)_YACC_OUTPUT_MAYBE)
|
---|
133 | local deps += $(TOOL_$(tool)_YACC_DEPEND) $(source)
|
---|
134 | local orderdeps += $(TOOL_$(tool)_YACC_DEPORD) $(dirdep)
|
---|
135 |
|
---|
136 | # Whether it generates a header file depends on flags.
|
---|
137 | local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
|
---|
138 |
|
---|
139 | # Generate the rule.
|
---|
140 | $(eval $(def_yacc_rule))
|
---|
141 |
|
---|
142 | endef # def_src_handler_yacc_y
|
---|
143 |
|
---|
144 |
|
---|
145 | ##
|
---|
146 | # Handler for .ypp/.y++ files listed in the SOURCES properties.
|
---|
147 | #
|
---|
148 | # .ypp/++ files are transformed into .cpp/++ (and maybe .hpp/++) files that then gets
|
---|
149 | # compiled by the C++ compiler.
|
---|
150 | #
|
---|
151 | # @param target The target file.
|
---|
152 | # @param source The source file.
|
---|
153 | # @param lots more
|
---|
154 | # @returns quite a bit.
|
---|
155 | #
|
---|
156 | define def_src_handler_yacc_ypp
|
---|
157 | # Figure out all the props.
|
---|
158 | local type := YACC
|
---|
159 | local tmp := $(kb-src-tool tool)
|
---|
160 | ifeq ($(tool),)
|
---|
161 | $(error kBuild: $(target) / $(sources) does not a (yacc) tool defined!)
|
---|
162 | endif
|
---|
163 | ifndef TOOL_$(tool)_YACC_CMDS
|
---|
164 | $(error kBuild: TOOL_$(tool)_YACC_CMDS isn't defined! target=$(target) source=$(source) )
|
---|
165 | endif
|
---|
166 | local out := $(kb-obj-base outbase).c$(substr $(suffix $(source),3))
|
---|
167 | local tmp := $(kb-src-prop YACCFLAGS,flags,left-to-right,)
|
---|
168 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
---|
169 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
---|
170 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
---|
171 |
|
---|
172 | # Adjust paths if we got a default path.
|
---|
173 | ifneq ($(defpath),)
|
---|
174 | local source := $(abspathex $(source),$(defpath))
|
---|
175 | endif
|
---|
176 |
|
---|
177 | # dependency file.
|
---|
178 | local dep := $(out)$(SUFF_DEP)
|
---|
179 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
180 | _DEPFILES_INCLUDED += $(dep)
|
---|
181 | $(eval includedep $(dep))
|
---|
182 | endif
|
---|
183 |
|
---|
184 | # Call the tool.
|
---|
185 | local cmds := $(TOOL_$(tool)_YACC_CMDS)
|
---|
186 | local output_extra := $(TOOL_$(tool)_YACC_OUTPUT)
|
---|
187 | local output_maybe := $(TOOL_$(tool)_YACC_OUTPUT_MAYBE)
|
---|
188 | local deps += $(TOOL_$(tool)_YACC_DEPEND) $(source)
|
---|
189 | local orderdeps += $(TOOL_$(tool)_YACC_DEPORD) $(dirdep)
|
---|
190 |
|
---|
191 | # Whether it generates a header file depends on flags.
|
---|
192 | local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
|
---|
193 |
|
---|
194 | # Generate the rule.
|
---|
195 | $(eval $(def_yacc_rule))
|
---|
196 |
|
---|
197 | endef # def_src_handler_yacc_ypp
|
---|
198 |
|
---|