go help build
usage: go build [-o output] [build flags] [packages] Build compiles the packages named by the import paths, // `build`はimport pathsで与えられた名前のgo srcをコンパイルします along with their dependencies, but it does not install the results. // 依存するパッケージはそのとき解決されます. // なお、go installは実行されません. If the arguments are a list of .go files, build treats them as a list of source files specifying a single package. // .goなファイルパスを複数渡した場合は、 // 単一のパッケージのソースと見なされます. When the command line specifies a single main package, // 引数に単一のmainパッケージ名を渡した場合、 build writes the resulting executable to output. // 実行可能ファイルが生成されます. Otherwise build compiles the packages but discards the results, // それ以外の場合では、パッケージをコンパイルした結果は破棄され、 serving only as a check that the packages can be built. // ビルドできるかどうかをチェックするだけとなります. The -o flag specifies the output file name. If not specified, the // `-o`フラグによって結果の実行可能ファイル名を指定できます. output file name depends on the arguments and derives from the name // `-o`フラグを使わない場合は、与えられたパッケージ名によって of the package, such as p.a for package p, unless p is 'main'. If // 実行ファイル名は決定されます. (例: go build p -> p.a) the package is main and file names are provided, the file name // mainパッケージに紐づく複数の.goファイルを渡した場合は、 derives from the first file name mentioned, such as f1 for 'go build' // 実行ファイルは引数の最初のファイル名から決定されます. 'f1.go f2.go'; with no files provided ('go build'), the output file // (例: go build f1.go f2.go -> f1.a) name is the base name of the containing directory. // 単に`go build`を実行した場合はカレントディレクトリ名から // ファイル名が決定されます. /* 訳注 the containing directory って何だ? 実行結果とか文脈見る限りカレントでいいんだけど... */ The build flags are shared by the build, install, run, and test commands: // buildコマンドのフラグはinstall, run, testと共通です. -a force rebuilding of packages that are already up-to-date. // 存在していてもビルドを実行します. -n print the commands but do not run them. // ビルド結果のコマンドを出力します. 実行はしません. -p n the number of builds that can be run in parallel. The default is the number of CPUs available. // 並列で実行するビルドプロセスの数を指定できます. // デフォルトでは利用可能CPU数です /* 訳注: コア数じゃないのかな? */ -race enable data race detection. Supported only on linux/amd64, darwin/amd64 and windows/amd64. // ビルド時にレースコンディションを検出します. /* 訳注: * [Go1.1 の Race Detector] * http://jxck.hatenablog.com/entry/20130530/1369928762 * [レースコンディションの一般的対策] * https://www.ipa.go.jp/security/awareness/vendor/programmingv2/contents/c304.html */ // linux/amd64, darwin/amd64, windows/amd64でのみ利用可能です. -v print the names of packages as they are compiled. // コンパイルされたパッケージの名前を出力します. -work print the name of the temporary work directory and do not delete it when exiting. // 使用しているワーキングディレクトリを出力します. // また、終了時にそれを削除しません. -x print the commands. // コマンドを出力します. /* 訳注: なんだそれ.使ってみたけど意味分からんかった */ -ccflags 'arg list' arguments to pass on each 5c, 6c, or 8c compiler invocation. // 5c, 6c, 8c コンパイラに渡す引数を指定できます. /* 訳注: * [GoのツールチェインのCコンパイラを使う] * http://moriyoshi.hatenablog.com/entry/2013/12/26/174829 */ -compiler name name of compiler to use, as in runtime.Compiler (gccgo or gc). // 使用するコンパイラを指定できます. // runtime.Compilerで定義されたものを指定可能です. -gccgoflags 'arg list' arguments to pass on each gccgo compiler/linker invocation. // gccgoのcompiler/linkerに渡す引数を指定できます. /* 訳注: http://golang.jp/tag/コンパイラ */ -gcflags 'arg list' arguments to pass on each 5g, 6g, or 8g compiler invocation. // 5g, 6g, 8gコンパイラに渡す引数を指定できます. /* 訳注: * [Goプログラマであるかを見分ける10の質問] * http://mattn.kaoriya.net/software/lang/go/20110308033821.htm * [ソースからのGo言語インストール] * http://golang.jp/install/source */ -installsuffix suffix a suffix to use in the name of the package installation directory, in order to keep output separate from default builds. If using the -race flag, the install suffix is automatically set to race or, if set explicitly, has _race appended to it. // パッケージをインストールするディレクトリの接尾語を指定できます. // デフォルトのビルド物と分別することができます. // -raceフラグを使用する場合、suffixは自動的にraceになり、 // さらに-installsuffixを使った場合は、与えられたsuffixの後ろに // _raceが自動的に付加されます. -ldflags 'flag list' arguments to pass on each 5l, 6l, or 8l linker invocation. // 5l,6l,8lリンカに渡す引数を指定できます. -tags 'tag list' a list of build tags to consider satisfied during the build. See the documentation for the go/build package for more information about build tags. // ビルドタグを指定できます. // ビルドタグについてはgo/buildパッケージの説明を見て下さい. /* 訳注: * [go/build] * http://golang.org/pkg/go/build/ * [Golang Cafe #25 まとめ デバッグとリリースビルドの切り替え方法を考える] * http://d.hatena.ne.jp/taknb2nch/20140414/1397459204 */ The list flags accept a space-separated list of strings. To embed spaces // 各フラグに渡す引数リストはスペース区切りの文字列で指定できます. in an element in the list, surround it with either single or double quotes. // もしスペースを含む要素を渡したいときは、 // シングルクオートまたはダブルクオートでラップしてください. For more about specifying packages, see 'go help packages'. // packageについてのより詳細な情報は // `go help packages`から参照できます. For more about where packages and binaries are installed, // パッケージとバイナリがインストールされたロケーションについては run 'go help gopath'. For more about calling between Go and C/C++, // `go help gopath`で参照できます. run 'go help c'. // Go言語からのC/C++呼び出しについては、 // `go help c`で参照できます. See also: go install, go get, go clean. // `go install`, `go get`, `go clean`についても見てくれよな!!
やなこった
Thanks to
- Go1.1 の Race Detector - Block Rockin’ Codes
- IPA ISEC セキュア・プログラミング講座:C/C++言語編 第4章 不測の事態対策:レースコンディションの一般的対策
- GoのツールチェインのCコンパイラを使う - moriyoshiの日記
- コンパイラ - golang.jp
- Big Sky :: Goプログラマであるかを見分ける10の質問
- ソースからのGo言語インストール - golang.jp
- build - The Go Programming Language
- Golang Cafe #25 まとめ デバッグとリリースビルドの切り替え方法を考える - taknb2nchのメモ
- gc - GoDoc
雑感
くっそ勉強になった