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

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

kBuild: svn attributes and some minor file header adjustments and corrections (still GPLv2 w/ big fat exception).

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