char *gohostarch;
char *gohostos;
char *goos;
-char *goroot;
+char *goroot = GOROOT_FINAL;
+char *goroot_final = GOROOT_FINAL;
char *workdir;
char *gochar;
-char *goroot_final;
char *goversion;
char *slash; // / for unix, \ for windows
-char *default_goroot = DEFAULT_GOROOT;
static bool shouldbuild(char*, char*);
static void copy(char*, char*);
binit(&b);
xgetenv(&b, "GOROOT");
- if(b.len == 0) {
- if(default_goroot == nil)
- fatal("$GOROOT not set and not available");
- bwritestr(&b, default_goroot);
- }
- goroot = btake(&b);
+ if(b.len > 0)
+ goroot = btake(&b);
xgetenv(&b, "GOBIN");
if(b.len == 0)
bprintf(&b, "%c", gochars[i]);
gochar = btake(&b);
- xgetenv(&b, "GOROOT_FINAL");
- if(b.len > 0)
- goroot_final = btake(&b);
- else
- goroot_final = goroot;
-
xsetenv("GOROOT", goroot);
xsetenv("GOARCH", goarch);
xsetenv("GOOS", goos);
if(streq(name, "goos.c")) {
vadd(&compile, bprintf(&b, "-DGOOS=\"%s\"", goos));
vadd(&compile, bprintf(&b, "-DGOARCH=\"%s\"", goarch));
- bprintf(&b1, "%s", goroot);
+ bprintf(&b1, "%s", goroot_final);
bsubst(&b1, "\\", "\\\\"); // turn into C string
vadd(&compile, bprintf(&b, "-DGOROOT=\"%s\"", bstr(&b1)));
vadd(&compile, bprintf(&b, "-DGOVERSION=\"%s\"", goversion));
echo '# Building C bootstrap tool.'
mkdir -p ../bin/tool
-DEFGOROOT='-DDEFAULT_GOROOT="'"$(cd .. && pwd)"'"'
+export GOROOT="$(cd .. && pwd)"
+GOROOT_FINAL="${GOROOT_FINAL:-$GOROOT}"
+DEFGOROOT='-DGOROOT_FINAL="'"$GOROOT_FINAL"'"'
gcc -O2 -Wall -Werror -o ../bin/tool/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c
echo
goto fail
:ok
-:: Grab default $GOROOT, escape \ for C string.
-:: The expression %CD:\=\\% means to take %CD%
+:: Grab default GOROOT_FINAL and set GOROOT for build.
+:: The expression %VAR:\=\\% means to take %VAR%
:: and apply the substitution \ = \\, escaping the
:: backslashes. Then we wrap that in quotes to create
:: a C string.
cd ..
-set DEFGOROOT=-DDEFAULT_GOROOT="\"%CD:\=\\%\""
+set GOROOT="%CD%"
cd src
+if "x%GOROOT_FINAL%"=="x" set GOROOT_FINAL="%GOROOT%"
+set DEFGOROOT=-DGOROOT_FINAL="\"%GOROOT_FINAL:\=\\%\""
echo # Building C bootstrap tool.
if not exist ..\bin\tool mkdir ..\bin\tool
del ..\bin\tool\go_bootstrap.exe
echo .
-if x%1==x--no-banner goto nobanner
+if "x%1"=="x--no-banner" goto nobanner
..\bin\tool\dist banner
:nobanner