Switch project to GNU Make + VS Code
This commit is contained in:
parent
973995fb56
commit
fd74076bb8
5 changed files with 242 additions and 95 deletions
126
makefile
Normal file
126
makefile
Normal file
|
@ -0,0 +1,126 @@
|
|||
include local.make
|
||||
|
||||
|
||||
arduino_packages = ~/.arduino15/packages/arduino
|
||||
arduino_lib = $(arduino_packages)/hardware/avr/1.8.6
|
||||
|
||||
|
||||
# Flags
|
||||
debug = -g
|
||||
lto = -flto
|
||||
mcu = -mmcu=atmega32u4
|
||||
optimization = -O3
|
||||
macros = \
|
||||
-D F_CPU=16000000L \
|
||||
-D ARDUINO=10607 \
|
||||
-D ARDUINO_AVR_MICRO \
|
||||
-D ARDUINO_ARCH_AVR \
|
||||
-D USB_PRODUCT='"Arduino Micro"' \
|
||||
-D USB_MANUFACTURER='"Unknown"' \
|
||||
-D USB_VID=0x2341 \
|
||||
-D USB_PID=0x8037
|
||||
header_locations = \
|
||||
-I $(arduino_lib)/cores/arduino \
|
||||
-I $(arduino_lib)/variants/micro
|
||||
|
||||
# Flag sets
|
||||
c_flags = $(debug) $(lto) $(mcu) $(optimization) $(macros) $(header_locations) \
|
||||
-std=gnu11 \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-fno-fat-lto-objects
|
||||
cplusplus_flags = $(debug) $(lto) $(mcu) $(optimization) $(macros) $(header_locations) \
|
||||
-std=gnu++11 \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-fpermissive \
|
||||
-fno-exceptions \
|
||||
-fno-threadsafe-statics \
|
||||
-Wno-error=narrowing
|
||||
assembly_flags = $(debug) $(lto) $(mcu) $(macros) $(header_locations)
|
||||
linking_flags = $(debug) $(lto) $(mcu) $(optimization) \
|
||||
-fuse-linker-plugin \
|
||||
-Wl,--gc-sections \
|
||||
-lm
|
||||
|
||||
|
||||
build/kulifuli-cpp.o : src/main.cpp
|
||||
mkdir -p build
|
||||
avr-g++ -c $(cplusplus_flags) -o $@ $<
|
||||
|
||||
build/arduino-lib/%-cpp.o : $(arduino_lib)/cores/arduino/%.cpp
|
||||
mkdir -p build/arduino-lib
|
||||
avr-g++ -c $(cplusplus_flags) -o $@ $<
|
||||
|
||||
build/arduino-lib/%-c.o : $(arduino_lib)/cores/arduino/%.c
|
||||
mkdir -p build/arduino-lib
|
||||
avr-gcc -c $(c_flags) -o $@ $<
|
||||
|
||||
build/arduino-lib/%-s.o : $(arduino_lib)/cores/arduino/%.S
|
||||
mkdir -p build/arduino-lib
|
||||
avr-gcc -c $(assembly_flags) -x assembler-with-cpp -o $@ $<
|
||||
|
||||
core_objects = $(addprefix build/arduino-lib/, \
|
||||
abi-cpp.o \
|
||||
CDC-cpp.o \
|
||||
HardwareSerial-cpp.o \
|
||||
HardwareSerial1-cpp.o \
|
||||
new-cpp.o \
|
||||
PluggableUSB-cpp.o \
|
||||
Print-cpp.o \
|
||||
Stream-cpp.o \
|
||||
USBCore-cpp.o \
|
||||
WMath-cpp.o \
|
||||
WString-cpp.o \
|
||||
hooks-c.o \
|
||||
WInterrupts-c.o \
|
||||
wiring_analog-c.o \
|
||||
wiring_digital-c.o \
|
||||
wiring_pulse-c.o \
|
||||
wiring_shift-c.o \
|
||||
wiring-c.o \
|
||||
wiring_pulse-s.o \
|
||||
)
|
||||
|
||||
build/arduino-lib/core.a : $(core_objects)
|
||||
avr-gcc-ar rcs $@ $^
|
||||
|
||||
# The order of the prerequisites is significant here for GCC
|
||||
build/kulifuli.elf : build/kulifuli-cpp.o build/arduino-lib/core.a
|
||||
avr-gcc $(linking_flags) -o $@ $^
|
||||
|
||||
build/kulifuli.eep : build/kulifuli.elf
|
||||
avr-objcopy \
|
||||
--output-target=ihex \
|
||||
--only-section=.eeprom \
|
||||
--set-section-flags=.eeprom=alloc,load \
|
||||
--no-change-warnings \
|
||||
--change-section-lma .eeprom=0 \
|
||||
$< $@
|
||||
|
||||
build/kulifuli.hex : build/kulifuli.elf
|
||||
avr-objcopy \
|
||||
--output-target=ihex \
|
||||
--remove-section=.eeprom \
|
||||
$< $@
|
||||
|
||||
|
||||
.PHONY : build
|
||||
build : build/kulifuli.eep build/kulifuli.hex
|
||||
|
||||
.PHONY : upload
|
||||
upload : build/kulifuli.hex
|
||||
stty --file=$(arduino_serial_port) speed 1200 > /dev/null
|
||||
sleep 1
|
||||
avrdude \
|
||||
--part atmega32u4 \
|
||||
--programmer avr109 \
|
||||
--memory flash:w:build/kulifuli.hex:i \
|
||||
--noverify-memory \
|
||||
--noerase \
|
||||
--port $(arduino_serial_port) \
|
||||
--baud 57600
|
||||
|
||||
.PHONY : clean
|
||||
clean :
|
||||
rm -rf build/*
|
Loading…
Add table
Add a link
Reference in a new issue