blob: 5a375225a5f359a964d929b04c08d9f5d0c59f9b [file] [log] [blame]
Peter Collingbournead9841e2014-11-27 00:06:42 +00001//===- main.go - Clang compiler wrapper for building libgo ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This is a wrapper for Clang that passes invocations with -fdump-go-spec to
11// GCC, and rewrites -fplan9-extensions to -fms-extensions. It is intended to
12// go away once libgo's build no longer uses these flags.
13//
14//===----------------------------------------------------------------------===//
15
16package main
17
18import (
19 "fmt"
20 "os"
21 "os/exec"
22 "strings"
23)
24
25func runproc(name string, argv []string) {
26 path, err := exec.LookPath(name)
27 if err != nil {
28 fmt.Fprintf(os.Stderr, "cc-wrapper: could not find %s: %v\n", name, err)
29 os.Exit(1)
30 }
31
32 proc, err := os.StartProcess(path, append([]string{name}, argv...), &os.ProcAttr{
33 Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
34 })
35 if err != nil {
36 fmt.Fprintf(os.Stderr, "cc-wrapper: could not start %s: %v\n", name, err)
37 os.Exit(1)
38 }
39
40 state, err := proc.Wait()
41 if err != nil {
42 fmt.Fprintf(os.Stderr, "cc-wrapper: could not wait for %s: %v\n", name, err)
43 os.Exit(1)
44 }
45
46 if state.Success() {
47 os.Exit(0)
48 } else {
49 os.Exit(1)
50 }
51}
52
53func main() {
54 newargs := make([]string, len(os.Args)-1)
55 for i, arg := range os.Args[1:] {
56 switch {
57 case strings.HasPrefix(arg, "-fdump-go-spec"):
58 runproc("gcc", os.Args[1:])
59
60 case arg == "-fplan9-extensions":
61 newargs[i] = "-fms-extensions"
62 newargs = append(newargs, "-Wno-microsoft")
63
64 default:
65 newargs[i] = arg
66 }
67 }
68
69 ccargs := strings.Split(os.Getenv("REAL_CC"), "@SPACE@")
70 runproc(ccargs[0], append(ccargs[1:], newargs...))
71}