define-options.ino
byte localAddress = LOCAL_ADDRESS;
byte destinationAddress = DESTINATION_ADDRESS;
void setup() {
Serial.begin(9600);
Serial.println("Define options...");
}
void loop() {
Serial.println("\nLocal address: " + String(localAddress, HEX));
Serial.println("Destination address: " + String(destinationAddress, HEX));
delay(1000);
}
BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*
BUILD=build
.PHONY: default lint all flash clean
default: lint compile_a flash clean
a: lint compile_a flash clean
b: lint compile_b flash clean
compile_a:
arduino-cli compile --clean --fqbn $(BOARD) --build-property compiler.cpp.extra_flags="-DLOCAL_ADDRESS=0xAA -DDESTINATION_ADDRESS=0xBB" --output-dir $(BUILD) ./
compile_b:
arduino-cli compile --clean --fqbn $(BOARD) --build-property compiler.cpp.extra_flags="-DLOCAL_ADDRESS=0xBB -DDESTINATION_ADDRESS=0xAA" --output-dir $(BUILD) ./
lint:
cpplint --extensions=ino --filter=-legal/copyright,-whitespace/line_length,-readability/casting,-readability/todo,-runtime/int *.ino
flash:
arduino-cli upload -p $(PORT) --fqbn $(BOARD) --input-dir $(BUILD) --verbose
clean:
rm -r build
Create options in using different variable values with #define
statement. The advantage of this method is that the same codebase can be used for different options.
Run command make a
to put the LOCAL_ADDRESS
value as 0xAA
.
Run make b
to put the LOCAL_ADDRESS
value as 0xBB
.
The make
command will run the arduino-cli compile
with options to #define
the LOCAL_ADDRESS
and DESTINATION_ADDRESS
values.
arduino-cli compile --clean --fqbn $(BOARD) --build-property compiler.cpp.extra_flags="-DLOCAL_ADDRESS=0xBB -DDESTINATION_ADDRESS=0xAA" --output-dir $(BUILD) ./