shithub: mc

Download patch

ref: abf4c98dec102c7a60607ea8128536f232f4219e
parent: 4ac1189b1022526ff74ed63a6dbbe97e012a7ad6
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 1 16:53:00 EST 2015

Add support for the gen command.

--- a/build.myr
+++ b/build.myr
@@ -23,6 +23,8 @@
 			buildbin(p, bt)
 		| `Lib lt:
 			buildlib(p, lt)
+		| `Gen gt:
+			genfiles(p, gt)
 		| `Sub subs:
 			subdirs(p, subs, `std.None)
 		| `Man m:
@@ -52,6 +54,12 @@
 				buildlib(p, lt)
 				found = true
 			;;
+		| `Gen gt:
+			for n in gt.out
+				if std.sleq(n, targ)
+					run(gt.cmd, "")
+				;;
+			;;
 		| `Sub subs:
 			found = true
 			subdirs(p, subs, `std.Some targ)
@@ -91,7 +99,7 @@
 	targ.built = true
 }
 
-const buildlib = {lib, targ
+const buildlib = {p, targ
 	var archive
 	var u, l
 	var dg
@@ -117,6 +125,15 @@
 	;;
 	std.slfree(archive)
 	targ.built = true
+}
+
+const genfiles = {p, gt
+	for f in gt.out
+		if !std.fexists(f)
+			run(gt.cmd, "")
+			->
+		;;
+	;;
 }
 
 const builddep = {dg, out, incs
--- a/clean.myr
+++ b/clean.myr
@@ -16,9 +16,15 @@
 	for t in p.targs
 		match t
 		| `Bin bt:
-			cleanup(bt.name, bt.inputs, true)
+			cleanup(p, bt.name, bt.inputs, true)
 		| `Lib lt:
-			cleanup(lt.name, lt.inputs, true)
+			cleanup(p, lt.name, lt.inputs, true)
+		| `Gen gt:
+			for f in gt.out
+				if std.remove(f)
+					std.put("\tclean %s\n", f)
+				;;
+			;;
 		| `Sub subs:
 			subdirs(p, subs, `std.None)
 		| `Man m:
@@ -32,12 +38,13 @@
 		match t
 		| `Bin bt:
 			if std.sleq(bt.name, targ)
-				cleanup(bt.name, bt.inputs, true)
+				cleanup(p, bt.name, bt.inputs, true)
 			;;
 		| `Lib lt:
 			if std.sleq(lt.name, targ)
-				cleanup(lt.name, lt.inputs, true)
+				cleanup(p, lt.name, lt.inputs, true)
 			;;
+		| `Gen gt:
 		| `Sub subs:
 			subdirs(p, subs, `std.Some targ)
 		| `Man m:
@@ -46,7 +53,7 @@
 	-> true
 }
 
-const cleanup = {out, leaves, islib
+const cleanup = {p, out, leaves, islib
 	var mchammer_files /* cant touch this */
 	var keys
 	var dg
@@ -56,7 +63,9 @@
 	;;
 	mchammer_files = std.mkht(std.strhash, std.streq)
 	for l in leaves
-		std.htput(mchammer_files, l, true)
+		if !std.hthas(p.gensrc, l)
+			std.htput(mchammer_files, l, true)
+		;;
 	;;
 
 	keys = std.htkeys(dg.deps)
--- a/config+plan9-x64.myr
+++ b/config+plan9-x64.myr
@@ -7,5 +7,5 @@
 	const Ascmd	= ["6a"]
 	const Directlib	= true
 	const Runtime	= "_myrrt.6"
-	const Manprefix	= "/sys/man/
+	const Manprefix	= "man/
 ;;
--- a/configure
+++ b/configure
@@ -42,7 +42,7 @@
 echo "const Ascmd = [\"as\", \"-g\"]" >> config.myr
 echo "const Directlib = false" >> config.myr
 echo "const Runtime = \"_myrrt.o\"" >> config.myr
-echo "const Manprefix = \"/usr/share/man/man\"" >> config.myr
+echo "const Manpath = \"share/man/man\"" >> config.myr
 case $OS in
     *Linux*)
         echo 'export SYS=linux' >> config.mk
--- a/install.myr
+++ b/install.myr
@@ -33,6 +33,8 @@
 			libarchive = std.fmt("lib%s.a", lt.name)
 			movefile(delete, libarchive, opt_instroot, opt_destdir, "lib/myr")
 			std.slfree(libarchive)
+		| `Gen gt:
+			/* nothing to do (?) */
 		| `Sub subs:
 			subdirs(p, subs, `std.None)
 		| `Man mans:
@@ -83,7 +85,7 @@
 		;;
 	;;
 
-	manrel = std.fmt("%s%s", config.Manprefix, man[sect:])
+	manrel = std.fmt("%s%s", opt_manpath, man[sect:])
 	movefile(delete, man, opt_instroot, opt_destdir, manrel)
 	std.slfree(manrel)
 }
--- a/main.myr
+++ b/main.myr
@@ -104,6 +104,7 @@
 	| `std.Fail _:	std.fatal(1, "could not open file 'bldfile'\n")
 	;;
 	p.rest = p.data
+	p.gensrc = std.mkht(std.strhash, std.streq)
 	bld.parse(p)
 
 	-> p
--- a/opts.myr
+++ b/opts.myr
@@ -10,6 +10,7 @@
 	var opt_ldscript	: byte[:]
 	var opt_incpaths	: byte[:][:]
 	var opt_instroot	: byte[:]
+	var opt_manpath	: byte[:]
 	var opt_destdir	: byte[:]
 	var opt_bldfile	: byte[:]
 	var opt_debug	: bool
@@ -33,6 +34,7 @@
 var opt_ldscript	= ""
 var opt_incpaths	/* FIXME: taking a constant slice is a nonconstant initializer */
 var opt_instroot	= ""
+var opt_manpath	= ""
 var opt_destdir	= ""
 var opt_debug	= false
 var opt_bldfile = "bldfile"
@@ -68,6 +70,7 @@
 
 	opt_incpaths = [][:]
 	opt_instroot = config.Instroot
+	opt_manpath = config.Manpath
 	opt_destdir = std.getenvv("DESTDIR", "")
 	opt_mc = std.getenvv("MYR_MC", "6m")
 	opt_muse = std.getenvv("MYR_MUSE", "muse")
--- a/parse.myr
+++ b/parse.myr
@@ -40,6 +40,7 @@
 	match word(p)
 	| `std.Some "bin":	bintarget(p)
 	| `std.Some "lib":	libtarget(p)
+	| `std.Some "gen":	gentarget(p)
 	| `std.Some "sub":	subtarget(p)
 	| `std.Some "man":	mantarget(p)
 	| `std.Some targtype:	failparse(p, "unknown targtype type %s\n", targtype)
@@ -66,7 +67,39 @@
 /* mantarget: anontarget */
 const mantarget = {p
 	p.targs = std.slpush(p.targs, `Man anontarget(p, "man"))
+}
 
+/* gentarget: wordlist = wordlist ;; */
+const gentarget = {p
+	var outlist, cmdlist
+	var gt
+
+	match wordlist(p)
+	| `std.None:	failparse(p, "gen target missing output files\n")
+	| `std.Some out:
+		outlist = out
+	;;
+
+	skipspace(p)
+	if !matchc(p, '=')
+		failparse(p, "expected '=' after '%s %s'\n", cmdlist, outlist[outlist.len-1])
+	;;
+
+	match wordlist(p)
+	| `std.None:	failparse(p, "gen target missing command\n")
+	| `std.Some cmd:
+		cmdlist = cmd
+	;;
+
+	if !matchc(p, ';') || !matchc(p, ';')
+		failparse(p, "expected ';;' terminating genfile command, got %c\n", peekc(p))
+	;;
+
+	gt = std.mk([.out = outlist, .cmd=cmdlist])
+	for o in outlist
+		std.htput(p.gensrc, o, gt)
+	;;
+	p.targs = std.slpush(p.targs, `Gen gt)
 }
 
 /*
@@ -145,7 +178,7 @@
 	])
 }
 
-/* anontarget: '=' namelist ';;' */
+/* anontarget: '=' wordlist ';;' */
 const anontarget = {p, targ
 	var inputs
 
--- a/types.myr
+++ b/types.myr
@@ -11,6 +11,7 @@
 
 		/* build params */
 		targs	: targ[:]
+		gensrc	: std.htab(byte[:], gentarg#)#
 		prefix	: byte[:]
 		system	: byte[:]
 		arch	: byte[:]
@@ -35,9 +36,15 @@
 		ldscript	: byte[:]
 	;;
 
+	type gentarg = struct
+		out	: byte[:][:]
+		cmd	: byte[:][:] 
+	;;
+
 	type targ = union
 		`Bin	myrtarg#
 		`Lib	myrtarg#
+		`Gen	gentarg#
 		`Sub	byte[:][:]
 		`Man	byte[:][:]
 	;;