Added build script

This commit is contained in:
Andreas Schneider 2018-04-08 21:37:38 +02:00
parent d7743b6ef2
commit 765f8fc077
1 changed files with 50 additions and 0 deletions

50
build.go Normal file
View File

@ -0,0 +1,50 @@
// +build ignore
package main
import (
"os"
"os/exec"
"strings"
)
func main() {
env := os.Environ()
wd, err := os.Getwd()
if err != nil {
panic(err)
}
env = append(env, "GOPATH="+wd)
args := []string{"build"}
if len(os.Args) == 2 {
target := os.Args[1]
targetParts := strings.Split(target, "/")
if len(targetParts) != 2 {
println("Invalid target specification. Example: windows/386")
os.Exit(1)
}
env = append(env,
"GOOS="+targetParts[0],
"GOARCH"+targetParts[1],
)
ext := ""
if targetParts[0] == "windows" {
ext = ".exe"
}
args = append(args, "-o", "calanonsync-"+targetParts[0]+"-"+targetParts[1]+ext)
}
args = append(args, "calanonsync")
cmd := exec.Command("go", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = env
err = cmd.Run()
if err != nil {
panic(err)
}
}