From f9a69cf4b55e515c6b630940c9e92366bbd9a9c5 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 18 Jan 2010 21:46:46 -0800 Subject: 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 --- src/lib9/Makefile | 4 ++++ src/lib9/goos.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/lib9/goos.c (limited to 'src/lib9') 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 +#include + +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); +} -- cgit v1.2.1