go/src/cmd/dist
Lucio De Re fd7ddad160 cmd/dist: Plan 9 build needs an additional include path
cmd/cc: bv.c imports libc.h twice

When using the Plan 9 compiler, the invocation

        #include <../ld/textflag.h>

works for the toolchain, but not for the MACH library.

Module cmd/cc/bv.c includes libc.h and "cc.h", which in
turn also includes libc.h.  In the Plan 9 context, this
causes a number of duplicate definitions.

R=golang-dev, rsc, r
CC=golang-dev
https://golang.org/cl/13303047
2013-09-06 16:15:44 +10:00
..
README cmd/dist: fix code example in README 2013-01-30 08:46:50 -08:00
a.h build: on OS X 10.8 and later, use clang instead of gcc 2013-08-02 14:58:27 -04:00
arg.h
arm.c cmd/dist: support for NetBSD/ARM 2013-03-03 06:50:17 +08:00
buf.c
build.c cmd/dist: Plan 9 build needs an additional include path 2013-09-06 16:15:44 +10:00
buildgc.c
buildgo.c cmd/dist: generate cmd/cgo/zdefaultcc.go on windows (fixes windows build) 2013-08-03 18:32:14 +10:00
buildruntime.c cmd/dist: fix darwin build 2013-08-14 12:57:05 -04:00
goc2c.c runtime/bytes: fast Compare for byte arrays and strings. 2013-05-14 16:05:51 -07:00
main.c
plan9.c all: be more idiomatic when documenting boolean return values. 2013-07-23 11:59:49 +10:00
unix.c all: compiler/bootstrap for dragonfly/amd64 2013-08-24 01:18:04 +10:00
windows.c cmd/dist: fix crash on windows 2013-07-27 13:53:18 +04:00

README

This program, dist, is the bootstrapping tool for the Go distribution.
It takes care of building the C programs (like the Go compiler) and
the initial bootstrap copy of the go tool.  It also serves as a catch-all
to replace odd jobs previously done with shell scripts.

Dist is itself written in very simple C.  All interaction with C libraries,
even standard C libraries, is confined to a single system-specific file
(plan9.c, unix.c, windows.c), to aid portability.  Functionality needed
by other files should be exposed via the portability layer.  Functions
in the portability layer begin with an x prefix when they would otherwise
use the same name as or be confused for an existing function.
For example, xprintf is the portable printf.

By far the most common data types in dist are strings and arrays of
strings.  Instead of using char* and char**, though, dist uses two named
data structures, Buf and Vec, which own all the data they point at.
The Buf operations are functions beginning with b; the Vec operations
are functions beginning with v.  The basic form of any function declaring
Bufs or Vecs on the stack should be

	void
	myfunc(void)
	{
		Buf b1, b2;
		Vec v1;
		
		binit(&b1);
		binit(&b2);
		vinit(&v1);
		
		... main code ...
		bprintf(&b1, "hello, world");
		vadd(&v1, bstr(&b1));  // v1 takes a copy of its argument
		bprintf(&b2, "another string");
		vadd(&v1, bstr(&b2));  // v1 now has two strings
		
		bfree(&b1);
		bfree(&b2);
		vfree(&v1);
	}
	
The binit/vinit calls prepare a buffer or vector for use, initializing the 
data structures, and the bfree/vfree calls free any memory they are still
holding onto.  Use of this idiom gives us lexically scoped allocations.