diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /doc/code.html | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-3e45412327a2654a77944249962b3652e6142299.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'doc/code.html')
-rw-r--r-- | doc/code.html | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/doc/code.html b/doc/code.html index 14bb6f9fe..55afe09af 100644 --- a/doc/code.html +++ b/doc/code.html @@ -64,7 +64,7 @@ is illustrated by <a href="../src/pkg/container/vector/Makefile"><code>src/pkg/c </p> <pre> -include ../../../Make.$(GOARCH) +include ../../../Make.inc TARG=container/vector GOFILES=\ @@ -80,7 +80,7 @@ Outside the Go source tree (for personal packages), the standard form is </p> <pre> -include $(GOROOT)/src/Make.$(GOARCH) +include $(GOROOT)/src/Make.inc TARG=mypackage GOFILES=\ @@ -99,6 +99,14 @@ This makes it easy for programmers to try Go. </p> <p> +If you have not set <code>$GOROOT</code> in your environment, +you must run <code>gomake</code> to use this form of makefile. +<code>Gomake</code> also takes care to invoke GNU Make +even on systems where it is installed as <code>gmake</code> +rather than <code>make</code>. +</p> + +<p> <code>TARG</code> is the target install path for the package, the string that clients will use to import it. Inside the Go tree, this string should be the same as the directory @@ -131,8 +139,8 @@ cd $GOROOT/src/pkg </pre> <p> to update the dependency file <code>Make.deps</code>. -(This happens automatically each time you run <code>make all</code> -or <code>make build</code>.) +(This happens automatically each time you run <code>all.bash</code> +or <code>make.bash</code>.) </p> <p> @@ -169,6 +177,32 @@ Writing clean, idiomatic Go code is beyond the scope of this document. that topic. </p> +<h2 id="Building_programs">Building programs</h2> +<p>To build a Go program with gomake, create a Makefile alongside your program's +source files. It should be similar to the example above, but include +<code>Make.cmd</code> instead of <code>Make.pkg</code>: + +<pre> +include $(GOROOT)/src/Make.inc + +TARG=helloworld +GOFILES=\ + helloworld.go\ + +include $(GOROOT)/src/Make.cmd +</pre> + +<p>Running <code>gomake</code> will compile <code>helloworld.go</code> +and produce an executable named <code>helloworld</code> in the current +directory. +</p> + +<p> +Running <code>gomake install</code> will build <code>helloworld</code> if +necessary and copy it to the <code>$GOBIN</code> directory +(<code>$GOROOT/bin/</code> is the default). +</p> + <h2 id="Testing">Testing</h2> <p> @@ -259,7 +293,7 @@ Finally, the <code>Makefile</code>: </p> <pre> -include $(GOROOT)/src/Make.$(GOARCH) +include $(GOROOT)/src/Make.inc TARG=numbers GOFILES=\ @@ -269,13 +303,13 @@ include $(GOROOT)/src/Make.pkg </pre> <p> -Running <code>make install</code> will build and install the package to +Running <code>gomake install</code> will build and install the package to the <code>$GOROOT/pkg/</code> directory (it can then be used by any program on the system). </p> <p> -Running <code>make test</code> (or just running the command +Running <code>gomake test</code> (or just running the command <code>gotest</code>) will rebuild the package, including the <code>numbers_test.go</code> file, and then run the <code>TestDouble</code> function. The output "<code>PASS</code>" indicates that all tests passed |