summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--6/main.c22
-rw-r--r--lib/crypto/test/md5.myr2
-rw-r--r--lib/crypto/test/sha1.myr2
-rw-r--r--lib/crypto/test/sha256.myr2
-rw-r--r--lib/crypto/test/sha512.myr2
-rw-r--r--lib/sys/sys+openbsd-x64.myr2
-rw-r--r--lib/thread/condvar+freebsd.myr6
-rw-r--r--lib/thread/condvar+linux.myr6
-rw-r--r--lib/thread/future.myr2
-rw-r--r--lib/thread/mutex+freebsd.myr4
-rw-r--r--lib/thread/mutex+linux.myr4
-rw-r--r--lib/thread/mutex+plan9.myr4
-rw-r--r--lib/thread/mutex.myr4
-rw-r--r--lib/thread/test/atomic.myr2
-rw-r--r--lib/thread/test/condvar.myr2
-rw-r--r--lib/thread/test/future.myr2
-rw-r--r--lib/thread/test/mutex.myr2
-rw-r--r--mbld/deps.myr13
-rw-r--r--muse/muse.c2
-rw-r--r--parse/parse.h1
-rw-r--r--parse/use.c26
-rw-r--r--util/util.c10
-rw-r--r--util/util.h1
23 files changed, 79 insertions, 44 deletions
diff --git a/6/main.c b/6/main.c
index b3218d8..056f27c 100644
--- a/6/main.c
+++ b/6/main.c
@@ -28,6 +28,7 @@ int extracheck = 1;
int p9asm;
char *outfile;
char **incpaths;
+char *localincpath;
size_t nincpaths;
Asmsyntax asmsyntax;
@@ -99,6 +100,17 @@ static void assemble(char *asmsrc, char *path)
}
}
+static char *dirname(char *path)
+{
+ char *p;
+
+ p = strrchr(path, '/');
+ if (p)
+ return strdupn(path, p - path);
+ else
+ return xstrdup(".");
+}
+
static char *gentempfile(char *buf, size_t bufsz, char *path, char *suffix)
{
char *tmpdir;
@@ -216,11 +228,15 @@ int main(int argc, char **argv)
if (ctx.nargs == 0) {
fprintf(stderr, "No input files given\n");
exit(1);
- }
- else if (ctx.nargs > 1)
+ } else if (ctx.nargs > 1)
outfile = NULL;
for (i = 0; i < ctx.nargs; i++) {
+ if (outfile)
+ localincpath = dirname(outfile);
+ else
+ localincpath = dirname(ctx.args[i]);
+
globls = mkstab(0);
tyinit(globls);
tokinit(ctx.args[i]);
@@ -250,6 +266,8 @@ int main(int argc, char **argv)
genuse(ctx.args[i]);
gen(file, buf);
assemble(buf, ctx.args[i]);
+
+ free(localincpath);
}
return 0;
diff --git a/lib/crypto/test/md5.myr b/lib/crypto/test/md5.myr
index 0548051..bc0939f 100644
--- a/lib/crypto/test/md5.myr
+++ b/lib/crypto/test/md5.myr
@@ -1,7 +1,7 @@
use std
use crypto
-use "test/util"
+use "util"
const main = {
hasheq(crypto.md5("")[:], \
diff --git a/lib/crypto/test/sha1.myr b/lib/crypto/test/sha1.myr
index 22813d9..e750f41 100644
--- a/lib/crypto/test/sha1.myr
+++ b/lib/crypto/test/sha1.myr
@@ -1,7 +1,7 @@
use std
use crypto
-use "test/util"
+use "util"
const main = {
hasheq(crypto.sha1("")[:], \
diff --git a/lib/crypto/test/sha256.myr b/lib/crypto/test/sha256.myr
index e883c84..958b993 100644
--- a/lib/crypto/test/sha256.myr
+++ b/lib/crypto/test/sha256.myr
@@ -1,7 +1,7 @@
use std
use crypto
-use "test/util"
+use "util"
const main = {
hasheq(crypto.sha224("")[:], \
diff --git a/lib/crypto/test/sha512.myr b/lib/crypto/test/sha512.myr
index 0ae81e4..ddee8e8 100644
--- a/lib/crypto/test/sha512.myr
+++ b/lib/crypto/test/sha512.myr
@@ -1,7 +1,7 @@
use std
use crypto
-use "test/util"
+use "util"
const main = {
hasheq(crypto.sha384("")[:], \
diff --git a/lib/sys/sys+openbsd-x64.myr b/lib/sys/sys+openbsd-x64.myr
index a0c46fd..ba52a74 100644
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -1,4 +1,4 @@
-use "systypes.use"
+use "systypes"
pkg sys =
type pid = int32 /* process id */
diff --git a/lib/thread/condvar+freebsd.myr b/lib/thread/condvar+freebsd.myr
index 24e5a32..65267a4 100644
--- a/lib/thread/condvar+freebsd.myr
+++ b/lib/thread/condvar+freebsd.myr
@@ -1,9 +1,9 @@
use std
use sys
-use "atomic.use"
-use "common.use"
-use "mutex.use"
+use "atomic"
+use "common"
+use "mutex"
pkg thread =
type cond = struct
diff --git a/lib/thread/condvar+linux.myr b/lib/thread/condvar+linux.myr
index 9e288d7..cd4ab8c 100644
--- a/lib/thread/condvar+linux.myr
+++ b/lib/thread/condvar+linux.myr
@@ -1,9 +1,9 @@
use std
use sys
-use "atomic.use"
-use "common.use"
-use "mutex.use"
+use "atomic"
+use "common"
+use "mutex"
pkg thread =
type cond = struct
diff --git a/lib/thread/future.myr b/lib/thread/future.myr
index da6252b..5637e6d 100644
--- a/lib/thread/future.myr
+++ b/lib/thread/future.myr
@@ -1,6 +1,6 @@
use std
-use "mutex.use"
+use "mutex"
pkg thread =
type future(@a) = struct
diff --git a/lib/thread/mutex+freebsd.myr b/lib/thread/mutex+freebsd.myr
index d66fd53..fc1f8c2 100644
--- a/lib/thread/mutex+freebsd.myr
+++ b/lib/thread/mutex+freebsd.myr
@@ -1,8 +1,8 @@
use std
use sys
-use "atomic.use"
-use "common.use"
+use "atomic"
+use "common"
pkg thread =
type mutex = struct
diff --git a/lib/thread/mutex+linux.myr b/lib/thread/mutex+linux.myr
index 37bec62..22b9904 100644
--- a/lib/thread/mutex+linux.myr
+++ b/lib/thread/mutex+linux.myr
@@ -1,8 +1,8 @@
use std
use sys
-use "atomic.use"
-use "common.use"
+use "atomic"
+use "common"
pkg thread =
type mutex = struct
diff --git a/lib/thread/mutex+plan9.myr b/lib/thread/mutex+plan9.myr
index 7c87218..e91cd90 100644
--- a/lib/thread/mutex+plan9.myr
+++ b/lib/thread/mutex+plan9.myr
@@ -2,8 +2,8 @@ use std
use sys
-use "atomic.use"
-use "common.use"
+use "atomic"
+use "common"
pkg thread =
type mutex = struct
diff --git a/lib/thread/mutex.myr b/lib/thread/mutex.myr
index 6dc4a44..5b90574 100644
--- a/lib/thread/mutex.myr
+++ b/lib/thread/mutex.myr
@@ -2,8 +2,8 @@ use std
use sys
-use "atomic.use"
-use "common.use"
+use "atomic"
+use "common"
pkg thread =
type mutex = struct
diff --git a/lib/thread/test/atomic.myr b/lib/thread/test/atomic.myr
index c005677..3dd3284 100644
--- a/lib/thread/test/atomic.myr
+++ b/lib/thread/test/atomic.myr
@@ -1,7 +1,7 @@
use std
use thread
-use "test/util.use"
+use "util"
const Nherd = 20
diff --git a/lib/thread/test/condvar.myr b/lib/thread/test/condvar.myr
index e8670b1..0f1de58 100644
--- a/lib/thread/test/condvar.myr
+++ b/lib/thread/test/condvar.myr
@@ -1,7 +1,7 @@
use std
use thread
-use "test/util.use"
+use "util"
const Nwakes = 1000
diff --git a/lib/thread/test/future.myr b/lib/thread/test/future.myr
index 63969a4..e69e1af 100644
--- a/lib/thread/test/future.myr
+++ b/lib/thread/test/future.myr
@@ -2,7 +2,7 @@ use std
use sys
use thread
-use "test/util.use"
+use "util"
var fut
var nready : int32
diff --git a/lib/thread/test/mutex.myr b/lib/thread/test/mutex.myr
index e29ae85..b366637 100644
--- a/lib/thread/test/mutex.myr
+++ b/lib/thread/test/mutex.myr
@@ -1,7 +1,7 @@
use std
use thread
-use "test/util.use"
+use "util"
const Nherd = 20
diff --git a/mbld/deps.myr b/mbld/deps.myr
index 0b66b5b..59a4e75 100644
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -148,7 +148,7 @@ const srcdeps = {b, ds, g, path, obj, usefile
;;
std.exit(1)
;;
- deps = getdeps(b, ds, path)
+ deps = getdeps(b, ds, path, std.dirname(path))
std.htput(g.seen, path, true)
for d in deps
match d
@@ -253,7 +253,7 @@ const getcflags = {ln, cflags, libs
-> (cflags, libs)
}
-const getdeps = {b, ds, path
+const getdeps = {b, ds, path, dir
var deps, lnum
var f
@@ -266,7 +266,7 @@ const getdeps = {b, ds, path
| `bio.Err e: std.fatal("unable to read {}: {}\n", path, e)
| `bio.Eof: break
| `bio.Ok ln:
- deps = depname(deps, ln, lnum)
+ deps = depname(deps, ln, lnum, dir)
std.slfree(ln)
;;
;;
@@ -288,7 +288,9 @@ const opensrc = {b, path
;;
}
-const depname = {deps, ln, lnum
+const depname = {deps, ln, lnum, dir
+ var p
+
/*
the regex pattern does some contortions to either grab
an unquoted path and put it into uses[4], or a quoted
@@ -299,7 +301,8 @@ const depname = {deps, ln, lnum
if uses[2].len > 0
std.slpush(&deps, `Lib (std.sldup(uses[2]), lnum))
else
- std.slpush(&deps, `Local (std.sldup(uses[3]), lnum))
+ p = std.pathcat(dir, std.sldup(uses[3]))
+ std.slpush(&deps, `Local (p, lnum))
;;
regex.matchfree(uses)
| `std.None:
diff --git a/muse/muse.c b/muse/muse.c
index ccd8c58..da55e99 100644
--- a/muse/muse.c
+++ b/muse/muse.c
@@ -25,6 +25,7 @@ char **incpaths;
size_t nincpaths;
char **extralibs;
size_t nextralibs;
+char *localincpath;
static void usage(char *prog)
{
@@ -94,6 +95,7 @@ int main(int argc, char **argv)
fprintf(stderr, "output file needed when merging usefiles.\n");
exit(1);
}
+ localincpath = ".";
if (!pkgname)
pkgname = outfile;
diff --git a/parse/parse.h b/parse/parse.h
index caa5181..83f3ae6 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -559,5 +559,6 @@ extern int asmonly;
extern char *outfile;
extern char **incpaths;
extern size_t nincpaths;
+extern char *localincpath;
void yyerror(const char *s);
diff --git a/parse/use.c b/parse/use.c
index 70cd299..28132bd 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -1031,18 +1031,18 @@ void readuse(Node *use, Stab *st, Vis vis)
char *t, *p;
char buf[512];
- /* local (quoted) uses are always relative to the cwd */
+ /* local (quoted) uses are always relative to the output */
fd = NULL;
p = NULL;
if (use->use.islocal) {
- if (hassuffix(use->use.name, ".use"))
- snprintf(buf, sizeof buf, "%s", use->use.name);
- else
- snprintf(buf,sizeof buf, "%s.use", use->use.name);
-
+ snprintf(buf,sizeof buf, "%s/%s.use", localincpath, use->use.name);
p = strdup(buf);
fd = fopen(p, "r");
- /* nonlocal (barename) uses are always searched on the include path */
+ if (!fd) {
+ fprintf(stderr, "could not open usefile %s\n", buf);
+ exit(1);
+ }
+ /* nonlocal (barename) uses are always searched on the include path */
} else {
for (i = 0; i < nincpaths; i++) {
snprintf(buf, sizeof buf, "lib%s.use", use->use.name);
@@ -1064,12 +1064,12 @@ void readuse(Node *use, Stab *st, Vis vis)
}
free(p);
}
- }
- if (!fd) {
- fprintf(stderr, "could not open usefile %s in search path:\n", use->use.name);
- for (i = 0; i < nincpaths; i++)
- fprintf(stderr, "\t%s\n", incpaths[i]);
- exit(1);
+ if (!fd) {
+ fprintf(stderr, "could not open usefile %s in search path:\n", use->use.name);
+ for (i = 0; i < nincpaths; i++)
+ fprintf(stderr, "\t%s\n", incpaths[i]);
+ exit(1);
+ }
}
if (!loaduse(p, fd, st, vis))
diff --git a/util/util.c b/util/util.c
index dccc90b..904ef26 100644
--- a/util/util.c
+++ b/util/util.c
@@ -24,6 +24,16 @@ char *strdupn(char *s, size_t len)
return ret;
}
+char *xstrdup(char *s)
+{
+ char *p;
+
+ p = strdup(s);
+ if (!p && s)
+ die("Out of memory");
+ return p;
+}
+
char *strjoin(char *u, char *v)
{
size_t n;
diff --git a/util/util.h b/util/util.h
index 60a344b..49f10d6 100644
--- a/util/util.h
+++ b/util/util.h
@@ -121,6 +121,7 @@ void *zrealloc(void *p, size_t oldsz, size_t size);
void *xrealloc(void *p, size_t size);
void die(char *msg, ...) FATAL;
char *strdupn(char *s, size_t len);
+char *xstrdup(char *s);
char *strjoin(char *u, char *v);
void *memdup(void *mem, size_t len);
size_t bprintf(char *buf, size_t len, char *fmt, ...);