2 set TM_PLATFORM
"$TM_OPSYS-$TM_MACHINE_ARCH"
4 # Check if a variable var is defined
6 if {[uplevel "info exists $var"]} {
13 # True if target is the current goal
15 global TM_CURRENT_GOAL
17 if {"$target" eq
"$TM_CURRENT_GOAL"} {
24 # True if operand is the empty string
25 proc empty
{operand
} {
26 if {[string length
$operand]} {
33 # Check if an array a contains a value for key
34 proc array_has
{a key
} {
35 if {[string length
[uplevel "array get $a $key"]]} {
42 # Set a global parameter var to val using mode mode
43 proc param
{var val
} {
48 if {[array_has TM_PARAM
$var]} {
49 uplevel "set $var {$TM_PARAM($var)}"
50 } elseif
{[info exists TM_ENV_LOOKUP
]} {
51 uplevel "set $var {$env($var)}"
53 uplevel "set $var {$val}"
57 # Clean up a list of options to make it suitable for exec
59 set OPTIONS
[split $str "\n"]
61 foreach OPT
$OPTIONS {
62 set trim
[string trim
$OPT]
63 if {[string length
$trim]} {
64 lappend TRIMOPTS
$trim
81 if {[defined TM_NO_EXECUTE
]} {
82 set noexec
$TM_NO_EXECUTE
85 if {[llength args
] == 0} {
89 if {"[lindex $args 0]" eq
"-flags"} {
90 if {[llength $args] < 2} {
91 error "No flags provided to -flags"
93 set flags
[lindex $args 1]
97 for {set i
0} {$i < [string length
$flags]} {incr i
} {
98 switch [string index
$flags $i] {
102 default {error "Unknown flag given to exec: [string index $i]"}
106 set rest
[lrange $args $start end
]
108 if {$echo && ![defined TM_SILENT_MODE
]} {
109 # Do it this way to avoid having Tcl escape quotes and such
111 foreach arg
[lrange $rest 0 end-1
] {
112 puts -nonewline "$arg "
114 puts "[lrange $rest end end]"
122 if {![defined TM_SILENT_MODE
]} {
123 set childpid
[tcl
::exec {*}$rest &]
124 set status
[os.wait
$childpid] ;# TODO: This might not work on Windows...
126 if {"[lindex $status 1]" eq
"exit" && [lindex $status 2] != 0} {
128 error "exec returned non-zero return code: $status"
130 } elseif
{"[lindex $status 1]" ne
"exit"} {
132 error "exec terminated abnormally: $status"
138 } on CHILDSTATUS
{pid code
} {
139 error "exec returned non-zero return code: $code"
140 } on CHILDKILLED
{pid sig msg
} {
141 error "exec terminated abnormally: $msg"
142 } on CHILDSUSP
{pid sig msg
} {
143 error "exec suspended: $msg"
151 # Take a list of filenames and replace the extensions that match x with y
152 proc replace-ext
{files x y
} {
155 if {"[file extension $f]" eq
"$x"} {
156 lappend ys
"[file rootname $f]$y"
165 # Define a substitution rule. Returns a list of all the targets created.
166 proc sub
{from to recipe
} {
169 foreach in
[glob *$from] {
170 set out
[replace-ext
$in $from $to]
171 rule
$out $in $recipe
178 # Create a list of filenames with dir prepended to a given list of filenames
179 proc in-dir
{dir files
} {
182 lappend newfiles
[file join $dir $f]