2013-08-02 13:20:42 -06:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
package main
|
|
|
|
|
2015-09-03 18:27:12 -06:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
)
|
2013-08-02 13:20:42 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helpers for building cmd/go and cmd/cgo.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// mkzdefaultcc writes zdefaultcc.go:
|
|
|
|
//
|
|
|
|
// package main
|
|
|
|
// const defaultCC = <defaultcc>
|
2013-09-23 22:17:08 -06:00
|
|
|
// const defaultCXX = <defaultcxx>
|
2013-08-02 13:20:42 -06:00
|
|
|
//
|
|
|
|
// It is invoked to write cmd/go/zdefaultcc.go
|
2015-01-07 09:38:00 -07:00
|
|
|
// but we also write cmd/cgo/zdefaultcc.go
|
|
|
|
func mkzdefaultcc(dir, file string) {
|
|
|
|
var out string
|
2013-08-02 13:20:42 -06:00
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
out = fmt.Sprintf(
|
|
|
|
"// auto generated by go tool dist\n"+
|
|
|
|
"\n"+
|
|
|
|
"package main\n"+
|
|
|
|
"\n"+
|
|
|
|
"const defaultCC = `%s`\n"+
|
|
|
|
"const defaultCXX = `%s`\n",
|
|
|
|
defaultcctarget, defaultcxxtarget)
|
2013-08-02 13:20:42 -06:00
|
|
|
|
2015-06-03 14:41:00 -06:00
|
|
|
writefile(out, file, writeSkipSame)
|
2013-08-02 13:20:42 -06:00
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
// Convert file name to replace: turn go into cgo.
|
|
|
|
i := len(file) - len("go/zdefaultcc.go")
|
|
|
|
file = file[:i] + "c" + file[i:]
|
2015-06-03 14:41:00 -06:00
|
|
|
writefile(out, file, writeSkipSame)
|
2013-08-02 13:20:42 -06:00
|
|
|
}
|
2015-09-03 18:27:12 -06:00
|
|
|
|
|
|
|
// mkzcgo writes zcgo.go for go/build package:
|
|
|
|
//
|
|
|
|
// package build
|
|
|
|
// var cgoEnabled = map[string]bool{}
|
|
|
|
//
|
|
|
|
// It is invoked to write go/build/zcgo.go.
|
|
|
|
func mkzcgo(dir, file string) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
|
|
|
fmt.Fprintf(&buf,
|
|
|
|
"// auto generated by go tool dist\n"+
|
|
|
|
"\n"+
|
|
|
|
"package build\n"+
|
|
|
|
"\n"+
|
|
|
|
"var cgoEnabled = map[string]bool{\n")
|
|
|
|
for plat := range cgoEnabled {
|
|
|
|
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&buf, "}")
|
|
|
|
|
|
|
|
writefile(buf.String(), file, writeSkipSame)
|
|
|
|
}
|