diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2014-11-27 00:15:21 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2014-11-27 00:15:21 +0000 |
commit | a9ce03858d657f4bab5cae242cfba7cfc1c144de (patch) | |
tree | d0a16e6312e4feed0c9d60ed9e319e19cfff7c26 /tools/llvm-go/llvm-go.go | |
parent | 51bd393f52d833d7c3542417f849217c125a539d (diff) |
Teach LLVM about llgo subproject.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222860 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-go/llvm-go.go')
-rw-r--r-- | tools/llvm-go/llvm-go.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/tools/llvm-go/llvm-go.go b/tools/llvm-go/llvm-go.go index 47f948150f0..cf520bd90e9 100644 --- a/tools/llvm-go/llvm-go.go +++ b/tools/llvm-go/llvm-go.go @@ -30,6 +30,7 @@ type pkg struct { var packages = []pkg{ {"bindings/go/llvm", "llvm.org/llvm/bindings/go/llvm"}, + {"tools/llgo", "llvm.org/llgo"}, } type compilerFlags struct { @@ -136,7 +137,7 @@ type (run_build_sh int) `, flags.cpp, flags.cxx, flags.ld) } -func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string) { +func runGoWithLLVMEnv(args []string, cc, cxx, llgo, cppflags, cxxflags, ldflags string) { args = addTag(args, "byollvm") srcdir := llvmConfig("--src-root") @@ -159,6 +160,28 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string } } + newpath := os.Getenv("PATH") + + if llgo != "" { + bindir := filepath.Join(tmpgopath, "bin") + + err = os.MkdirAll(bindir, os.ModePerm) + if err != nil { + panic(err.Error()) + } + + err = os.Symlink(llgo, filepath.Join(bindir, "gccgo")) + if err != nil { + panic(err.Error()) + } + + newpathlist := []string{bindir} + newpathlist = append(newpathlist, filepath.SplitList(newpath)...) + newpath = strings.Join(newpathlist, string(filepath.ListSeparator)) + + args = append([]string{args[0], "-compiler", "gccgo"}, args[1:]...) + } + newgopathlist := []string{tmpgopath} newgopathlist = append(newgopathlist, filepath.SplitList(os.Getenv("GOPATH"))...) newgopath := strings.Join(newgopathlist, string(filepath.ListSeparator)) @@ -172,6 +195,7 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string "CGO_CXXFLAGS=" + flags.cxx + " " + cxxflags, "CGO_LDFLAGS=" + flags.ld + " " + ldflags, "GOPATH=" + newgopath, + "PATH=" + newpath, } for _, v := range os.Environ() { if !strings.HasPrefix(v, "CC=") && @@ -179,7 +203,8 @@ func runGoWithLLVMEnv(args []string, cc, cxx, cppflags, cxxflags, ldflags string !strings.HasPrefix(v, "CGO_CPPFLAGS=") && !strings.HasPrefix(v, "CGO_CXXFLAGS=") && !strings.HasPrefix(v, "CGO_LDFLAGS=") && - !strings.HasPrefix(v, "GOPATH=") { + !strings.HasPrefix(v, "GOPATH=") && + !strings.HasPrefix(v, "PATH=") { newenv = append(newenv, v) } } @@ -222,6 +247,7 @@ func main() { cppflags := os.Getenv("CGO_CPPFLAGS") cxxflags := os.Getenv("CGO_CXXFLAGS") ldflags := os.Getenv("CGO_LDFLAGS") + llgo := "" args := os.Args[1:] DONE: for { @@ -234,6 +260,9 @@ func main() { case strings.HasPrefix(args[0], "cxx="): cxx = args[0][4:] args = args[1:] + case strings.HasPrefix(args[0], "llgo="): + llgo = args[0][5:] + args = args[1:] case strings.HasPrefix(args[0], "cppflags="): cppflags = args[0][9:] args = args[1:] @@ -250,7 +279,7 @@ func main() { switch args[0] { case "build", "get", "install", "run", "test": - runGoWithLLVMEnv(args, cc, cxx, cppflags, cxxflags, ldflags) + runGoWithLLVMEnv(args, cc, cxx, llgo, cppflags, cxxflags, ldflags) case "print-components": printComponents() case "print-config": |