| 1 | # $Id: dtrace.kmk 2726 2014-02-26 23:23:54Z bird $
|
|---|
| 2 | ## @file
|
|---|
| 3 | # DTrace unit.
|
|---|
| 4 | #
|
|---|
| 5 |
|
|---|
| 6 | #
|
|---|
| 7 | # Copyright (c) 2012-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_dtrace
|
|---|
| 35 | $(error kBuild: The lex unit was included twice!)
|
|---|
| 36 | endif
|
|---|
| 37 | UNIT_dtrace = dtrace
|
|---|
| 38 |
|
|---|
| 39 | # Add our target properties.
|
|---|
| 40 | PROPS_TOOLS += DTRACETOOL
|
|---|
| 41 | PROPS_SINGLE += DTRACETOOL
|
|---|
| 42 | PROPS_ACCUMULATE_R += DTRACE_HDR_FLAGS DTRACE_OBJ_FLAGS
|
|---|
| 43 |
|
|---|
| 44 | # Add ourselves to the default source handlers.
|
|---|
| 45 | KBUILD_SRC_HANDLERS += \
|
|---|
| 46 | .d:def_src_handler_dtrace
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | ## wrapper the compile command dependency check.
|
|---|
| 50 | ifndef NO_COMPILE_CMDS_DEPS
|
|---|
| 51 | _DEP_DTRACE_HDR_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_DTRACE_HDR_CMDS_PREV_),$$(commands $(out)),FORCE)
|
|---|
| 52 | _DEP_DTRACE_OBJ_CMDS = $$(comp-cmds-ex $$($(target)_$(subst :,_,$(source))_DTRACE_OBJ_CMDS_PREV_),$$(commands $(out)),FORCE)
|
|---|
| 53 | else
|
|---|
| 54 | _DEP_DTRACE_HDR_CMDS =
|
|---|
| 55 | _DEP_DTRACE_OBJ_CMDS =
|
|---|
| 56 | endif
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | ##
|
|---|
| 60 | # Generates the rule for creating a DTrace header from a D source file.
|
|---|
| 61 | #
|
|---|
| 62 | # @param out The output file.
|
|---|
| 63 | # @param cmds The dtrace command(s).
|
|---|
| 64 | # @param lots more
|
|---|
| 65 | #
|
|---|
| 66 | define def_dtrace_hdr_rule
|
|---|
| 67 | $(out): \
|
|---|
| 68 | $(deps) \
|
|---|
| 69 | $(value _DEP_DTRACE_HDR_CMDS) \
|
|---|
| 70 | | \
|
|---|
| 71 | $(orderdeps)
|
|---|
| 72 | %$$(call MSG_GENERATE,$(target),$$@,$(source))
|
|---|
| 73 | $$(QUIET)$$(RM) -f -- $(dep) $(out)
|
|---|
| 74 |
|
|---|
| 75 | $(cmds)
|
|---|
| 76 |
|
|---|
| 77 | ifndef NO_COMPILE_CMDS_DEPS
|
|---|
| 78 | %$$(QUIET2)$$(APPEND) '$(dep)'
|
|---|
| 79 | %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_DTRACE_HDR_CMDS_PREV_'
|
|---|
| 80 | %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
|
|---|
| 81 | %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
|
|---|
| 82 | endif
|
|---|
| 83 |
|
|---|
| 84 | # update globals
|
|---|
| 85 | _OUT_FILES += $(out)
|
|---|
| 86 | $(target)_INTERMEDIATES += $(out)
|
|---|
| 87 |
|
|---|
| 88 | endef # def_dtrace_hdr_rule
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | ##
|
|---|
| 92 | # Generates the rule for creating a DTrace object file from a D source file
|
|---|
| 93 | # and a bunch of object files.
|
|---|
| 94 | #
|
|---|
| 95 | # @param out The output file.
|
|---|
| 96 | # @param cmds The dtrace command(s).
|
|---|
| 97 | # @param lots more
|
|---|
| 98 | #
|
|---|
| 99 | define def_dtrace_obj_rule
|
|---|
| 100 | $(out): \
|
|---|
| 101 | $(deps) \
|
|---|
| 102 | $$$$(filter-out %-dtrace-object-format.o, $$$$($(target)_2_OBJS)) \
|
|---|
| 103 | $(value _DEP_DTRACE_OBJ_CMDS) \
|
|---|
| 104 | | \
|
|---|
| 105 | $(orderdeps)
|
|---|
| 106 | %$$(call MSG_GENERATE,$(target),$$@,$(source) ++)
|
|---|
| 107 | $$(QUIET)$$(RM) -f -- $(dep) $(out)
|
|---|
| 108 |
|
|---|
| 109 | $(cmds)
|
|---|
| 110 |
|
|---|
| 111 | ifndef NO_COMPILE_CMDS_DEPS
|
|---|
| 112 | %$$(QUIET2)$$(APPEND) '$(dep)'
|
|---|
| 113 | %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_DTRACE_OBJ_CMDS_PREV_'
|
|---|
| 114 | %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
|
|---|
| 115 | %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
|
|---|
| 116 | endif
|
|---|
| 117 |
|
|---|
| 118 | # update globals
|
|---|
| 119 | _OUT_FILES += $(out)
|
|---|
| 120 | $(target)_2_OBJS <= $(out)
|
|---|
| 121 |
|
|---|
| 122 | endef # def_dtrace_hdr_rule
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | ##
|
|---|
| 126 | # Handler for .d files listed in the SOURCES properties.
|
|---|
| 127 | #
|
|---|
| 128 | # .d files are transformed into .h that is used when compiling, thus needing
|
|---|
| 129 | # to be generated before anything is compiled, and into object files that needs
|
|---|
| 130 | # to go into the linking. Mac does not create object files.
|
|---|
| 131 | #
|
|---|
| 132 | # The step producing the object file requires all the object files with dtrace
|
|---|
| 133 | # probes in them as input/output as well, because it adjusts the dtrace symbols
|
|---|
| 134 | # from UNDEF to IGNORE. This is really ugly and cannot be expressed in make
|
|---|
| 135 | # syntax (prerequisite object files being modified). Fortunately, it works
|
|---|
| 136 | # fine because the object files won't be used by anyone else before the dtrace
|
|---|
| 137 | # object file exists.
|
|---|
| 138 | #
|
|---|
| 139 | # @param target The target file.
|
|---|
| 140 | # @param source The source file.
|
|---|
| 141 | # @param lots more
|
|---|
| 142 | # @returns quite a bit.
|
|---|
| 143 | define def_src_handler_dtrace
|
|---|
| 144 |
|
|---|
| 145 | local type := DTRACE
|
|---|
| 146 | local tmp := $(kb-src-tool tool)
|
|---|
| 147 | ifeq ($(tool),)
|
|---|
| 148 | $ (error kBuild: $(target) / $(sources) does not have a (DTRACE) tool defined!)
|
|---|
| 149 | endif
|
|---|
| 150 | local dtracedir := $($(target)_0_OUTDIR)/dtrace
|
|---|
| 151 |
|
|---|
| 152 | #
|
|---|
| 153 | # The header file first.
|
|---|
| 154 | #
|
|---|
| 155 |
|
|---|
| 156 | # Figure out all the props.
|
|---|
| 157 | ifndef TOOL_$(tool)_DTRACE_HDR_CMDS
|
|---|
| 158 | $(error kBuild: TOOL_$(tool)_DTRACE_HDR_CMDS isn't defined! target=$(target) source=$(source) )
|
|---|
| 159 | endif
|
|---|
| 160 | ## @todo put the header in a subdir and add this to INCS? Do we have a early per-target hook for this??
|
|---|
| 161 | local outbase := $(dtracedir)/dtrace/$(basename $(notdir $(source)))
|
|---|
| 162 | local out := $(outbase).h
|
|---|
| 163 | local tmp := $(kb-src-prop DTRACE_HDR_FLAGS,flags,left-to-right,)
|
|---|
| 164 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
|---|
| 165 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
|---|
| 166 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
|---|
| 167 |
|
|---|
| 168 | # Adjust paths if we got a default path.
|
|---|
| 169 | ifneq ($(defpath),)
|
|---|
| 170 | local source := $(abspathex $(source),$(defpath))
|
|---|
| 171 | endif
|
|---|
| 172 |
|
|---|
| 173 | # dependency file.
|
|---|
| 174 | local dep := $(out)$(SUFF_DEP)
|
|---|
| 175 | ifndef NO_COMPILE_CMDS_DEPS
|
|---|
| 176 | _DEPFILES_INCLUDED += $(dep)
|
|---|
| 177 | $(eval includedep $(dep))
|
|---|
| 178 | endif
|
|---|
| 179 |
|
|---|
| 180 | # call the tool
|
|---|
| 181 | local cmds := $(TOOL_$(tool)_DTRACE_HDR_CMDS)
|
|---|
| 182 | local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
|
|---|
| 183 | local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
|
|---|
| 184 |
|
|---|
| 185 | # generate the rule.
|
|---|
| 186 | $(eval $(def_dtrace_hdr_rule))
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 | #
|
|---|
| 190 | # Adjust the object files and generate one from the D source, if needed.
|
|---|
| 191 | #
|
|---|
| 192 | ifn1of ($(bld_trg), $(TOOL_$(tool)_DTRACE_OBJ_NOT_NEEDED))
|
|---|
| 193 | # Figure out all the props.
|
|---|
| 194 | ifndef TOOL_$(tool)_DTRACE_OBJ_CMDS
|
|---|
| 195 | $(error kBuild: TOOL_$(tool)_DTRACE_OBJ_CMDS isn't defined! target=$(target) source=$(source) )
|
|---|
| 196 | endif
|
|---|
| 197 | local outbase := $(dtracedir)/$(basename $(notdir $(source)))
|
|---|
| 198 | local out := $(outbase)-dtrace-object-format.o
|
|---|
| 199 | local tmp := $(kb-src-prop DTRACE_OBJ_FLAGS,flags,left-to-right,)
|
|---|
| 200 | local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
|
|---|
| 201 | local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
|
|---|
| 202 | local dirdep := $(call DIRDEP,$(dir $(out)))
|
|---|
| 203 |
|
|---|
| 204 | # Adjust paths if we got a default path.
|
|---|
| 205 | ifneq ($(defpath),)
|
|---|
| 206 | local source := $(abspathex $(source),$(defpath))
|
|---|
| 207 | endif
|
|---|
| 208 |
|
|---|
| 209 | # dependency file.
|
|---|
| 210 | local dep := $(out)$(SUFF_DEP)
|
|---|
| 211 | ifndef NO_COMPILE_CMDS_DEPS
|
|---|
| 212 | _DEPFILES_INCLUDED += $(dep)
|
|---|
| 213 | $(eval includedep $(dep))
|
|---|
| 214 | endif
|
|---|
| 215 |
|
|---|
| 216 | # call the tool
|
|---|
| 217 | local cmds := $(TOOL_$(tool)_DTRACE_OBJ_CMDS)
|
|---|
| 218 | local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
|
|---|
| 219 | local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
|
|---|
| 220 |
|
|---|
| 221 | # generate the rule.
|
|---|
| 222 | $(eval $(def_dtrace_obj_rule))
|
|---|
| 223 | endif
|
|---|
| 224 |
|
|---|
| 225 | endef # def_src_handler_dtrace
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 | #
|
|---|
| 230 | # The pre-target hook.
|
|---|
| 231 | #
|
|---|
| 232 | define def_unit_dtrace_target_pre
|
|---|
| 233 |
|
|---|
| 234 | local dtracedir := $($(target)_0_OUTDIR)/dtrace
|
|---|
| 235 | $(eval $(target)_INCS += $(dtracedir))
|
|---|
| 236 |
|
|---|
| 237 | endef #def_unit_dtrace_target_pre
|
|---|
| 238 |
|
|---|