Brian Silverman | f7bd1c2 | 2015-12-24 16:07:11 -0800 | [diff] [blame^] | 1 | def compilerPrefix = 'arm-frc-linux-gnueabi-' |
| 2 | model { |
| 3 | toolChains { |
| 4 | gcc(Gcc) { |
| 5 | target("arm"){ |
| 6 | // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name> |
| 7 | // If this ever changes, the prefix will need to be changed here |
| 8 | cppCompiler.executable = compilerPrefix + cppCompiler.executable |
| 9 | linker.executable = compilerPrefix + linker.executable |
| 10 | assembler.executable = compilerPrefix + assembler.executable |
| 11 | // Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports |
| 12 | // arm, and doesn't understand this flag, so it is removed from both |
| 13 | cppCompiler.withArguments { args -> |
| 14 | args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' |
| 15 | args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-rdynamic' |
| 16 | //TODO: When the compiler allows us to actually call deprecated functions from within |
| 17 | // deprecated function, remove this line (this will cause calling deprecated functions |
| 18 | // to be treated as a warning rather than an error). |
| 19 | args << '-Wno-error=deprecated-declarations' |
| 20 | args.remove('-m32') |
| 21 | } |
| 22 | linker.withArguments { args -> |
| 23 | args << '-rdynamic' |
| 24 | args.remove('-m32') |
| 25 | } |
| 26 | staticLibArchiver.executable = compilerPrefix + staticLibArchiver.executable |
| 27 | } |
| 28 | } |
| 29 | // Workaround for OS X. Macs for some reason want to use Xcode's gcc |
| 30 | // (which just wraps Clang), so we have to explicitly make it so |
| 31 | // that trying to compile with Clang will call gcc instead |
| 32 | macGcc(Clang) { |
| 33 | target('arm') { |
| 34 | // We use a custom-built cross compiler with the prefix arm-frc-linux-gnueabi-<util name> |
| 35 | // If this ever changes, the prefix will need to be changed here |
| 36 | cppCompiler.executable = compilerPrefix + 'g++' |
| 37 | linker.executable = compilerPrefix + 'g++' |
| 38 | assembler.executable = compilerPrefix + 'gcc' |
| 39 | // Gradle auto-adds the -m32 argument to the linker and compiler. Our compiler only supports |
| 40 | // arm, and doesn't understand this flag, so it is removed from both |
| 41 | cppCompiler.withArguments { args -> |
| 42 | args << '-std=c++1y' << '-Wformat=2' << '-Wall' << '-Wextra' << '-Werror' << '-pedantic' |
| 43 | args << '-Wno-psabi' << '-Wno-unused-parameter' << '-fPIC' << '-O0' << '-g3' << '-rdynamic' |
| 44 | //TODO: When the compiler allows us to actually call deprecated functions from within |
| 45 | // deprecated function, remove this line (this will cause calling deprecated functions |
| 46 | // to be treated as a warning rather than an error). |
| 47 | args << '-Wno-error=deprecated-declarations' |
| 48 | args.remove('-m32') |
| 49 | } |
| 50 | linker.withArguments { args -> |
| 51 | args << '-rdynamic' |
| 52 | args.remove('-m32') |
| 53 | } |
| 54 | staticLibArchiver.executable = compilerPrefix + 'ar' |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | ext.setupReleaseDefines = { cppCompiler, linker -> |
| 61 | cppCompiler.args '-O2', '-g' |
| 62 | } |
| 63 | |
| 64 | ext.setupDebugDefines = { cppCompiler, linker -> |
| 65 | cppCompiler.args '-g', '-O0' |
| 66 | } |
| 67 | |
| 68 | ext.releaseSetup = { releaseTasks -> |
| 69 | binaries.withType(SharedLibraryBinarySpec) { binary -> |
| 70 | if (!project.hasProperty('debug')) { |
| 71 | def library = binary.sharedLibraryFile.absolutePath |
| 72 | def debugLibrary = binary.sharedLibraryFile.absolutePath + ".debug" |
| 73 | if (project.tasks.findByName("firstObjcopy${binary.name}") == null) { |
| 74 | def firstObjcopy = project.tasks.create("firstObjcopy${binary.name}", Exec) { task -> |
| 75 | task.commandLine "${compilerPrefix}objcopy", '--only-keep-debug', library, debugLibrary |
| 76 | } |
| 77 | def strip = project.tasks.create("strip${binary.name}", Exec) { task -> |
| 78 | task.commandLine "${compilerPrefix}strip", '-g', library |
| 79 | } |
| 80 | def secondObjcopy = project.tasks.create("secondObjcopy${binary.name}", Exec) { task -> |
| 81 | task.commandLine "${compilerPrefix}objcopy", "--add-gnu-debuglink=$debugLibrary", library |
| 82 | } |
| 83 | secondObjcopy.dependsOn strip |
| 84 | strip.dependsOn firstObjcopy |
| 85 | binary.tasks.whenObjectAdded { task -> |
| 86 | if (task.name.contains('link')) { |
| 87 | firstObjcopy.dependsOn task |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | releaseTasks.each { it.dependsOn project.tasks.getByName("secondObjcopy${binary.name}") } |
| 92 | } |
| 93 | } |
| 94 | } |