blob: 4fe9f862f72804cd896c76a98b4074b2c5207648 [file] [log] [blame]
Brian Silverman890a32a2018-03-11 15:41:56 -07001ext.isArm = true
2ext.buildPlatform = 'arm'
3
4def compilerPrefix = project.hasProperty('compilerPrefix') ? project.compilerPrefix : 'arm-frc-linux-gnueabi-'
5def toolChainPath = project.hasProperty('toolChainPath') ? project.toolChainPath : null
6model {
7 platforms {
8 arm {
9 architecture 'arm'
10 operatingSystem 'linux'
11 }
12 }
13 toolChains {
14 armGcc(Gcc) {
15 if (toolChainPath != null) path(toolChainPath)
16 target("arm") {
17 // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
18 // If this ever changes, the prefix will need to be changed here
19 cCompiler.executable = compilerPrefix + cCompiler.executable
20 cppCompiler.executable = compilerPrefix + cppCompiler.executable
21 linker.executable = compilerPrefix + linker.executable
22 assembler.executable = compilerPrefix + assembler.executable
23 // Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
24 // arm, and doesn't understand this flag, so it is removed from both
25 cppCompiler.withArguments { args ->
26 args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
27 args << '-fPIC' << '-rdynamic'
28 args << '-pthread'
29 args.remove('-m32')
30 }
31 linker.withArguments { args ->
32 args << '-rdynamic' << '-pthread'
33 args.remove('-m32')
34 }
35 staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
36 }
37 }
38 }
39}
40
41ext.binTools = { tool ->
42 if (toolChainPath != null) return "${toolChainPath}/${compilerPrefix}${tool}"
43 return "${compilerPrefix}${tool}"
44}
45
46ext.setupReleaseDefines = { cppCompiler, linker ->
47 cppCompiler.args '-O2', '-g'
48}
49
50ext.setupDebugDefines = { cppCompiler, linker ->
51 cppCompiler.args '-g', '-O0'
52}
53
54// Used only on Windows.
55ext.setupDef = { linker, deffile -> }
56
57ext.debugStripSetup = {
58 if (!project.hasProperty('debug')) {
59 project.tasks.whenObjectAdded { task ->
60 if (task.name.contains('link') && task.name.contains('SharedLibrary')) {
61 def library = task.outputFile.absolutePath
62 def debugLibrary = task.outputFile.absolutePath + ".debug"
63 task.doLast {
64 exec { commandLine binTools('objcopy'), '--only-keep-debug', library, debugLibrary }
65 exec { commandLine binTools('strip'), '-g', library }
66 exec { commandLine binTools('objcopy'), "--add-gnu-debuglink=$debugLibrary", library }
67 }
68 }
69 }
70 }
71}
72
73ext.checkNativeSymbols = { getSymbolFunc ->
74 project.tasks.whenObjectAdded { task ->
75 if (task.name.contains('link') && task.name.contains('SharedLibrary')) {
76 def library = task.outputFile.absolutePath
77 task.doLast {
78 def nmOutput = new ByteArrayOutputStream()
79 exec {
80 commandLine binTools('nm'), library
81 standardOutput nmOutput
82 }
83 // Remove '\r' so we can check for full string contents
84 String nmSymbols = nmOutput.toString().replace('\r', '')
85
86 def symbolList = getSymbolFunc()
87 symbolList.each {
88 //Add \n so we can check for the exact symbol
89 def found = nmSymbols.contains(it + '\n')
90 if (!found) {
91 throw new GradleException("Found a definition that does not have a matching symbol ${it}")
92 }
93 }
94 }
95 }
96 }
97}