source: trunk/kBuild/units/lex.kmk@ 2009

Last change on this file since 2009 was 1625, checked in by bird, 17 years ago

setup a context for each source we process.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1# $Id: lex.kmk 1625 2008-05-12 21:42:23Z bird $
2## @file
3# lex unit.
4#
5
6#
7# Copyright (c) 2008 knut st. osmundsen <bird-src-spam@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
27UNIT_lex = lex
28
29# Add ourselves to the default source handlers.
30KBUILD_SRC_HANDLERS += \
31 .l:def_src_handler_lex
32
33
34## wrapper the compile command dependency check.
35ifndef NO_COMPILE_CMDS_DEPS
36 _DEP_LEX_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_),$$(commands $(out)),FORCE)
37else
38 _DEP_LEX_CMDS =
39endif
40
41
42##
43# Generates the rules for running flex on a specific source file.
44#
45# @param $(obj) The object file.
46# @param lots more
47define def_lex_rule
48$(out) + $(output_extra) +| $(output_maybe) : \
49 $(deps) \
50 $(value _DEP_LEX_CMDS) \
51 | \
52 $(orderdeps)
53 %$$(call MSG_COMPILE,$(target),$(source),$$@,$(type))
54 $$(QUIET)$$(RM) -f -- $(dep) $(out) $(output_extra) $(output_maybe)
55
56$(cmds)
57
58ifndef NO_COMPILE_CMDS_DEPS
59 %$$(QUIET2)$$(APPEND) '$(dep)'
60 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_'
61 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
62 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
63endif
64
65# update globals
66_OUT_FILES += $(out) $(output_extra) $(output_maybe)
67$(target)_GEN_SOURCES_ += $(out)
68
69endef # def_lex_rule
70
71##
72# Handler for .l files listed in the SOURCES properties.
73#
74# .l files are transformed into .c files that then gets compiled by
75# the C compiler.
76#
77# @param target The target file.
78# @param source The source file.
79# @param lots more
80# @returns quite a bit.
81define def_src_handler_lex
82# Figure out all the props.
83local type := LEX
84local tmp := $(kb-src-tool tool)
85ifeq ($(tool),)
86$(error kBuild: $(target) / $(sources) does not a (lex) tool defined!)
87endif
88ifndef TOOL_$(tool)_LEX_CMDS
89$(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
90endif
91local out := $(kb-obj-base outbase).c
92local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
93local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
94local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
95ifdef TOOL_$(tool)_LEX_OUT_FILE # .c/.cpp output depends on flags.
96 local out := $(strip $(TOOL_$(tool)_LEX_OUT_FILE))
97 ifeq ($(out),)
98 local out := $(outbase).c
99 endif
100endif
101local dirdep := $(call DIRDEP,$(dir $(out)))
102
103# Adjust paths if we got a default path.
104ifneq ($(defpath),)
105 local source := $(abspathex $(source),$(defpath))
106endif
107
108# dependency file.
109local dep := $(out)$(SUFF_DEP)
110ifndef NO_COMPILE_CMDS_DEPS
111 _DEPFILES_INCLUDED += $(dep)
112 $(eval includedep $(dep))
113endif
114
115# call the tool
116local cmds := $(TOOL_$(tool)_LEX_CMDS)
117local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
118local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
119local deps += $(TOOL_$(tool)_LEX_DEPEND) $(source)
120local orderdeps += $(TOOL_$(tool)_LEX_DEPORD)
121
122# generate the rule.
123$(eval $(def_lex_rule))
124
125endef # def_src_handler_lex
126
127
Note: See TracBrowser for help on using the repository browser.