summaryrefslogtreecommitdiff
path: root/myrbuild
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-08-11 19:34:12 -0400
committerOri Bernstein <ori@eigenstate.org>2014-08-11 19:36:19 -0400
commit70ab782a15f19d4ea160304bb35f7cd1defa7d5d (patch)
treebfb3798d0cb0e5757eebccd645217ac88faa252b /myrbuild
parentfb85c50fc2abd8ba903f72b59567b9e7f2e31c1c (diff)
downloadmc-70ab782a15f19d4ea160304bb35f7cd1defa7d5d.tar.gz
Spit out the runtime from libstd.
This will allow linking code without libstd, as well as fixing link order on freebsd. Freebsd seems to be picky aobut where '_start' is searched from.
Diffstat (limited to 'myrbuild')
-rw-r--r--myrbuild/myrbuild.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/myrbuild/myrbuild.c b/myrbuild/myrbuild.c
index a25978a..cb1951d 100644
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -30,6 +30,8 @@ char *as = "as";
char *ar = "ar";
char *ld = "ld";
char *muse = "muse";
+char *runtime = "_myrrt.o";
+char *runtimepath;
/* the name of the output file */
char *libname;
char *binname;
@@ -194,7 +196,6 @@ FILE *openlib(char *lib)
char buf[1024];
size_t i;
- snprintf(buf, sizeof buf, "%s/%s/%s", Instroot, "/lib/myr", lib);
f = fopen(buf, "r");
if (f)
return f;
@@ -404,6 +405,10 @@ void linkobj(char **files, size_t nfiles)
lappend(&args, &nargs, strdup(buf));
}
+ if (runtimepath) {
+ lappend(&args, &nargs, strdup(runtimepath));
+ }
+
/* ld -T ldscript -o outfile foo.o bar.o baz.o */
for (i = 0; i < nfiles; i++) {
if (hassuffix(files[i], ".myr"))
@@ -420,8 +425,6 @@ void linkobj(char **files, size_t nfiles)
snprintf(buf, sizeof buf, "-L%s", incpaths[i]);
lappend(&args, &nargs, strdup(buf));
}
- snprintf(buf, sizeof buf, "-L%s%s", Instroot, "/lib/myr");
- lappend(&args, &nargs, strdup(buf));
/* ld -T ldscript -o outfile foo.o bar.o baz.o -L/path1 -L/path2 -llib1 -llib2*/
addlibs(&args, &nargs, libgraph);
@@ -442,6 +445,24 @@ void linkobj(char **files, size_t nfiles)
lfree(&args, &nargs);
}
+void findruntime()
+{
+ char buf[2048];
+ size_t i;
+
+ if (!strcmp(runtime, "none"))
+ runtimepath = NULL;
+ for (i = 0; i < nincpaths; i++) {
+ snprintf(buf, sizeof buf, "%s/%s", incpaths[i], runtime);
+ if (access(buf, R_OK) == 0) {
+ printf("Got %s\n", buf);
+ runtimepath = strdup(buf);
+ return;
+ }
+ }
+ err(1, "Could not find runtime %s", runtime);
+}
+
int main(int argc, char **argv)
{
int opt;
@@ -450,7 +471,8 @@ int main(int argc, char **argv)
if (uname(&name) == 0)
sysname = strdup(name.sysname);
- while ((opt = getopt(argc, argv, "hb:l:s:SI:C:A:M:L:R:")) != -1) {
+ lappend(&incpaths, &nincpaths, strdup(Instroot "/lib/myr"));
+ while ((opt = getopt(argc, argv, "hb:l:s:r:SI:C:A:M:L:R:")) != -1) {
switch (opt) {
case 'b': binname = optarg; break;
case 'l': libname = optarg; break;
@@ -461,8 +483,9 @@ int main(int argc, char **argv)
case 'M': muse = optarg; break;
case 'L': ld = optarg; break;
case 'R': ar = optarg; break;
+ case 'r': runtime = optarg; break;
case 'I':
- lappend(&incpaths, &nincpaths, optarg);
+ lappend(&incpaths, &nincpaths, strdup(optarg));
break;
case 'h':
usage(argv[0]);
@@ -481,6 +504,7 @@ int main(int argc, char **argv)
libgraph = mkht(strhash, streq);
compiled = mkht(strhash, streq);
loopdetect = mkht(strhash, streq);
+ findruntime();
regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED);
for (i = optind; i < argc; i++)
compile(argv[i]);