Built win.arm64 against r3658
[kbuild-mirror.git] / kBuild / units / dtrace.kmk
blob14273f4bdd5031560cb641c84aa9ef9f4db82b06
1 # $Id$
2 ## @file
3 # DTrace unit.
7 # Copyright (c) 2012-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
9 # This file is part of kBuild.
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.
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.
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
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.
34 ifdef UNIT_dtrace
35 $(error kBuild: The dtrace unit was included twice!)
36 endif
37 UNIT_dtrace = dtrace
39 # Add our target properties.
40 PROPS_TOOLS += DTRACETOOL
41 PROPS_SINGLE += DTRACETOOL
42 PROPS_ACCUMULATE_R += DTRACE_HDR_FLAGS DTRACE_OBJ_FLAGS
44 # Add ourselves to the default source handlers.
45 KBUILD_SRC_HANDLERS += \
46 .d:def_src_handler_dtrace
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
60 # Generates the rule for creating a DTrace header from a D source file.
62 # @param out The output file.
63 # @param cmds The dtrace command(s).
64 # @param lots more
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)
75 $(cmds)
77 ifndef NO_COMPILE_CMDS_DEPS
78 ifdef KBUILD_HAVE_OPTIMIZED_APPEND
79 %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
80 'define $(target)_$(subst :,_,$(source))_DTRACE_HDR_CMDS_PREV_' \
81 '--insert-command=$(out)' \
82 'endef'
83 else
84 %$$(QUIET2)$$(APPEND) '$(dep)'
85 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_DTRACE_HDR_CMDS_PREV_'
86 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
87 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
88 endif
89 endif
91 # update globals
92 _OUT_FILES += $(out)
93 $(target)_2_INTERMEDIATES += $(out)
95 endef # def_dtrace_hdr_rule
99 # Generates the rule for creating a DTrace object file from a D source file
100 # and a bunch of object files.
102 # @param out The output file.
103 # @param cmds The dtrace command(s).
104 # @param lots more
106 define def_dtrace_obj_rule
107 $(out): \
108 $(deps) \
109 $$$$(filter-out %-dtrace-object-format.o, $$$$($(target)_2_OBJS)) \
110 $(value _DEP_DTRACE_OBJ_CMDS) \
112 $(orderdeps)
113 %$$(call MSG_GENERATE,$(target),$$@,$(source) ++)
114 $$(QUIET)$$(RM) -f -- $(dep) $(out)
116 $(cmds)
118 ifndef NO_COMPILE_CMDS_DEPS
119 ifdef KBUILD_HAVE_OPTIMIZED_APPEND
120 %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
121 'define $(target)_$(subst :,_,$(source))_DTRACE_OBJ_CMDS_PREV_' \
122 '--insert-command=$(out)' \
123 'endef'
124 else
125 %$$(QUIET2)$$(APPEND) '$(dep)'
126 %$$(QUIET2)$$(APPEND) '$(dep)' 'define $(target)_$(subst :,_,$(source))_DTRACE_OBJ_CMDS_PREV_'
127 %$$(QUIET2)$$(APPEND) -c '$(dep)' '$(out)'
128 %$$(QUIET2)$$(APPEND) '$(dep)' 'endef'
129 endif
130 endif
132 # update globals
133 _OUT_FILES += $(out)
134 $(target)_2_OBJS <= $(out)
136 endef # def_dtrace_obj_rule
140 # Handler for .d files listed in the SOURCES properties.
142 # .d files are transformed into .h that is used when compiling, thus needing
143 # to be generated before anything is compiled, and into object files that needs
144 # to go into the linking. Mac does not create object files.
146 # The step producing the object file requires all the object files with dtrace
147 # probes in them as input/output as well, because it adjusts the dtrace symbols
148 # from UNDEF to IGNORE. This is really ugly and cannot be expressed in make
149 # syntax (prerequisite object files being modified). Fortunately, it works
150 # fine because the object files won't be used by anyone else before the dtrace
151 # object file exists.
153 # @param target The target file.
154 # @param source The source file.
155 # @param lots more
156 # @returns quite a bit.
157 define def_src_handler_dtrace
159 local type := DTRACE
160 local tmp := $(kb-src-tool tool)
161 ifeq ($(tool),)
162 $ (error kBuild: $(target) / $(sources) does not have a (DTRACE) tool defined!)
163 endif
164 local dtracedir := $($(target)_0_OUTDIR)/dtrace
167 # The header file first.
170 # Figure out all the props.
171 ifndef TOOL_$(tool)_DTRACE_HDR_CMDS
172 $(error kBuild: TOOL_$(tool)_DTRACE_HDR_CMDS isn't defined! target=$(target) source=$(source) )
173 endif
174 ## @todo put the header in a subdir and add this to INCS? Do we have a early per-target hook for this??
175 local outbase := $(dtracedir)/dtrace/$(basename $(notdir $(source)))
176 local out := $(outbase).h
177 local tmp := $(kb-src-prop DTRACE_HDR_FLAGS,flags,left-to-right,)
178 local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
179 local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
180 local dirdep := $(call DIRDEP,$(dir $(out)))
182 # Adjust paths if we got a default path.
183 ifneq ($(defpath),)
184 local source := $(abspathex $(source),$(defpath))
185 endif
187 # dependency file.
188 local dep := $(out)$(SUFF_DEP)
189 ifndef NO_COMPILE_CMDS_DEPS
190 _DEPFILES_INCLUDED += $(dep)
191 $(eval includedep $(dep))
192 endif
194 # call the tool
195 local cmds := $(TOOL_$(tool)_DTRACE_HDR_CMDS)
196 local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
197 local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
199 # generate the rule.
200 $(eval $(def_dtrace_hdr_rule))
204 # Adjust the object files and generate one from the D source, if needed.
206 ifn1of ($(bld_trg), $(TOOL_$(tool)_DTRACE_OBJ_NOT_NEEDED))
207 # Figure out all the props.
208 ifndef TOOL_$(tool)_DTRACE_OBJ_CMDS
209 $(error kBuild: TOOL_$(tool)_DTRACE_OBJ_CMDS isn't defined! target=$(target) source=$(source) )
210 endif
211 local outbase := $(dtracedir)/$(basename $(notdir $(source)))
212 local out := $(outbase)-dtrace-object-format.o
213 local tmp := $(kb-src-prop DTRACE_OBJ_FLAGS,flags,left-to-right,)
214 local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
215 local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
216 local dirdep := $(call DIRDEP,$(dir $(out)))
218 # Adjust paths if we got a default path.
219 ifneq ($(defpath),)
220 local source := $(abspathex $(source),$(defpath))
221 endif
223 # dependency file.
224 local dep := $(out)$(SUFF_DEP)
225 ifndef NO_COMPILE_CMDS_DEPS
226 _DEPFILES_INCLUDED += $(dep)
227 $(eval includedep $(dep))
228 endif
230 # call the tool
231 local cmds := $(TOOL_$(tool)_DTRACE_OBJ_CMDS)
232 local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
233 local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
235 # generate the rule.
236 $(eval $(def_dtrace_obj_rule))
237 endif
239 endef # def_src_handler_dtrace
244 # The pre-target hook.
246 define def_unit_dtrace_target_pre
248 local dtracedir := $($(target)_0_OUTDIR)/dtrace
249 $(eval $(target)_INCS += $(dtracedir))
251 endef #def_unit_dtrace_target_pre