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