source: trunk/kBuild/units/dtrace.kmk@ 3229

Last change on this file since 3229 was 3160, checked in by bird, 7 years ago

kBuild//*.kmk: Use optimized kmk_builtin_append when availble.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.3 KB
Line 
1# $Id: dtrace.kmk 3160 2018-03-19 22:39:19Z bird $
2## @file
3# DTrace unit.
4#
5
6#
7# Copyright (c) 2012-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@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
34ifdef UNIT_dtrace
35 $(error kBuild: The lex unit was included twice!)
36endif
37UNIT_dtrace = dtrace
38
39# Add our target properties.
40PROPS_TOOLS += DTRACETOOL
41PROPS_SINGLE += DTRACETOOL
42PROPS_ACCUMULATE_R += DTRACE_HDR_FLAGS DTRACE_OBJ_FLAGS
43
44# Add ourselves to the default source handlers.
45KBUILD_SRC_HANDLERS += \
46 .d:def_src_handler_dtrace
47
48
49## wrapper the compile command dependency check.
50ifndef 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)
53else
54 _DEP_DTRACE_HDR_CMDS =
55 _DEP_DTRACE_OBJ_CMDS =
56endif
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#
66define 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
77ifndef NO_COMPILE_CMDS_DEPS
78ifdef KBUILD_HAVE_OPTIMIZED_APPEND
79 %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
80 'define $(target)_$(subst :,_,$(source))_DTRACE_HDR_CMDS_PREV_' \
81 '--insert-command=$(out)' \
82 'endef'
83else
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'
88endif
89endif
90
91# update globals
92_OUT_FILES += $(out)
93$(target)_INTERMEDIATES += $(out)
94
95endef # def_dtrace_hdr_rule
96
97
98##
99# Generates the rule for creating a DTrace object file from a D source file
100# and a bunch of object files.
101#
102# @param out The output file.
103# @param cmds The dtrace command(s).
104# @param lots more
105#
106define def_dtrace_obj_rule
107$(out): \
108 $(deps) \
109 $$$$(filter-out %-dtrace-object-format.o, $$$$($(target)_2_OBJS)) \
110 $(value _DEP_DTRACE_OBJ_CMDS) \
111 | \
112 $(orderdeps)
113 %$$(call MSG_GENERATE,$(target),$$@,$(source) ++)
114 $$(QUIET)$$(RM) -f -- $(dep) $(out)
115
116$(cmds)
117
118ifndef NO_COMPILE_CMDS_DEPS
119ifdef KBUILD_HAVE_OPTIMIZED_APPEND
120 %$$(QUIET2)$$(APPEND) -ni '$(dep)' \
121 'define $(target)_$(subst :,_,$(source))_DTRACE_OBJ_CMDS_PREV_' \
122 '--insert-command=$(out)' \
123 'endef'
124else
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'
129endif
130endif
131
132# update globals
133_OUT_FILES += $(out)
134$(target)_2_OBJS <= $(out)
135
136endef # def_dtrace_hdr_rule
137
138
139##
140# Handler for .d files listed in the SOURCES properties.
141#
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.
145#
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.
152#
153# @param target The target file.
154# @param source The source file.
155# @param lots more
156# @returns quite a bit.
157define def_src_handler_dtrace
158
159local type := DTRACE
160local tmp := $(kb-src-tool tool)
161ifeq ($(tool),)
162$ (error kBuild: $(target) / $(sources) does not have a (DTRACE) tool defined!)
163endif
164local dtracedir := $($(target)_0_OUTDIR)/dtrace
165
166#
167# The header file first.
168#
169
170# Figure out all the props.
171ifndef TOOL_$(tool)_DTRACE_HDR_CMDS
172$(error kBuild: TOOL_$(tool)_DTRACE_HDR_CMDS isn't defined! target=$(target) source=$(source) )
173endif
174## @todo put the header in a subdir and add this to INCS? Do we have a early per-target hook for this??
175local outbase := $(dtracedir)/dtrace/$(basename $(notdir $(source)))
176local out := $(outbase).h
177local tmp := $(kb-src-prop DTRACE_HDR_FLAGS,flags,left-to-right,)
178local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
179local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
180local dirdep := $(call DIRDEP,$(dir $(out)))
181
182# Adjust paths if we got a default path.
183ifneq ($(defpath),)
184 local source := $(abspathex $(source),$(defpath))
185endif
186
187# dependency file.
188local dep := $(out)$(SUFF_DEP)
189ifndef NO_COMPILE_CMDS_DEPS
190 _DEPFILES_INCLUDED += $(dep)
191 $(eval includedep $(dep))
192endif
193
194# call the tool
195local cmds := $(TOOL_$(tool)_DTRACE_HDR_CMDS)
196local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
197local orderdeps += $(TOOL_$(tool)_DTRACE_DEPORD) $(dirdep)
198
199# generate the rule.
200$(eval $(def_dtrace_hdr_rule))
201
202
203#
204# Adjust the object files and generate one from the D source, if needed.
205#
206ifn1of ($(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)))
217
218 # Adjust paths if we got a default path.
219 ifneq ($(defpath),)
220 local source := $(abspathex $(source),$(defpath))
221 endif
222
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
229
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)
234
235 # generate the rule.
236 $(eval $(def_dtrace_obj_rule))
237endif
238
239endef # def_src_handler_dtrace
240
241
242
243#
244# The pre-target hook.
245#
246define def_unit_dtrace_target_pre
247
248local dtracedir := $($(target)_0_OUTDIR)/dtrace
249$(eval $(target)_INCS += $(dtracedir))
250
251endef #def_unit_dtrace_target_pre
252
Note: See TracBrowser for help on using the repository browser.