diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 29953666dd5..d01f57c3a85 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -196,7 +196,8 @@ public boolean compile(Sketch sketch, List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", - "-Wl,--gc-sections"+optRelax, + (Preferences.get("build.linker_options")!= null ? Preferences.get("build.linker_options")+optRelax : + "-Wl,--gc-sections"+optRelax), "-mmcu=" + boardPreferences.get("build.mcu"), "-o", buildPath + File.separator + primaryClassName + ".elf" @@ -208,8 +209,14 @@ public boolean compile(Sketch sketch, baseCommandLinker.add(runtimeLibraryName); baseCommandLinker.add("-L" + buildPath); - baseCommandLinker.add("-lm"); - + if (Preferences.get("build.linker_additional_options") != null) { + for (String addopt : Preferences.get("build.linker_additional_options").split(" ")) { + baseCommandLinker.add(addopt); + } + } else { + baseCommandLinker.add("-lm"); + } + execAsynchronously(baseCommandLinker); List baseCommandObjcopy = new ArrayList(Arrays.asList(new String[] { diff --git a/build/shared/examples/8.Strings/lprintfscanf_test/lprintfscanf_test.ino b/build/shared/examples/8.Strings/lprintfscanf_test/lprintfscanf_test.ino new file mode 100644 index 00000000000..25638cd01ae --- /dev/null +++ b/build/shared/examples/8.Strings/lprintfscanf_test/lprintfscanf_test.ino @@ -0,0 +1,82 @@ +/* + lprintfscanf_test sketch + by George Schreiber + 2012.03.26. + + this sketch does nothing but verifies if the binary has been linked with the float-capable versions + of printf and scanf. + + to link these libraries, a patched version of Arduino IDE (or other options to tweak with the AVR linker options) + is necessary. + + to go with a patched version of Arduino(TM)-1.0, download and build sources from http://github.com/srejbi/Arduino.git + + then add to the user's Arduino preferences.txt: + build.linker_options=-Wl,-u,vfprintf,-u,vfscanf,--gc-sections + build.linker_additional_options=-lprintf_flt -lscanf_flt -lm + + re-compile, upload and enjoy! +*/ + + +boolean testprintf(); // test function for printf +boolean testscanf(); // test function for scanf +void printscan(); // a dummy function that relies on the float-enabled versions of printf/scanf + +void setup(void) { + Serial.begin(57600); + Serial.println("printf/scanf linking tester"); + if (testprintf() && testscanf()) printscan(); +} + +void loop(void) { + // we're done already. +} + +// checks printf float behaviour with known value +boolean testprintf() { + float ftest = 0; + + char sztest[10] =""; + sprintf(sztest,"%.4f", 2012.0326); // print 2012.0326 to string + Serial.print(sztest); + Serial.print(" - version of printf linked: "); + if (sztest[0] == '?') { // minimal version + Serial.println("minimal"); + } else if (strstr(sztest,"2012.0326")==sztest) { // if float conversion was ok + Serial.println("float-capable"); + return true; + } else { // something unexpected happened... + Serial.println("wtf?"); + } + return false; +} + +// checks sscanf float behaviour with known value +boolean testscanf() { + float ftest = 0; + + sscanf("2012.0326","%f", &ftest); // scan 2012.0326 from string + Serial.print(ftest,4); + Serial.print(" - version of scanf linked:"); + if (ftest == 0) { // if no value, we have minimal version + Serial.println("minimal"); + } else if (ftest == 2012.0326 ) { // if the value matches, we're good + Serial.println("float-capable"); + return true; + } else { // expecting the unexpected + Serial.println("wtf?"); + } + return false; +} + +// happy to print what it scans :) +void printscan() { + char szbuf[10]; + float tfloat = 0; + sscanf("2012.0326","%f",&tfloat); + sprintf(szbuf,"%.4f",tfloat); + Serial.print("Oh happy day:"); + Serial.println(szbuf); +} +