]> Cypherpunks repositories - gostls13.git/commitdiff
build: move GOOS, GOARCH, GOROOT lookup into central library.
authorRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 05:46:46 +0000 (21:46 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 05:46:46 +0000 (21:46 -0800)
bake default values in during build.

R=r
CC=golang-dev
https://golang.org/cl/186173

src/cmd/gc/lex.c
src/cmd/ld/lib.c
src/lib9/Makefile
src/lib9/goos.c [new file with mode: 0644]

index c433c1ec9e904f8ef48ab2b7ab3eb9aab571ea2b..84e6a2e97b5c1cc29e77ae1e8cebbe4910444c67 100644 (file)
@@ -223,8 +223,8 @@ findpkg(Strlit *name)
        Idir *p;
 
        if(goroot == nil) {
-               goroot = getenv("GOROOT");
-               goos = getenv("GOOS");
+               goroot = getgoroot();
+               goos = getgoos();
                goarch = thestring;
        }
 
index f702bae237503fa47dea591888c0d43bff1d74d7..b70c8743902a0537a59bd6ebb1f4572cf518ce08 100644 (file)
@@ -720,21 +720,9 @@ mywhatsys(void)
 {
        char *s;
 
-       goroot = getenv("GOROOT");
-       goos = getenv("GOOS");
-
-       if(goroot == nil) {
-               s = getenv("HOME");
-               if(s == nil)
-                       s = "/home/ken";
-               goroot = mal(strlen(s) + 10);
-               strcpy(goroot, s);
-               strcat(goroot, "/go");
-       }
+       goroot = getgoroot();
+       goos = getgoos();
        goarch = thestring;     // ignore $GOARCH - we know who we are
-       if(goos == nil) {
-               goos = "linux";
-       }
 }
 
 int
index 9038730b1fa41454acbc690fde0eb806a62dfb1a..592bc3b1a614d879422768c19c0c4f8ecd549029 100644 (file)
@@ -69,6 +69,7 @@ LIB9OFILES=\
        getenv.$O\
        getfields.$O\
        getwd.$O\
+       goos.$O\
        main.$O\
        nan.$O\
        nulldir.$O\
@@ -115,6 +116,9 @@ $(LIB): $(OFILES)
 %.$O: utf/%.c
        $(CC) -c $(CFLAGS) $<
 
+goos.$O: goos.c
+       $(CC) -c $(CFLAGS) -DGOOS='"$(GOOS)"' -DGOARCH='"$(GOARCH)"' -DGOROOT='"$(GOROOT)"' $<
+
 clean:
        rm -f *.$O *.6 6.out $(LIB)
 
diff --git a/src/lib9/goos.c b/src/lib9/goos.c
new file mode 100644 (file)
index 0000000..668dc19
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+#include <u.h>
+#include <libc.h>
+
+static char*
+defgetenv(char *name, char *def)
+{
+       char *p;
+       
+       p = getenv(name);
+       if(p == nil || p[0] == '\0')
+               p = def;
+       return p;
+}
+
+char*
+getgoos(void)
+{
+       return defgetenv("GOOS", GOOS);
+}
+
+char*
+getgoarch(void)
+{
+       return defgetenv("GOARCH", GOARCH);
+}
+
+char*
+getgoroot(void)
+{
+       return defgetenv("GOROOT", GOROOT);
+}