1
0
mirror of https://github.com/golang/go synced 2024-10-03 09:11:22 -06:00
go/src/cmd/dist
Russ Cox 6d888f1e1b build: clang support
This works with at least one version of clang
that existed at one moment in time.
No guarantees about clangs past or future.

To try:
        CC=clang all.bash

It does not work with the Xcode clang,
because that clang fails at printing a useful answer
to:
        clang -print-libgcc-file-name
The clang that works prints a full path name for
that command, not just "libgcc.a".

Fixes #4713.

R=iant, minux.ma
CC=golang-dev
https://golang.org/cl/7323068
2013-02-15 13:37:43 -08:00
..
a.h build: change GO386=sse to GO386=sse2 2013-01-18 15:10:36 -05:00
arg.h build: dist-based build for Plan 9 2012-05-01 22:32:46 -07:00
arm.c cmd/dist: make GOARM detection better compatible with thumb toolchain 2012-12-22 02:39:54 +08:00
buf.c cmd/dist: clear execute bit from source file 2012-02-11 13:23:44 +09:00
build.c build: clang support 2013-02-15 13:37:43 -08:00
buildgc.c build: dist-based build for Plan 9 2012-05-01 22:32:46 -07:00
buildruntime.c cmd/dist: redirect acid output to file to separate from errors 2013-01-31 22:02:20 -08:00
goc2c.c build: make int 64 bits on amd64 2012-09-24 20:57:01 -04:00
main.c cmd/dist: generate files for package runtime 2012-02-03 18:16:42 -05:00
plan9.c cmd/8g, cmd/dist, cmd/gc: fix warnings on Plan 9 2013-01-18 19:08:00 -08:00
README cmd/dist: fix code example in README 2013-01-30 08:46:50 -08:00
unix.c build: change GO386=sse to GO386=sse2 2013-01-18 15:10:36 -05:00
windows.c cmd/dist: fix build 2013-01-31 22:57:30 -08:00

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.