Implemented "build_flags" option for environments // closed issue #4

This commit is contained in:
Ivan Kravets
2014-06-21 22:27:58 +03:00
parent fd1fc9941a
commit a2402c31b7
10 changed files with 62 additions and 43 deletions

View File

@@ -1,11 +1,14 @@
Release History Release History
=============== ===============
0.3.0 (?) 0.3.0 (2014-06-21)
--------- ---------
* Allowed to pass multiple "SomePlatform" to install/uninstall commands * Allowed to pass multiple "SomePlatform" to install/uninstall commands
* Added "IDE Integration" section to README with Eclipse project examples * Added "IDE Integration" section to README with Eclipse project examples
* Created auto installer script for *PlatformIO* (`issue #3 <https://github.com/ivankravets/platformio/issues/3>`_)
* Added "Super-Quick" way to Installation section (README)
* Implemented "build_flags" option for environments (`issue #4 <https://github.com/ivankravets/platformio/issues/4>`_)
0.2.0 (2014-06-15) 0.2.0 (2014-06-15)

View File

@@ -16,3 +16,4 @@ board = lpmsp430g2553
platform = titiva platform = titiva
framework = energia framework = energia
board = lplm4f120h5qr board = lplm4f120h5qr
build_flags = "-DLED_PIN=GREEN_LED"

View File

@@ -8,27 +8,22 @@
with intervals of 1 second (1000 milliseconds) with intervals of 1 second (1000 milliseconds)
*/ */
#ifdef ENERGIA
#include "Energia.h"
#define WLED RED_LED
#else
#include "Arduino.h" #include "Arduino.h"
#define WLED 13 // Most Arduino boards already have an LED attached to pin 13 on the board itself
#ifndef LED_PIN
#define LED_PIN 13 // Most Arduino boards already have an LED attached to pin 13 on the board itself
#endif #endif
void setup() void setup()
{ {
pinMode(WLED, OUTPUT); // set pin as output pinMode(LED_PIN, OUTPUT); // set pin as output
} }
void loop() void loop()
{ {
digitalWrite(WLED, HIGH); // set the LED on digitalWrite(LED_PIN, HIGH); // set the LED on
delay(1000); // wait for a second delay(1000); // wait for a second
digitalWrite(WLED, LOW); // set the LED off digitalWrite(LED_PIN, LOW); // set the LED off
delay(1000); // wait for a second delay(1000); // wait for a second
} }

View File

@@ -16,6 +16,7 @@ commonvars.AddVariables(
("PIOENV",), ("PIOENV",),
("PLATFORM",), ("PLATFORM",),
("FRAMEWORK",), ("FRAMEWORK",),
("BUILD_FLAGS",),
# board options # board options
("BOARD",), ("BOARD",),

View File

@@ -26,9 +26,9 @@ env.Replace(
ASFLAGS=[ ASFLAGS=[
"-g", # include debugging info (so errors include line numbers) "-g", # include debugging info (so errors include line numbers)
"-x", "assembler-with-cpp", "-x", "assembler-with-cpp",
"-mmcu=$BOARD_MCU", "-mmcu=$BOARD_MCU"
"-DF_CPU=$BOARD_F_CPU"
], ],
CCFLAGS=[ CCFLAGS=[
"-g", # include debugging info (so errors include line numbers) "-g", # include debugging info (so errors include line numbers)
"-Os", # optimize for size "-Os", # optimize for size
@@ -36,11 +36,15 @@ env.Replace(
"-ffunction-sections", # place each function in its own section "-ffunction-sections", # place each function in its own section
"-fdata-sections", "-fdata-sections",
"-MMD", # output dependancy info "-MMD", # output dependancy info
"-mmcu=$BOARD_MCU", "-mmcu=$BOARD_MCU"
"-DF_CPU=$BOARD_F_CPU"
], ],
CXXFLAGS=["-fno-exceptions"], CXXFLAGS=["-fno-exceptions"],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU"
],
LINKFLAGS=[ LINKFLAGS=[
"-Os", "-Os",
"-Wl,--gc-sections", "-Wl,--gc-sections",
@@ -62,6 +66,9 @@ env.Replace(
UPLOADEEPCMD="$UPLOADER $UPLOADERFLAGS -U eeprom:w:$SOURCES:i" UPLOADEEPCMD="$UPLOADER $UPLOADERFLAGS -U eeprom:w:$SOURCES:i"
) )
if "BUILD_FLAGS" in env:
env.MergeFlags(env['BUILD_FLAGS'])
env.Append( env.Append(
BUILDERS=dict( BUILDERS=dict(
ElfToEep=Builder( ElfToEep=Builder(

View File

@@ -19,18 +19,14 @@ BOARD_OPTIONS = env.ParseBoardOptions(
ARDUINO_VERSION = int( ARDUINO_VERSION = int(
open(join(env.subst("$PLATFORMFW_DIR"), open(join(env.subst("$PLATFORMFW_DIR"),
"version.txt")).read().replace(".", "").strip()) "version.txt")).read().replace(".", "").strip())
ARDUINO_FLAGS = [
"-DARDUINO=%d" % ARDUINO_VERSION,
"-DARDUINO_%s" % BOARD_OPTIONS['build.board']
]
# usb flags # usb flags
ARDUINO_USBDEFINES = []
if "build.usb_product" in BOARD_OPTIONS: if "build.usb_product" in BOARD_OPTIONS:
ARDUINO_FLAGS += [ ARDUINO_USBDEFINES = [
"-DUSB_VID=%s" % BOARD_OPTIONS['build.vid'], "USB_VID=%s" % BOARD_OPTIONS['build.vid'],
"-DUSB_PID=%s" % BOARD_OPTIONS['build.pid'], "USB_PID=%s" % BOARD_OPTIONS['build.pid'],
"-DUSB_PRODUCT=%s" % BOARD_OPTIONS['build.usb_product'].replace( "USB_PRODUCT=%s" % BOARD_OPTIONS['build.usb_product'].replace('"', "")
'"', "")
] ]
# include board variant # include board variant
@@ -40,8 +36,10 @@ env.VariantDir(
) )
env.Append( env.Append(
ASFLAGS=ARDUINO_FLAGS, CPPDEFINES=[
CCFLAGS=ARDUINO_FLAGS, "ARDUINO=%d" % ARDUINO_VERSION,
"ARDUINO_%s" % BOARD_OPTIONS['build.board']
] + ARDUINO_USBDEFINES,
CPPPATH=[ CPPPATH=[
join("$BUILD_DIR", "core"), join("$BUILD_DIR", "core"),
join("$BUILD_DIR", "variant") join("$BUILD_DIR", "variant")

View File

@@ -19,10 +19,6 @@ BOARD_OPTIONS = env.ParseBoardOptions(
ENERGIA_VERSION = int( ENERGIA_VERSION = int(
open(join(env.subst("$PLATFORMFW_DIR"), open(join(env.subst("$PLATFORMFW_DIR"),
"version.txt")).read().replace(".", "").strip()) "version.txt")).read().replace(".", "").strip())
ENERGIA_FLAGS = [
"-DARDUINO=101",
"-DENERGIA=%d" % ENERGIA_VERSION
]
# include board variant # include board variant
env.VariantDir( env.VariantDir(
@@ -31,8 +27,10 @@ env.VariantDir(
) )
env.Append( env.Append(
ASFLAGS=ENERGIA_FLAGS, CPPDEFINES=[
CCFLAGS=ENERGIA_FLAGS, "ARDUINO=101",
"ENERGIA=%d" % ENERGIA_VERSION
],
CPPPATH=[ CPPPATH=[
join("$BUILD_DIR", "core"), join("$BUILD_DIR", "core"),
join("$BUILD_DIR", "variant") join("$BUILD_DIR", "variant")

View File

@@ -28,9 +28,9 @@ env.Replace(
ASFLAGS=[ ASFLAGS=[
"-g", # include debugging info (so errors include line numbers) "-g", # include debugging info (so errors include line numbers)
"-x", "-assembler-with-cpp", "-x", "-assembler-with-cpp",
"-mmcu=$BOARD_MCU", "-mmcu=$BOARD_MCU"
"-DF_CPU=$BOARD_F_CPU"
], ],
CCFLAGS=[ CCFLAGS=[
"-g", # include debugging info (so errors include line numbers) "-g", # include debugging info (so errors include line numbers)
"-Os", # optimize for size "-Os", # optimize for size
@@ -38,8 +38,11 @@ env.Replace(
"-ffunction-sections", # place each function in its own section "-ffunction-sections", # place each function in its own section
"-fdata-sections", "-fdata-sections",
"-MMD", # output dependancy info "-MMD", # output dependancy info
"-mmcu=$BOARD_MCU", "-mmcu=$BOARD_MCU"
"-DF_CPU=$BOARD_F_CPU" ],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU"
], ],
LINK="$CC", LINK="$CC",
@@ -57,6 +60,9 @@ env.Replace(
UPLOADCMD='$UPLOADER $UPLOADERFLAGS "prog $SOURCES"' UPLOADCMD='$UPLOADER $UPLOADERFLAGS "prog $SOURCES"'
) )
if "BUILD_FLAGS" in env:
env.MergeFlags(env['BUILD_FLAGS'])
env.Append( env.Append(
BUILDERS=dict( BUILDERS=dict(
ElfToHex=Builder( ElfToHex=Builder(

View File

@@ -31,8 +31,7 @@ env.Replace(
"-mcpu=cortex-m4", "-mcpu=cortex-m4",
"-mfloat-abi=hard", "-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16", "-mfpu=fpv4-sp-d16",
"-fsingle-precision-constant", "-fsingle-precision-constant"
"-DF_CPU=$BOARD_F_CPU"
], ],
CCFLAGS=[ CCFLAGS=[
@@ -47,8 +46,7 @@ env.Replace(
"-mfloat-abi=hard", "-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16", "-mfpu=fpv4-sp-d16",
"-fsingle-precision-constant", "-fsingle-precision-constant",
"-MMD", # output dependancy info "-MMD" # output dependancy info
"-DF_CPU=$BOARD_F_CPU"
], ],
CXXFLAGS=[ CXXFLAGS=[
@@ -56,6 +54,10 @@ env.Replace(
"-fno-exceptions" "-fno-exceptions"
], ],
CPPDEFINES=[
"F_CPU=$BOARD_F_CPU"
],
LINKFLAGS=[ LINKFLAGS=[
"-Os", "-Os",
"-nostartfiles", "-nostartfiles",
@@ -73,6 +75,9 @@ env.Replace(
UPLOADCMD="$UPLOADER $SOURCES" UPLOADCMD="$UPLOADER $SOURCES"
) )
if "BUILD_FLAGS" in env:
env.MergeFlags(env['BUILD_FLAGS'])
env.Append( env.Append(
BUILDERS=dict( BUILDERS=dict(
ElfToBin=Builder( ElfToBin=Builder(

View File

@@ -11,6 +11,11 @@
#[env:mybaseenv] #[env:mybaseenv]
#platform = %INSTALLED_PLATFORM_NAME_HERE% #platform = %INSTALLED_PLATFORM_NAME_HERE%
# Environment with specific build flags
#[env:specbuildflags]
#platform = %INSTALLED_PLATFORM_NAME_HERE%
#build_flags = "-I/opt/include -L/opt/lib -lfoo -DMYDEFINE=13"
# #
# Atmel AVR based board # Atmel AVR based board
# #