footer.kmk: Don't forget to clean up the OUTPUT_MAYBE files when linking.
[kbuild-mirror.git] / kBuild / units / lex.kmk
blobd34453f5013b0c424a141241047dde0ff61ef7ca
1 # $Id$
2 ## @file
3 # lex unit.
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.
34 UNIT_lex = lex
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)
44 else
45 _DEP_LEX_CMDS =
46 endif
50 # Generates the rules for running flex on a specific source file.
52 # @param $(obj) The object file.
53 # @param lots more
54 define 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)
63 $(cmds)
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'
70 endif
72 # update globals
73 _OUT_FILES += $(out) $(output_extra) $(output_maybe)
74 $(target)_GEN_SOURCES_ += $(out)
76 endef # def_lex_rule
79 # Handler for .l files listed in the SOURCES properties.
81 # .l files are transformed into .c files that then gets compiled by
82 # the C compiler.
84 # @param target The target file.
85 # @param source The source file.
86 # @param lots more
87 # @returns quite a bit.
88 define def_src_handler_lex
89 # Figure out all the props.
90 local type := LEX
91 local tmp := $(kb-src-tool tool)
92 ifeq ($(tool),)
93 $(error kBuild: $(target) / $(sources) does not a (lex) tool defined!)
94 endif
95 ifndef TOOL_$(tool)_LEX_CMDS
96 $(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
97 endif
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))
104 ifeq ($(out),)
105 local out := $(outbase).c
106 endif
107 endif
108 local dirdep := $(call DIRDEP,$(dir $(out)))
110 # Adjust paths if we got a default path.
111 ifneq ($(defpath),)
112 local source := $(abspathex $(source),$(defpath))
113 endif
115 # dependency file.
116 local dep := $(out)$(SUFF_DEP)
117 ifndef NO_COMPILE_CMDS_DEPS
118 _DEPFILES_INCLUDED += $(dep)
119 $(eval includedep $(dep))
120 endif
122 # call the tool
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)
129 # generate the rule.
130 $(eval $(def_lex_rule))
132 endef # def_src_handler_lex