diff options
-rw-r--r-- | build.myr | 53 | ||||
-rw-r--r-- | clean.myr | 4 | ||||
-rw-r--r-- | install.myr | 2 | ||||
-rw-r--r-- | main.myr | 4 | ||||
-rw-r--r-- | parse.myr | 17 | ||||
-rw-r--r-- | test.myr | 2 | ||||
-rw-r--r-- | types.myr | 3 | ||||
-rw-r--r-- | util.myr | 17 |
8 files changed, 60 insertions, 42 deletions
@@ -17,7 +17,7 @@ pkg bld = const buildall = {b for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Bin bt: buildbin(b, bt, false) | `Lib lt: buildlib(b, lt) | `Test tt: /* build on 'mbld test' by default */ @@ -30,7 +30,7 @@ const buildall = {b const genall = {b for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Gen gt: run(gt.cmd) | _: /* skip */ ;; @@ -40,7 +40,7 @@ const genall = {b } const build = {b, targ - match std.htget(b._targs, targ) + match std.htget(b.targs, targ) | `std.Some (`Bin bt): buildbin(b, bt, false) | `std.Some (`Lib lt): buildlib(b, lt) | `std.Some (`Test tt): buildbin(b, tt, false) @@ -58,14 +58,8 @@ const buildbin = {b, targ, addsrc -> ;; setdir(b, targ.dir) - if targ.libdeps.len > 0 - for (inc, lib, subtarg) in targ.libdeps - if !hasinc(targ.incpath, inc) - targ.incpath = std.slpush(targ.incpath, inc) - ;; - build(b, subtarg) - ;; - ;; + addincludes(b, targ) + buildlibdeps(b, targ) std.put("%s...\n", targ.name) if !myrdeps(b, targ, false, false, addsrc, &dg) std.fatal(1, "Could not load dependencies for %s\n", targ.name) @@ -81,15 +75,6 @@ const buildbin = {b, targ, addsrc targ.built = true } -const hasinc = {path, t - for e in path - if std.sleq(e, t) - -> true - ;; - ;; - -> false -} - const buildlib = {b, targ var archive var u, l @@ -100,6 +85,8 @@ const buildlib = {b, targ -> ;; setdir(b, targ.dir) + addincludes(b, targ) + buildlibdeps(b, targ) lib = targ.name std.put("lib%s.a...\n", lib) archive = std.fmt("lib%s.a", lib) @@ -125,11 +112,35 @@ const genfiles = {b, gt for f in gt.out if !std.fexists(f) run(gt.cmd) - -> + break ;; ;; } +const addincludes = {b, targ + for (inc, lib, subtarg) in targ.libdeps + if !hasinc(targ.incpath, inc) + targ.incpath = std.slpush(targ.incpath, inc) + ;; + ;; +} + +const buildlibdeps = {b, targ + for (inc, lib, subtarg) in targ.libdeps + build(b, subtarg) + ;; +} + +const hasinc = {path, t + for e in path + if std.sleq(e, t) + -> true + ;; + ;; + -> false +} + + const builddep = {b, dg, out, incs var stale @@ -15,7 +15,7 @@ pkg bld = const cleanall = {b for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Bin bt: cleanup(b, bt, bt.inputs, true) | `Lib lt: @@ -36,7 +36,7 @@ const cleanall = {b const clean = {b, targ for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Bin bt: if std.sleq(bt.name, targ) cleanup(b, bt, bt.inputs, true) diff --git a/install.myr b/install.myr index e91011c..a895166 100644 --- a/install.myr +++ b/install.myr @@ -27,7 +27,7 @@ const movetargs = {b, delete var libarchive for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Bin bt: movefile(delete, bt.name, opt_instroot, opt_destdir, "bin", 0o755) | `Lib lt: @@ -97,10 +97,10 @@ const mkbuild = { var b b = std.zalloc() - b._targs = std.mkht(std.strhash, std.streq) + b.targs = std.mkht(std.strhash, std.streq) b.gensrc = std.mkht(std.strhash, std.streq) b.basedir = std.getcwd() - std.put("base dir = %s\n", b.basedir) + b.curdir = "" -> b } @@ -363,7 +363,6 @@ const inputlist = {p match word(p) | `std.Some l: (dir, lib, targ) = libpath(p, l) - std.put("dir: %s, lib: %s, targ: %s\n", dir, lib, targ) libs = std.slpush(libs, (dir, lib, targ)) | `std.None: failparse(p, "expected lib name after 'lib'\n") @@ -502,21 +501,21 @@ const addtarg = {p, b, name, targ var tn tn = std.fmt("%s:%s", p.fdir, name) - if std.hthas(b._targs, tn) + if std.hthas(b.targs, tn) failparse(p, "duplicate target %s\n", tn) ;; b.all = std.slpush(b.all, tn) - std.htput(b._targs, tn, targ) + std.htput(b.targs, tn, targ) } const libpath = {p, libpath - var dir, lib_, targ + var dir, lib, targ match(std.strrfind(libpath, ":")) | `std.None: dir = std.sldup(".") - lib_ = std.sldup(libpath) - targ = std.fmt("%s:%s", p.fdir, lib_) + lib = std.sldup(libpath) + targ = std.fmt("%s:%s", p.fdir, lib) | `std.Some idx: if idx == libpath.len std.fatal(1, "libdep %s missing library after ':'\n") @@ -524,17 +523,17 @@ const libpath = {p, libpath /* absolute path */ if std.hasprefix(libpath, "@/") || std.hasprefix(libpath, "@:") dir = std.pathcat(p.basedir, libpath[2:idx]) - lib_ = std.sldup(libpath[idx+1:]) + lib = std.sldup(libpath[idx+1:]) targ = std.sldup(libpath[2:]) /* relative path */ else dir = std.sldup(libpath[:idx]) - lib_ = std.sldup(libpath[idx+1:]) + lib = std.sldup(libpath[idx+1:]) targ = std.pathcat(p.fdir, libpath) if std.hasprefix(targ, "../") std.fatal(1, "library %s outside of project\n", libpath) ;; ;; ;; - -> (dir, lib_, targ) + -> (dir, lib, targ) } @@ -22,7 +22,7 @@ const test = {b ok = true if std.fexists("test") for tn in b.all - match gettarg(b._targs, tn) + match gettarg(b.targs, tn) | `Bin bt: if !dotest(b, bt, ok) ok = false @@ -5,9 +5,10 @@ pkg bld = cmd : byte[:][:] /* command that we ran */ /* build state */ basedir : byte[:] + curdir : byte[:] /* build params */ all : byte[:][:] - _targs : std.htab(byte[:], targ)# /* dir => target mapping */ + targs : std.htab(byte[:], targ)# /* dir => target mapping */ tdeps : std.htab(byte[:], byte[:][:]) /* targname => depname[:] mapping */ gensrc : std.htab(byte[:], gentarg#)# /* generated src => generating target mapping */ prefix : byte[:] @@ -106,11 +106,18 @@ const gettarg = {tab, n const setdir = {b, dir var p - p = std.pathcat(b.basedir, dir) - std.put("changing into '%s'\n", p) - if !std.chdir(p) - std.fatal(1, "could not cd into %s\n") + if !std.sleq(b.curdir, dir) + p = std.pathcat(b.basedir, dir) + if b.curdir.len != 0 + std.put("Leaving directory %s\n", b.curdir) + ;; + + std.put("Entering directory '%s'\n", dir) + if !std.chdir(p) + std.fatal(1, "could not cd into %s\n") + ;; + b.curdir = dir + std.slfree(p) ;; - std.slfree(p) } |