From: Andrew Gerrand Date: Fri, 4 Mar 2011 01:28:08 +0000 (+1100) Subject: doc: describe platform-specific conventions in code.html X-Git-Tag: weekly.2011-03-07~33 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ee1cb829ac6d3b3a79b4fe92d9cea1d19baf15bf;p=gostls13.git doc: describe platform-specific conventions in code.html R=r, rsc, gri CC=golang-dev https://golang.org/cl/4257049 --- diff --git a/doc/code.html b/doc/code.html index 8bd9eec3d4..06af93727f 100644 --- a/doc/code.html +++ b/doc/code.html @@ -322,3 +322,47 @@ reported. See the gotest documentation and the testing package for more detail.

+ +

Architecture- and operating system-specific code

+ +

First, a disclaimer: very few Go packages should need to know about the +hardware and operating system they run on. In the vast majority of cases the +language and standard library handle most portability issues. This section is +a guide for experienced systems programmers who have a good reason to write +platform-specific code, such as assembly-language support for fast +trigonometric functions or code that implements a common interface above +different operating systems.

+ +

To compile such code, use the $GOOS and $GOARCH +environment variables in your +source file names and Makefile.

+ +

For example, this Makefile describes a package that builds on +different operating systems by parameterizing the file name with +$GOOS.

+ +
+include $(GOROOT)/src/Make.inc
+
+TARG=mypackage
+GOFILES=\
+	my.go\
+	my_$(GOOS).go\
+
+include $(GOROOT)/src/Make.pkg
+
+ +

The OS-specific code goes in my_linux.go, +my_darwin.go, and so on.

+ +

If you follow these conventional parameterizations, tools such as +goinstall will work seamlessly with your package: +

+ +
+my_$(GOOS).go
+my_$(GOARCH).go
+my_$(GOOS)_$(GOARCH).go
+
+ +

The same holds for .s (assembly) and .cgo files.