1 | # Raspberry Pi settings |
2 | CC = gcc --std=c11 |
3 | CCFLAGS = -Wall -Wextra -pedantic -O3 -g |
4 | SOURCES = $(shell find src/rpi -name '*.c') |
5 | OBJECTS = $(SOURCES:%.c=%.o) |
6 | OUT = autoplow |
7 |
|
8 |
|
9 | # Arduino Settings |
10 | F_CPU = 16000000L |
11 | MCU = atmega328p |
12 |
|
13 | ARDUINO_CC = avr-gcc |
14 | ARDUINO_CXX = avr-g++ |
15 | ARDUINO_AR = avr-ar |
16 | ARDUINO_OBJCOPY = avr-objcopy |
17 |
|
18 | ARDUINO_FLAGS = -c -g -Os -Wall -Wextra -pedantic -MMD -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(F_CPU) -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 |
19 | ARDUINO_CC_FLAGS = $(ARDUINO_FLAGS) |
20 | ARDUINO_CXX_FLAGS = $(ARDUINO_FLAGS) -fno-exceptions |
21 |
|
22 | ARDUINO_INCLUDE = "include/arduino/" |
23 |
|
24 | ARD1_SOURCES = $(shell find src/ard1 -name '*.cpp') |
25 | ARD1_CORE_CXX = $(shell find include/arduino -name '*.cpp') |
26 | ARD1_CORE_CC = $(shell find include/arduino -name '*.c') |
27 | ARD1_OUT = bin/ard1.hex |
28 | # ARD2_SOURCES = $(shell find src/ard2 -name '*.cpp') |
29 |
|
30 |
|
31 | .PHONY: all ard1-build ard1-upload |
32 |
|
33 | all: $(OUT) $(OBJECTS) |
34 |
|
35 | $(OUT): $(OBJECTS) |
36 | $(CC) $(CCFLAGS) $(OBJECTS) -o $(OUT) |
37 |
|
38 | ard1-build: $(ARD1_OUT) $(ARD1_SOURCES) $(ARD1_CORE_CXX) $(ARD1_CORE_CC) |
39 | $(ARDUINO_CXX) $(ARDUINO_CXX_FLAGS) -I$(ARDUINO_INCLUDE) $(ARD1_CORE_CC) -o $(ARD1_CORE_CC:%.c=%.o) |
40 | $(ARDUINO_CXX) $(ARDUINO_CXX_FLAGS) -I$(ARDUINO_INCLUDE) $(ARD1_CORE_CXX) -o $(ARD1_CORE_CXX:%.cpp=%.o) |
41 | $(ARDUINO_CXX) $(ARDUINO_CXX_FLAGS) -I$(ARDUINO_INCLUDE) $(ARD1_SOURCES) -o $(ARD1_SOURCES:%.cpp=%.o) |
42 | $(ARDUINO_AR) rcs core.a $(shell find include/arduino -name '*.o') |
43 | $(ARDUINO_AR) rcs core.a $(ARD1_SOURCES:%.cpp:%.o) |
44 | $(ARDUINO_CC) -Os -Wl,--gc-sections -mmcu=$(MCU) -o $(ARD1_SOURCES:%.cpp:%.elf) $(ARD1_SOURCES:%.cpp:%.o) core.a -lm |
45 | $(ARDUINO_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $(ARD1_SOURCES:%.cpp:%.elf) $(ARD1_SOURCES:%.cpp:%.eep) |
46 | $(ARDUINO_OBJCOPY) -O ihex -R .eeprom $(ARD1_SOURCES:%.cpp:%.elf) $(ARD1_OUT) |
47 | rm core.a |
48 |
|