]> Cypherpunks repositories - gostls13.git/commitdiff
enable autolib
authorRob Pike <r@golang.org>
Wed, 9 Jul 2008 23:05:03 +0000 (16:05 -0700)
committerRob Pike <r@golang.org>
Wed, 9 Jul 2008 23:05:03 +0000 (16:05 -0700)
handle archives with __.PKGDEF elements (although we can't create them yet)
introduce a pkg directory
search the pkg directory for packages during compilation

SVN=126574

src/cmd/6l/obj.c
src/cmd/gc/lex.c

index 49fd5956c4c447923a033c5d39e8ca350359985d..02bd12298f2e9372b1821379229e6a4d3da04f3a 100644 (file)
@@ -363,6 +363,7 @@ main(int argc, char *argv[])
                objfile(*argv++);
 
        if(!debug['l']) {
+               loadlib();
                a = mal(strlen(goroot)+strlen(goarch)+strlen(goos)+20);
                sprint(a, "%s/lib/lib_%s_%s.a", goroot, goarch, goos);
                objfile(a);
index 20cd642b93f5000ae82ef017cd299bdc068cf652..e9eaab8b48295d795340a28ed518718124413aa5 100644 (file)
@@ -6,6 +6,7 @@
 #define                EXTERN
 #include       "go.h"
 #include       "y.tab.h"
+#include <ar.h>
 
 #define        DBG     if(!debug['x']);else print
 enum
@@ -124,26 +125,100 @@ setfilename(char *file)
        filename = strdup(namebuf);
 }
 
+int
+arsize(Biobuf *b, char *name){
+       struct ar_hdr *a;
+
+       if((a = Brdline(b, '\n')) == nil)
+               return 0;
+       if(Blinelen(b) != sizeof(struct ar_hdr))
+               return 0;
+       if(strncmp(a->name, name, strlen(name)) != 0)
+               return 0;
+       return atoi(a->size);
+}
+
+int
+skiptopkgdef(Biobuf *b)
+{
+       char *p;
+       int sz;
+
+       /* archive header */
+       if((p = Brdline(b, '\n')) == nil)
+               return 0;
+       if(Blinelen(b) != 8)
+               return 0;
+       if(memcmp(p, "!<arch>\n", 8) != 0)
+               return 0;
+       /* symbol table is first; skip it */
+       sz = arsize(b, "__.SYMDEF");
+       if(sz <= 0)
+               return 0;
+       Bseek(b, sz, 1);
+       /* package export block is second */
+       sz = arsize(b, "__.PKGDEF");
+       if(sz <= 0)
+               return 0;
+       return 1;
+}
+
+int
+findpkg(String *name)
+{
+       static char* goroot;
+
+       if(goroot == nil) {
+               goroot = getenv("GOROOT");
+               if(goroot == nil)
+                       return 0;
+       }
+
+       // BOTCH need to get .6 from backend
+       snprint(namebuf, sizeof(namebuf), "%Z.6", name);
+       if(access(namebuf, 0) >= 0)
+               return 1;
+       snprint(namebuf, sizeof(namebuf), "%Z.a", name);
+       if(access(namebuf, 0) >= 0)
+               return 1;
+       snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.6", goroot, name);
+       if(access(namebuf, 0) >= 0)
+               return 1;
+       snprint(namebuf, sizeof(namebuf), "%s/pkg/%Z.a", goroot, name);
+       if(access(namebuf, 0) >= 0)
+               return 1;
+       return 0;
+}
+
 void
 importfile(Val *f)
 {
        Biobuf *imp;
        char *file;
        long c;
+       char *p;
+       int len;
 
        if(f->ctype != CTSTR) {
                yyerror("import statement not a string");
                return;
        }
 
-       // BOTCH need to get .6 from backend
-       snprint(namebuf, sizeof(namebuf), "%Z.6", f->sval);
+       if(!findpkg(f->sval))
+               fatal("can't find import: %Z", f->sval);
+       imp = Bopen(namebuf, OREAD);
+       if(imp == nil)
+               fatal("can't open import: %Z", f->sval);
        file = strdup(namebuf);
-       linehist(file, 0);
 
-       imp = Bopen(file, OREAD);
-       if(imp == nil)
-               fatal("cant open import: %s", namebuf);
+       len = strlen(namebuf);
+       if(len > 2)
+       if(namebuf[len-2] == '.')
+       if(namebuf[len-1] == 'a')
+       if(!skiptopkgdef(imp))
+               fatal("import not package file: %s", namebuf);
+
+       linehist(file, 0);
        linehist(file, -1);     // acts as #pragma lib
 
        /*
@@ -675,6 +750,8 @@ getc(void)
 
        switch(c) {
        case 0:
+               if(curio.bin != nil)
+                       break;
        case EOF:
                return EOF;