shithub: mc

Download patch

ref: 6799d5048886a3c61b200bf367f305bf8c068164
parent: ea60cdb464fe0bb4d289fb841304a44539d24593
author: Ori Bernstein <[email protected]>
date: Thu Oct 1 19:26:57 EDT 2015

Propagate extra libraries through the system.

--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -234,8 +234,7 @@
         die("size of empty type => bailing.");
     switch (t->type) {
         case Tyvoid:
-            die("void has no size");
-            return 1;
+            return 0;
         case Tybool: case Tyint8:
         case Tybyte: case Tyuint8:
             return 1;
--- a/mbld/build.myr
+++ b/mbld/build.myr
@@ -268,7 +268,7 @@
 	;;
 }
 
-const linkbin = {dg, bin, srcfiles, ldscript, rt, incs, extralibs
+const linkbin = {dg, bin, srcfiles, ldscript, rt, incs, extlibs
 	var cmd
 
 	cmd = [][:]
@@ -300,7 +300,7 @@
 	cmd = addlibs(cmd, dg.libs, incs)
 
 	/* add extra libs */
-	for l in dg.extralibs
+	for l in dg.extlibs
 		cmd = std.slpush(cmd, std.fmt("-l{}", l))
 	;;
 
@@ -344,9 +344,12 @@
 	for f in files
 		if std.hassuffix(f, ".myr")
 			cmd = std.slpush(cmd, srcswapsuffix(f, ".use"))
-		elif !std.hassuffix(f, ".s")
+		elif !std.hassuffix(f, ".s") && !std.hassuffix(f, ".glue.c")
 			std.fatal("unknown file type for {}\n", f)
 		;;
+	;;
+	for l in dg.extlibs
+		cmd = std.slpush(cmd, std.fmt("-l{}", l))
 	;;
 	run(cmd)
 	strlistfree(cmd)
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -55,7 +55,7 @@
 		.seen = std.mkht(std.strhash, std.streq),
 		.done = std.mkht(std.strhash, std.streq),
 		.cflags = std.mkht(std.strhash, std.streq),
-		.extralibs = [][:],
+		.extlibs = [][:],
 		.dynamic = false,
 	])
 	/* direct dependencies of binary */
@@ -87,7 +87,7 @@
 		elif std.hassuffix(srcs[i], ".glue.c")
 			(cflags, libs) = scrapecflags(b, dg, srcs[i])
 			std.htput(dg.cflags, srcs[i], cflags)
-			dg.extralibs = std.sljoin(dg.extralibs, libs)
+			dg.extlibs = std.sljoin(dg.extlibs, libs)
 			dg.dynamic = true
 		;;
 	;;
@@ -232,7 +232,6 @@
 	match regex.exec(cflagpat, ln)
 	| `std.None:
 	| `std.Some m:
-		std.put("Got cflags {}\n", m)
 		flags = std.strtok(m[1])
 		for fl in flags
 			cflags = std.slpush(cflags, std.sldup(fl))
@@ -243,7 +242,6 @@
 	match regex.exec(clibpat, ln)
 	| `std.None:
 	| `std.Some m:
-		std.put("Got libs {}\n", m)
 		flags = std.strtok(m[1])
 		for fl in flags
 			libs = std.slpush(libs, std.sldup(fl))
@@ -315,7 +313,6 @@
 		->
 	;;
 
-	deps = [][:]
 	f = openlib(lib, incs)
 	match bio.getc(f)
 	| `std.Some 'U': /* nothing */
@@ -333,12 +330,17 @@
 	| `std.None:	std.fatal("library {}: corrupt or invalid usefile\n", lib)
 	;;
 	std.slfree(rdstr(f))
+
 	done = false
+	deps = [][:]
 	while !done
 		match bio.getc(f)
 		| `std.Some 'L':
 			d = rdstr(f)
 			deps = std.slpush(deps, d)
+		| `std.Some 'X':
+			d = rdstr(f)
+			dg.extlibs = std.slpush(dg.extlibs, d)
 		| `std.Some _:	done = true
 		| `std.None:	done = true
 		;;
--- a/mbld/types.myr
+++ b/mbld/types.myr
@@ -72,7 +72,7 @@
 		done	: std.htab(byte[:], bool)#
 
 		/* used for linking C */
-		extralibs	: byte[:][:]
+		extlibs	: byte[:][:]
 		cflags	: std.htab(byte[:], byte[:][:])#
 		dynamic	: bool
 	;;
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -21,6 +21,8 @@
 char debugopt[128];
 char **incpaths;
 size_t nincpaths;
+char **extralibs;
+size_t nextralibs;
 
 static void usage(char *prog)
 {
@@ -52,7 +54,7 @@
     size_t i;
     FILE *f;
 
-    optinit(&ctx, "d:hmo:I:", argv, argc);
+    optinit(&ctx, "d:hmo:I:l:", argv, argc);
     while (!optdone(&ctx)) {
         switch (optnext(&ctx)) {
             case 'h':
@@ -69,6 +71,9 @@
             case 'I':
                 lappend(&incpaths, &nincpaths, ctx.optarg);
                 break;
+            case 'l':
+                lappend(&extralibs, &nextralibs, ctx.optarg);
+                break;
             case 's':
                 show = 1;
                 break;
@@ -85,6 +90,7 @@
         exit(1);
     }
 
+    /* read and parse the file */
     file = mkfile("internal");
     file->file.globls = mkstab(0);
     updatens(file->file.globls, outfile);
@@ -93,6 +99,9 @@
         mergeuse(ctx.args[i]);
     infer(file);
     tagexports(file, 1);
+    addextlibs(file, extralibs, nextralibs);
+
+    /* generate the usefile */
     f = fopen(outfile, "w");
     if (debugopt['s'] || show)
         dumpstab(file->file.globls, stdout);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -218,6 +218,8 @@
             size_t nuses;
             char **libdeps;     /* library dependencies */
             size_t nlibdeps;
+            char **extlibs;     /* non-myrddin libraries */
+            size_t nextlibs;
             Node **stmts;       /* all top level statements */
             size_t nstmts;
             Node **init;        /* a list of all __init__ function names of our deps. NB, this is a Nname, not an Ndecl */
@@ -595,6 +597,7 @@
 void readuse(Node *use, Stab *into, Vis vis);
 void writeuse(FILE *fd, Node *file);
 void tagexports(Node *file, int hidelocal);
+void addextlibs(Node *file, char **libs, size_t nlibs);
 
 /* typechecking/inference */
 void infer(Node *file);
--- a/parse/use.c
+++ b/parse/use.c
@@ -41,6 +41,18 @@
 static size_t ntraitfixid; /* size of replacement list */
 
 
+void addextlibs(Node *file, char **libs, size_t nlibs)
+{
+    size_t i, j;
+
+    for (i = 0; i < nlibs; i++) {
+        for (j = 0; j < file->file.nextlibs; j++)
+            if (!strcmp(file->file.extlibs[j], libs[i]))
+                continue;
+        lappend(&file->file.extlibs, &file->file.nextlibs, libs[i]);
+    }
+}
+
 /* Outputs a symbol table to file in a way that can be
  * read back usefully. Only writes declarations, types
  * and sub-namespaces. Captured variables are ommitted. */
@@ -862,6 +874,15 @@
                 lappend(&file->file.libdeps, &file->file.nlibdeps, lib);
 foundlib:
                 break;
+            case 'X':
+                lib = rdstr(f);
+                for (i = 0; i < file->file.nextlibs; i++)
+                    if (!strcmp(file->file.extlibs[i], lib))
+                        /* break out of both loop and switch */
+                        goto foundextlib;
+                lappend(&file->file.extlibs, &file->file.nextlibs, lib);
+foundextlib:
+                break;
             case 'F':
                 lappend(&file->file.files, &file->file.nfiles, rdstr(f));
                 break;
@@ -994,6 +1015,10 @@
     for (i = 0; i < file->file.nlibdeps; i++) {
         wrbyte(f, 'L');
         wrstr(f, file->file.libdeps[i]);
+    }
+    for (i = 0; i < file->file.nextlibs; i++) {
+        wrbyte(f, 'X');
+        wrstr(f, file->file.extlibs[i]);
     }
 
     /* source file name */