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

Last change on this file since 3023 was 2726, checked in by bird, 11 years ago

s/PATH_DEVTOOLS/KBUILD_DEVTOOLS/g, (c) & e-mail updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
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
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
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'
82endif
83
84# update globals
85_OUT_FILES += $(out)
86$(target)_INTERMEDIATES += $(out)
87
88endef # 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#
99define 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
111ifndef 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'
116endif
117
118# update globals
119_OUT_FILES += $(out)
120$(target)_2_OBJS <= $(out)
121
122endef # 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.
143define def_src_handler_dtrace
144
145local type := DTRACE
146local tmp := $(kb-src-tool tool)
147ifeq ($(tool),)
148$ (error kBuild: $(target) / $(sources) does not have a (DTRACE) tool defined!)
149endif
150local dtracedir := $($(target)_0_OUTDIR)/dtrace
151
152#
153# The header file first.
154#
155
156# Figure out all the props.
157ifndef TOOL_$(tool)_DTRACE_HDR_CMDS
158$(error kBuild: TOOL_$(tool)_DTRACE_HDR_CMDS isn't defined! target=$(target) source=$(source) )
159endif
160## @todo put the header in a subdir and add this to INCS? Do we have a early per-target hook for this??
161local outbase := $(dtracedir)/dtrace/$(basename $(notdir $(source)))
162local out := $(outbase).h
163local tmp := $(kb-src-prop DTRACE_HDR_FLAGS,flags,left-to-right,)
164local tmp := $(kb-src-prop DEPS,deps,left-to-right,$(defpath))
165local tmp := $(kb-src-prop ORDERDEPS,orderdeps,left-to-right,$(defpath))
166local dirdep := $(call DIRDEP,$(dir $(out)))
167
168# Adjust paths if we got a default path.
169ifneq ($(defpath),)
170 local source := $(abspathex $(source),$(defpath))
171endif
172
173# dependency file.
174local dep := $(out)$(SUFF_DEP)
175ifndef NO_COMPILE_CMDS_DEPS
176 _DEPFILES_INCLUDED += $(dep)
177 $(eval includedep $(dep))
178endif
179
180# call the tool
181local cmds := $(TOOL_$(tool)_DTRACE_HDR_CMDS)
182local deps += $(TOOL_$(tool)_DTRACE_DEPEND) $(source)
183local 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#
192ifn1of ($(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))
223endif
224
225endef # def_src_handler_dtrace
226
227
228
229#
230# The pre-target hook.
231#
232define def_unit_dtrace_target_pre
233
234local dtracedir := $($(target)_0_OUTDIR)/dtrace
235$(eval $(target)_INCS += $(dtracedir))
236
237endef #def_unit_dtrace_target_pre
238
Note: See TracBrowser for help on using the repository browser.