// init handles initialization of the various global state, like goroot and goarch. void init(void) { char *p; int i; Buf b; binit(&b); xgetenv(&b, "GOROOT"); if(b.len > 0) { // if not "/", then strip trailing path separator if(b.len >= 2 && b.p[b.len - 1] == slash[0]) b.len--; goroot = btake(&b); } xgetenv(&b, "GOBIN"); if(b.len == 0) bprintf(&b, "%s%sbin", goroot, slash); gobin = btake(&b); xgetenv(&b, "GOOS"); if(b.len == 0) bwritestr(&b, gohostos); goos = btake(&b); if(find(goos, okgoos, nelem(okgoos)) < 0) fatal("unknown $GOOS %s", goos); xgetenv(&b, "GOARM"); if(b.len == 0) bwritestr(&b, xgetgoarm()); goarm = btake(&b); xgetenv(&b, "GO386"); if(b.len == 0) { if(cansse2()) bwritestr(&b, "sse2"); else bwritestr(&b, "387"); } go386 = btake(&b); p = bpathf(&b, "%s/include/u.h", goroot); if(!isfile(p)) { fatal("$GOROOT is not set correctly or not exported\n" "\tGOROOT=%s\n" "\t%s does not exist", goroot, p); } xgetenv(&b, "GOHOSTARCH"); if(b.len > 0) gohostarch = btake(&b); i = find(gohostarch, okgoarch, nelem(okgoarch)); if(i < 0) fatal("unknown $GOHOSTARCH %s", gohostarch); bprintf(&b, "%c", gochars[i]); gohostchar = btake(&b); xgetenv(&b, "GOARCH"); if(b.len == 0) bwritestr(&b, gohostarch); goarch = btake(&b); i = find(goarch, okgoarch, nelem(okgoarch)); if(i < 0) fatal("unknown $GOARCH %s", goarch); bprintf(&b, "%c", gochars[i]); gochar = btake(&b); xgetenv(&b, "GO_EXTLINK_ENABLED"); if(b.len > 0) { goextlinkenabled = btake(&b); if(!streq(goextlinkenabled, "0") && !streq(goextlinkenabled, "1")) fatal("unknown $GO_EXTLINK_ENABLED %s", goextlinkenabled); } xgetenv(&b, "CC"); if(b.len == 0) { // Use clang on OS X, because gcc is deprecated there. // Xcode for OS X 10.9 Mavericks will ship a fake "gcc" binary that // actually runs clang. We prepare different command // lines for the two binaries, so it matters what we call it. // See golang.org/issue/5822. if(defaultclang) bprintf(&b, "clang"); else bprintf(&b, "gcc"); } defaultcc = btake(&b); xgetenv(&b, "CFLAGS"); defaultcflags = btake(&b); xgetenv(&b, "LDFLAGS"); defaultldflags = btake(&b); xgetenv(&b, "CC_FOR_TARGET"); if(b.len == 0) { bprintf(&b, defaultcc); } defaultcctarget = btake(&b); xgetenv(&b, "CXX_FOR_TARGET"); if(b.len == 0) { xgetenv(&b, "CXX"); if(b.len == 0) { if(defaultclang) bprintf(&b, "clang++"); else bprintf(&b, "g++"); } } defaultcxxtarget = btake(&b); xsetenv("GOROOT", goroot); xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); xsetenv("GOARM", goarm); xsetenv("GO386", go386); // Make the environment more predictable. xsetenv("LANG", "C"); xsetenv("LANGUAGE", "en_US.UTF8"); goversion = findgoversion(); workdir = xworkdir(); xatexit(rmworkdir); bpathf(&b, "%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch); tooldir = btake(&b); bfree(&b); }
// init handles initialization of the various global state, like goroot and goarch. void init(void) { char *p; int i; Buf b; binit(&b); xgetenv(&b, "GOROOT"); if(b.len > 0) { // if not "/", then strip trailing path separator if(b.len >= 2 && b.p[b.len - 1] == slash[0]) b.len--; goroot = btake(&b); } xgetenv(&b, "GOBIN"); if(b.len == 0) bprintf(&b, "%s%sbin", goroot, slash); gobin = btake(&b); xgetenv(&b, "GOOS"); if(b.len == 0) bwritestr(&b, gohostos); goos = btake(&b); if(find(goos, okgoos, nelem(okgoos)) < 0) fatal("unknown $GOOS %s", goos); xgetenv(&b, "GOARM"); if(b.len == 0) bwritestr(&b, xgetgoarm()); goarm = btake(&b); xgetenv(&b, "GO386"); if(b.len == 0) { if(cansse2()) bwritestr(&b, "sse2"); else bwritestr(&b, "387"); } go386 = btake(&b); p = bpathf(&b, "%s/include/u.h", goroot); if(!isfile(p)) { fatal("$GOROOT is not set correctly or not exported\n" "\tGOROOT=%s\n" "\t%s does not exist", goroot, p); } xgetenv(&b, "GOHOSTARCH"); if(b.len > 0) gohostarch = btake(&b); i = find(gohostarch, okgoarch, nelem(okgoarch)); if(i < 0) fatal("unknown $GOHOSTARCH %s", gohostarch); bprintf(&b, "%c", gochars[i]); gohostchar = btake(&b); xgetenv(&b, "GOARCH"); if(b.len == 0) bwritestr(&b, gohostarch); goarch = btake(&b); i = find(goarch, okgoarch, nelem(okgoarch)); if(i < 0) fatal("unknown $GOARCH %s", goarch); bprintf(&b, "%c", gochars[i]); gochar = btake(&b); xgetenv(&b, "GO_EXTLINK_ENABLED"); if(b.len > 0) { goextlinkenabled = btake(&b); if(!streq(goextlinkenabled, "0") && !streq(goextlinkenabled, "1")) fatal("unknown $GO_EXTLINK_ENABLED %s", goextlinkenabled); } xsetenv("GOROOT", goroot); xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); xsetenv("GOARM", goarm); xsetenv("GO386", go386); // Make the environment more predictable. xsetenv("LANG", "C"); xsetenv("LANGUAGE", "en_US.UTF8"); goversion = findgoversion(); workdir = xworkdir(); xatexit(rmworkdir); bpathf(&b, "%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch); tooldir = btake(&b); bfree(&b); }