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

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

*: Updated copyright to 2009 and normalized name & email.

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