source: trunk/kBuild/units/yacc.kmk@ 3037

Last change on this file since 3037 was 2726, checked in by bird, 11 years ago

s/PATH_DEVTOOLS/KBUILD_DEVTOOLS/g, (c) & e-mail updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1# $Id: yacc.kmk 2726 2014-02-26 23:23:54Z bird $
2## @file
3# yacc/bison unit.
4#
5
6#
7# Copyright (c) 2008-2014 knut st. osmundsen <bird-kBuild-spam-xiv@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
34ifdef UNIT_yacc
35 $(error kBuild: The yacc unit was included twice!)
36endif
37UNIT_yacc = yacc
38
39# Add our target properties.
40PROPS_TOOLS += YACCTOOL
41PROPS_SINGLE += YACCTOOL
42PROPS_ACCUMULATE_R += YACCFLAGS
43
44# Add ourselves to the default source handlers.
45KBUILD_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.
52ifndef NO_COMPILE_CMDS_DEPS
53 _DEP_YACC_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_YACC_CMDS_PREV_),$$(commands $(out)),FORCE)
54else
55 _DEP_YACC_CMDS =
56endif
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
64define 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
75ifndef 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'
80endif
81
82# update globals and target properties.
83_OUT_FILES += $(out) $(output_extra) $(output_maybe)
84$(target)_GEN_SOURCES_ += $(out)
85$(target)_INTERMEDIATES += $(intermediates)
86
87endef # 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#
101define def_src_handler_yacc_y
102# Figure out all the props.
103local type := YACC
104local tmp := $(kb-src-tool tool)
105ifeq ($(tool),)
106$(error kBuild: $(target) / $(sources) does not a (yacc) tool defined!)
107endif
108ifndef TOOL_$(tool)_YACC_CMDS
109$(error kBuild: TOOL_$(tool)_YACC_CMDS isn't defined! target=$(target) source=$(source) )
110endif
111local out := $(kb-obj-base outbase).c
112local tmp := $(kb-src-prop YACCFLAGS,flags,left-to-right,)
113local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
114local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
115local dirdep := $(call DIRDEP,$(dir $(out)))
116
117# Adjust paths if we got a default path.
118ifneq ($(defpath),)
119 local source := $(abspathex $(source),$(defpath))
120endif
121
122# dependency file.
123local dep := $(out)$(SUFF_DEP)
124ifndef NO_COMPILE_CMDS_DEPS
125 _DEPFILES_INCLUDED += $(dep)
126 $(eval includedep $(dep))
127endif
128
129# Call the tool.
130local cmds := $(TOOL_$(tool)_YACC_CMDS)
131local output_extra := $(TOOL_$(tool)_YACC_OUTPUT)
132local output_maybe := $(TOOL_$(tool)_YACC_OUTPUT_MAYBE)
133local deps += $(TOOL_$(tool)_YACC_DEPEND) $(source)
134local orderdeps += $(TOOL_$(tool)_YACC_DEPORD) $(dirdep)
135
136# Whether it generates a header file depends on flags.
137local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
138
139# Generate the rule.
140$(eval $(def_yacc_rule))
141
142endef # 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#
156define def_src_handler_yacc_ypp
157# Figure out all the props.
158local type := YACC
159local tmp := $(kb-src-tool tool)
160ifeq ($(tool),)
161$(error kBuild: $(target) / $(sources) does not a (yacc) tool defined!)
162endif
163ifndef TOOL_$(tool)_YACC_CMDS
164$(error kBuild: TOOL_$(tool)_YACC_CMDS isn't defined! target=$(target) source=$(source) )
165endif
166local out := $(kb-obj-base outbase).c$(substr $(suffix $(source),3))
167local tmp := $(kb-src-prop YACCFLAGS,flags,left-to-right,)
168local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
169local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
170local dirdep := $(call DIRDEP,$(dir $(out)))
171
172# Adjust paths if we got a default path.
173ifneq ($(defpath),)
174 local source := $(abspathex $(source),$(defpath))
175endif
176
177# dependency file.
178local dep := $(out)$(SUFF_DEP)
179ifndef NO_COMPILE_CMDS_DEPS
180 _DEPFILES_INCLUDED += $(dep)
181 $(eval includedep $(dep))
182endif
183
184# Call the tool.
185local cmds := $(TOOL_$(tool)_YACC_CMDS)
186local output_extra := $(TOOL_$(tool)_YACC_OUTPUT)
187local output_maybe := $(TOOL_$(tool)_YACC_OUTPUT_MAYBE)
188local deps += $(TOOL_$(tool)_YACC_DEPEND) $(source)
189local orderdeps += $(TOOL_$(tool)_YACC_DEPORD) $(dirdep)
190
191# Whether it generates a header file depends on flags.
192local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
193
194# Generate the rule.
195$(eval $(def_yacc_rule))
196
197endef # def_src_handler_yacc_ypp
198
Note: See TracBrowser for help on using the repository browser.