shithub: mc

Download patch

ref: 334ffbc2750c2be18dbbf8dc3ebbe8b22e8a9db3
parent: 847f11bb87ebfa7e4de48c05d65c83758d9220e1
author: Ori Bernstein <[email protected]>
date: Sun Mar 15 05:28:07 EDT 2020

Add support for LDFLAGS lines.

--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -21,11 +21,13 @@
 
 var usepat	: regex.regex#
 var cflagpat	: regex.regex#
+var ldflagpat	: regex.regex#
 var clibpat	: regex.regex#
 
 const __init__ = {
 	usepat = std.try(regex.compile("^\\s*use\\s+((\\<\\S+\\>)|\"(\\S+)\").*"))
 	cflagpat = std.try(regex.compile("/\\*\\s*CFLAGS:\\s*(.*)\\s*\\*/"))
+	ldflagpat = std.try(regex.compile("/\\*\\s*LDFLAGS:\\s*(.*)\\s*\\*/"))
 	clibpat = std.try(regex.compile("/\\*\\s*LIBS:\\s*(.*)\\s*\\*/"))
 }
 
@@ -57,8 +59,8 @@
 
 const myrdeps = {b, name, mt
 	var t, p, o, u, n, to, tu
-	var libs, dynlibs
-	var cflags, ll
+	var libs, dynlibs, ldflags
+	var cflags, ll, lf
 	var g, a, deps
 	var gu, go
 
@@ -123,6 +125,7 @@
 	;;
 
 	libs = [][:]
+	ldflags = [][:]
 	dynlibs = [][:]
 	for f : mt.inputs
 		p = std.pathcat(mt.dir, f)
@@ -170,7 +173,7 @@
 			o = std.pathcat(opt_objdir, t)
 			std.slfree(t)
 
-			(cflags, ll) = scrapecflags(b, mt, p)
+			(cflags, ll, lf) = scrapecflags(b, mt, p)
 			depends(g, go, o)
 			n = node(g, o)
 			generates(g, n, o)
@@ -179,6 +182,10 @@
 			for l : ll
 				std.slpush(&dynlibs, l)
 			;;
+			std.put("lf.len: {}\n", lf.len)
+			for l : lf
+				std.slpush(&ldflags, l)
+			;;
 			mt.isdyn = true
 		elif std.hassuffix(f, config.Objsuffix)
 			depends(g, go, p)
@@ -192,7 +199,7 @@
 		musecmd(b, gu, mt, tu, dynlibs)
 		builtlib(b, mt, libs, dynlibs)
 	else
-		linkcmd(b, go, mt, to, libs, dynlibs, false)
+		linkcmd(b, go, mt, to, libs, dynlibs, ldflags, false)
 		std.slfree(libs)
 	;;
 }
@@ -344,7 +351,7 @@
 	n = node(g, tp)
 	generates(g, n, tp)
 	depends(g, n, op)
-	linkcmd(b, n, mt, tp, libs, [][:], true)
+	linkcmd(b, n, mt, tp, libs, [][:], [][:], true)
 	std.slfree(libs)
 
 	n = node(g, tp)
@@ -432,7 +439,7 @@
 	;;
 }
 
-const linkcmd = {b, n, mt, bin, libs, dynlibs, istest
+const linkcmd = {b, n, mt, bin, libs, dynlibs, ldflags, istest
 	var dynlink
 
 	for c : config.Linkcmd
@@ -460,6 +467,9 @@
 	;;
 
 	dynlink = addlibs(b, &n.cmd, libs, mt.incpath) || mt.isdyn
+	for f : ldflags
+		std.slpush(&n.cmd, std.sldup(f))
+	;;
 	for l : dynlibs
 		std.slpush(&n.cmd, std.fmt("-l{}", l))
 	;;
@@ -561,8 +571,22 @@
 	-> l
 }
 
+const collectflags = {pat, ln, dst
+	var fl
+
+	match regex.exec(pat, ln)
+	| `std.None:	/* skip */
+	| `std.Some m:
+		fl = std.strtok(m[1])
+		for s : fl
+			std.slpush(dst, std.sldup(s))
+		;;
+		std.slfree(fl)
+	;;
+}
+
 const scrapecflags = {b, mt, path
-	var f, fl, cflags, libs
+	var f, cflags, libs, ldflags
 
 	match bio.open(path, bio.Rd)
 	| `std.Ok fd:	f = fd
@@ -571,27 +595,14 @@
 
 	cflags = [][:]
 	libs = [][:]
+	ldflags = [][:]
 	for ln : bio.byline(f)
-		match regex.exec(cflagpat, ln)
-		| `std.None:	/* skip */
-		| `std.Some m:
-			fl = std.strtok(m[1])
-			for s : fl
-				std.slpush(&cflags, std.sldup(s))
-			;;
-			std.slfree(fl)
-		;;
-		match regex.exec(clibpat, ln)
-		| `std.None:	/* skip */
-		| `std.Some m:
-			fl = std.strtok(m[1])
-			for s : fl
-				std.slpush(&libs, std.sldup(s))
-			;;
-			std.slfree(fl)
-		;;
+		collectflags(cflagpat, ln, &cflags)
+		collectflags(ldflagpat, ln, &ldflags)
+		collectflags(clibpat, ln, &libs)
 	;;
-	-> (cflags, libs)
+	std.put("cflags.len: {}, ldflags.len: {}, libs.len: {}\n", cflags.len, ldflags.len, libs.len)
+	-> (cflags, libs, ldflags)
 }
 
 const generates = {g, n, dep
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -42,9 +42,12 @@
 		libdeps	: (byte[:], byte[:], byte[:])[:]
 		tstdeps	: (byte[:], byte[:], byte[:])[:]
 		runtime	: byte[:]
-		incpath	: byte[:][:]
 		tags	: byte[:][:]
 		ldscript	: byte[:]
+
+		/* linking C */
+		incpath	: byte[:][:]
+		ldflags	: byte[:][:]
 
 		islib	: bool
 		istest	: bool