Commit 38590329 authored by Anthony Martin's avatar Anthony Martin

build: dist-based build for Plan 9

R=rsc, iant, iant, seed
CC=golang-dev
https://golang.org/cl/5608059
parent ce30769c
#!/bin/rc -e
# Copyright 2012 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.
if(! test -f make.rc){
echo 'all.rc must be run from $GOROOT/src' >[1=2]
exit wrongdir
}
. ./make.rc --no-banner
./run.rc --no-rebuild
$GOTOOLDIR/dist banner # print build info
#!/bin/rc -e
# Copyright 2012 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.
eval `{go tool dist env -9}
if(! test -x $GOTOOLDIR/dist){
echo 'cannot find $GOTOOLDIR/dist; nothing to clean' >[1=2]
exit noclean
}
$GOBIN/go clean -i std
$GOTOOLDIR/dist clean
......@@ -10,7 +10,9 @@ typedef long long Time;
#define nil ((void*)0)
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
#ifndef PLAN9
#define USED(x) ((void)(x))
#endif
// A Buf is a byte buffer, like Go's []byte.
typedef struct Buf Buf;
......
......@@ -28,7 +28,7 @@ THE SOFTWARE.
/* command line */
extern char *argv0;
#define ARGBEGIN for((argv0?0:(argv0=(*argv))),argv++,argc--;\
#define ARGBEGIN for((argv0=(argv0?argv0:*argv)),argv++,argc--;\
argv[0] && argv[0][0]=='-' && argv[0][1];\
argc--, argv++) {\
char *_args, *_argt;\
......@@ -37,7 +37,6 @@ extern char *argv0;
if(_args[0]=='-' && _args[1]==0){\
argc--; argv++; break;\
}\
_argc = 0;\
while((_argc = *_args++) != 0)\
switch(_argc)
#define ARGEND _argt=0;USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc);
......
......@@ -539,7 +539,7 @@ install(char *dir)
Buf b, b1, path;
Vec compile, files, link, go, missing, clean, lib, extra;
Time ttarg, t;
int i, j, k, n, doclean, targ;
int i, j, k, n, doclean, targ, usecpp;
if(vflag) {
if(!streq(goos, gohostos) || !streq(goarch, gohostarch))
......@@ -560,6 +560,7 @@ install(char *dir)
vinit(&lib);
vinit(&extra);
// path = full path to dir.
bpathf(&path, "%s/src/%s", goroot, dir);
name = lastelem(dir);
......@@ -605,7 +606,10 @@ install(char *dir)
if(islib) {
// C library.
vadd(&link, "ar");
vadd(&link, "rsc");
if(streq(gohostos, "plan9"))
vadd(&link, "rc");
else
vadd(&link, "rsc");
prefix = "";
if(!hasprefix(name, "lib"))
prefix = "lib";
......@@ -631,14 +635,21 @@ install(char *dir)
vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe));
} else {
// C command. Use gccargs.
vcopy(&link, gccargs.p, gccargs.len);
vadd(&link, "-o");
targ = link.len;
vadd(&link, bpathf(&b, "%s/%s%s", tooldir, name, exe));
if(streq(gohostarch, "amd64"))
vadd(&link, "-m64");
else if(streq(gohostarch, "386"))
vadd(&link, "-m32");
if(streq(gohostos, "plan9")) {
vadd(&link, bprintf(&b, "%sl", gohostchar));
vadd(&link, "-o");
targ = link.len;
vadd(&link, bpathf(&b, "%s/%s", tooldir, name));
} else {
vcopy(&link, gccargs.p, gccargs.len);
vadd(&link, "-o");
targ = link.len;
vadd(&link, bpathf(&b, "%s/%s%s", tooldir, name, exe));
if(streq(gohostarch, "amd64"))
vadd(&link, "-m64");
else if(streq(gohostarch, "386"))
vadd(&link, "-m32");
}
}
ttarg = mtime(link.p[targ]);
......@@ -672,6 +683,8 @@ install(char *dir)
bsubst(&b1, "$GOARCH", goarch);
p = bstr(&b1);
if(hassuffix(p, ".a")) {
if(streq(gohostos, "plan9") && hassuffix(p, "libbio.a"))
continue;
vadd(&lib, bpathf(&b, "%s", p));
continue;
}
......@@ -741,6 +754,10 @@ install(char *dir)
}
files.len = n;
// If there are no files to compile, we're done.
if(files.len == 0)
goto out;
for(i=0; i<lib.len && !stale; i++)
if(mtime(lib.p[i]) > ttarg)
stale = 1;
......@@ -799,10 +816,10 @@ install(char *dir)
p = files.p[i];
if(!hassuffix(p, ".goc"))
continue;
// b = path/zp but with _goarch.c instead of .goc
// b = path/zp but with _goos_goarch.c instead of .goc
bprintf(&b, "%s%sz%s", bstr(&path), slash, lastelem(p));
b.len -= 4;
bwritef(&b, "_%s.c", goarch);
bwritef(&b, "_%s_%s.c", goos, goarch);
goc2c(p, bstr(&b));
vadd(&files, bstr(&b));
}
......@@ -816,6 +833,20 @@ install(char *dir)
goto nobuild;
}
// The files generated by GNU Bison use macros that aren't
// supported by the Plan 9 compilers so we have to use the
// external preprocessor when compiling.
usecpp = 0;
if(streq(gohostos, "plan9")) {
for(i=0; i<files.len; i++) {
p = files.p[i];
if(hassuffix(p, "y.tab.c") || hassuffix(p, "y.tab.h")){
usecpp = 1;
break;
}
}
}
// Compile the files.
for(i=0; i<files.len; i++) {
if(!hassuffix(files.p[i], ".c") && !hassuffix(files.p[i], ".s"))
......@@ -825,17 +856,26 @@ install(char *dir)
vreset(&compile);
if(!isgo) {
// C library or tool.
vcopy(&compile, gccargs.p, gccargs.len);
vadd(&compile, "-c");
if(streq(gohostarch, "amd64"))
vadd(&compile, "-m64");
else if(streq(gohostarch, "386"))
vadd(&compile, "-m32");
if(streq(dir, "lib9"))
vadd(&compile, "-DPLAN9PORT");
vadd(&compile, "-I");
vadd(&compile, bpathf(&b, "%s/include", goroot));
if(streq(gohostos, "plan9")) {
vadd(&compile, bprintf(&b, "%sc", gohostchar));
vadd(&compile, "-FTVw");
if(usecpp)
vadd(&compile, "-Bp+");
vadd(&compile, bpathf(&b, "-I%s/include/plan9", goroot));
vadd(&compile, bpathf(&b, "-I%s/include/plan9/%s", goroot, gohostarch));
} else {
vcopy(&compile, gccargs.p, gccargs.len);
vadd(&compile, "-c");
if(streq(gohostarch, "amd64"))
vadd(&compile, "-m64");
else if(streq(gohostarch, "386"))
vadd(&compile, "-m32");
if(streq(dir, "lib9"))
vadd(&compile, "-DPLAN9PORT");
vadd(&compile, "-I");
vadd(&compile, bpathf(&b, "%s/include", goroot));
}
vadd(&compile, "-I");
vadd(&compile, bstr(&path));
......@@ -882,7 +922,11 @@ install(char *dir)
doclean = 0;
}
b.p[b.len-1] = 'o'; // was c or s
// Change the last character of the output file (which was c or s).
if(streq(gohostos, "plan9"))
b.p[b.len-1] = gohostchar[0];
else
b.p[b.len-1] = 'o';
vadd(&compile, "-o");
vadd(&compile, bstr(&b));
vadd(&compile, files.p[i]);
......@@ -923,7 +967,8 @@ install(char *dir)
if(!islib && !isgo) {
// C binaries need the libraries explicitly, and -lm.
vcopy(&link, lib.p, lib.len);
vadd(&link, "-lm");
if(!streq(gohostos, "plan9"))
vadd(&link, "-lm");
}
// Remove target before writing it.
......@@ -981,6 +1026,16 @@ shouldbuild(char *file, char *dir)
Buf b;
Vec lines, fields;
// On Plan 9, most of the libraries are already present.
// The main exception is libmach which has been modified
// in various places to support Go object files.
if(streq(gohostos, "plan9")) {
if(streq(dir, "lib9") && !hassuffix(file, "lib9/goos.c"))
return 0;
if(streq(dir, "libbio"))
return 0;
}
// Check file name for GOOS or GOARCH.
name = lastelem(file);
for(i=0; i<nelem(okgoos); i++)
......@@ -1285,6 +1340,9 @@ cmdenv(int argc, char **argv)
format = "%s=\"%s\"\n";
pflag = 0;
ARGBEGIN{
case '9':
format = "%s='%s'\n";
break;
case 'p':
pflag = 1;
break;
......
......@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.
#include "a.h"
#include <stdio.h>
/*
* Helpers for building cmd/gc.
......
......@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.
#include "a.h"
#include <stdio.h>
/*
* Helpers for building pkg/runtime.
......@@ -20,6 +19,8 @@ mkzversion(char *dir, char *file)
{
Buf b, out;
USED(dir);
binit(&b);
binit(&out);
......@@ -46,6 +47,8 @@ void
mkzgoarch(char *dir, char *file)
{
Buf b, out;
USED(dir);
binit(&b);
binit(&out);
......@@ -72,6 +75,8 @@ void
mkzgoos(char *dir, char *file)
{
Buf b, out;
USED(dir);
binit(&b);
binit(&out);
......
......@@ -111,7 +111,7 @@ static struct {
{"int64", 8},
{"uint64", 8},
{nil},
{nil, 0},
};
/* Fixed structure alignment (non-gcc only) */
......@@ -570,8 +570,9 @@ write_gcc_func_header(char *package, char *name, struct params *params,
static void
write_gcc_func_trailer(char *package, char *name, struct params *rets)
{
if (rets == nil)
;
if (rets == nil) {
// nothing to do
}
else if (rets->next == nil)
bwritef(output, "return %s;\n", rets->name);
else {
......
This diff is collapsed.
#!/bin/rc -e
# Copyright 2012 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.
# Environment variables that control make.rc:
#
# GOROOT_FINAL: The expected final Go root, baked into binaries.
# The default is the location of the Go tree during the build.
#
# GOHOSTARCH: The architecture for host tools (compilers and
# binaries). Binaries of this type must be executable on the current
# system, so the only common reason to set this is to set
# GOHOSTARCH=386 on an amd64 machine.
#
# GOARCH: The target architecture for installed packages and tools.
#
# GOOS: The target operating system for installed packages and tools.
#
# GO_GCFLAGS: Additional 5g/6g/8g arguments to use when
# building the packages and commands.
#
# GO_LDFLAGS: Additional 5l/6l/8l arguments to use when
# building the commands.
#
# CGO_ENABLED: Setting this to 0 disables the use of cgo
# in the built and installed packages and tools.
rfork e
if(! test -f run.bash){
echo 'make.rc must be run from $GOROOT/src' >[1=2]
exit wrongdir
}
# Clean old generated file that will cause problems in the build.
rm -rf ./pkg/runtime/runtime_defs.go
# Determine the host compiler toolchain.
eval `{grep '^(CC|LD|O)=' /$objtype/mkfile}
echo '# Building C bootstrap tool.'
echo cmd/dist
GOROOT = `{cd .. && pwd}
if(! ~ $#GOROOT_FINAL 1)
GOROOT_FINAL = $GOROOT
DEFGOROOT='-DGOROOT_FINAL="'$GOROOT_FINAL'"'
for(i in cmd/dist/*.c)
$CC -FTVwp+ -DPLAN9 $DEFGOROOT $i
$LD -o cmd/dist/dist *.$O
rm *.$O
eval `{./cmd/dist/dist env -9}
echo
if(~ $1 --dist-tool){
# Stop after building dist tool.
mkdir -p $GOTOOLDIR
if(! ~ $2 '')
cp cmd/dist/dist $2
mv cmd/dist/dist $GOTOOLDIR/dist
exit
}
echo '# Building compilers and Go bootstrap tool for host,' $GOHOSTOS/$GOHOSTARCH^.
buildall = -a
if(~ $1 --no-clean)
buildall = ()
./cmd/dist/dist bootstrap $buildall -v # builds go_bootstrap
# Delay move of dist tool to now, because bootstrap may clear tool directory.
mv cmd/dist/dist $GOTOOLDIR/dist
$GOTOOLDIR/go_bootstrap clean -i std
echo
# TODO(ality): remove the -p flag once the exec/await/RFNOTEG race is fixed.
if(! ~ $GOHOSTARCH $GOARCH || ! ~ $GOHOSTOS $GOOS){
echo '# Building packages and commands for host,' $GOHOSTOS/$GOHOSTARCH^.
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
$GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v -p 1 std
echo
}
echo '# Building packages and commands for' $GOOS/$GOARCH^.
$GOTOOLDIR/go_bootstrap install -gcflags $"GO_GCFLAGS -ldflags $"GO_LDFLAGS -v -p 1 std
echo
rm -f $GOTOOLDIR/go_bootstrap
if(! ~ $1 --no-banner)
$GOTOOLDIR/dist banner
#!/bin/rc -e
# Copyright 2012 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.
eval `{go env -9}
# allow all.rc to avoid double-build of everything
rebuild = true
if(~ $1 --no-rebuild)
shift
if not {
echo '# Building packages and commands.'
time go install -a -v -p 1 std
echo
}
echo '# Testing packages.'
time go test std -short -timeout 120s
echo
echo '# GOMAXPROCS=2 runtime -cpu=1,2,4'
GOMAXPROCS=2 go test runtime -short -timeout 120s -cpu 1,2,4
echo
echo '# sync -cpu=10'
go test sync -short -timeout 120s -cpu 10
echo
fn xcd {
echo
echo '#' $1
cd $"GOROOT/src/$1
}
echo
echo '#' ../misc/dashboard/builder ../misc/goplay
go build ../misc/dashboard/builder ../misc/gplay
echo
echo '#' ../test/bench/go1
go test ../test/bench/go1
@{
xcd ../test
time go run run.go
}
echo
echo ALL TESTS PASSED
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment