Skip to content

Commit

Permalink
build: dist-based build for Plan 9
Browse files Browse the repository at this point in the history
R=rsc, iant, iant, seed
CC=golang-dev
https://golang.org/cl/5608059
  • Loading branch information
ality committed May 2, 2012
1 parent ce30769 commit 3859032
Show file tree
Hide file tree
Showing 11 changed files with 998 additions and 32 deletions.
13 changes: 13 additions & 0 deletions src/all.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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
14 changes: 14 additions & 0 deletions src/clean.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/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
2 changes: 2 additions & 0 deletions src/cmd/dist/a.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/dist/arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;\
Expand All @@ -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);
Expand Down
108 changes: 83 additions & 25 deletions src/cmd/dist/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand Down Expand Up @@ -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";
Expand All @@ -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]);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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"))
Expand All @@ -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));
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/cmd/dist/buildgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

#include "a.h"
#include <stdio.h>

/*
* Helpers for building cmd/gc.
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/dist/buildruntime.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

#include "a.h"
#include <stdio.h>

/*
* Helpers for building pkg/runtime.
Expand All @@ -20,6 +19,8 @@ mkzversion(char *dir, char *file)
{
Buf b, out;

USED(dir);

binit(&b);
binit(&out);

Expand All @@ -46,6 +47,8 @@ void
mkzgoarch(char *dir, char *file)
{
Buf b, out;

USED(dir);

binit(&b);
binit(&out);
Expand All @@ -72,6 +75,8 @@ void
mkzgoos(char *dir, char *file)
{
Buf b, out;

USED(dir);

binit(&b);
binit(&out);
Expand Down
7 changes: 4 additions & 3 deletions src/cmd/dist/goc2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static struct {
{"int64", 8},
{"uint64", 8},

{nil},
{nil, 0},
};

/* Fixed structure alignment (non-gcc only) */
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 3859032

Please sign in to comment.