source: trunk/kBuild/units/lex.kmk

Last change on this file was 3284, checked in by bird, 7 years ago

footer-pass2-compiling-targets.kmk,units: Added a dedicated pass 2 variable for units to put their intermediates in so as to not mess with inheritance or for us to do silly things wrt expansion for every property variant. Only the new variable is now always listed as an order-only dependency for each source compilation rule.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
RevLine 
[1621]1# $Id: lex.kmk 3284 2019-01-05 01:40:31Z bird $
2## @file
3# lex unit.
4#
5
6#
[3121]7# Copyright (c) 2008-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
[1621]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#
[2018]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#
[1621]33
[2224]34ifdef UNIT_lex
35 $(error kBuild: The lex unit was included twice!)
36endif
[1621]37UNIT_lex = lex
38
[2224]39# Add our target properties.
40PROPS_TOOLS += LEXTOOL
41PROPS_SINGLE += LEXTOOL
42PROPS_ACCUMULATE_R += LEXFLAGS
43
[1621]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
[3160]74ifdef KBUILD_HAVE_OPTIMIZED_APPEND
75 %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
76 'define $(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_' \
77 '--insert-command=$(out)' \
78 'endef'
79else
[1621]80 %$$(QUIET2)$$(APPEND) '$(dep)'
81 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_'
82 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
83 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
84endif
[3160]85endif
[1621]86
87# update globals
88_OUT_FILES += $(out) $(output_extra) $(output_maybe)
89$(target)_GEN_SOURCES_ += $(out)
[3284]90$(target)_2_INTERMEDIATES += $(intermediates)
[1621]91
92endef # def_lex_rule
93
94##
95# Handler for .l files listed in the SOURCES properties.
96#
97# .l files are transformed into .c files that then gets compiled by
98# the C compiler.
99#
100# @param target The target file.
101# @param source The source file.
102# @param lots more
103# @returns quite a bit.
[1625]104define def_src_handler_lex
[1621]105# Figure out all the props.
106local type := LEX
107local tmp := $(kb-src-tool tool)
108ifeq ($(tool),)
109$(error kBuild: $(target) / $(sources) does not a (lex) tool defined!)
110endif
[1623]111ifndef TOOL_$(tool)_LEX_CMDS
112$(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
113endif
[1621]114local out := $(kb-obj-base outbase).c
115local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
116local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
117local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
[1623]118ifdef TOOL_$(tool)_LEX_OUT_FILE # .c/.cpp output depends on flags.
119 local out := $(strip $(TOOL_$(tool)_LEX_OUT_FILE))
120 ifeq ($(out),)
121 local out := $(outbase).c
122 endif
123endif
[1621]124local dirdep := $(call DIRDEP,$(dir $(out)))
125
126# Adjust paths if we got a default path.
127ifneq ($(defpath),)
[1623]128 local source := $(abspathex $(source),$(defpath))
[1621]129endif
130
131# dependency file.
132local dep := $(out)$(SUFF_DEP)
133ifndef NO_COMPILE_CMDS_DEPS
134 _DEPFILES_INCLUDED += $(dep)
135 $(eval includedep $(dep))
136endif
137
138# call the tool
139local cmds := $(TOOL_$(tool)_LEX_CMDS)
140local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
141local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
[1623]142local deps += $(TOOL_$(tool)_LEX_DEPEND) $(source)
[2224]143local orderdeps += $(TOOL_$(tool)_LEX_DEPORD) $(dirdep)
[1621]144
[2224]145# Whether it generates a header file depends on the tool / flags.
146local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
147
[1621]148# generate the rule.
149$(eval $(def_lex_rule))
150
[1625]151endef # def_src_handler_lex
[1621]152
153
Note: See TracBrowser for help on using the repository browser.