bake default values in during build.
R=r
CC=golang-dev
https://golang.org/cl/186173
Idir *p;
if(goroot == nil) {
- goroot = getenv("GOROOT");
- goos = getenv("GOOS");
+ goroot = getgoroot();
+ goos = getgoos();
goarch = thestring;
}
{
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
getenv.$O\
getfields.$O\
getwd.$O\
+ goos.$O\
main.$O\
nan.$O\
nulldir.$O\
%.$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)
--- /dev/null
+// 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);
+}