shithub: mc

Download patch

ref: cfc5ff6b83b8b7f1556debbaff2dd9dda1e23581
parent: 4e2a253a02cd6cf934f2acbb4b725db5971cd337
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Sep 23 10:26:58 EDT 2014

Add support for './mbld clean'

--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,12 @@
 MYRBIN=mbld
 MYRSRC= \
-	main.myr \
 	build.myr \
-	parse.myr \
-	deps.myr \
+	clean.myr \
 	config.myr \
+	deps.myr \
+	main.myr \
 	opts.myr \
+	parse.myr \
 	util.myr \
 
 include config.mk
--- a/bldfile
+++ b/bldfile
@@ -1,2 +1,2 @@
 # comment
-bin mbld2 = main.myr build.myr parse.myr deps.myr config.myr opts.myr util.myr; # comment
+bin mbld2 = main.myr build.myr parse.myr deps.myr config.myr opts.myr util.myr clean.myr; # comment
--- a/build.myr
+++ b/build.myr
@@ -8,7 +8,6 @@
 
 pkg bld =
 	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)
@@ -31,11 +30,6 @@
 		;;
 	;;
 	-> true
-}
-
-const cleanall= {p
-	std.fatal(1, "cleaning not yet supported\n")
-	-> false
 }
 
 const install = {p
--- /dev/null
+++ b/clean.myr
@@ -1,0 +1,48 @@
+use std
+
+use "config.use"
+use "deps.use"
+use "opts.use"
+use "parse.use"
+
+pkg bld =
+	const cleanall	: (p : parser# -> bool)
+	/*const clean	: (p : parser#, targ : byte[:] -> bool)*/
+;;
+
+const cleanall = {p
+	for t in p.targs
+		match t
+		| `Bin (bin, leaves):
+			cleanup(bin, leaves, true)
+		| `Lib (lib, leaves):
+			cleanup(lib, leaves, true)
+		| `Sub subs:
+		| `Man m:
+		;;
+	;;
+	-> true
+}
+
+const cleanup = {out, leaves, islib
+	var mchammer_files /* cant touch this */
+	var keys
+	var dg
+
+	if !myrdeps(&dg, out, leaves, islib)
+		std.fatal(1, "Could not load dependencies for %s\n", out)
+	;;
+	mchammer_files = std.mkht(std.strhash, std.streq)
+	for l in leaves
+		std.htput(mchammer_files, l, true)
+	;;
+
+	keys = std.htkeys(dg.deps)
+	for k in keys
+		if !std.htgetv(mchammer_files, k, false)
+			std.put("\tclean %s\n", k)
+			std.unlink(k)
+		;;
+	;;
+}
+
--- a/config.myr
+++ b/config.myr
@@ -1,4 +1,4 @@
 pkg config = 
-const Instroot = "/Users/orib/bin"
-const Sys = "OSX"
+const Instroot = "/usr/local/google/home/orib/bin"
+const Sys = "Linux"
 ;;
--- a/deps.myr
+++ b/deps.myr
@@ -67,7 +67,7 @@
 	std.put("digraph dg {\n")
 	for k in keys
 		for v in std.htgetv(dg.deps, k, ["WTFUNKNOWN!"][:])
-			std.put("\t%s -> %s;\n", k, v)
+			std.put("\t\"%s\" -> \"%s\";\n", k, v)
 		;;
 	;;
 	std.put("}\n")
@@ -207,13 +207,13 @@
 
 
 /* pushes a dep into the dependency list */
-const pushdep = {dg, to, from
+const pushdep = {dg, dst, src
 	var sl
 
-	std.put("%s ==> %s\n", from, to)
-	sl = std.htgetv(dg.deps, from, [][:])
-	sl = std.slpush(sl, to)
-	std.htput(dg.deps, from, sl)
+	std.put("%s ==> %s\n", src, dst)
+	sl = std.htgetv(dg.deps, src, [][:])
+	sl = std.slpush(sl, dst)
+	std.htput(dg.deps, src, sl)
 }
 
 const srcswapsuffix = {s, new
--- a/main.myr
+++ b/main.myr
@@ -2,6 +2,7 @@
 
 use "parse.use"
 use "build.use"
+use "clean.use"
 use "opts.use"
 
 const main = {args : byte[:][:]
@@ -41,6 +42,8 @@
 		bld.buildlib(bld.opt_libname, optctx.args)
 	else
 		p = loadbuild(bld.opt_bldfile)
+		/*bld.configure()*/
+		/* default: buildall */
 		if optctx.args.len == 0
 			bld.buildall(p)
 		else