-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.go
62 lines (55 loc) · 1.8 KB
/
compiler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// dcc - dependency-driven C/C++ compiler front end
//
// Copyright © A.Newman 2015.
//
// This source code is released under version 2 of the GNU Public License.
// See the file LICENSE for details.
//
package main
import (
"io"
"log"
"strings"
)
// The Compiler interface defines the interface to a compiler
// that can generate dependency information.
//
// The interface exists to accomonodate the differences between
// gcc-style dependency generation (as done by gcc, clang and icc)
// and the approach taken with Microsoft C++ (parsing the output
// of its /showIncludes switch).
type Compiler interface {
// Return a name for the compiler.
//
Name() string
// Compile the source file named by source using the supplied options
// and create an object file named object and a dependencies file
// called deps.
//
Compile(source, object, deps string, options []string, w io.Writer) error
// Read a compiler-generated depdencies file and return the dependent filenames.
//
ReadDependencies(path string) (string, []string, error)
// Return the command line options used to name the ouput executable
// file when the compiler (driver) is used to link a program
DefineExecutableArgs(exeName string) []string
}
// GetCompiler is a factory function to return a value that implements
// the Compiler interface.
func GetCompiler(name string) Compiler {
switch name {
case "cl", "cl.exe":
return NewMsvcCompiler()
case "cc", "c++", "gcc", "g++", "clang", "clang++", "icc", "icpc":
return NewGccStyleCompiler(name)
default:
if strings.Contains(name, "gcc") || strings.Contains(name, "clang") {
return NewGccStyleCompiler(name)
}
if strings.Contains(name, "g++") || strings.Contains(name, "clang++") {
return NewGccStyleCompiler(name)
}
}
log.Fatalf("%s: unsupported compiler", name)
return nil
}