1# Copyright (c) 2009 Sun Microsystems, Inc. 2# Use is subject to license terms. 3# 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; version 2 of the License. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA 16 17# Generates an ELF object file with dtrace entry points. 18# This object that must to be linked with together with 19# the target. This script needs to run on Solaris only 20 21# Do not follow symlinks in GLOB_RECURSE 22CMAKE_POLICY(SET CMP0009 NEW) 23FILE(REMOVE ${OUTFILE}) 24 25MACRO(CONVERT_TO_RELATIVE_PATHS files rel_paths) 26 GET_FILENAME_COMPONENT(abs_dir . ABSOLUTE) 27 SET(${rel_paths}) 28 FOREACH(file ${files}) 29 FILE(RELATIVE_PATH rel ${abs_dir} ${file}) 30 LIST(APPEND ${rel_paths} ${rel}) 31 ENDFOREACH() 32ENDMACRO() 33 34IF(TYPE STREQUAL "MERGE") 35 # Rerun dtrace on objects that are already in static libraries. 36 # Object paths are stored in text files named 'dtrace_objects' 37 # in the input directories. We have to copy the objects into temp. 38 # directory, as running dtrace -G on original files will change 39 # timestamps and cause rebuilds or the libraries / excessive 40 # relink 41 FILE(REMOVE_RECURSE dtrace_objects_merge) 42 MAKE_DIRECTORY(dtrace_objects_merge) 43 44 FOREACH(dir ${DIRS}) 45 FILE(STRINGS ${dir}/dtrace_objects OBJS) 46 FOREACH(obj ${OBJS}) 47 IF(obj) 48 EXECUTE_PROCESS(COMMAND cp ${obj} dtrace_objects_merge) 49 ENDIF() 50 ENDFOREACH() 51 ENDFOREACH() 52 FILE(GLOB_RECURSE OBJECTS dtrace_objects_merge/*.o) 53 CONVERT_TO_RELATIVE_PATHS("${OBJECTS}" REL_OBJECTS) 54 EXECUTE_PROCESS( 55 COMMAND ${DTRACE} ${DTRACE_FLAGS} -o ${OUTFILE} -G -s ${DFILE} ${REL_OBJECTS} 56 ) 57 RETURN() 58ENDIF() 59 60FOREACH(dir ${DIRS}) 61 FILE(GLOB_RECURSE OBJECTS ${dir}/*.o) 62 CONVERT_TO_RELATIVE_PATHS("${OBJECTS}" REL) 63 LIST(APPEND REL_OBJECTS ${REL}) 64ENDFOREACH() 65 66FILE(WRITE dtrace_timestamp "") 67EXECUTE_PROCESS( 68 COMMAND ${DTRACE} ${DTRACE_FLAGS} -o ${OUTFILE} -G -s ${DFILE} ${REL_OBJECTS} 69) 70 71# Save objects that contain dtrace probes in a file. 72# This file is used when script is called with -DTYPE=MERGE 73# to dtrace from static libs. 74# To find objects with probes, look at the timestamp, it was updated 75# by dtrace -G run 76IF(TYPE MATCHES "STATIC") 77 FILE(WRITE dtrace_objects "") 78 FOREACH(obj ${REL_OBJECTS}) 79 IF(${obj} IS_NEWER_THAN dtrace_timestamp) 80 GET_FILENAME_COMPONENT(obj_absolute_path ${obj} ABSOLUTE) 81 FILE(APPEND dtrace_objects "${obj_absolute_path}\n" ) 82 ENDIF() 83 ENDFOREACH() 84ENDIF() 85