ref: 2894f41c107da1c708a72ad82d1d321997fd9468
parent: 0eac125e778c6d7052e7d2f45539a8c15daa679a
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 23 08:44:15 EDT 2014
Start adding support for useful targets. This is a step towards replacing make for all code.
--- a/build.myr
+++ b/build.myr
@@ -7,13 +7,17 @@
use "util.use"
pkg bld =
- const build : (p : parser# -> bool)
+ const buildall : (p : parser# -> bool)
+ const cleanall : (p : parser# -> bool)
+ const install : (p : parser# -> bool)
+ const uninstall : (p : parser# -> bool)
+ const test : (p : parser# -> bool)
+ const build : (p : parser#, target : byte[:] -> bool)
const buildbin : (bin : byte[:], inputs : byte[:][:] -> void)
const buildlib : (lib : byte[:], inputs : byte[:][:] -> void)
;;
-const build = {p
-
+const buildall = {p
for t in p.targs
match t
| `Bin (b, leaves):
@@ -20,6 +24,46 @@
buildbin(b, leaves)
| `Lib (l, leaves):
buildlib(l, leaves)
+ | `Sub sub:
+ dosub(sub)
+ | `Man m:
+ /* nothing needed */
+ ;;
+ ;;
+ -> true
+}
+
+const cleanall= {p
+ std.fatal(1, "cleaning not yet supported\n")
+ -> false
+}
+
+const install = {p
+ std.fatal(1, "installing not yet supported\n")
+ -> false
+}
+
+const uninstall = {p
+ std.fatal(1, "uninstalling not yet supported\n")
+ -> false
+}
+
+const test = {p
+ std.fatal(1, "testing not yet supported\n")
+ -> false
+}
+
+const build = {p, targ
+ for t in p.targs
+ match t
+ | `Bin (b, leaves):
+ if std.sleq(b, targ)
+ buildbin(b, leaves)
+ ;;
+ | `Lib (l, leaves):
+ if std.sleq(l, targ)
+ buildlib(l, leaves)
+ ;;
| `Sub sub:
dosub(sub)
| `Man m:
--- a/main.myr
+++ b/main.myr
@@ -15,6 +15,7 @@
| ('b', arg): bld.opt_binname = arg
| ('l', arg): bld.opt_libname = arg
| ('s', arg): bld.opt_ldscript = arg
+ | ('f', arg): bld.opt_bldfile = arg
| ('I', arg): bld.opt_incpaths = std.slpush(bld.opt_incpaths, arg)
| ('r', arg):
if std.sleq(arg, "none")
@@ -39,20 +40,39 @@
elif bld.opt_libname.len != 0
bld.buildlib(bld.opt_libname, optctx.args)
else
- p = std.alloc()
- p.line = 1
- p.fname = "bldfile"
- match std.slurp("bldfile")
- | `std.Ok d: p.data = d
- | `std.Fail _: std.fatal(1, "could not open file 'bldfile'\n")
+ p = loadbuild(bld.opt_bldfile)
+ if optctx.args.len == 0
+ bld.buildall(p)
+ else
+ for cmd in optctx.args
+ match cmd
+ | "all": bld.buildall(p)
+ | "clean": bld.cleanall(p)
+ | "install": bld.install(p)
+ | "uninstall": bld.uninstall(p)
+ | "test": bld.test(p)
+ | target: bld.build(p, target)
+ ;;
+ ;;
;;
- p.rest = p.data
-
- bld.parse(p)
- bld.build(p)
;;
}
+const loadbuild = {path
+ var p
+
+ p = std.alloc()
+ p.line = 1
+ p.fname = path
+ match std.slurp(path)
+ | `std.Ok d: p.data = d
+ | `std.Fail _: std.fatal(1, "could not open file 'bldfile'\n")
+ ;;
+ p.rest = p.data
+ bld.parse(p)
+
+ -> p
+}
const usage = {prog
std.put("%s [-h] [-I path] [-l lib] [-b bin] inputs...\n", prog)
std.put("\t-h\tprint this help\n")
--- a/opts.myr
+++ b/opts.myr
@@ -7,6 +7,7 @@
var opt_runtime : byte[:]
var opt_ldscript : byte[:]
var opt_incpaths : byte[:][:]
+ var opt_bldfile : byte[:]
/* undocumented/unsupported opts */
var opt_mc : byte[:]
@@ -24,6 +25,7 @@
var opt_runtime
var opt_ldscript
var opt_incpaths
+var opt_bldfile = "bldfile"
var opt_mc = "6m"
var opt_as = "as"
var opt_muse = "muse"