ref: 6bc97a3d153ba5bb77dc67c2cf7eb495ff277855
parent: 4cde6d1902f33eb617fc9e45416c5482fd2f4a24
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Oct 6 17:25:41 EDT 2014
Add include path attribute.
--- a/build.myr
+++ b/build.myr
@@ -13,17 +13,17 @@
const buildall : (p : parser# -> bool)
const test : (p : parser# -> bool)
const build : (p : parser#, target : byte[:] -> bool)
- const buildbin : (bin : byte[:], inputs : byte[:][:], ldscript : byte[:], rt : byte[:] -> void)
- const buildlib : (lib : byte[:], inputs : byte[:][:] -> void)
+ const buildbin : (bin : byte[:], inputs : byte[:][:], ldscript : byte[:], rt : byte[:], incs : byte[:][:] -> void)
+ const buildlib : (lib : byte[:], inputs : byte[:][:], incs : byte[:][:] -> void)
;;
const buildall = {p
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves, .ldscript=lds, .runtime=rt]:
- buildbin(bin, leaves, lds, rt)
- | `Lib [.name=lib, .inputs=leaves]:
- buildlib(lib, leaves)
+ | `Bin [.name=bin, .inputs=leaves, .ldscript=lds, .runtime=rt, .incpath=incpath]:
+ buildbin(bin, leaves, lds, rt, incpath)
+ | `Lib [.name=lib, .inputs=leaves, .incpath=incpath]:
+ buildlib(lib, leaves, incpath)
| `Sub subs:
subdirs(p, subs, `std.None)
| `Man m:
@@ -44,14 +44,14 @@
built = false
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves, .ldscript=lds, .runtime=rt]:
+ | `Bin [.name=bin, .inputs=leaves, .ldscript=lds, .runtime=rt, .incpath=incpath]:
if std.sleq(bin, targ)
- buildbin(bin, leaves, lds, rt)
+ buildbin(bin, leaves, lds, rt, incpath)
built = true
;;
- | `Lib [.name=lib, .inputs=leaves]:
+ | `Lib [.name=lib, .inputs=leaves, .incpath=incpath]:
if std.sleq(lib, targ)
- buildlib(lib, leaves)
+ buildlib(lib, leaves, incpath)
built = true
;;
| `Sub subs:
@@ -66,7 +66,7 @@
-> built
}
-const buildbin = {bin, inputs, ldscript, rt
+const buildbin = {bin, inputs, ldscript, rt, incs
var dg
if !myrdeps(&dg, bin, inputs, false)
@@ -75,12 +75,12 @@
if !std.hthas(dg.deps, bin)
std.fatal(1, "no target declared for %s\n", bin)
;;
- if builddep(&dg, bin)
- linkbin(&dg, bin, inputs, ldscript, rt)
+ if builddep(&dg, bin, incs)
+ linkbin(&dg, bin, inputs, ldscript, rt, incs)
;;
}
-const buildlib = {lib, inputs
+const buildlib = {lib, inputs, incs
var archive
var u, l
var dg
@@ -92,16 +92,16 @@
if !std.hthas(dg.deps, lib)
std.fatal(1, "no target declared for %s\n", lib)
;;
- u = builddep(&dg, lib)
- l = builddep(&dg, archive)
+ u = builddep(&dg, lib, incs)
+ l = builddep(&dg, archive, incs)
if u || l
- mergeuse(&dg, lib, inputs)
- archivelib(&dg, lib, inputs)
+ mergeuse(&dg, lib, inputs, incs)
+ archivelib(&dg, lib, inputs, incs)
;;
std.slfree(archive)
}
-const builddep = {dg, out
+const builddep = {dg, out, incs
var stale
stale = false
@@ -112,7 +112,7 @@
match std.htget(dg.deps, out)
| `std.Some deps:
for d in deps
- if builddep(dg, d)
+ if builddep(dg, d, incs)
stale = true
;;
if !isfresh(d, out)
@@ -129,7 +129,7 @@
match std.htget(dg.sources, out)
| `std.Some src:
if stale
- compile(src)
+ compile(src, incs)
;;
std.htput(dg.updated, out, true)
| `std.None:
@@ -137,11 +137,23 @@
-> stale
}
-const compile = {src
+const compile = {src, incs
var o
+ var cmd
if std.hassuffix(src, ".myr")
- run(["6m", src][:], "")
+ cmd = [][:]
+ cmd = std.slpush(cmd, "6m")
+ for inc in incs
+ cmd = std.slpush(cmd, "-I")
+ cmd = std.slpush(cmd, inc)
+ ;;
+ if opt_genasm
+ cmd = std.slpush(cmd, "-S")
+ ;;
+ cmd = std.slpush(cmd, src)
+ run(cmd, "")
+ std.slfree(cmd)
elif std.hassuffix(src, ".s")
o = srcswapsuffix(src, ".o")
run(["as", src, "-o", o][:], "")
@@ -151,7 +163,7 @@
;;
}
-const linkbin = {dg, bin, srcfiles, ldscript, rt
+const linkbin = {dg, bin, srcfiles, ldscript, rt, incs
var cmd
cmd = [][:]
@@ -182,7 +194,7 @@
cmd = addlibs(cmd, dg.libs)
/* -L incpath... */
- for inc in opt_incpaths
+ for inc in incs
cmd = std.slpush(cmd, std.fmt("-L%s", inc))
;;
cmd = std.slpush(cmd, std.fmt("-L%s%s", opt_instroot, "/lib/myr"))
@@ -197,7 +209,7 @@
strlistfree(cmd)
}
-const archivelib = {dg, lib, files
+const archivelib = {dg, lib, files, incs
var cmd
var obj
@@ -213,7 +225,7 @@
strlistfree(cmd)
}
-const mergeuse = {dg, lib, files
+const mergeuse = {dg, lib, files, incs
var cmd
cmd = [][:]
--- a/main.myr
+++ b/main.myr
@@ -12,7 +12,7 @@
var p : bld.parser#
var optctx
- optctx = std.optinit("hb:l:s:r:I:C:A:M:L:R:d", args)
+ optctx = std.optinit("hb:l:s:Sr:I:C:A:M:L:R:d", args)
bld.initopts()
while !std.optdone(optctx)
match std.optnext(optctx)
@@ -22,6 +22,7 @@
| ('s', arg): bld.opt_ldscript = arg
| ('f', arg): bld.opt_bldfile = arg
| ('I', arg): bld.opt_incpaths = std.slpush(bld.opt_incpaths, arg)
+ | ('S', _): bld.opt_genasm = true
| ('r', arg):
if std.sleq(arg, "none")
bld.opt_runtime = ""
@@ -43,9 +44,9 @@
;;
if bld.opt_binname.len != 0
- bld.buildbin(bld.opt_binname, optctx.args, bld.opt_ldscript, bld.opt_runtime)
+ bld.buildbin(bld.opt_binname, optctx.args, bld.opt_ldscript, bld.opt_runtime, bld.opt_incpaths)
elif bld.opt_libname.len != 0
- bld.buildlib(bld.opt_libname, optctx.args)
+ bld.buildlib(bld.opt_libname, optctx.args, bld.opt_incpaths)
else
p = loadbuild(bld.opt_bldfile)
p.cmd = args
--- a/opts.myr
+++ b/opts.myr
@@ -9,6 +9,7 @@
var opt_binname : byte[:]
var opt_libname : byte[:]
var opt_runtime : byte[:]
+ var opt_genasm : bool
var opt_ldscript : byte[:]
var opt_incpaths : byte[:][:]
var opt_instroot : byte[:]
@@ -46,6 +47,7 @@
var opt_muse = "muse"
var opt_ld = "ld"
var opt_ar = "ar"
+var opt_genasm = false
/* derived */
var sysarchstr = ""
--- a/parse.myr
+++ b/parse.myr
@@ -2,6 +2,7 @@
use "types.use"
use "util.use"
+use "opts.use"
pkg bld =
const parse : (p : parser# -> bool)
@@ -64,7 +65,7 @@
}
const myrtarget = {p, targ
var name, inputs, attrs
- var ldscript, runtime, inst
+ var ldscript, runtime, inst, incpath
match word(p)
| `std.Some n: name = n
@@ -106,15 +107,19 @@
inst = true
ldscript = ""
runtime = ""
+ incpath = [][:]
for elt in attrs
match elt
| ("ldscript", lds): ldscript = std.sldup(lds)
| ("runtime", rt): runtime = std.sldup(rt)
+ | ("inc", path): incpath = std.slpush(incpath, std.sldup(path))
| ("noinst", val):
if val.len != 0
failparse(p, "noinst attr does not take argument\n")
;;
inst = false
+ | (invalid, _):
+ std.fatal(1, "got invalid attr '%s'\n", invalid)
;;
;;
-> [
@@ -122,7 +127,8 @@
.inputs=inputs,
.install=inst,
.ldscript=ldscript,
- .runtime=runtime
+ .runtime=runtime,
+ .incpath=incpath
]
}
--- a/types.myr
+++ b/types.myr
@@ -30,6 +30,7 @@
install : bool
ldscript : byte[:]
runtime : byte[:]
+ incpath : byte[:][:]
;;
type target = union
--- a/util.myr
+++ b/util.myr
@@ -5,6 +5,7 @@
pkg bld =
const run : (cmd : byte[:][:], dir : byte[:] -> void)
+ const printcmd
const srcsplit : (src : byte[:] -> (byte[:], byte[:], byte[:]))
const swapsuffix : (f : byte[:], suff : byte[:], newsuff : byte[:] -> byte[:])
const srcswapsuffix : (f : byte[:], newsuff : byte[:] -> byte[:])