From a46e503a30e6ab8adef0f4b1c2a12c8fc9c162cb Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 4 Apr 2014 10:33:20 +0200 Subject: [PATCH 1/3] Allow overriding platform.txt using platform.local.txt This helps advanced users that want to change options (e.g. to use a different toolchain or enable warnings), without having to change platform.txt (which could make git report changed files all the time). --- app/src/processing/app/debug/TargetPlatform.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index da4a1b28a..3dfb29f6e 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -110,6 +110,20 @@ public class TargetPlatform { format(_("Error loading {0}"), platformsFile.getAbsolutePath()), e); } + // Allow overriding values in platform.txt. This allows changing + // platform.txt (e.g. to use a system-wide toolchain), without + // having to modify platform.txt (which, when running from git, + // prevents files being marked as changed). + File localPlatformsFile = new File(folder, "platform.local.txt"); + try { + if (localPlatformsFile.exists() && localPlatformsFile.canRead()) { + preferences.load(localPlatformsFile); + } + } catch (IOException e) { + throw new TargetPlatformException( + format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e); + } + File progFile = new File(folder, "programmers.txt"); try { if (progFile.exists() && progFile.canRead()) { From d2ec05611cb66ad3d894bc7a2538c3bbf434fe27 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 4 Apr 2014 11:31:50 +0200 Subject: [PATCH 2/3] Add (empty) compiler.*.extra_flags variables in platform.txt These make it easier for a user to add extra compiler flags in a platform.local.txt file. --- hardware/arduino/avr/platform.txt | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index 78f530aa4..d1b5fd3ef 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -28,32 +28,42 @@ compiler.elf2hex.flags=-O ihex -R .eeprom compiler.elf2hex.cmd=avr-objcopy compiler.ldflags= compiler.size.cmd=avr-size -# this can be overriden in boards.txt + +# This can be overriden in boards.txt build.extra_flags= +# These can be overridden in platform.local.txt +compiler.c.extra_flags= +compiler.c.elf.extra_flags= +compiler.S.extra_flags= +compiler.cpp.extra_flags= +compiler.ar.extra_flags= +compiler.objcopy.eep.extra_flags= +compiler.elf2hex.extra_flags= + # AVR compile patterns # -------------------- ## Compile c files -recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Compile c++ files -recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Compile S files -recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" +recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.S.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" ## Create archives -recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} "{build.path}/{archive_file}" "{object_file}" +recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "-L{build.path}" -lm ## Create eeprom -recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" +recipe.objcopy.eep.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.objcopy.eep.flags} {compiler.objcopy.eep.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep" ## Create hex -recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" +recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex" ## Compute size recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" From a89f5e68cf5cc5e323d099cb798dfd9cc6c0c11a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 4 Apr 2014 12:04:57 +0200 Subject: [PATCH 3/3] Explicitly define compiler.path in avr/platform.txt Previously, this relied on an (ugly, avr-specific) magic default for the compiler.path variable, set by the IDE. This allowed the IDE to fall back to a system-wide toolchain when no bundled toolchain was found (by making compiler.path empty). However, - this only worked for avr, not sam, - this worked only for gcc, a system-wide avrdude would break on the avrdude.conf path in platform.txt, and This would mean that automatic system-wide fallback didn't work in all situations, so you'd still have to modify platform.txt (or create platform.local.txt). Since doing that explictly is the most reliable way, this commit removes the partial-working ability to do this automatically. Note that the code to automatically set compiler.path is still kept around, in case third-party hardware still relies on this. At some point, this code should be removed, but for now it just shows a warning message. --- app/src/processing/app/debug/Compiler.java | 8 +++++++- hardware/arduino/avr/platform.txt | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index a3f8940a7..92f25a1c5 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -197,8 +197,14 @@ public class Compiler implements MessageConsumer { targetArch = targetPlatform.getId(); p.put("build.arch", targetArch.toUpperCase()); - if (!p.containsKey("compiler.path")) + // Platform.txt should define its own compiler.path. For + // compatibility with earlier 1.5 versions, we define a (ugly, + // avr-specific) default for it, but this should be removed at some + // point. + if (!p.containsKey("compiler.path")) { + System.err.println(_("Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer.")); p.put("compiler.path", Base.getAvrBasePath()); + } // Core folder TargetPlatform tp = corePlatform; diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index d1b5fd3ef..58af56b07 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -12,7 +12,7 @@ version=1.5.6 # --------------------- # Default "compiler.path" is correct, change only if you want to overidde the initial value -#compiler.path={ide.path}/tools/avr/bin/.. +compiler.path={runtime.ide.path}/hardware/tools/avr/bin/ compiler.c.cmd=avr-gcc compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD compiler.c.elf.flags=-Os -Wl,--gc-sections