forked from sedmelluq/lavaplayer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
native.gradle
97 lines (83 loc) · 2.75 KB
/
native.gradle
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
import org.apache.tools.ant.taskdefs.condition.Os
def getBuildParameters(base, bits) {
def bitSuffix = (bits == 32) ? 'x86' : 'x86-64'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
return [
'identifier': "win-${bitSuffix}",
'library': "${base}.dll",
'setupArguments': ["-DBITZ:STRING=${bits}", '-A', (bits == 64 ? 'x64' : 'Win32')],
'buildArguments': ['--config', 'Release'],
'env': [:]
]
} else if (Os.isFamily(Os.FAMILY_MAC)) {
return [
'identifier': 'darwin',
'library': "lib${base}.so",
'setupArguments': ["-DBITZ:STRING=${bits}"],
'buildArguments': [],
'env': ['CXXFLAGS': "-m${bits}", 'CFLAGS': "-m${bits}", 'LDFLAGS': "-m${bits}"]
]
} else {
return [
'identifier': "linux-${bitSuffix}",
'library': "lib${base}.dylib",
'setupArguments': ["-DBITZ:STRING=${bits}"],
'buildArguments': [],
'env': ['CXXFLAGS': "-m${bits}", 'CFLAGS': "-m${bits}", 'LDFLAGS': "-m${bits}"]
]
}
}
def getHomeDirectory() {
def directory = file(System.getProperty('java.home'))
return directory.name == 'jre' ? directory.parentFile.absolutePath : directory.absolutePath
}
def createBuildTask(buildBase, projectBase, deployBase, compileTask, checkTask, base, bits) {
def parameters = getBuildParameters(base, bits)
def buildDirectory = "$buildBase/${parameters.identifier}"
def distDirectory = "$projectBase/dist/${parameters.identifier}"
def deployDirectory = "$deployBase/src/main/resources/natives/${parameters.identifier}"
def taskBase = "${base}-${bits}"
if (Os.isFamily(Os.FAMILY_MAC) && bits != 64) {
return
}
parameters.env.put('DIST_DIR', distDirectory)
parameters.env.put('JAVA_HOME', getHomeDirectory())
def setupTask = tasks.create("${taskBase}-setup", Exec) {
doFirst {
buildOpus(bits, false)
file(buildDirectory).with {
it.deleteDir()
it.mkdirs()
}
}
workingDir buildDirectory
executable 'cmake'
args(parameters.setupArguments + ['../..'])
environment parameters.env
}
def buildTask = tasks.create("${taskBase}-build", Exec) {
workingDir buildDirectory
executable 'cmake'
args(['--build', '.'] + parameters.buildArguments)
environment parameters.env
}
def deployTask = tasks.create("${taskBase}-deploy") << {
copy {
from distDirectory
into deployDirectory
}
}
tasks.create("${taskBase}-deploy-only") << {
copy {
from distDirectory
into deployDirectory
}
}
setupTask.dependsOn(tasks.load)
buildTask.dependsOn(setupTask)
deployTask.dependsOn(buildTask)
compileTask.dependsOn(deployTask)
if (!file("${deployDirectory}/${parameters.library}").exists()) {
checkTask.dependsOn(deployTask)
}
}