[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] | 34 | ifdef UNIT_lex
|
---|
| 35 | $(error kBuild: The lex unit was included twice!)
|
---|
| 36 | endif
|
---|
[1621] | 37 | UNIT_lex = lex
|
---|
| 38 |
|
---|
[2224] | 39 | # Add our target properties.
|
---|
| 40 | PROPS_TOOLS += LEXTOOL
|
---|
| 41 | PROPS_SINGLE += LEXTOOL
|
---|
| 42 | PROPS_ACCUMULATE_R += LEXFLAGS
|
---|
| 43 |
|
---|
[1621] | 44 | # Add ourselves to the default source handlers.
|
---|
| 45 | KBUILD_SRC_HANDLERS += \
|
---|
| 46 | .l:def_src_handler_lex
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | ## wrapper the compile command dependency check.
|
---|
| 50 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
| 51 | _DEP_LEX_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_),$$(commands $(out)),FORCE)
|
---|
| 52 | else
|
---|
| 53 | _DEP_LEX_CMDS =
|
---|
| 54 | endif
|
---|
| 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
|
---|
| 62 | define 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 |
|
---|
| 73 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
[3160] | 74 | ifdef KBUILD_HAVE_OPTIMIZED_APPEND
|
---|
| 75 | %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
|
---|
| 76 | 'define $(target)_$(subst :,_,$(source))_LEX_CMDS_PREV_' \
|
---|
| 77 | '--insert-command=$(out)' \
|
---|
| 78 | 'endef'
|
---|
| 79 | else
|
---|
[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'
|
---|
| 84 | endif
|
---|
[3160] | 85 | endif
|
---|
[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 |
|
---|
| 92 | endef # 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] | 104 | define def_src_handler_lex
|
---|
[1621] | 105 | # Figure out all the props.
|
---|
| 106 | local type := LEX
|
---|
| 107 | local tmp := $(kb-src-tool tool)
|
---|
| 108 | ifeq ($(tool),)
|
---|
| 109 | $(error kBuild: $(target) / $(sources) does not a (lex) tool defined!)
|
---|
| 110 | endif
|
---|
[1623] | 111 | ifndef TOOL_$(tool)_LEX_CMDS
|
---|
| 112 | $(error kBuild: TOOL_$(tool)_LEX_CMDS isn't defined! target=$(target) source=$(source) )
|
---|
| 113 | endif
|
---|
[1621] | 114 | local out := $(kb-obj-base outbase).c
|
---|
| 115 | local tmp := $(kb-src-prop LEXFLAGS,flags,left-to-right,)
|
---|
| 116 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
---|
| 117 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
---|
[1623] | 118 | ifdef 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
|
---|
| 123 | endif
|
---|
[1621] | 124 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
---|
| 125 |
|
---|
| 126 | # Adjust paths if we got a default path.
|
---|
| 127 | ifneq ($(defpath),)
|
---|
[1623] | 128 | local source := $(abspathex $(source),$(defpath))
|
---|
[1621] | 129 | endif
|
---|
| 130 |
|
---|
| 131 | # dependency file.
|
---|
| 132 | local dep := $(out)$(SUFF_DEP)
|
---|
| 133 | ifndef NO_COMPILE_CMDS_DEPS
|
---|
| 134 | _DEPFILES_INCLUDED += $(dep)
|
---|
| 135 | $(eval includedep $(dep))
|
---|
| 136 | endif
|
---|
| 137 |
|
---|
| 138 | # call the tool
|
---|
| 139 | local cmds := $(TOOL_$(tool)_LEX_CMDS)
|
---|
| 140 | local output_extra := $(TOOL_$(tool)_LEX_OUTPUT)
|
---|
| 141 | local output_maybe := $(TOOL_$(tool)_LEX_OUTPUT_MAYBE)
|
---|
[1623] | 142 | local deps += $(TOOL_$(tool)_LEX_DEPEND) $(source)
|
---|
[2224] | 143 | local orderdeps += $(TOOL_$(tool)_LEX_DEPORD) $(dirdep)
|
---|
[1621] | 144 |
|
---|
[2224] | 145 | # Whether it generates a header file depends on the tool / flags.
|
---|
| 146 | local intermediates := $(filter %.h %.hpp %.h++ %.H,$(output_extra))
|
---|
| 147 |
|
---|
[1621] | 148 | # generate the rule.
|
---|
| 149 | $(eval $(def_lex_rule))
|
---|
| 150 |
|
---|
[1625] | 151 | endef # def_src_handler_lex
|
---|
[1621] | 152 |
|
---|
| 153 |
|
---|