// The bootstrap command runs a build from scratch, // stopping at having installed the go_bootstrap command. void cmdbootstrap(int argc, char **argv) { int i; Buf b; char *oldgoos, *oldgoarch, *oldgochar; binit(&b); ARGBEGIN{ case 'a': rebuildall = 1; break; case 'v': vflag++; break; default: usage(); }ARGEND if(argc > 0) usage(); if(rebuildall) clean(); goversion = findgoversion(); setup(); xsetenv("GOROOT", goroot); xsetenv("GOROOT_FINAL", goroot_final); // For the main bootstrap, building for host os/arch. oldgoos = goos; oldgoarch = goarch; oldgochar = gochar; goos = gohostos; goarch = gohostarch; gochar = gohostchar; xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); for(i=0; i<nelem(buildorder); i++) { install(bprintf(&b, buildorder[i], gohostchar)); if(!streq(oldgochar, gohostchar) && xstrstr(buildorder[i], "%s")) install(bprintf(&b, buildorder[i], oldgochar)); } goos = oldgoos; goarch = oldgoarch; gochar = oldgochar; xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); // Build pkg/runtime for actual goos/goarch too. if(!streq(goos, gohostos) || !streq(goarch, gohostarch)) install("pkg/runtime"); 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); } 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); 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); xsetenv("GOROOT", goroot); xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); // 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); }
// The bootstrap command runs a build from scratch, // stopping at having installed the go_bootstrap command. void cmdbootstrap(int argc, char **argv) { int i; Buf b; char *oldgoos, *oldgoarch, *oldgochar; binit(&b); ARGBEGIN{ case 'a': rebuildall = 1; break; case 's': sflag++; break; case 'v': vflag++; break; default: usage(); }ARGEND if(argc > 0) usage(); if(isdir(bpathf(&b, "%s/src/pkg", goroot))) { fatal("\n\n" "The Go package sources have moved to $GOROOT/src.\n" "*** %s still exists. ***\n" "It probably contains stale files that may confuse the build.\n" "Please (check what's there and) remove it and try again.\n" "See http://golang.org/s/go14nopkg\n", bpathf(&b, "%s/src/pkg", goroot)); } if(rebuildall) clean(); goversion = findgoversion(); setup(); xsetenv("GOROOT", goroot); xsetenv("GOROOT_FINAL", goroot_final); // For the main bootstrap, building for host os/arch. oldgoos = goos; oldgoarch = goarch; oldgochar = gochar; goos = gohostos; goarch = gohostarch; gochar = gohostchar; xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); for(i=0; i<nelem(buildorder); i++) { install(bprintf(&b, buildorder[i], gohostchar)); if(!streq(oldgochar, gohostchar) && xstrstr(buildorder[i], "%s")) install(bprintf(&b, buildorder[i], oldgochar)); } goos = oldgoos; goarch = oldgoarch; gochar = oldgochar; xsetenv("GOARCH", goarch); xsetenv("GOOS", goos); // Build runtime for actual goos/goarch too. if(!streq(goos, gohostos) || !streq(goarch, gohostarch)) install("runtime"); bfree(&b); }