shithub: mc

Download patch

ref: 557383038cbb660e1d706a513f56fd0538b933b8
parent: 0171bdcc17275a08a3d0369d3e99e5577d99b8d5
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 1 10:53:27 EST 2015

Initial plan9 toolchain support for mbld.

--- a/bldfile
+++ b/bldfile
@@ -3,7 +3,7 @@
 	build.myr
 	clean.myr
 	config.myr	# config, as generated by the ./configure script
-	config+plan9.myr	# config, as hardcoded for Plan 9
+	config+plan9-x64.myr	# config, as hardcoded for Plan 9
 	deps.myr
 	fsel.myr
 	install.myr
--- a/build.myr
+++ b/build.myr
@@ -155,8 +155,8 @@
 	var o
 	var cmd
 
+	cmd = [][:]
 	if std.hassuffix(src, ".myr")
-		cmd = [][:]
 		cmd = std.slpush(cmd, "6m")
 		for inc in incs 
 			cmd = std.slpush(cmd, "-I")
@@ -169,8 +169,14 @@
 		run(cmd, "")
 		std.slfree(cmd)
 	elif std.hassuffix(src, ".s")
-		o = srcswapsuffix(src, ".o")
-		run(["as", src, "-o", o][:], "")
+		o = srcswapsuffix(src, config.Objsuffix)
+		for c in config.Ascmd
+			cmd = std.slpush(cmd, c)
+		;;
+		cmd = std.slpush(cmd,"-o")
+		cmd = std.slpush(cmd, o)
+		cmd = std.slpush(cmd, src)
+		run(cmd, "")
 		std.slfree(o)
 	else
 		std.fatal(1, "Unknown file type for %s\n", src)
@@ -183,8 +189,9 @@
 	cmd = [][:]
 
 	/* ld -o bin */
-	cmd = std.slpush(cmd, std.sldup("ld"))
-	cmd = std.slpush(cmd, std.sldup("-o"))
+	for c in config.Linkcmd
+		cmd = std.slpush(cmd, std.sldup(c))
+	;;
 	cmd = std.slpush(cmd, std.sldup(bin))
 
 	/* [-T script] */
@@ -201,20 +208,15 @@
 
 	/* input.o list.o... */
 	for f in srcfiles
-		cmd = std.slpush(cmd, srcswapsuffix(f, ".o"))
+		cmd = std.slpush(cmd, srcswapsuffix(f, config.Objsuffix))
 	;;
 
-	/* -l lib... */
-	cmd = addlibs(cmd, dg.libs)
+	/* -L path -l lib... */
+	cmd = addlibs(cmd, dg.libs, incs)
 	for l in extralibs
 		cmd = std.slpush(cmd, std.fmt("-l%s", l))
 	;;
 
-	/* -L incpath... */
-	for inc in incs
-		cmd = std.slpush(cmd, std.fmt("-L%s", inc))
-	;;
-	cmd = std.slpush(cmd, std.fmt("-L%s%s", opt_instroot, "/lib/myr"))
 
 	/* special for OSX: it warns if we don't add this */
 	if std.sleq(opt_sys, "osx")
@@ -231,11 +233,12 @@
 	var obj
 
 	cmd = [][:]
-	cmd = std.slpush(cmd, std.sldup(opt_ar))
-	cmd = std.slpush(cmd, std.sldup("-rcs"))
+	for c in config.Arcmd
+		cmd = std.slpush(cmd, std.sldup(c))
+	;;
 	cmd = std.slpush(cmd, std.fmt("lib%s.a", lib))
 	for f in files
-		obj = srcswapsuffix(f, ".o")
+		obj = srcswapsuffix(f, config.Objsuffix)
 		cmd = std.slpush(cmd, obj)
 	;;
 	run(cmd, "")
@@ -260,23 +263,33 @@
 	strlistfree(cmd)
 }
 
-const addlibs = {cmd, libgraph
+const addlibs = {cmd, libgraph, incs
 	var looped : std.htab(byte[:], bool)#
 	var marked : std.htab(byte[:], bool)#
 	var libs
 	var head
 
+	/* -L incpath... */
+	if !config.Directlib
+		for inc in incs
+			cmd = std.slpush(cmd, std.fmt("-L%s", inc))
+		;;
+		cmd = std.slpush(cmd, std.fmt("-L%s%s", opt_instroot, "/lib/myr"))
+	;;
+
 	libs = std.htkeys(libgraph)
 	looped = std.mkht(std.strhash, std.streq)
 	marked = std.mkht(std.strhash, std.streq)
 	head = cmd.len
+
 	for lib in libs
-		cmd = visit(cmd, head, libgraph, lib, looped, marked)
+		cmd = visit(cmd, head, libgraph, lib, looped, marked, incs)
 	;;
+
 	-> cmd
 }
 
-const visit = {cmd, head, g, lib, looped, marked -> byte[:][:]
+const visit = {cmd, head, g, lib, looped, marked, incs
 	if std.hthas(looped, lib)
 		std.fatal(1, "cycle in library graph involving \"%s\"\n", lib)
 	elif std.hthas(marked, lib)
@@ -285,12 +298,38 @@
 
 	std.htput(looped, lib, true)
 	for dep in std.htgetv(g, lib, [][:])
-		cmd = visit(cmd, head, g, dep, looped, marked)
+		cmd = visit(cmd, head, g, dep, looped, marked, incs)
 	;;
 	std.htdel(looped, lib)
 	std.htput(marked, lib, true)
-	-> std.slput(cmd, head, std.fmt("-l%s", lib))
+	-> putlib(cmd, head, lib, incs)
 }
+
+const putlib = {cmd, head, lib, incs
+	var buf : byte[512]
+	var n, p
+
+	if !config.Directlib
+		-> std.slput(cmd, head, std.fmt("-l%s", lib))
+	;;
+
+	n = std.bfmt(buf[:], "lib%s.a", lib)
+	for i in incs
+		p = std.pathjoin([i, "lib/myr", buf[:n]][:])
+		if std.fexists(p)
+			-> std.slput(cmd, head, p)
+		;;
+		std.slfree(p)
+	;;
+	p = std.pathjoin([config.Instroot, "lib/myr", buf[:n]][:])
+	if std.fexists(p)
+		-> std.slput(cmd, head, p)
+	;;
+	std.fatal(1, "could not find library lib%s.a", lib)
+}
+
+
+
 
 const isfresh = {src, dst
 	var srcmt, dstmt
--- a/config+plan9-x64.myr
+++ b/config+plan9-x64.myr
@@ -2,8 +2,9 @@
 	const Instroot	= "/amd64"
 	const Sys	= "Plan9"
 	const Objsuffix	= ".6"
-	const Linkcmd	= ["6l", "-l", "-o"]
+	const Linkcmd	= ["6l", "-lo"]
 	const Arcmd	= ["ar", "vu"]
 	const Ascmd	= ["6a"]
 	const Directlib	= true
+	const Runtime	= "_myrrt.6"
 ;;
--- a/configure
+++ b/configure
@@ -32,9 +32,15 @@
 
 OS=`uname`
 
+echo export INST_ROOT=$prefix > config.mk
+
 echo "pkg config = " > config.myr
 echo "const Instroot = \"$prefix\"" >> config.myr
-echo export INST_ROOT=$prefix > config.mk
+echo "const Objsuffix = \".o\"" >> config.myr
+echo "const Linkcmd = [\"ld\", \"-o\"]" >> config.myr
+echo "const Arcmd = [\"ar\", \"-rcs\"]" >> config.myr
+echo "const Ascmd = [\"as\", \"-g\"]" >> config.myr
+echo "const Directlib = false" >> config.myr
 case $OS in
     *Linux*)
         echo 'export SYS=linux' >> config.mk
--- a/deps.myr
+++ b/deps.myr
@@ -42,7 +42,7 @@
 		out = std.sldup(targ)
 		useout = ""
 	;;
-	objs = swapall(srcs, ".o")
+	objs = swapall(srcs, config.Objsuffix)
 	uses = swapall(srcs, ".use")
 	for i = 0; i < srcs.len; i++
 		std.htput(dg.sources, objs[i], srcs[i])
--- a/main.myr
+++ b/main.myr
@@ -45,10 +45,7 @@
 		*/
 		| ('d', arg): bld.opt_debug = true
 		| ('C', arg): bld.opt_mc = arg
-		| ('A', arg): bld.opt_as = arg
 		| ('M', arg): bld.opt_muse = arg
-		| ('L', arg): bld.opt_ld = arg
-		| ('D', arg): bld.opt_ar = arg
 		| _:	std.die("got invalid arg\n")
 		;;
 	;;
--- a/opts.myr
+++ b/opts.myr
@@ -16,10 +16,7 @@
 
 	/* undocumented/unsupported opts */
 	var opt_mc	: byte[:]
-	var opt_as	: byte[:]
 	var opt_muse	: byte[:]
-	var opt_ld	: byte[:]
-	var opt_ar	: byte[:]
 
 	var sysarchstr	: byte[:]
 	var archstr	: byte[:]
@@ -59,6 +56,7 @@
 	| "Linux":	opt_sys = "linux"
 	| "Darwin":	opt_sys = "osx"
 	| "FreeBSD":	opt_sys = "freebsd"
+	| "Plan9":	opt_sys = "plan9"
 	| unknown:	std.fatal(1, "unknown system \"%s\"\n", unknown)
 	;;
 
@@ -72,9 +70,6 @@
 	opt_instroot = config.Instroot
 	opt_destdir = std.getenvv("DESTDIR", "")
 	opt_mc = std.getenvv("MYR_MC", "6m")
-	opt_as = std.getenvv("MYR_AS", "as")
-	opt_ld = std.getenvv("MYR_LD", "ld")
-	opt_ar = std.getenvv("MYR_AR", "ar")
 	opt_muse = std.getenvv("MYR_MUSE", "muse")
 
 	sysarchstr = std.fmt("+%s-%s", opt_sys, opt_arch)
@@ -81,6 +76,6 @@
 	sysstr = std.fmt("+%s", opt_sys)
 	archstr = std.fmt("+%s", opt_arch)
 
-	opt_runtime = std.pathcat(config.Instroot, "/lib/myr/_myrrt.o")
+	opt_runtime = std.pathjoin([config.Instroot, "lib/myr", config.Runtime][:]) 
 }