Squashed 'third_party/Phoenix-frc-lib/' content from commit 666d176

Change-Id: Ibaca2fc8ffb1177e786576cc1e4cc9f7a8c98f13
git-subtree-dir: third_party/Phoenix-frc-lib
git-subtree-split: 666d176a08151793044ab74e0005f13d3732ed96
diff --git a/toolchains/arm.gradle b/toolchains/arm.gradle
new file mode 100644
index 0000000..4fe9f86
--- /dev/null
+++ b/toolchains/arm.gradle
@@ -0,0 +1,97 @@
+ext.isArm = true
+ext.buildPlatform = 'arm'
+
+def compilerPrefix = project.hasProperty('compilerPrefix') ? project.compilerPrefix : 'arm-frc-linux-gnueabi-'
+def toolChainPath = project.hasProperty('toolChainPath') ? project.toolChainPath : null
+model {
+    platforms {
+        arm {
+            architecture 'arm'
+            operatingSystem 'linux'
+        }
+    }
+    toolChains {
+        armGcc(Gcc) {
+            if (toolChainPath != null) path(toolChainPath)
+            target("arm") {
+                // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name>
+                // If this ever changes, the prefix will need to be changed here
+                cCompiler.executable = compilerPrefix + cCompiler.executable
+                cppCompiler.executable = compilerPrefix + cppCompiler.executable
+                linker.executable = compilerPrefix + linker.executable
+                assembler.executable = compilerPrefix + assembler.executable
+                // Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports
+                // arm, and doesn't understand this flag, so it is removed from both
+                cppCompiler.withArguments { args ->
+					args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic'
+                    args << '-fPIC' << '-rdynamic'
+                    args << '-pthread'
+                    args.remove('-m32')
+                }
+                linker.withArguments { args ->
+                    args << '-rdynamic' << '-pthread'
+                    args.remove('-m32')
+                }
+                staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable
+            }
+        }
+    }
+}
+
+ext.binTools = { tool ->
+    if (toolChainPath != null) return "${toolChainPath}/${compilerPrefix}${tool}"
+    return "${compilerPrefix}${tool}"
+}
+
+ext.setupReleaseDefines = { cppCompiler, linker ->
+    cppCompiler.args '-O2', '-g'
+}
+
+ext.setupDebugDefines = { cppCompiler, linker ->
+    cppCompiler.args '-g', '-O0'
+}
+
+// Used only on Windows.
+ext.setupDef = { linker, deffile -> }
+
+ext.debugStripSetup = {
+    if (!project.hasProperty('debug')) {
+        project.tasks.whenObjectAdded { task ->
+            if (task.name.contains('link') && task.name.contains('SharedLibrary')) {
+                def library = task.outputFile.absolutePath
+                def debugLibrary = task.outputFile.absolutePath + ".debug"
+                task.doLast {
+                    exec { commandLine binTools('objcopy'), '--only-keep-debug', library, debugLibrary }
+                    exec { commandLine binTools('strip'), '-g', library }
+                    exec { commandLine binTools('objcopy'), "--add-gnu-debuglink=$debugLibrary", library }
+                }
+            }
+        }
+    }
+}
+
+ext.checkNativeSymbols = { getSymbolFunc ->
+    project.tasks.whenObjectAdded { task ->
+        if (task.name.contains('link') && task.name.contains('SharedLibrary')) {
+            def library = task.outputFile.absolutePath
+            task.doLast {
+                def nmOutput = new ByteArrayOutputStream()
+                exec { 
+                    commandLine binTools('nm'), library
+                    standardOutput nmOutput
+                }
+                // Remove '\r' so we can check for full string contents
+                String nmSymbols = nmOutput.toString().replace('\r', '')
+
+                def symbolList = getSymbolFunc()
+                symbolList.each {
+                    //Add \n so we can check for the exact symbol
+                    def found = nmSymbols.contains(it + '\n')
+                    if (!found) {
+                        throw new GradleException("Found a definition that does not have a matching symbol ${it}")
+                    }
+                }
+            }
+        }
+    }
+}