shithub: mc

Download patch

ref: b3e7de02f2cfa3d43b7e03aac491be373b5c46df
parent: 7b10f09efa9184669c5f7aba9544358986341115
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 25 08:31:29 EDT 2014

Add support for entering/building subdirectories.

    Very suboptimal.

--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,9 @@
 	main.myr \
 	opts.myr \
 	parse.myr \
+	subdir.myr \
 	util.myr \
+	types.myr
 
 include config.mk
 include mk/myr.mk
--- a/bldfile
+++ b/bldfile
@@ -1,5 +1,6 @@
 # comment
-bin mbld2 =
+sub = foo;
+bin mbld =
 	build.myr
 	clean.myr
 	config.myr
@@ -8,6 +9,8 @@
 	main.myr
 	opts.myr
 	parse.myr
+	subdir.myr
         types.myr
 	util.myr
 ;
+
--- a/build.myr
+++ b/build.myr
@@ -6,6 +6,7 @@
 use "parse.use"
 use "types.use"
 use "util.use"
+use "subdir.use"
 
 pkg bld =
 	const buildall	: (p : parser# -> bool)
@@ -23,9 +24,7 @@
 		| `Lib [.name=lib, .inputs=leaves]:
 			buildlib(lib, leaves)
 		| `Sub subs:
-			for s in subs
-				dosub(s)
-			;;
+			subdirs(p, subs, `std.None)
 		| `Man m:
 			/* nothing needed */
 		;;
@@ -55,12 +54,7 @@
 				built = true
 			;;
 		| `Sub subs:
-			for s in subs
-				if std.sleq(s, targ)
-					dosub(s)
-					built = true
-				;;
-			;;
+			subdirs(p, subs, `std.Some targ)
 		| `Man m:
 			/* nothing needed */
 		;;
@@ -117,10 +111,6 @@
 	;;
 }
 
-const dosub = {sub
-	std.put("subdir %s\n", sub)
-}
-
 const builddep = {dg, dep, out
 	var freshdep
 
@@ -140,7 +130,7 @@
 		-> false
 	;;
 	if std.hassuffix(dep, ".myr")
-		run(["6m", dep][:])
+		run(["6m", dep][:], "")
 	;;
 	-> true
 }
@@ -195,7 +185,7 @@
 		cmd = std.slpush(cmd, std.sldup("10.6"))
 	;;
 
-	run(cmd)
+	run(cmd, "")
 	strlistfree(cmd)
 }
 
@@ -217,7 +207,7 @@
 		;;
 		cmd = std.slpush(cmd, obj)
 	;;
-	run(cmd)
+	run(cmd, "")
 	strlistfree(cmd)
 }
 
@@ -254,6 +244,7 @@
 	std.htput(marked, lib, true)
 	-> std.slput(cmd, head, std.fmt("-l%s", lib))
 }
+
 const isfresh = {src, dst
 	var srcsb, dstsb
 
--- a/clean.myr
+++ b/clean.myr
@@ -4,6 +4,7 @@
 use "deps.use"
 use "opts.use"
 use "parse.use"
+use "subdir.use"
 use "types.use"
 
 pkg bld =
@@ -19,6 +20,7 @@
 		| `Lib [.name=lib, .inputs=leaves]:
 			cleanup(lib, leaves, true)
 		| `Sub subs:
+			subdirs(p, subs, `std.None)
 		| `Man m:
 		;;
 	;;
@@ -37,6 +39,7 @@
 				cleanup(lib, leaves, true)
 			;;
 		| `Sub subs:
+			subdirs(p, subs, `std.Some targ)
 		| `Man m:
 		;;
 	;;
--- a/config.myr
+++ /dev/null
@@ -1,4 +1,0 @@
-pkg config = 
-const Instroot = "/usr/local/google/home/orib/bin"
-const Sys = "Linux"
-;;
--- a/install.myr
+++ b/install.myr
@@ -4,8 +4,9 @@
 use "deps.use"
 use "opts.use"
 use "parse.use"
-use "util.use"
+use "subdir.use"
 use "types.use"
+use "util.use"
 
 pkg bld =
 	const install	: (p : parser#	-> bool)
@@ -33,11 +34,7 @@
 			movefile(delete, libarchive, opt_instroot, opt_destdir, "lib/myr")
 			std.slfree(libarchive)
 		| `Sub subs:
-			/*
-			for s in subs
-				dosub(s)
-			;;
-			*/
+			subdirs(p, subs, `std.None)
 		| `Man mans:
 			/* FIXME: figure out man section by number */
 			for m in mans
--- a/main.myr
+++ b/main.myr
@@ -48,6 +48,7 @@
 		bld.buildlib(bld.opt_libname, optctx.args)
 	else
 		p = loadbuild(bld.opt_bldfile)
+		p.cmd = args
 		/*bld.configure()*/
 		/* default: buildall */
 		if optctx.args.len == 0
--- a/parse.myr
+++ b/parse.myr
@@ -87,7 +87,7 @@
 
 	match wordlist(p)
 	| `std.Some wl: inputs = wl
-	| `std.None: failparse(p, "expected list of file names after %s target\n", targ)
+	| `std.None: failparse(p, "expected list of file names after '%s %s'\n", targ, name)
 	;;
 	skipspace(p)
 	if !matchc(p, ';')
@@ -120,8 +120,13 @@
 const anontarget = {p, targ
 	var inputs
 
+	skipspace(p)
+	if !matchc(p, '=')
+		failparse(p, "expected '=' after '%s' target", targ)
+	;;
+
 	match wordlist(p)
-	| `std.None:	failparse(p, "expected list of file names after %s target\n", targ)
+	| `std.None:	failparse(p, "expected list of file names after '%s' target\n", targ)
 	| `std.Some wl:	inputs = wl
 	;;
 	skipspace(p)
--- a/types.myr
+++ b/types.myr
@@ -2,6 +2,7 @@
 
 pkg bld =
 	type parser = struct
+		cmd	: byte[:][:]
 		/* parse input */
 		data	: byte[:]
 		rest	: byte[:]
--- a/util.myr
+++ b/util.myr
@@ -1,13 +1,13 @@
 use std
 
 pkg bld =
-	const run	: (cmd : byte[:][:] -> void)
+	const run	: (cmd : byte[:][:], dir : byte[:] -> void)
 	const swapsuffix	: (f : byte[:], suff : byte[:], newsuff : byte[:] -> byte[:])
 	const strlistfree	: (sl : byte[:][:] -> void)
 ;;
 
 
-const run = {cmd
+const run = {cmd, dir
 	var pid
 	var status
 
@@ -16,6 +16,9 @@
 	if pid == -1
 		std.fatal(1, "could not fork command\n")
 	elif pid == 0
+		if dir.len > 0
+			std.chdir(dir)
+		;;
 		if std.execvp(cmd[0], cmd) < 0
 			std.fatal(1, "failed to exec %s\n", cmd[0])
 		;;