1
0
mirror of https://github.com/golang/go synced 2024-10-04 09:11:21 -06:00
go/src/cmd/dist/buildgc.c
Russ Cox 3dd1e5be54 cmd/dist: new command
dist is short for distribution.  This is the new Go distribution tool.

The plan is to replace the Makefiles with what amounts to
'go tool dist bootstrap', although it cannot be invoked like
that since it is in charge of getting us to the point where we
can build the go command.

It will also add additional commands to replace bash scripts
like test/run (go tool dist testrun), eventually eliminating our
dependence on not just bash but all the Unix tools and all
of cygwin.

This is strong enough to build (cc *.c) and run (a.out bootstrap)
to build not just the C libraries and tools but also the basic
Go packages up to the bootstrap form of the go command
(go_bootstrap).  I've run it successfully on both Linux and Windows.
This means that once we've switched to this tool in the build,
we can delete the buildscripts.

This tool is not nearly as nice as the go tool.  There are many
special cases that turn into simple if statements or tables in
the code.  Please forgive that.  C does not enjoy the benefits
that we designed into Go.

I was planning to wait to do this until after Go 1, but the
Windows builders are both broken due to a bug in either
make or bash or both involving the parsing of quoted command
arguments.  Make thinks it is invoking

        quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c

but bash (quietgcc is a bash script) thinks it is being invoked as

        quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c

which obviously does not have the desired effect.  Rather than fight
these clumsy ports, I accelerated the schedule for the new tool.
We should be completely off cygwin (using just the mingw gcc port,
which is much more standalone) before Go 1.

It is big for a single CL, and for that I apologize.  I can cut it into
separate CLs along file boundaries if people would prefer that.

R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter
CC=golang-dev
https://golang.org/cl/5620045
2012-02-02 19:41:39 -05:00

107 lines
2.1 KiB
C

// 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.
#include "a.h"
#include <stdio.h>
/*
* Helpers for building cmd/gc.
*/
// gcopnames creates opnames.h from go.h.
// It finds the OXXX enum, pulls out all the constants
// from OXXX to OEND, and writes a table mapping
// op to string.
void
gcopnames(char *dir, char *file)
{
char *p, *q;
int i, j, end;
Buf in, b, out;
Vec lines, fields;
binit(&in);
binit(&b);
binit(&out);
vinit(&lines);
vinit(&fields);
bwritestr(&out, bprintf(&b, "// auto generated by go tool dist\n"));
bwritestr(&out, bprintf(&b, "static char *opnames[] = {\n"));
readfile(&in, bprintf(&b, "%s/go.h", dir));
splitlines(&lines, bstr(&in));
i = 0;
while(i<lines.len && !contains(lines.p[i], "OXXX"))
i++;
end = 0;
for(; i<lines.len && !end; i++) {
p = xstrstr(lines.p[i], "//");
if(p != nil)
*p = '\0';
end = contains(lines.p[i], "OEND");
splitfields(&fields, lines.p[i]);
for(j=0; j<fields.len; j++) {
q = fields.p[j];
if(*q == 'O')
q++;
p = q+xstrlen(q)-1;
if(*p == ',')
*p = '\0';
bwritestr(&out, bprintf(&b, " [O%s] = \"%s\",\n", q, q));
}
}
bwritestr(&out, bprintf(&b, "};\n"));
writefile(&out, file);
bfree(&in);
bfree(&b);
bfree(&out);
vfree(&lines);
vfree(&fields);
}
// mkenam reads [568].out.h and writes enam.c
// The format is much the same as the Go opcodes above.
void
mkenam(char *dir, char *file)
{
int i, ch;
Buf in, b, out;
Vec lines;
char *p;
binit(&b);
binit(&in);
binit(&out);
vinit(&lines);
ch = dir[xstrlen(dir)-2];
bprintf(&b, "%s/../%cl/%c.out.h", dir, ch, ch);
readfile(&in, bstr(&b));
splitlines(&lines, bstr(&in));
bwritestr(&out, "char* anames[] = {\n");
for(i=0; i<lines.len; i++) {
if(hasprefix(lines.p[i], "\tA")) {
p = xstrstr(lines.p[i], ",");
if(p)
*p = '\0';
p = xstrstr(lines.p[i], "\n");
if(p)
*p = '\0';
p = lines.p[i] + 2;
bwritestr(&out, bprintf(&b, "\t\"%s\",\n", p));
}
}
bwritestr(&out, "};\n");
writefile(&out, file);
bfree(&b);
bfree(&in);
bfree(&out);
vfree(&lines);
}