10bbfda8aSnia# Try setting up some bits for dtrace.
20bbfda8aSnia#
30bbfda8aSnia# By itself, dtrace can trace things like function entry/return points
40bbfda8aSnia# just fine, and even pull numeric and string arguments.  More involved
50bbfda8aSnia# data structures, though, would either need manual definition in the D
60bbfda8aSnia# scripts (which is practically impossible for anything sizable), manual
70bbfda8aSnia# specification of offsets (even worse), or CTF info included in the
80bbfda8aSnia# binary (hey, we can do that!).  So, see if we can pull that stuff in...
90bbfda8aSnia
100bbfda8aSniafind_program(CTFCONVERT ctfconvert)
110bbfda8aSniafind_program(CTFMERGE   ctfmerge)
120bbfda8aSnia
130bbfda8aSniaif(CTFCONVERT AND CTFMERGE)
140bbfda8aSnia	message(STATUS "Found ctfconvert/ctfmerge, setting up CTF info for dtrace.")
150bbfda8aSnia
160bbfda8aSnia	# ctfconvert/merge is about pulling over debug info, so make sure we
170bbfda8aSnia	# enable that in the objects.
180bbfda8aSnia	add_definitions("-g")
190bbfda8aSnia
200bbfda8aSnia	# ctfconvert/merge on BSD has a '-g' option, which we want to use
210bbfda8aSnia	# (preserves the -g info in the final binary).  Solarish apparently
220bbfda8aSnia	# doesn't; maybe it always does it anyway?  Regardless, figure out
230bbfda8aSnia	# whether it takes that arg...
240bbfda8aSnia	execute_process(COMMAND ${CTFCONVERT} -g -l0 /dev/null
250bbfda8aSnia		OUTPUT_QUIET ERROR_VARIABLE _CTFCONVERT_G_OUT)
260bbfda8aSnia	if(${_CTFCONVERT_G_OUT} MATCHES "^Usage:")
270bbfda8aSnia		# No -g; leave vars alone
280bbfda8aSnia	else()
290bbfda8aSnia		# Add -g
300bbfda8aSnia		set(CTFCONVERT "${CTFCONVERT} -g")
310bbfda8aSnia		set(CTFMERGE "${CTFMERGE} -g")
320bbfda8aSnia	endif()
330bbfda8aSnia
340bbfda8aSnia	# This is a horrific hack.  cmake provides no way to actually find
350bbfda8aSnia	# out the list of object files, or where they are, because that would
360bbfda8aSnia	# be too easy.  So we have to "know", and take our best shot.  Sigh.
370bbfda8aSnia	# Well, it's really only a dev tool anyway, so I guess some manual
380bbfda8aSnia	# mess isn't the end of the world.  We can't check the existence yet
390bbfda8aSnia	# here, since it hasn't been created at this point in the process.
400bbfda8aSnia	# So we just have to hope.  mk_ctf_info.sh will warn us if things
410bbfda8aSnia	# change...
420bbfda8aSnia	set(CODIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ctwmlib.dir)
430bbfda8aSnia
440bbfda8aSnia	add_custom_command(TARGET ctwm POST_BUILD
450bbfda8aSnia		COMMAND ${CMAKE_COMMAND} -E env
460bbfda8aSnia			CTFCONVERT=${CTFCONVERT} CTFMERGE=${CTFMERGE}
470bbfda8aSnia			${TOOLS}/mk_ctf_info.sh ${CODIR}
480bbfda8aSnia			${CMAKE_CURRENT_BINARY_DIR}/ctwm
490bbfda8aSnia		COMMENT "Converting in CTF info for dtrace"
500bbfda8aSnia	)
510bbfda8aSniaendif()
52