mirror of https://github.com/golang/go.git
build: move GOOS, GOARCH, GOROOT lookup into central library.
bake default values in during build. R=r CC=golang-dev https://golang.org/cl/186173
This commit is contained in:
parent
539ff7b0c4
commit
4f8117d9eb
|
|
@ -223,8 +223,8 @@ findpkg(Strlit *name)
|
|||
Idir *p;
|
||||
|
||||
if(goroot == nil) {
|
||||
goroot = getenv("GOROOT");
|
||||
goos = getenv("GOOS");
|
||||
goroot = getgoroot();
|
||||
goos = getgoos();
|
||||
goarch = thestring;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
Loading…
Reference in New Issue