Skip to content

Instantly share code, notes, and snippets.

@keizo042
Created January 20, 2015 17:00
Show Gist options
  • Save keizo042/3e34abca3f69a6664bc5 to your computer and use it in GitHub Desktop.
Save keizo042/3e34abca3f69a6664bc5 to your computer and use it in GitHub Desktop.
ghc pretty wrapper for easy compile on sandbox (under MITL, author keizo)
package main
import (
"flag"
"fmt"
"os"
"os/exec"
)
func main() {
ghcf := "-package-db "
flag.Parse()
dir := ".cabal-sandbox/"
hostArchEnv := os.Getenv("GOHOSTARCH")
if hostArchEnv == "" {
hostArchEnv = "x86_64"
}
hostOsEnv := os.Getenv("GOHOSTOS")
if hostOsEnv == "" {
hostOsEnv = "linux"
}
if hostArchEnv == "amd64" {
hostArchEnv = "x86_64"
}
opt := ghcf + dir + hostArchEnv + "-" + hostOsEnv + "-" + "ghc-" + "7.8.4" + "-package.conf.d"
fmt.Println(opt)
if flag.NArg() == 0 {
r,err := exec.Command("ghc","--help").Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(r))
return
}
if _, err := os.Stat("./cabal-sandbox"); os.IsExist(err) {
r, err := exec.Command("ghc", opt, flag.Arg(0)).Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Print( string(r) )
} else {
r,err := exec.Command("ghc", flag.Arg(0)).Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Print( string(r) )
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment