-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_darwin.go
89 lines (82 loc) · 2.35 KB
/
platform_darwin.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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 (
"fmt"
"os"
"strings"
)
var platform = Platform{
DefaultCC: "cc",
DefaultCXX: "c++",
ObjectFileSuffix: ".o",
StaticLibPrefix: "lib",
StaticLibSuffix: ".a",
DynamicLibPrefix: "lib",
DynamicLibSuffix: ".dylib",
PluginPrefix: "",
PluginSuffix: ".bundle",
DefaultExecutable: "a.out",
LibraryPaths: []string{"/usr/lib"},
CreateLibrary: MacosCreateLibrary,
CreateDLL: MacosCreateDLL,
CreatePlugin: MacosCreatePlugin,
IsRoot: UnixIsRoot,
}
func logCommand(cmd string, args []string) {
if Quiet {
return
}
if Verbose {
fmt.Fprintln(os.Stdout, cmd, strings.Join(args, " "))
return
}
filename := ""
nargs := len(args)
for index, arg := range args {
if arg == "-o" {
if index < nargs-1 {
filename = args[index+1]
break
}
}
}
fmt.Fprintln(os.Stdout, cmd, filename)
}
// MacosCreateLibrary creates a static library using libtool.
//
func MacosCreateLibrary(filename string, objectFiles []string) error {
const libtool = "libtool"
args := []string{"-static", "-o", filename}
args = append(args, objectFiles...)
logCommand(libtool, args)
return Exec(libtool, args, os.Stderr)
}
// MacosCreateDLL creates a dynamic library using the underlying
// compiler and its -shared option.
//
func MacosCreateDLL(filename string, objectFiles []string, libraryFiles []string, linkerOptions []string, frameworks []string) error {
args := []string{"-shared", "-o", filename}
args = append(args, linkerOptions...)
args = append(args, objectFiles...)
args = append(args, libraryFiles...)
args = append(args, frameworks...)
logCommand(ActualCompiler.Name(), args)
return Exec(ActualCompiler.Name(), args, os.Stderr)
}
// MacosCreatePlugin creates a bundle
//
func MacosCreatePlugin(filename string, objectFiles []string, libraryFiles []string, linkerOptions []string, frameworks []string) error {
args := []string{"-bundle", "-o", filename}
args = append(args, linkerOptions...)
args = append(args, objectFiles...)
args = append(args, libraryFiles...)
args = append(args, frameworks...)
logCommand(ActualCompiler.Name(), args)
return Exec(ActualCompiler.Name(), args, os.Stderr)
}