ref: d8e7409cd405de9a996e44ac184e5b8cd83c65c6
parent: 81b900c50e5acb2a1b9a5e255e00270464c46ba9
author: Ori Bernstein <orib@orib-mbp.dhcp.thefacebook.com>
date: Tue Dec 16 10:00:22 EST 2014
Add support for 'lib libname' dependency in source list
--- 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[:], incs : byte[:][:] -> void)
- const buildlib : (lib : byte[:], inputs : byte[:][:], incs : byte[:][:] -> void)
+ const buildbin : (p : parser#, bt : myrtarg# -> void)
+ const buildlib : (p : parser#, lt : myrtarg# -> void)
;;
const buildall = {p
for t in p.targs
match t
- | `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)
+ | `Bin bt:
+ buildbin(p, bt)
+ | `Lib lt:
+ buildlib(p, lt)
| `Sub subs:
subdirs(p, subs, `std.None)
| `Man m:
@@ -39,66 +39,85 @@
}
const build = {p, targ
- var built
+ var found
- built = false
+ found = false
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves, .ldscript=lds, .runtime=rt, .incpath=incpath]:
- if std.sleq(bin, targ)
- buildbin(bin, leaves, lds, rt, incpath)
- built = true
+ | `Bin bt:
+ if std.sleq(bt.name, targ)
+ buildbin(p, bt)
;;
- | `Lib [.name=lib, .inputs=leaves, .incpath=incpath]:
- if std.sleq(lib, targ)
- buildlib(lib, leaves, incpath)
- built = true
+ | `Lib lt:
+ if std.sleq(lt.name, targ)
+ buildlib(p, lt)
+ found = true
;;
| `Sub subs:
+ found = true
subdirs(p, subs, `std.Some targ)
| `Man m:
+ found = true
/* nothing needed */
;;
;;
- if !built
+ if !found
std.fatal(1, "%s: no such target\n", targ)
;;
- -> built
+ -> found
}
-const buildbin = {bin, inputs, ldscript, rt, incs
+const buildbin = {p, targ
var dg
- if !myrdeps(&dg, bin, inputs, false)
- std.fatal(1, "Could not load dependencies for %s\n", bin)
+ if targ.built
+ ->
;;
- if !std.hthas(dg.deps, bin)
- std.fatal(1, "no target declared for %s\n", bin)
+ if targ.libdeps.len > 0
+ targ.incpath = std.slpush(targ.incpath, ".")
+ for l in targ.libdeps
+ build(p, l)
+ ;;
;;
- if builddep(&dg, bin, incs)
- linkbin(&dg, bin, inputs, ldscript, rt, incs)
+ std.put("%s...\n", targ.name)
+ if !myrdeps(&dg, targ.name, targ.inputs, false)
+ std.fatal(1, "Could not load dependencies for %s\n", targ.name)
;;
+ if !std.hthas(dg.deps, targ.name)
+ std.fatal(1, "no target declared for %s\n", targ.name)
+ ;;
+ if builddep(&dg, targ.name, targ.incpath)
+ linkbin(&dg, targ.name, targ.inputs, targ.ldscript, targ.runtime, targ.incpath, targ.libdeps)
+ ;;
+ targ.built = true
}
-const buildlib = {lib, inputs, incs
+const buildlib = {lib, targ
var archive
var u, l
var dg
+ var lib
+ if targ.built
+ ->
+ ;;
+ lib = targ.name
+ std.put("lib%s.a...\n", lib)
archive = std.fmt("lib%s.a", lib)
- if !myrdeps(&dg, lib, inputs, true)
+ if !myrdeps(&dg, lib, targ.inputs, true)
std.fatal(1, "Could not load dependencies for %s\n", lib)
;;
if !std.hthas(dg.deps, lib)
std.fatal(1, "no target declared for %s\n", lib)
;;
- u = builddep(&dg, lib, incs)
- l = builddep(&dg, archive, incs)
+ u = builddep(&dg, targ.name, targ.incpath)
+ l = builddep(&dg, archive, targ.incpath)
if u || l
- mergeuse(&dg, lib, inputs, incs)
- archivelib(&dg, lib, inputs, incs)
+ mergeuse(&dg, lib, targ.inputs, targ.incpath)
+ archivelib(&dg, lib, targ.inputs, targ.incpath)
;;
std.slfree(archive)
+ targ.built = true
}
const builddep = {dg, out, incs
@@ -159,7 +178,7 @@
;;
}
-const linkbin = {dg, bin, srcfiles, ldscript, rt, incs
+const linkbin = {dg, bin, srcfiles, ldscript, rt, incs, extralibs
var cmd
cmd = [][:]
@@ -188,6 +207,9 @@
/* -l lib... */
cmd = addlibs(cmd, dg.libs)
+ for l in extralibs
+ cmd = std.slpush(cmd, std.fmt("-l%s", l))
+ ;;
/* -L incpath... */
for inc in incs
--- a/clean.myr
+++ b/clean.myr
@@ -16,10 +16,10 @@
const cleanall = {p
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves]:
- cleanup(bin, leaves, true)
- | `Lib [.name=lib, .inputs=leaves]:
- cleanup(lib, leaves, true)
+ | `Bin bt:
+ cleanup(bt.name, bt.inputs, true)
+ | `Lib lt:
+ cleanup(lt.name, lt.inputs, true)
| `Sub subs:
subdirs(p, subs, `std.None)
| `Man m:
@@ -31,13 +31,13 @@
const clean = {p, targ
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves]:
- if std.sleq(bin, targ)
- cleanup(bin, leaves, true)
+ | `Bin bt:
+ if std.sleq(bt.name, targ)
+ cleanup(bt.name, bt.inputs, true)
;;
- | `Lib [.name=lib, .inputs=leaves]:
- if std.sleq(lib, targ)
- cleanup(lib, leaves, true)
+ | `Lib lt:
+ if std.sleq(lt.name, targ)
+ cleanup(lt.name, lt.inputs, true)
;;
| `Sub subs:
subdirs(p, subs, `std.Some targ)
--- a/deps.myr
+++ b/deps.myr
@@ -9,7 +9,13 @@
pkg bld =
const myrdeps : (dg : depgraph#, targ : byte[:], srcs : byte[:][:], islib : bool -> bool)
+
+
+ /* a bit ugly: initialized from main() */
+ var usepat : regex.regex#
+
;;
+var usepat : regex.regex#
type dep = union
`Local byte[:]
@@ -16,18 +22,11 @@
`Lib byte[:]
;;
-var usepat : regex.regex#
-
const myrdeps = {dg, targ, srcs, islib
var seentab, donetab
var out, useout
var objs, uses
var i
-
- match regex.compile("^\\s*use\\s+((\\<\\S+\\>)|(\"(\\S+)\")).*")
- | `std.Ok re: usepat = re
- | `std.Fail f: std.fatal(1, "Failed to compile use pattern regex\n")
- ;;
dg.deps = std.mkht(std.strhash, std.streq)
dg.libs = std.mkht(std.strhash, std.streq)
--- a/install.myr
+++ b/install.myr
@@ -26,11 +26,11 @@
for t in p.targs
match t
- | `Bin [.name=bin, .inputs=leaves, .install=true]:
- movefile(delete, bin, opt_instroot, opt_destdir, "bin")
- | `Lib [.name=lib, .inputs=leaves, .install=true]:
- movefile(delete, lib, opt_instroot, opt_destdir, "lib/myr")
- libarchive = std.fmt("lib%s.a", lib)
+ | `Bin bt:
+ movefile(delete, bt.name, opt_instroot, opt_destdir, "bin")
+ | `Lib lt:
+ movefile(delete, lt.name, opt_instroot, opt_destdir, "lib/myr")
+ libarchive = std.fmt("lib%s.a", lt.name)
movefile(delete, libarchive, opt_instroot, opt_destdir, "lib/myr")
std.slfree(libarchive)
| `Sub subs:
--- a/main.myr
+++ b/main.myr
@@ -1,8 +1,10 @@
use std
+use regex
use "build.use"
use "clean.use"
use "config.use"
+use "deps.use"
use "install.use"
use "opts.use"
use "parse.use"
@@ -10,6 +12,7 @@
const main = {args : byte[:][:]
var p : bld.parser#
+ var mt : bld.myrtarg
var optctx
optctx = std.optinit("hb:l:s:Sr:I:C:A:M:L:R:d", args)
@@ -44,10 +47,33 @@
;;
;;
+ match regex.compile("^\\s*use\\s+((\\<\\S+\\>)|(\"(\\S+)\")).*")
+ | `std.Ok re: bld.usepat = re
+ | `std.Fail f: std.fatal(1, "Failed to compile use pattern regex\n")
+ ;;
+
if bld.opt_binname.len != 0
- bld.buildbin(bld.opt_binname, optctx.args, bld.opt_ldscript, bld.opt_runtime, bld.opt_incpaths)
+ mt = [
+ .name=bld.opt_binname,
+ .inputs=optctx.args,
+ .runtime=bld.opt_runtime,
+ .incpath=bld.opt_incpaths,
+ .ldscript=bld.opt_ldscript,
+ .libdeps=[][:]
+ ]
+ p = std.zalloc()
+ bld.buildbin(p, &mt)
+ std.free(p)
elif bld.opt_libname.len != 0
- bld.buildlib(bld.opt_libname, optctx.args, bld.opt_incpaths)
+ mt = [
+ .name=bld.opt_libname,
+ .inputs=optctx.args,
+ .incpath=bld.opt_incpaths,
+ .libdeps=[][:]
+ ]
+ p = std.zalloc()
+ bld.buildbin(p, &mt)
+ std.free(p)
else
p = loadbuild(bld.opt_bldfile)
p.cmd = args
--- a/parse.myr
+++ b/parse.myr
@@ -123,7 +123,7 @@
std.fatal(1, "got invalid attr '%s'\n", invalid)
;;
;;
- -> [
+ -> std.mk([
.name=name,
.inputs=inputs,
.libdeps=libdeps,
@@ -130,8 +130,9 @@
.install=inst,
.ldscript=ldscript,
.runtime=runtime,
- .incpath=incpath
- ]
+ .incpath=incpath,
+ .built=false
+ ])
}
const anontarget = {p, targ
--- a/types.myr
+++ b/types.myr
@@ -10,7 +10,7 @@
line : int
/* build params */
- targs : target[:]
+ targs : targ[:]
prefix : byte[:]
system : byte[:]
arch : byte[:]
@@ -28,15 +28,16 @@
name : byte[:]
inputs : byte[:][:]
libdeps : byte[:][:]
+ built : bool
install : bool
- ldscript : byte[:]
runtime : byte[:]
incpath : byte[:][:]
+ ldscript : byte[:]
;;
- type target = union
- `Bin myrtarg
- `Lib myrtarg
+ type targ = union
+ `Bin myrtarg#
+ `Lib myrtarg#
`Sub byte[:][:]
`Man byte[:][:]
;;