summaryrefslogtreecommitdiff
path: root/src/lib9
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-01-18 21:46:46 -0800
committerRuss Cox <rsc@golang.org>2010-01-18 21:46:46 -0800
commitf9a69cf4b55e515c6b630940c9e92366bbd9a9c5 (patch)
treef74bfc9b5f62762739020b8e403e799318406afd /src/lib9
parente2739a4a3a4d4ed97a2aafe468553587c221791f (diff)
downloadgo-f9a69cf4b55e515c6b630940c9e92366bbd9a9c5.tar.gz
build: move GOOS, GOARCH, GOROOT lookup into central library.
bake default values in during build. R=r CC=golang-dev http://codereview.appspot.com/186173
Diffstat (limited to 'src/lib9')
-rw-r--r--src/lib9/Makefile4
-rw-r--r--src/lib9/goos.c35
2 files changed, 39 insertions, 0 deletions
diff --git a/src/lib9/Makefile b/src/lib9/Makefile
index 9038730b1..592bc3b1a 100644
--- a/src/lib9/Makefile
+++ b/src/lib9/Makefile
@@ -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
index 000000000..668dc1941
--- /dev/null
+++ b/src/lib9/goos.c
@@ -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);
+}