1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/tools/build/env.go

120 lines
2.0 KiB
Go
Raw Normal View History

2015-10-17 18:50:51 -04:00
package main
import (
"strings"
)
type GoOS string
const (
Windows = GoOS("windows")
MacOS = GoOS("darwin")
Linux = GoOS("linux")
2016-07-27 10:56:32 -04:00
FreeBSD = GoOS("freebsd")
2016-10-17 08:41:54 -04:00
OpenBSD = GoOS("openbsd")
2015-10-17 18:50:51 -04:00
UnknownOS = GoOS("unknown")
)
type GoArch string
const (
X86 = GoArch("386")
Amd64 = GoArch("amd64")
Arm = GoArch("arm")
Arm64 = GoArch("arm64")
2016-02-20 06:32:42 -05:00
Mips64 = GoArch("mips64")
2017-01-09 09:47:10 -05:00
Mips = GoArch("mips")
MipsLE = GoArch("mipsle")
2015-10-17 18:50:51 -04:00
UnknownArch = GoArch("unknown")
)
func parseOS(rawOS string) GoOS {
osStr := strings.ToLower(rawOS)
2016-12-21 10:44:59 -05:00
switch osStr {
case "windows", "win":
2015-10-17 18:50:51 -04:00
return Windows
2016-12-21 10:44:59 -05:00
case "darwin", "mac", "macos", "osx":
2015-10-17 18:50:51 -04:00
return MacOS
2016-12-21 10:44:59 -05:00
case "linux", "debian", "ubuntu", "redhat", "centos":
2015-10-17 18:50:51 -04:00
return Linux
2016-12-21 10:44:59 -05:00
case "freebsd":
2016-07-27 10:56:32 -04:00
return FreeBSD
2016-12-21 10:44:59 -05:00
case "openbsd":
2016-10-17 08:41:54 -04:00
return OpenBSD
2016-12-21 10:44:59 -05:00
default:
return UnknownOS
2016-10-17 08:41:54 -04:00
}
2015-10-17 18:50:51 -04:00
}
func parseArch(rawArch string) GoArch {
archStr := strings.ToLower(rawArch)
2016-12-21 10:44:59 -05:00
switch archStr {
case "x86", "386", "i386":
2015-10-17 18:50:51 -04:00
return X86
2016-12-21 10:44:59 -05:00
case "amd64", "x86-64", "x64":
2015-10-17 18:50:51 -04:00
return Amd64
2016-12-21 10:44:59 -05:00
case "arm":
2015-10-17 18:50:51 -04:00
return Arm
2016-12-21 10:44:59 -05:00
case "arm64":
2015-10-17 18:50:51 -04:00
return Arm64
2017-01-09 09:47:10 -05:00
case "mips":
return Mips
case "mipsle":
return MipsLE
case "mips64":
2016-02-20 06:32:42 -05:00
return Mips64
2016-12-21 10:44:59 -05:00
default:
return UnknownArch
2016-02-20 06:32:42 -05:00
}
2015-10-17 18:50:51 -04:00
}
func getSuffix(os GoOS, arch GoArch) string {
suffix := "-custom"
switch os {
case Windows:
switch arch {
case X86:
suffix = "-windows-32"
case Amd64:
suffix = "-windows-64"
}
case MacOS:
suffix = "-macos"
case Linux:
switch arch {
case X86:
suffix = "-linux-32"
case Amd64:
suffix = "-linux-64"
case Arm:
suffix = "-linux-arm"
case Arm64:
suffix = "-linux-arm64"
2016-02-20 06:32:42 -05:00
case Mips64:
suffix = "-linux-mips64"
2017-01-09 09:47:10 -05:00
case Mips:
suffix = "-linux-mips"
case MipsLE:
suffix = "-linux-mipsle"
2015-10-17 18:50:51 -04:00
}
2016-07-27 10:56:32 -04:00
case FreeBSD:
switch arch {
case X86:
suffix = "-freebsd-32"
case Amd64:
suffix = "-freebsd-64"
case Arm:
suffix = "-freebsd-arm"
}
2016-10-17 09:23:45 -04:00
case OpenBSD:
switch arch {
case X86:
suffix = "-openbsd-32"
case Amd64:
suffix = "-openbsd-64"
}
2015-10-17 18:50:51 -04:00
}
2016-10-17 09:23:45 -04:00
2015-10-17 18:50:51 -04:00
return suffix
}