Skip to content

Commit a2402c3

Browse files
committed
Implemented "build_flags" option for environments // closed issue #4
1 parent fd1fc99 commit a2402c3

File tree

10 files changed

+62
-43
lines changed

10 files changed

+62
-43
lines changed

HISTORY.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
Release History
22
===============
33

4-
0.3.0 (?)
4+
0.3.0 (2014-06-21)
55
---------
66

77
* Allowed to pass multiple "SomePlatform" to install/uninstall commands
88
* Added "IDE Integration" section to README with Eclipse project examples
9+
* Created auto installer script for *PlatformIO* (`issue #3 <https://github.com/ivankravets/platformio/issues/3>`_)
10+
* Added "Super-Quick" way to Installation section (README)
11+
* Implemented "build_flags" option for environments (`issue #4 <https://github.com/ivankravets/platformio/issues/4>`_)
912

1013

1114
0.2.0 (2014-06-15)

examples/wiring-blink/platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ board = lpmsp430g2553
1616
platform = titiva
1717
framework = energia
1818
board = lplm4f120h5qr
19+
build_flags = "-DLED_PIN=GREEN_LED"

examples/wiring-blink/src/main.c

+8-13
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,22 @@
88
with intervals of 1 second (1000 milliseconds)
99
*/
1010

11-
#ifdef ENERGIA
12-
13-
#include "Energia.h"
14-
#define WLED RED_LED
15-
16-
#else
17-
1811
#include "Arduino.h"
19-
#define WLED 13 // Most Arduino boards already have an LED attached to pin 13 on the board itself
2012

13+
#ifndef LED_PIN
14+
#define LED_PIN 13 // Most Arduino boards already have an LED attached to pin 13 on the board itself
2115
#endif
2216

17+
2318
void setup()
2419
{
25-
pinMode(WLED, OUTPUT); // set pin as output
20+
pinMode(LED_PIN, OUTPUT); // set pin as output
2621
}
2722

2823
void loop()
2924
{
30-
digitalWrite(WLED, HIGH); // set the LED on
31-
delay(1000); // wait for a second
32-
digitalWrite(WLED, LOW); // set the LED off
33-
delay(1000); // wait for a second
25+
digitalWrite(LED_PIN, HIGH); // set the LED on
26+
delay(1000); // wait for a second
27+
digitalWrite(LED_PIN, LOW); // set the LED off
28+
delay(1000); // wait for a second
3429
}

platformio/builder/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
("PIOENV",),
1717
("PLATFORM",),
1818
("FRAMEWORK",),
19+
("BUILD_FLAGS",),
1920

2021
# board options
2122
("BOARD",),

platformio/builder/scripts/atmelavr.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,25 @@
2626
ASFLAGS=[
2727
"-g", # include debugging info (so errors include line numbers)
2828
"-x", "assembler-with-cpp",
29-
"-mmcu=$BOARD_MCU",
30-
"-DF_CPU=$BOARD_F_CPU"
29+
"-mmcu=$BOARD_MCU"
3130
],
31+
3232
CCFLAGS=[
3333
"-g", # include debugging info (so errors include line numbers)
3434
"-Os", # optimize for size
3535
"-Wall", # show warnings
3636
"-ffunction-sections", # place each function in its own section
3737
"-fdata-sections",
3838
"-MMD", # output dependancy info
39-
"-mmcu=$BOARD_MCU",
40-
"-DF_CPU=$BOARD_F_CPU"
39+
"-mmcu=$BOARD_MCU"
4140
],
41+
4242
CXXFLAGS=["-fno-exceptions"],
4343

44+
CPPDEFINES=[
45+
"F_CPU=$BOARD_F_CPU"
46+
],
47+
4448
LINKFLAGS=[
4549
"-Os",
4650
"-Wl,--gc-sections",
@@ -62,6 +66,9 @@
6266
UPLOADEEPCMD="$UPLOADER $UPLOADERFLAGS -U eeprom:w:$SOURCES:i"
6367
)
6468

69+
if "BUILD_FLAGS" in env:
70+
env.MergeFlags(env['BUILD_FLAGS'])
71+
6572
env.Append(
6673
BUILDERS=dict(
6774
ElfToEep=Builder(

platformio/builder/scripts/frameworks/arduino.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@
1919
ARDUINO_VERSION = int(
2020
open(join(env.subst("$PLATFORMFW_DIR"),
2121
"version.txt")).read().replace(".", "").strip())
22-
ARDUINO_FLAGS = [
23-
"-DARDUINO=%d" % ARDUINO_VERSION,
24-
"-DARDUINO_%s" % BOARD_OPTIONS['build.board']
25-
]
2622

2723
# usb flags
24+
ARDUINO_USBDEFINES = []
2825
if "build.usb_product" in BOARD_OPTIONS:
29-
ARDUINO_FLAGS += [
30-
"-DUSB_VID=%s" % BOARD_OPTIONS['build.vid'],
31-
"-DUSB_PID=%s" % BOARD_OPTIONS['build.pid'],
32-
"-DUSB_PRODUCT=%s" % BOARD_OPTIONS['build.usb_product'].replace(
33-
'"', "")
26+
ARDUINO_USBDEFINES = [
27+
"USB_VID=%s" % BOARD_OPTIONS['build.vid'],
28+
"USB_PID=%s" % BOARD_OPTIONS['build.pid'],
29+
"USB_PRODUCT=%s" % BOARD_OPTIONS['build.usb_product'].replace('"', "")
3430
]
3531

3632
# include board variant
@@ -40,8 +36,10 @@
4036
)
4137

4238
env.Append(
43-
ASFLAGS=ARDUINO_FLAGS,
44-
CCFLAGS=ARDUINO_FLAGS,
39+
CPPDEFINES=[
40+
"ARDUINO=%d" % ARDUINO_VERSION,
41+
"ARDUINO_%s" % BOARD_OPTIONS['build.board']
42+
] + ARDUINO_USBDEFINES,
4543
CPPPATH=[
4644
join("$BUILD_DIR", "core"),
4745
join("$BUILD_DIR", "variant")

platformio/builder/scripts/frameworks/energia.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
ENERGIA_VERSION = int(
2020
open(join(env.subst("$PLATFORMFW_DIR"),
2121
"version.txt")).read().replace(".", "").strip())
22-
ENERGIA_FLAGS = [
23-
"-DARDUINO=101",
24-
"-DENERGIA=%d" % ENERGIA_VERSION
25-
]
2622

2723
# include board variant
2824
env.VariantDir(
@@ -31,8 +27,10 @@
3127
)
3228

3329
env.Append(
34-
ASFLAGS=ENERGIA_FLAGS,
35-
CCFLAGS=ENERGIA_FLAGS,
30+
CPPDEFINES=[
31+
"ARDUINO=101",
32+
"ENERGIA=%d" % ENERGIA_VERSION
33+
],
3634
CPPPATH=[
3735
join("$BUILD_DIR", "core"),
3836
join("$BUILD_DIR", "variant")

platformio/builder/scripts/timsp430.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@
2828
ASFLAGS=[
2929
"-g", # include debugging info (so errors include line numbers)
3030
"-x", "-assembler-with-cpp",
31-
"-mmcu=$BOARD_MCU",
32-
"-DF_CPU=$BOARD_F_CPU"
31+
"-mmcu=$BOARD_MCU"
3332
],
33+
3434
CCFLAGS=[
3535
"-g", # include debugging info (so errors include line numbers)
3636
"-Os", # optimize for size
3737
"-Wall", # show warnings
3838
"-ffunction-sections", # place each function in its own section
3939
"-fdata-sections",
4040
"-MMD", # output dependancy info
41-
"-mmcu=$BOARD_MCU",
42-
"-DF_CPU=$BOARD_F_CPU"
41+
"-mmcu=$BOARD_MCU"
42+
],
43+
44+
CPPDEFINES=[
45+
"F_CPU=$BOARD_F_CPU"
4346
],
4447

4548
LINK="$CC",
@@ -57,6 +60,9 @@
5760
UPLOADCMD='$UPLOADER $UPLOADERFLAGS "prog $SOURCES"'
5861
)
5962

63+
if "BUILD_FLAGS" in env:
64+
env.MergeFlags(env['BUILD_FLAGS'])
65+
6066
env.Append(
6167
BUILDERS=dict(
6268
ElfToHex=Builder(

platformio/builder/scripts/titiva.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"-mcpu=cortex-m4",
3232
"-mfloat-abi=hard",
3333
"-mfpu=fpv4-sp-d16",
34-
"-fsingle-precision-constant",
35-
"-DF_CPU=$BOARD_F_CPU"
34+
"-fsingle-precision-constant"
3635
],
3736

3837
CCFLAGS=[
@@ -47,15 +46,18 @@
4746
"-mfloat-abi=hard",
4847
"-mfpu=fpv4-sp-d16",
4948
"-fsingle-precision-constant",
50-
"-MMD", # output dependancy info
51-
"-DF_CPU=$BOARD_F_CPU"
49+
"-MMD" # output dependancy info
5250
],
5351

5452
CXXFLAGS=[
5553
"-fno-rtti",
5654
"-fno-exceptions"
5755
],
5856

57+
CPPDEFINES=[
58+
"F_CPU=$BOARD_F_CPU"
59+
],
60+
5961
LINKFLAGS=[
6062
"-Os",
6163
"-nostartfiles",
@@ -73,6 +75,9 @@
7375
UPLOADCMD="$UPLOADER $SOURCES"
7476
)
7577

78+
if "BUILD_FLAGS" in env:
79+
env.MergeFlags(env['BUILD_FLAGS'])
80+
7681
env.Append(
7782
BUILDERS=dict(
7883
ElfToBin=Builder(

platformio/projectconftpl.ini

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#[env:mybaseenv]
1212
#platform = %INSTALLED_PLATFORM_NAME_HERE%
1313

14+
# Environment with specific build flags
15+
#[env:specbuildflags]
16+
#platform = %INSTALLED_PLATFORM_NAME_HERE%
17+
#build_flags = "-I/opt/include -L/opt/lib -lfoo -DMYDEFINE=13"
18+
1419
#
1520
# Atmel AVR based board
1621
#

0 commit comments

Comments
 (0)