-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.go
More file actions
141 lines (126 loc) · 3.05 KB
/
platform.go
File metadata and controls
141 lines (126 loc) · 3.05 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// dmake - a build tool on top of dcc
//
// Copyright (C) 2017 A.Newman.
//
// This source code is released under version 2 of the GNU Public
// License. See the file LICENSE for details.
//
package main
import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
)
type PlatformSpecific struct {
objsuffix string
exesuffix string
libprefix string
libsuffix string
dllprefix string
dllsuffix string
pluginprefix string
pluginsuffix string
installfile func(filename, destdir string, filemode os.FileMode) error
}
var (
windowsPlatform = PlatformSpecific{
objsuffix: ".obj",
exesuffix: ".exe",
libprefix: "",
libsuffix: ".lib",
dllprefix: "",
dllsuffix: ".dll",
pluginprefix: "",
pluginsuffix: ".dll",
installfile: installByCopyingFile,
}
macosPlatform = PlatformSpecific{
objsuffix: ".o",
exesuffix: "",
libprefix: "lib",
libsuffix: ".a",
dllprefix: "lib",
dllsuffix: ".dylib",
pluginprefix: "",
pluginsuffix: ".bundle",
installfile: installWithUsrBinInstall,
}
elfPlatform = PlatformSpecific{
objsuffix: ".o",
exesuffix: "",
libprefix: "lib",
libsuffix: ".a",
dllprefix: "lib",
dllsuffix: ".so",
pluginprefix: "lib",
pluginsuffix: ".so",
installfile: installWithUsrBinInstall,
}
)
var (
// The PlatformSpecific for the build host.
//
platform *PlatformSpecific
// This matches platforms **other** than this one. This is
// used to ignore files using Go-style platform-specific
// filenames.
//
otherPlatformNamesRegexp *regexp.Regexp
)
func init() {
platforms := []string{
"aix",
"darwin",
"dragonfly",
"freebsd",
"illumos",
"ios",
"linux",
"netbsd",
"openbsd",
"solaris",
"windows",
}
switch runtime.GOOS {
case "windows":
platform = &windowsPlatform
case "darwin":
platform = &macosPlatform
default:
platform = &elfPlatform
}
var otherPlatformNames []string
for _, name := range platforms {
if name != runtime.GOOS {
otherPlatformNames = append(otherPlatformNames, name)
}
}
otherPlatformNamesRegexp = regexp.MustCompile("_(" + strings.Join(otherPlatformNames, "|") + ")\\.")
}
func (p *PlatformSpecific) LibFilename(path string) string {
return formFilename(p.libprefix, path, p.libsuffix)
}
func (p *PlatformSpecific) DllFilename(path string) string {
return formFilename(p.dllprefix, path, p.dllsuffix)
}
func (p *PlatformSpecific) PluginFilename(path string) string {
return formFilename(p.pluginprefix, path, p.pluginsuffix)
}
func (p *PlatformSpecific) ExeFilename(path string) string {
return formFilename("", path, p.exesuffix)
}
func (p *PlatformSpecific) ObjFilename(path string) string {
return formFilename("", path, p.objsuffix)
}
func formFilename(prefix, path, suffix string) string {
dirname, basename := filepath.Dir(path), filepath.Base(path)
if prefix != "" && !strings.HasPrefix(basename, prefix) {
basename = prefix + basename
}
if suffix != "" && !strings.HasSuffix(basename, suffix) {
basename += suffix
}
return filepath.Clean(filepath.Join(dirname, basename))
}