set exec_prefix @exec_prefix@ set libdir @libdir@ set bindir @bindir@ set topdir [lindex $argv 0] set os $tcl_platform(os) if { $os == "Linux" } { proc change_path { file } { if { [catch {exec chrpath $file 2> /dev/null} rpath] == 0 } { global libdir if { [regexp -- ".*PATH=$libdir" $rpath] } { if { ![file writable $file] } { file attributes $file -permissions u+w } exec chrpath -r {$ORIGIN/../lib} $file } } } foreach i [glob -nocomplain [file join $topdir bin *]] { change_path $i } foreach i [glob -nocomplain $topdir/lib/*.so $topdir/lib/*/*.so] { change_path $i } } elseif { $os == "Darwin" } { proc change_path { file } { if { [catch {exec otool -L $file 2> /dev/null} rpaths] == 0 } { global libdir set pattern [format {^\t(%s/lib[a-zA-Z0-9\._\-]+dylib)} $libdir] foreach line [split $rpaths \n] { if { [regexp -- $pattern $line match libpath] } { if { ![file writable $file] } { file attributes $file -permissions u+w } set lib [file tail $libpath] exec install_name_tool -change $libpath \ @executable_path/../lib/$lib $file } } } } proc change_no_path { file } { if { [catch {exec otool -L $file 2> /dev/null} rpaths] == 0 } { set pattern {^\t(lib[a-zA-Z0-9\._\-]+dylib)} foreach line [split $rpaths \n] { if { [regexp -- $pattern $line match lib] } { if { ![file writable $file] } { file attributes $file -permissions u+w } exec install_name_tool -change $lib \ @executable_path/../lib/$lib $file } } } } foreach i [glob -nocomplain $topdir/MacOS/* $topdir/bin/*] { change_path $i } foreach i [glob -nocomplain $topdir/lib/*.dylib $topdir/lib/*/*.dylib] { change_path $i change_no_path $i } }