Initial commit
1 parent d8a7b5f commit 4638cf95f5fa1bd9fcc9d8cabbc1fd9f33902482
root authored on 13 Aug 2021
Showing 8 changed files
View
54
README.md
multiCompile
===============
 
A small program to quickly compile golang scripts for multiple OS's
A small program to quickly compile golang scripts for multiple OS's from either windows or linux.
 
Running on linux:
 
```
$> ./multiCompile-linux-amd64 -p ./multiCompile.go
Dir: ./
File: multiCompile.go
1) Compiling windows-386 - (linux compiler)... Built ./multiCompile-windows-386.exe
2) Compiling windows-amd64 - (linux compiler)... Built ./multiCompile-windows-amd64.exe
3) Compiling linux-386 - (linux compiler)... Built ./multiCompile-linux-386
4) Compiling linux-amd64 - (linux compiler)... Built ./multiCompile-linux-amd64
 
```
 
Running on windows:
 
```
C:\>multiCompile-windows-amd64.exe -p .\multiCompile.go
Dir: .\
File: multiCompile.go
1) Compiling windows-386 - (windows compiler) Built .\multiCompile-windows-386.exe
2) Compiling windows-amd64 - (windows compiler) Built .\multiCompile-windows-amd64.exe
3) Compiling linux-386 - (windows compiler) Built .\multiCompile-linux-386
4) Compiling linux-amd64 - (windows compiler) Built .\multiCompile-linux-amd64
 
```
View
6
go.mod 0 → 100755
module multiCompile
 
go 1.16
 
require github.com/akamensky/argparse v1.3.1
View
3
■■
go.sum 0 → 100755
github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g=
github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
View
multiCompile-linux-386 0 → 100755
Not supported
View
multiCompile-linux-amd64 0 → 100755
Not supported
View
multiCompile-windows-386.exe 0 → 100755
Not supported
View
multiCompile-windows-amd64.exe 0 → 100755
Not supported
View
58
multiCompile.go 0 → 100755
package main
 
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
 
"github.com/akamensky/argparse"
)
 
func main() {
parser := argparse.NewParser("print", "Multi-OS Golang compiler ("+runtime.GOOS+")")
p := parser.String("p", "path", &argparse.Options{Required: true, Help: "path/to/program.go t compile"})
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
os.Exit(1)
}
// convert CRLF to LF
fullPath := strings.Replace(*p, "\n", "", -1)
dir, file := filepath.Split(fullPath)
fmt.Println("Dir: " + dir)
fmt.Println("File: " + file)
 
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
fmt.Println("[-] file does not exist!")
os.Exit(1)
}
 
osASM := [4]string{"windows-386", "windows-amd64", "linux-386", "linux-amd64"}
for index, element := range osASM {
fmt.Printf("%v) Compiling %v - ", index+1, element)
elemSplit := strings.Split(element, "-")
 
fileNoExt := strings.TrimSuffix(file, filepath.Ext(file))
var ext string
if elemSplit[0] == "windows" {
ext = ".exe"
} else {
ext = ""
}
if runtime.GOOS == "windows" {
fmt.Print("(windows compiler)... ")
exec.Command("go", "env", "-w", "GOOS="+elemSplit[0]).Output() // windows
exec.Command("go", "env", "-w", "GOARCH="+elemSplit[1]).Output() // windows
exec.Command("go", "build", "-o", dir+fileNoExt+"-"+element+ext, fullPath).Output()
}
if runtime.GOOS == "linux" {
fmt.Print("(linux compiler)... ")
exec.Command("env", "GOOS="+elemSplit[0], "GOARC="+elemSplit[1], "go", "build", "-o", dir+fileNoExt+"-"+element+ext, fullPath).Output() // linux
}
fmt.Printf("Built %v\n", dir+fileNoExt+"-"+element+ext)
}
}
Buy Me A Coffee