-
Notifications
You must be signed in to change notification settings - Fork 0
/
dll.go
82 lines (77 loc) · 2.26 KB
/
dll.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
// 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 (
"os"
"strings"
)
// Dll runs the compiler to link the given inputs and create the given
// shared/dynamic library target using the supplied options. Returns a
// corresponding error value. If the target exists and is newer than
// any of the inputs no linking occurs.
//
func dllOrPlugin(target string, inputs []string, libs *Options, options *Options, otherFiles *Options, frameworks []string, create func(string, []string, []string, []string, []string) error) error {
createDllOrPlugin := func() error {
inputs = append(inputs, otherFiles.Values...)
return create(target, inputs, libs.Values, options.Values, frameworks)
}
if IgnoreDependencies {
return createDllOrPlugin()
}
targetInfo, err := Stat(target)
if os.IsNotExist(err) {
return createDllOrPlugin()
}
if err != nil {
return err
}
if MostRecentModTime(options, libs).After(targetInfo.ModTime()) {
return createDllOrPlugin()
}
newestInput, err := NewestOf(inputs)
if err != nil {
return err
}
if newestInput.After(targetInfo.ModTime()) {
return createDllOrPlugin()
}
if len(otherFiles.Values) > 0 {
newestOther, err := NewestOf(otherFiles.Values)
if err != nil {
return err
}
if newestOther.After(targetInfo.ModTime()) {
return createDllOrPlugin()
}
}
skipNext := false
for _, name := range libs.Values {
if skipNext {
skipNext = false
continue
}
if name == "-framework" {
skipNext = true
continue
}
if !strings.HasPrefix(name, "-l") {
if libInfo, err := Stat(name); err != nil {
return err
} else if FileIsNewer(libInfo, targetInfo) {
return createDllOrPlugin()
}
}
}
return nil
}
func Dll(target string, inputs []string, libs *Options, options *Options, otherFiles *Options, frameworks []string) error {
return dllOrPlugin(target, inputs, libs, options, otherFiles, frameworks, platform.CreateDLL)
}
func Plugin(target string, inputs []string, libs *Options, options *Options, otherFiles *Options, frameworks []string) error {
return dllOrPlugin(target, inputs, libs, options, otherFiles, frameworks, platform.CreatePlugin)
}