1 | # Raspberry Pi settings |
2 | CC = gcc --std=c11 |
3 | CCFLAGS = -Wall -Wextra -pedantic -Os |
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 -w -Os -MMD -ffunction-sections -fdata-sections -DF_CPU=$(F_CPU) -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -mmcu=$(MCU) |
19 | ARDUINO_CC_FLAGS = $(ARDUINO_FLAGS) |
20 | ARDUINO_CXX_FLAGS = $(ARDUINO_FLAGS) -fno-exceptions |
21 |
|
22 | ARDUINO_INCLUDE = "include/arduino/" |
23 | ARDUINO_CORE_CXX_SRC = $(shell find include/arduino -name '*.cpp') |
24 | ARDUINO_CORE_CXX = $(ARDUINO_CORE_CXX_SRC:cpp=o) |
25 | ARDUINO_CORE_CC_SRC = $(shell find include/arduino -name '*.c') |
26 | ARDUINO_CORE_CC = $(ARDUINO_CORE_CC_SRC:c=o) |
27 |
|
28 | ARD1_SOURCES = $(shell find src/ard1 -name '*.cpp') |
29 | ARD1_OBJECTS = $(ARD1_SOURCES:%.cpp=%.o) |
30 | ARD1_OUT = bin/ard1.hex |
31 | # ARD2_SOURCES = $(shell find src/ard2 -name '*.cpp') |
32 |
|
33 | ARDUINO_ALL_OBJECTS := $(ARD1_OBJECTS) |
34 | ARDUINO_ALL_OBJECTS += $(ARDUINO_CORE_CXX) |
35 | ARDUINO_ALL_OBJECTS += $(ARDUINO_CORE_CC) |
36 |
|
37 | .PHONY: all ard1-build |
38 |
|
39 | all: $(OUT) |
40 |
|
41 | $(OUT): $(OBJECTS) |
42 | $(CC) $(CCFLAGS) $(OBJECTS) -o $(OUT) |
43 |
|
44 |
|
45 | ard1-build: $(ARD1_OUT) |
46 |
|
47 | $(ARDUINO_CORE_CC): $(ARDUINO_CORE_CC_SRC) |
48 | $(ARDUINO_CC) $(ARDUINO_CC_FLAGS) -I$(ARDUINO_INCLUDE) $< -o $@ |
49 |
|
50 | $(ARDUINO_CORE_CXX): $(ARDUINO_CORE_CXX_SRC) |
51 | $(ARDUINO_CXX) $(ARDUINO_CXX_FLAGS) -I$(ARDUINO_INCLUDE) $< -o $@ |
52 |
|
53 | $(ARD1_OBJECTS): $(ARD1_SOURCES) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_CC) |
54 | $(ARDUINO_CXX) $(ARDUINO_CXX_FLAGS) -I$(ARDUINO_INCLUDE) $< -o $@ |
55 |
|
56 |
|
57 | $(ARD1_OUT): $(ARDUINO_ALL_OBJECTS) $(ARD1_OBJECTS) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_CC) |
58 | $(ARDUINO_AR) rcs core.a $< |
59 | $(ARDUINO_CC) -Os -Wl,--gc-sections -mmcu=$(MCU) -o $(ARD1_SOURCES:cpp=elf) $(ARD1_OBJECTS) core.a -lm |
60 | $(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) |
61 | $(ARDUINO_OBJCOPY) -O ihex -R .eeprom $(ARD1_SOURCES:cpp=elf) $@ |
62 | rm core.a |
63 |
|