shithub: mc

Download patch

ref: d7d95f9f1db8434f40d5ac3c81ba486223e3893b
parent: d60e706a5f499863320b9359519438c62a4df303
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Sep 30 20:50:08 EDT 2015

Add muse support for C linking on Linux.

    We know know about foo.glue.c, which will attempt to
    link in libfoo. We don't do anything about dependencies
    of libfoo yet.

--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -252,6 +252,14 @@
 		cmd = std.slpush(cmd, src)
 		run(cmd)
 		std.slfree(o)
+	elif std.hassuffix(src, ".glue.c")
+		o = srcswapsuffix(src, config.Objsuffix)
+		cmd = std.slpush(cmd, "cc")
+		cmd = std.slpush(cmd,"-c")
+		cmd = std.slpush(cmd,"-o")
+		cmd = std.slpush(cmd, o)
+		cmd = std.slpush(cmd, src)
+		run(cmd)
 	else
 		std.fatal("Unknown file type for {}\n", src)
 	;;
@@ -292,6 +300,9 @@
 	if std.sleq(opt_sys, "osx")
 		cmd = std.slpush(cmd, std.sldup("-macosx_version_min"))
 		cmd = std.slpush(cmd, std.sldup("10.6"))
+	elif std.sleq(opt_sys, "linux") && dg.dynamic
+		cmd = std.slpush(cmd, std.sldup("-dynamic-linker"))
+		cmd = std.slpush(cmd, std.sldup("/lib64/ld-linux-x86-64.so.2"))
 	;;
 
 	run(cmd)
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -9,9 +9,6 @@
 
 pkg bld =
 	const myrdeps	: (b : build#, mt : myrtarg#, doclean : bool, addsrc : bool -> depgraph#)
-
-	/* a bit ugly: initialized from main() */
-	var usepat	: regex.regex#
 ;;
 
 const Abiversion = 8
@@ -18,6 +15,14 @@
 
 var usepat	: regex.regex#
 
+const __init__ = {
+	match regex.compile("^\\s*use\\s+((\\<\\S+\\>)|\"(\\S+)\").*")
+	| `std.Ok re:	usepat = re
+	| `std.Fail f:	std.fatal("Failed to compile use pattern regex\n")
+	;;
+}
+
+
 type dep = union
 	`Local	(byte[:], int)
 	`Lib	(byte[:], int)
@@ -33,7 +38,7 @@
 ;;
 
 const myrdeps = {b, mt, doclean, addsrc
-	var objs, uses, srcs
+	var objs, uses, srcs, clib
 	var out, useout
 	var dg : depgraph#
 	var ds : depscan
@@ -47,6 +52,7 @@
 		.updated = std.mkht(std.strhash, std.streq),
 		.seen = std.mkht(std.strhash, std.streq),
 		.done = std.mkht(std.strhash, std.streq),
+		.dynamic = false,
 	])
 	/* direct dependencies of binary */
 	if mt.islib
@@ -74,6 +80,10 @@
 		if std.hassuffix(srcs[i], ".myr")
 			std.htput(dg.input, uses[i], srcs[i])
 			pushdep(dg, srcs[i], uses[i])
+		elif std.hassuffix(srcs[i], ".glue.c")
+			clib = swapsuffix(srcs[i], ".glue.c", "")
+			std.htput(dg.libs, clib, [][:])
+			dg.dynamic = true
 		;;
 	;;
 
--- a/mbld/main.myr
+++ b/mbld/main.myr
@@ -79,11 +79,6 @@
 		bld.opt_incpaths = std.slpush(bld.opt_incpaths, libpath)
 	;;
 
-	match regex.compile("^\\s*use\\s+((\\<\\S+\\>)|\"(\\S+)\").*")
-	| `std.Ok re:	bld.usepat = re
-	| `std.Fail f:	std.fatal("Failed to compile use pattern regex\n")
-	;;
-
 	b = mkbuild(tags)
 	if targname.len != 0
 		mt = [
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -70,5 +70,6 @@
 		updated	: std.htab(byte[:], bool)#
 		seen	: std.htab(byte[:], bool)#
 		done	: std.htab(byte[:], bool)#
+		dynamic	: bool
 	;;
 ;;
--- a/mbld/util.myr
+++ b/mbld/util.myr
@@ -51,7 +51,7 @@
 
 	platf = ""
 	suff = ""
-	match std.strrfind(src, ".")
+	match std.strfind(src, ".")
 	| `std.Some i:
 		suff = src[i:]
 		src = src[:i]
@@ -80,10 +80,12 @@
 	var base, platf, suff
 
 	(base, platf, suff) = srcsplit(src)
-	if std.sleq(suff, ".myr")
+	if std.hassuffix(suff, ".myr")
 		-> std.strcat(base, new)
-	elif std.sleq(suff, ".s")
+	elif std.hassuffix(suff, ".s")
 		-> std.strcat(base, new)
+	elif std.hassuffix(suff, ".glue.c")
+		-> std.strjoin([base, ".glue", new][:], "")
 	else
 		std.fatal("unrecognized source {}\n", src)
 	;;