Commit 4f8117d9 authored by Russ Cox's avatar Russ Cox

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
parent 539ff7b0
...@@ -223,8 +223,8 @@ findpkg(Strlit *name) ...@@ -223,8 +223,8 @@ findpkg(Strlit *name)
Idir *p; Idir *p;
if(goroot == nil) { if(goroot == nil) {
goroot = getenv("GOROOT"); goroot = getgoroot();
goos = getenv("GOOS"); goos = getgoos();
goarch = thestring; goarch = thestring;
} }
......
...@@ -720,21 +720,9 @@ mywhatsys(void) ...@@ -720,21 +720,9 @@ mywhatsys(void)
{ {
char *s; char *s;
goroot = getenv("GOROOT"); goroot = getgoroot();
goos = getenv("GOOS"); goos = getgoos();
if(goroot == nil) {
s = getenv("HOME");
if(s == nil)
s = "/home/ken";
goroot = mal(strlen(s) + 10);
strcpy(goroot, s);
strcat(goroot, "/go");
}
goarch = thestring; // ignore $GOARCH - we know who we are goarch = thestring; // ignore $GOARCH - we know who we are
if(goos == nil) {
goos = "linux";
}
} }
int int
......
...@@ -69,6 +69,7 @@ LIB9OFILES=\ ...@@ -69,6 +69,7 @@ LIB9OFILES=\
getenv.$O\ getenv.$O\
getfields.$O\ getfields.$O\
getwd.$O\ getwd.$O\
goos.$O\
main.$O\ main.$O\
nan.$O\ nan.$O\
nulldir.$O\ nulldir.$O\
...@@ -115,6 +116,9 @@ $(LIB): $(OFILES) ...@@ -115,6 +116,9 @@ $(LIB): $(OFILES)
%.$O: utf/%.c %.$O: utf/%.c
$(CC) -c $(CFLAGS) $< $(CC) -c $(CFLAGS) $<
goos.$O: goos.c
$(CC) -c $(CFLAGS) -DGOOS='"$(GOOS)"' -DGOARCH='"$(GOARCH)"' -DGOROOT='"$(GOROOT)"' $<
clean: clean:
rm -f *.$O *.6 6.out $(LIB) rm -f *.$O *.6 6.out $(LIB)
......
// 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment