1 | # $Id: lex.kmk 1625 2008-05-12 21:42:23Z 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 |
|
---|
27 | UNIT_lex = lex
|
---|
28 |
|
---|
29 | # Add ourselves to the default source handlers.
|
---|
30 | KBUILD_SRC_HANDLERS += \
|
---|
31 | .l:def_src_handler_lex
|
---|
32 |
|
---|
33 |
|
---|
34 | ## wrapper the compile command dependency check.
|
---|
35 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
36 | _DEP_LEX_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_),$$(commands $(out)),FORCE)
|
---|
37 | else
|
---|
38 | _DEP_LEX_CMDS =
|
---|
39 | endif
|
---|
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
|
---|
47 | define 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 |
|
---|
58 | ifndef 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'
|
---|
63 | endif
|
---|
64 |
|
---|
65 | # update globals
|
---|
66 | _OUT_FILES += $(out) $(output_extra) $(output_maybe)
|
---|
67 | $(target)_GEN_SOURCES_ += $(out)
|
---|
68 |
|
---|
69 | endef # 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.
|
---|
81 | define def_src_handler_lex
|
---|
82 | # Figure out all the props.
|
---|
83 | local type := LEX
|
---|
84 | local tmp := $(kb-src-tool tool)
|
---|
85 | ifeq ($(tool),)
|
---|
86 | $(error kBuild: $(target) / $(sources) does not a (lex) tool defined!)
|
---|
87 | endif
|
---|
88 | ifndef TOOL_$(tool)_LEX_CMDS
|
---|
89 | $(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
|
---|
90 | endif
|
---|
91 | local out := $(kb-obj-base outbase).c
|
---|
92 | local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
|
---|
93 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
---|
94 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
---|
95 | ifdef TOOL_$(tool)_LEX_OUT_FILE # .c/.cpp output depends on flags.
|
---|
96 | local out := $(strip $(TOOL_$(tool)_LEX_OUT_FILE))
|
---|
97 | ifeq ($(out),)
|
---|
98 | local out := $(outbase).c
|
---|
99 | endif
|
---|
100 | endif
|
---|
101 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
---|
102 |
|
---|
103 | # Adjust paths if we got a default path.
|
---|
104 | ifneq ($(defpath),)
|
---|
105 | local source := $(abspathex $(source),$(defpath))
|
---|
106 | endif
|
---|
107 |
|
---|
108 | # dependency file.
|
---|
109 | local dep := $(out)$(SUFF_DEP)
|
---|
110 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
111 | _DEPFILES_INCLUDED += $(dep)
|
---|
112 | $(eval includedep $(dep))
|
---|
113 | endif
|
---|
114 |
|
---|
115 | # call the tool
|
---|
116 | local cmds := $(TOOL_$(tool)_LEX_CMDS)
|
---|
117 | local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
|
---|
118 | local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
|
---|
119 | local deps += $(TOOL_$(tool)_LEX_DEPEND) $(source)
|
---|
120 | local orderdeps += $(TOOL_$(tool)_LEX_DEPORD)
|
---|
121 |
|
---|
122 | # generate the rule.
|
---|
123 | $(eval $(def_lex_rule))
|
---|
124 |
|
---|
125 | endef # def_src_handler_lex
|
---|
126 |
|
---|
127 |
|
---|