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

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

Introduce the concept of units to prevent footer.kmk from growing beyond proportions. Features that are rarely used are put into units and dragged in via the USES property when needed. The first example of this is how lex (.l files) is handled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1# $Id: lex.kmk 1621 2008-05-12 19:44:45Z 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_ctx
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
88local out := $(kb-obj-base outbase).c
89local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
90local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
91local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
92local dirdep := $(call DIRDEP,$(dir $(out)))
93
94# workaround for bug in kb-src-prop - remove when it has been fixed.
95flags := $(patsubst /%,%,$(flags))
96
97# Adjust paths if we got a default path.
98ifneq ($(defpath),)
99 deps := $(abspathex $(deps),$(defpath))
100 orderdeps := $(abspathex $(orderdeps),$(defpath))
101 source := $(abspathex $(source),$(defpath))
102endif
103
104# dependency file.
105local dep := $(out)$(SUFF_DEP)
106ifndef NO_COMPILE_CMDS_DEPS
107 _DEPFILES_INCLUDED += $(dep)
108 $(eval includedep $(dep))
109endif
110
111# check that the tool is defined.
112ifndef TOOL_$(tool)_LEX_CMDS
113$(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
114endif
115
116# call the tool
117local cmds := $(TOOL_$(tool)_LEX_CMDS)
118local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
119local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
120deps += $(TOOL_$(tool)_DEPEND) $(source)
121orderdeps += $(TOOL_$(tool)_DEPORD)
122
123# generate the rule.
124$(eval $(def_lex_rule))
125
126# cleanup (non-localized stuff)
127tool :=
128outbase :=
129flags :=
130deps :=
131orderdeps :=
132
133endef # def_src_handler_lex_ctx
134
135## @todo the source handlers should be evaluated in a fresh context!
136define def_src_handler_lex
137$(evalvalctx def_src_handler_lex_ctx)
138endef
139
140
Note: See TracBrowser for help on using the repository browser.