summaryrefslogtreecommitdiff
path: root/mbld
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-28 23:11:39 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-28 23:11:39 -0800
commit07f5aa5bbf9445c1ff188a6f75a6fa162119cc35 (patch)
tree86d3ddf93bfa09cba7bafffbed6e7fa7ac863faa /mbld
parent5f46919fc6a471d9a75bb25fae64aecefc9ec864 (diff)
downloadmc-07f5aa5bbf9445c1ff188a6f75a6fa162119cc35.tar.gz
Add the '-R' option to mbld.
You can now build and run directly as one step.
Diffstat (limited to 'mbld')
-rw-r--r--mbld/build.myr8
-rw-r--r--mbld/deps.myr2
-rw-r--r--mbld/install.myr2
-rw-r--r--mbld/main.myr64
-rw-r--r--mbld/mbld.117
-rw-r--r--mbld/opts.myr8
6 files changed, 68 insertions, 33 deletions
diff --git a/mbld/build.myr b/mbld/build.myr
index 80fe928..64f01c9 100644
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -129,8 +129,8 @@ const buildbin = {b, targ, addsrc
src = std.htkeys(dg.sources)
incs = std.sldup(targ.incpath)
- if opt_instroot.len > 0 && !std.sleq(opt_instroot, "none")
- libpath = std.pathcat(bld.opt_instroot, config.Libpath)
+ if opt_instbase.len > 0 && !std.sleq(opt_instbase, "none")
+ libpath = std.pathcat(bld.opt_instbase, config.Libpath)
incs = std.slpush(incs, libpath)
;;
linkbin(dg, targ.name, src, targ.ldscript, targ.runtime, incs, targ.libdeps)
@@ -442,7 +442,7 @@ const findlib = {lib, incs
std.slfree(p)
;;
- p = std.pathjoin([opt_instroot, config.Libpath, lib][:])
+ p = std.pathjoin([opt_instbase, config.Libpath, lib][:])
if std.fexists(p)
-> `std.Some p
;;
@@ -468,7 +468,7 @@ const freshlibs = {targ, libgraph
for inc in targ.incpath
std.fput(1, "\t{}\n", inc)
;;
- std.fput(1, "\t{}/{}\n", opt_instroot, config.Libpath)
+ std.fput(1, "\t{}/{}\n", opt_instbase, config.Libpath)
std.exit(1)
;;
;;
diff --git a/mbld/deps.myr b/mbld/deps.myr
index c0ff61d..2c87dde 100644
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -369,7 +369,7 @@ const openlib = {lib, incs
| `std.Fail m: /* nothing */
;;
;;
- path = std.pathjoin([opt_instroot, config.Libpath, lib][:])
+ path = std.pathjoin([opt_instbase, config.Libpath, lib][:])
match bio.open(path, bio.Rd)
| `std.Ok file: -> file
| `std.Fail m: /* nothing */
diff --git a/mbld/install.myr b/mbld/install.myr
index 3238c36..e8c368e 100644
--- a/mbld/install.myr
+++ b/mbld/install.myr
@@ -57,7 +57,7 @@ const movefile = {b, rm, dir, file, prefix, perm
var path
setdir(b, dir)
- path = std.pathjoin([opt_destdir, opt_instroot, prefix, file][:])
+ path = std.pathjoin([opt_destdir, opt_instbase, prefix, file][:])
if rm
std.put("\trm {}\n", path)
if !std.remove(path)
diff --git a/mbld/main.myr b/mbld/main.myr
index 428892b..2a147c9 100644
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -15,16 +15,14 @@ use "syssel.use"
const main = {args : byte[:][:]
var b : bld.build#
- var mt : bld.myrtarg
var cleanfirst
var dumponly
- var targname
var bintarg
+ var targname
+ var runsrc
var cmd
var tags
- dumponly = false
- cleanfirst = false
cmd = std.optparse(args, &[
.argdesc = "[inputs...]",
.opts = [
@@ -36,6 +34,7 @@ const main = {args : byte[:][:]
[.opt='I', .arg="inc", .desc="add 'inc' to your include path"],
[.opt='R', .arg="root", .desc="install into 'root'"],
[.opt='b', .arg="bin", .desc="compile binary named 'bin' from inputs"],
+ [.opt='G', .arg="bin", .desc="compile and run binary 'bin' from inputs"],
[.opt='l', .arg="lib", .desc="compile lib named 'lib' from inputs"],
[.opt='r', .arg="rt", .desc="link against runtime 'rt' instead of default"],
[.opt='C', .arg="mc", .desc="compile with 'mc' instead of the default compiler"],
@@ -43,8 +42,12 @@ const main = {args : byte[:][:]
][:]
])
- targname = ""
tags = [][:]
+ runsrc = ""
+ targname = ""
+ dumponly = false
+ cleanfirst = false
+
bld.initopts()
for opt in cmd.opts
match opt
@@ -52,8 +55,9 @@ const main = {args : byte[:][:]
| ('S', ""): bld.opt_genasm = true
| ('c', ""): cleanfirst = true
| ('I', arg): bld.opt_incpaths = std.slpush(bld.opt_incpaths, arg)
- | ('R', arg): bld.opt_instroot = arg
+ | ('B', arg): bld.opt_instbase = arg
| ('t', tag): tags = std.slpush(tags, tag)
+ | ('R', arg): runsrc = arg
| ('b', arg):
targname = arg
bintarg = true
@@ -80,20 +84,16 @@ const main = {args : byte[:][:]
b = mkbuild(tags)
if targname.len != 0
- mt = [
- .name=targname,
- .inputs=cmd.args,
- .runtime=bld.opt_runtime,
- .incpath=bld.opt_incpaths,
- .libdeps=[][:]
- ]
- if cleanfirst
- bld.cleanmyr(b, &mt)
- ;;
- if bintarg
- bld.buildbin(b, &mt, true)
- else
- bld.buildlib(b, &mt)
+ buildimm(b, targname, cmd.args, bintarg, cleanfirst)
+ elif runsrc.len != 0
+ match std.mktemp("run", std.Ordwr, 0o755)
+ | `std.Ok (fd, tmp):
+ buildimm(b, "/tmp/foo", [runsrc][:], true, cleanfirst)
+ runcmd("/tmp/foo", cmd.args)
+ std.remove(tmp)
+ std.close(fd)
+ | `std.Fail e:
+ std.put("unable to open tmp file: {}\n", e)
;;
elif dumponly
findproj(b, "bld.proj")
@@ -127,6 +127,30 @@ const main = {args : byte[:][:]
;;
}
+const buildimm = {b, targ, inputs, bintarg, cleanfirst
+ var mt : bld.myrtarg
+
+ mt = [
+ .name=targ,
+ .inputs=inputs,
+ .runtime=bld.opt_runtime,
+ .incpath=bld.opt_incpaths,
+ .libdeps=[][:]
+ ]
+ if cleanfirst
+ bld.cleanmyr(b, &mt)
+ ;;
+ if bintarg
+ bld.buildbin(b, &mt, true)
+ else
+ bld.buildlib(b, &mt)
+ ;;
+}
+
+const runcmd = {bin, args
+ bld.run(std.sljoin([bin][:], args))
+}
+
const mkbuild = {tags
var b
diff --git a/mbld/mbld.1 b/mbld/mbld.1
index 0fc2ae1..dbd0a10 100644
--- a/mbld/mbld.1
+++ b/mbld/mbld.1
@@ -4,11 +4,12 @@ mbld
.SH SYNOPSIS
.B mbld
.I [all | clean | install | uninstall | test]
-.I -[hsSfr]
+.I -[?csSfr]
.I [-b bin]
.I [-l lib]
+.I [-R src]
.I [-I inc]
-.I [-R root]
+.I [-B base]
.I [-r runtime]
.I [file... | targets...]
.br
@@ -31,10 +32,14 @@ system.
The myrbuild options are:
.TP
-.B -h
+.B -[h|?]
Print a summary of the available options.
.TP
+.B -c
+cleans the code before building. This applies to both
+
+.TP
.B -b \fIbinname\fP
Compile source into a binary named 'name'. If neither this option nor
the '-l' option are given, myrbuild will create a binary called 'a.out'.
@@ -55,6 +60,12 @@ libraries are currently supported. Ignores the contents of \fIbld.proj\fP
and \fIbld.sub\fP if they exist.
.TP
+.B -R
+.I src
+Compile source given into a binary in temporary storage, and then execute it
+with the command line arguments passed in.
+
+.TP
.B -S
Tell the toolchain to generate assembly for the code being compiled as well
as the .o files, as though '-S' was passed to 6m.
diff --git a/mbld/opts.myr b/mbld/opts.myr
index c05c592..d3238f0 100644
--- a/mbld/opts.myr
+++ b/mbld/opts.myr
@@ -8,7 +8,7 @@ pkg bld =
var opt_runtime : byte[:]
var opt_genasm : bool
var opt_incpaths : byte[:][:]
- var opt_instroot : byte[:]
+ var opt_instbase : byte[:]
var opt_manpath : byte[:]
var opt_destdir : byte[:]
var opt_outdir : byte[:]
@@ -31,7 +31,7 @@ var opt_binname = ""
var opt_libname = ""
var opt_runtime = ""
var opt_incpaths /* FIXME: taking a constant slice is a nonconstant initializer */
-var opt_instroot = ""
+var opt_instbase = ""
var opt_manpath = ""
var opt_destdir = ""
var opt_debug = false
@@ -61,14 +61,14 @@ const initopts = {
;;
opt_incpaths = [][:]
- opt_instroot = config.Instroot
+ opt_instbase = config.Instroot
opt_manpath = config.Manpath
opt_destdir = std.getenvv("DESTDIR", "")
opt_mc = std.getenvv("MYR_MC", "6m")
opt_muse = std.getenvv("MYR_MUSE", "muse")
opt_runtime = std.getenvv("MYR_RT", "")
if opt_runtime.len == 0
- opt_runtime = std.pathjoin([opt_instroot, config.Libpath, config.Runtime][:])
+ opt_runtime = std.pathjoin([opt_instbase, config.Libpath, config.Runtime][:])
;;
}