ref: 82532ed187c6041e7dff5505de21e95d7fd380d9
dir: /util.myr/
use std
use "opts.use"
pkg bld =
const run : (cmd : byte[:][:], dir : byte[:] -> void)
const srcsplit : (src : byte[:] -> (byte[:], byte[:], byte[:]))
const swapsuffix : (f : byte[:], suff : byte[:], newsuff : byte[:] -> byte[:])
const srcswapsuffix : (f : byte[:], newsuff : byte[:] -> byte[:])
const strlistfree : (sl : byte[:][:] -> void)
const isplatform : (src : byte[:] -> bool)
;;
const run = {cmd, dir
var pid
var status
printcmd(cmd)
pid = std.fork()
if pid == -1
std.fatal(1, "could not fork command\n")
elif pid == 0
if dir.len > 0
if std.chdir(dir) < 0
std.fatal(1, "unable to enter directory %s\n", dir)
;;
;;
if std.execvp(cmd[0], cmd) < 0
std.fatal(1, "failed to exec %s\n", cmd[0])
;;
else
std.waitpid(pid, &status, 0)
;;
match std.waitstatus(status)
| `std.Waitexit estatus:
if estatus != 0
std.exit(estatus castto(int))
;;
| `std.Waitsig sig:
std.fatal(1, "%s exited with signal %i\n", cmd[0], sig)
;;
}
const printcmd = {lst
if lst.len > 0
std.put("\t")
std.put("%s\t", lst[0])
for l in lst[1:]
std.put("%s ", l)
;;
;;
std.put("\n")
}
const srcsplit = {src
var platf, suff
platf = ""
suff = ""
match std.strrfind(src, ".")
| `std.Some i:
suff = src[i:]
src = src[:i]
;;
match std.strrfind(src, "+")
| `std.Some i:
platf = src[i:]
src = src[:i]
;;
-> (src, platf, suff)
}
const swapsuffix = {f, suff, newsuff
if std.hassuffix(f, suff)
f = f[:f.len - suff.len]
;;
-> std.fmt("%s%s", f, newsuff)
}
const srcswapsuffix = {src, new
var base, platf, suff
(base, platf, suff) = srcsplit(src)
if std.sleq(suff, ".myr")
-> std.strcat(base, new)
elif std.sleq(suff, ".s")
-> std.strcat(base, new)
else
std.fatal(1, "unrecognized source %s\n", src)
;;
}
const isplatform = {src
var base, platf, suff
(base, platf, suff) = srcsplit(src)
-> platf.len == 0 || \
std.sleq(platf, sysarchstr) || \
std.sleq(platf, sysstr) || \
std.sleq(platf, archstr)
}
const strlistfree = {sl
for s in sl
std.slfree(s)
;;
std.slfree(sl)
}