ngspice/src/libtool_wrapper_for_cuda.tcl

77 lines
2.1 KiB
Tcl
Executable File

#!/usr/bin/tclsh
if {$argc == 0} {
puts "Usage: 'libtool_wrapper_for_cuda.tcl' 'filename' '-static | -shared' 'compilation line'"
exit 1
}
# Rename object file .lo in .o
set filename_lo [lindex $argv 0]
set filename_o [file rootname $filename_lo].o
# Determine where the object file has to be created and the NVCC compilation command
if {[lindex $argv 1] == "-static"} {
set filename $filename_o
set command [lrange $argv 2 end]
append command " -o $filename"
} else {
file mkdir [file dirname $filename_o]/.libs
set filename "[file dirname $filename_o]/.libs/[file tail $filename_o]"
set command [lrange $argv 2 end]
append command " -Xcompiler -fPIC"
append command " -o $filename"
}
# Compile
#puts "Executing: $command"
exec /bin/sh -c $command
# Determine the libtool version (including compiler version)
set output ""
catch {exec uname} output
if {$output == "Darwin"} {
# Mac version
catch {exec glibtool --version} output
set output [split $output "\n"]
foreach elem $output {
if {[regexp -- {glibtool \(GNU libtool\) (.+)$} $elem -> version]} {
break
}
}
} elseif {$output == "Linux"} {
# Linux version
catch {exec libtoolize --version} output
set output [split $output "\n"]
foreach elem $output {
if {[regexp -- {libtoolize \(GNU libtool\) (.+)$} $elem -> version]} {
break
}
}
} else {
puts "Unknown architecture '$output'"
exit 1
}
# Generate the .lo libtool object file
set fid [open $filename_lo w]
puts $fid "# [file tail $filename_lo] - a libtool object file"
puts $fid "# Generated by libtool $version"
puts $fid "#"
puts $fid "# Please DO NOT delete this file!"
puts $fid "# It is necessary for linking the library."
puts $fid ""
if {[lindex $argv 1] == "-static"} {
puts $fid "# Name of the PIC object."
puts $fid "pic_object=none"
puts $fid ""
puts $fid "# Name of the non-PIC object"
puts $fid "non_pic_object='[file tail $filename]'"
} else {
puts $fid "# Name of the PIC object."
puts $fid "pic_object='.libs/[file tail $filename]'"
puts $fid ""
puts $fid "# Name of the non-PIC object"
puts $fid "non_pic_object=none"
}
close $fid