7 # Copyright (c) 2008 knut st. osmundsen <bird-src-spam@anduin.net>
9 # This file is part of kBuild.
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.
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.
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
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.
36 # Add ourselves to the default source handlers.
37 KBUILD_SRC_HANDLERS
+= \
38 .l
:def_src_handler_lex
41 ## wrapper the compile command dependency check.
42 ifndef NO_COMPILE_CMDS_DEPS
43 _DEP_LEX_CMDS
= $$(comp-cmds-ex
$$($(target
)_
$(subst :,_
,$(source
))_LEX_CMDS_PREV_
),$$(commands
$(out
)),FORCE
)
50 # Generates the rules for running flex on a specific source file.
52 # @param $(obj) The object file.
55 $(out
) + $(output_extra
) +|
$(output_maybe
) : \
57 $(value _DEP_LEX_CMDS
) \
60 %$$(call MSG_COMPILE
,$(target
),$(source
),$$@
,$(type
))
61 $$(QUIET
)$$(RM
) -f
-- $(dep
) $(out
) $(output_extra
) $(output_maybe
)
65 ifndef 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'
73 _OUT_FILES
+= $(out
) $(output_extra
) $(output_maybe
)
74 $(target
)_GEN_SOURCES_
+= $(out
)
79 # Handler for .l files listed in the SOURCES properties.
81 # .l files are transformed into .c files that then gets compiled by
84 # @param target The target file.
85 # @param source The source file.
87 # @returns quite a bit.
88 define def_src_handler_lex
89 # Figure out all the props.
91 local tmp
:= $(kb-src-tool tool
)
93 $(error kBuild
: $(target
) / $(sources
) does not a
(lex) tool defined
!)
95 ifndef TOOL_
$(tool
)_LEX_CMDS
96 $(error kBuild
: TOOL_
$(tool
)_LEX_CMDS isn
't defined! target=$(target) source=$(source) )
98 local out := $(kb-obj-base outbase).c
99 local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
100 local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
101 local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
102 ifdef TOOL_$(tool)_LEX_OUT_FILE # .c/.cpp output depends on flags.
103 local out := $(strip $(TOOL_$(tool)_LEX_OUT_FILE))
105 local out := $(outbase).c
108 local dirdep := $(call DIRDEP,$(dir $(out)))
110 # Adjust paths if we got a default path.
112 local source := $(abspathex $(source),$(defpath))
116 local dep := $(out)$(SUFF_DEP)
117 ifndef NO_COMPILE_CMDS_DEPS
118 _DEPFILES_INCLUDED += $(dep)
119 $(eval includedep $(dep))
123 local cmds := $(TOOL_$(tool)_LEX_CMDS)
124 local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
125 local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
126 local deps += $(TOOL_$(tool)_LEX_DEPEND) $(source)
127 local orderdeps += $(TOOL_$(tool)_LEX_DEPORD)
130 $(eval $(def_lex_rule))
132 endef # def_src_handler_lex