diff --git a/go.go b/go.go index 37edb36..3f40584 100644 --- a/go.go +++ b/go.go @@ -15,9 +15,11 @@ import ( ) type OutputTemplateData struct { - Dir string - OS string - Arch string + Dir string + OS string + OSUname string + Arch string + ArchUname string } type CompileOpts struct { @@ -59,9 +61,11 @@ func GoCrossCompile(opts *CompileOpts) error { return err } tplData := OutputTemplateData{ - Dir: filepath.Base(opts.PackagePath), - OS: opts.Platform.OS, - Arch: opts.Platform.Arch, + Dir: filepath.Base(opts.PackagePath), + OS: opts.Platform.OS, + OSUname: opts.Platform.OSUname(), + Arch: opts.Platform.Arch, + ArchUname: opts.Platform.ArchUname(), } if err := tpl.Execute(&outputPath, &tplData); err != nil { return err diff --git a/main.go b/main.go index d8098c9..dee98b1 100644 --- a/main.go +++ b/main.go @@ -200,8 +200,9 @@ Output path template: The output path for the compiled binaries is specified with the "-output" flag. The value is a string that is a Go text template. - The default value is "{{.Dir}}_{{.OS}}_{{.Arch}}". The variables and - their values should be self-explanatory. + The default value is "{{.Dir}}_{{.OS}}_{{.Arch}}". Other available + variables are OSUname and ArchUname which should correspond to uname -s + and uname -m respectively. Platforms (OS/Arch): diff --git a/platform.go b/platform.go index 88428bc..5a1270f 100644 --- a/platform.go +++ b/platform.go @@ -25,6 +25,51 @@ func (p *Platform) String() string { return fmt.Sprintf("%s/%s", p.OS, p.Arch) } +/// Like `uname -s` +// Matches https://github.com/golang/go/blob/master/src/go/build/syslist.go +func (p *Platform) OSUname() string { + return map[string]string{ + //"android": + "darwin": "Darwin", + "dragonfly": "DragonFly", + "freebsd": "FreeBSD", + "linux": "Linux", + //"nacl": + "netbsd": "NetBSD", + "openbsd": "OpenBSD", + "plan9": "Plan9", + "solaris": "SunOS", + "windows": "Windows", + //"zos": + }[p.OS] +} + +/// Like `uname -m` +// Matches https://github.com/golang/go/blob/master/src/go/build/syslist.go +func (p *Platform) ArchUname() string { + return map[string]string{ + "386": "i386", + "amd64": "x86_64", + //"amd64p32": + "arm": "arm", + //"armbe": + "arm64": "aarch64", + //"arm64be": + "ppc64": "ppc64", + "ppc64le": "ppc64le", + //"mips": + //"mipsle": + //"mips64": + //"mips64p32": + //"mips64p32le": + //"ppc": + //"s390": + //"s390x": + //"sparc": + //"sparc64": + }[p.Arch] +} + var ( Platforms_1_0 = []Platform{ {"darwin", "386", true},