summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2020-03-15 09:28:07 -0700
committerOri Bernstein <ori@eigenstate.org>2020-03-15 09:28:07 -0700
commit334ffbc2750c2be18dbbf8dc3ebbe8b22e8a9db3 (patch)
tree1bc4d8377c17c45ab5a500a43dda6ae74fe63f77
parent847f11bb87ebfa7e4de48c05d65c83758d9220e1 (diff)
downloadmc-334ffbc2750c2be18dbbf8dc3ebbe8b22e8a9db3.tar.gz
Add support for LDFLAGS lines.
-rw-r--r--mbld/deps.myr63
-rw-r--r--mbld/types.myr5
2 files changed, 41 insertions, 27 deletions
diff --git a/mbld/deps.myr b/mbld/deps.myr
index 5947969..930be27 100644
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -21,11 +21,13 @@ type dep = union
var usepat : regex.regex#
var cflagpat : regex.regex#
+var ldflagpat : regex.regex#
var clibpat : regex.regex#
const __init__ = {
usepat = std.try(regex.compile("^\\s*use\\s+((\\<\\S+\\>)|\"(\\S+)\").*"))
cflagpat = std.try(regex.compile("/\\*\\s*CFLAGS:\\s*(.*)\\s*\\*/"))
+ ldflagpat = std.try(regex.compile("/\\*\\s*LDFLAGS:\\s*(.*)\\s*\\*/"))
clibpat = std.try(regex.compile("/\\*\\s*LIBS:\\s*(.*)\\s*\\*/"))
}
@@ -57,8 +59,8 @@ const testdeps = {b
const myrdeps = {b, name, mt
var t, p, o, u, n, to, tu
- var libs, dynlibs
- var cflags, ll
+ var libs, dynlibs, ldflags
+ var cflags, ll, lf
var g, a, deps
var gu, go
@@ -123,6 +125,7 @@ const myrdeps = {b, name, mt
;;
libs = [][:]
+ ldflags = [][:]
dynlibs = [][:]
for f : mt.inputs
p = std.pathcat(mt.dir, f)
@@ -170,7 +173,7 @@ const myrdeps = {b, name, mt
o = std.pathcat(opt_objdir, t)
std.slfree(t)
- (cflags, ll) = scrapecflags(b, mt, p)
+ (cflags, ll, lf) = scrapecflags(b, mt, p)
depends(g, go, o)
n = node(g, o)
generates(g, n, o)
@@ -179,6 +182,10 @@ const myrdeps = {b, name, mt
for l : ll
std.slpush(&dynlibs, l)
;;
+ std.put("lf.len: {}\n", lf.len)
+ for l : lf
+ std.slpush(&ldflags, l)
+ ;;
mt.isdyn = true
elif std.hassuffix(f, config.Objsuffix)
depends(g, go, p)
@@ -192,7 +199,7 @@ const myrdeps = {b, name, mt
musecmd(b, gu, mt, tu, dynlibs)
builtlib(b, mt, libs, dynlibs)
else
- linkcmd(b, go, mt, to, libs, dynlibs, false)
+ linkcmd(b, go, mt, to, libs, dynlibs, ldflags, false)
std.slfree(libs)
;;
}
@@ -344,7 +351,7 @@ const addalt = {b, mt, kind, f
n = node(g, tp)
generates(g, n, tp)
depends(g, n, op)
- linkcmd(b, n, mt, tp, libs, [][:], true)
+ linkcmd(b, n, mt, tp, libs, [][:], [][:], true)
std.slfree(libs)
n = node(g, tp)
@@ -432,7 +439,7 @@ const arcmd = {b, n, mt, ar
;;
}
-const linkcmd = {b, n, mt, bin, libs, dynlibs, istest
+const linkcmd = {b, n, mt, bin, libs, dynlibs, ldflags, istest
var dynlink
for c : config.Linkcmd
@@ -460,6 +467,9 @@ const linkcmd = {b, n, mt, bin, libs, dynlibs, istest
;;
dynlink = addlibs(b, &n.cmd, libs, mt.incpath) || mt.isdyn
+ for f : ldflags
+ std.slpush(&n.cmd, std.sldup(f))
+ ;;
for l : dynlibs
std.slpush(&n.cmd, std.fmt("-l{}", l))
;;
@@ -561,8 +571,22 @@ const scrapedeps = {b : build#, mt, path
-> l
}
+const collectflags = {pat, ln, dst
+ var fl
+
+ match regex.exec(pat, ln)
+ | `std.None: /* skip */
+ | `std.Some m:
+ fl = std.strtok(m[1])
+ for s : fl
+ std.slpush(dst, std.sldup(s))
+ ;;
+ std.slfree(fl)
+ ;;
+}
+
const scrapecflags = {b, mt, path
- var f, fl, cflags, libs
+ var f, cflags, libs, ldflags
match bio.open(path, bio.Rd)
| `std.Ok fd: f = fd
@@ -571,27 +595,14 @@ const scrapecflags = {b, mt, path
cflags = [][:]
libs = [][:]
+ ldflags = [][:]
for ln : bio.byline(f)
- match regex.exec(cflagpat, ln)
- | `std.None: /* skip */
- | `std.Some m:
- fl = std.strtok(m[1])
- for s : fl
- std.slpush(&cflags, std.sldup(s))
- ;;
- std.slfree(fl)
- ;;
- match regex.exec(clibpat, ln)
- | `std.None: /* skip */
- | `std.Some m:
- fl = std.strtok(m[1])
- for s : fl
- std.slpush(&libs, std.sldup(s))
- ;;
- std.slfree(fl)
- ;;
+ collectflags(cflagpat, ln, &cflags)
+ collectflags(ldflagpat, ln, &ldflags)
+ collectflags(clibpat, ln, &libs)
;;
- -> (cflags, libs)
+ std.put("cflags.len: {}, ldflags.len: {}, libs.len: {}\n", cflags.len, ldflags.len, libs.len)
+ -> (cflags, libs, ldflags)
}
const generates = {g, n, dep
diff --git a/mbld/types.myr b/mbld/types.myr
index 809a543..f18aafa 100644
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -42,10 +42,13 @@ pkg bld =
libdeps : (byte[:], byte[:], byte[:])[:]
tstdeps : (byte[:], byte[:], byte[:])[:]
runtime : byte[:]
- incpath : byte[:][:]
tags : byte[:][:]
ldscript : byte[:]
+ /* linking C */
+ incpath : byte[:][:]
+ ldflags : byte[:][:]
+
islib : bool
istest : bool
isbench : bool