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.
35 $(error kBuild
: The dtrace unit was included twice
!)
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
)
54 _DEP_DTRACE_HDR_CMDS
=
55 _DEP_DTRACE_OBJ_CMDS
=
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).
66 define def_dtrace_hdr_rule
69 $(value _DEP_DTRACE_HDR_CMDS
) \
72 %$$(call MSG_GENERATE
,$(target
),$$@
,$(source
))
73 $$(QUIET
)$$(RM
) -f
-- $(dep
) $(out
)
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)' \
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'
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).
106 define def_dtrace_obj_rule
109 $$$$(filter-out %-dtrace-object-format.o
, $$$$($(target
)_2_OBJS
)) \
110 $(value _DEP_DTRACE_OBJ_CMDS
) \
113 %$$(call MSG_GENERATE
,$(target
),$$@
,$(source
) ++)
114 $$(QUIET
)$$(RM
) -f
-- $(dep
) $(out
)
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)' \
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'
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.
156 # @returns quite a bit.
157 define def_src_handler_dtrace
160 local tmp
:= $(kb-src-tool tool
)
162 $ (error kBuild
: $(target
) / $(sources
) does not have a
(DTRACE
) tool defined
!)
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) )
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.
184 local source := $(abspathex $(source),$(defpath))
188 local dep := $(out)$(SUFF_DEP)
189 ifndef NO_COMPILE_CMDS_DEPS
190 _DEPFILES_INCLUDED += $(dep)
191 $(eval includedep $(dep))
195 local cmds := $(TOOL_$(tool)_DTRACE_HDR_CMDS)
196 local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
197 local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
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
) )
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.
220 local source
:= $(abspathex
$(source
),$(defpath
))
224 local dep
:= $(out
)$(SUFF_DEP
)
225 ifndef NO_COMPILE_CMDS_DEPS
226 _DEPFILES_INCLUDED
+= $(dep
)
227 $(eval includedep
$(dep
))
231 local cmds
:= $(TOOL_
$(tool
)_DTRACE_OBJ_CMDS
)
232 local deps
+= $(TOOL_
$(tool
)_DTRACE_DEPEND
) $(source
)
233 local orderdeps
+= $(TOOL_
$(tool
)_DTRACE_DEPORD
) $(dirdep
)
236 $(eval
$(def_dtrace_obj_rule
))
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