1 | # Raspberry Pi settings |
2 | CC = gcc --std=c18 |
3 | CFLAGS = -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_AVRDUDE = avrdude |
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_CFLAGS = $(ARDUINO_FLAGS) |
20 | ARDUINO_CXXFLAGS = $(ARDUINO_FLAGS) -fno-exceptions |
21 |
|
22 | ARDUINO_AVRDUDE_CONF = "include/arduino/avrdude.conf" |
23 | ARDUINO_INCLUDE = "include/arduino/" |
24 |
|
25 | ARDUINO_CORE_CXX_SRC = $(shell find include/arduino -name '*.cpp') |
26 | ARDUINO_CORE_C_SRC = $(shell find include/arduino -name '*.c') |
27 | ARDUINO_CORE_ASM_SRC = $(shell find include/arduino -name '*.S') |
28 |
|
29 | ARD1_SOURCES = $(shell find src/ard1 -name '*.cpp') |
30 |
|
31 | ARDUINO_CORE_C = $(ARDUINO_CORE_C_SRC:%.c=%.o) |
32 | ARDUINO_CORE_CXX = $(ARDUINO_CORE_CXX_SRC:%.cpp=%.o) |
33 | ARDUINO_CORE_ASM = $(ARDUINO_CORE_ASM_SRC:%.S=%.o) |
34 |
|
35 | ARD1_OBJECTS = $(ARD1_SOURCES:%.cpp=%.o) |
36 |
|
37 | ARD1_OUT = bin/ard1.hex |
38 |
|
39 |
|
40 |
|
41 | .PHONY: all ard1-build |
42 |
|
43 | all: $(OUT) |
44 |
|
45 | $(OUT): $(OBJECTS) |
46 | $(CC) $(CFLAGS) $(OBJECTS) -o $(OUT) |
47 |
|
48 | $(OBJECTS): $(SOURCES) |
49 | $(CC) -c $(CFLAGS) $(SOURCES) |
50 |
|
51 |
|
52 | ard1-build: $(ARD1_OUT) |
53 |
|
54 | %.o: %.c |
55 | @echo |
56 | @echo Compiling Arduino C file: $< to $@ |
57 | $(ARDUINO_CC) $(ARDUINO_CFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
58 |
|
59 | %.o: %.cpp |
60 | @echo |
61 | @echo Compiling Arduino C++ file: $< to $@ |
62 | $(ARDUINO_CXX) $(ARDUINO_CXXFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
63 |
|
64 | %.o: %.S |
65 | @echo |
66 | @echo Compiling Arduino Assembly file: $< to $@ |
67 | $(ARDUINO_CC) $(ARDUINO_CFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
68 |
|
69 |
|
70 | $(ARD1_OUT): $(ARD1_OBJECTS) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_C) $(ARDUINO_CORE_ASM) |
71 | @echo |
72 | @echo |
73 | @echo |
74 | @echo |
75 | @echo |
76 | @echo Compiling Arduino objects to $(MCU) hex |
77 | $(ARDUINO_CC) -Os -Wl,-Map,bin/main.map -mmcu=$(MCU) $(ARD1_OBJECTS) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_C) $(ARDUINO_CORE_ASM) -o bin/main.elf |
78 | $(ARDUINO_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 bin/main.elf bin/main.eep |
79 | $(ARDUINO_OBJCOPY) -O ihex -R .eeprom bin/main.elf $@ |
80 | @echo |
81 | @echo |
82 | @echo |
83 | @echo |
84 | @echo |
85 | @echo Uploading $(ARD1_OUT) to /dev/ttyACM0 |
86 | $(ARDUINO_AVRDUDE) -C$(ARDUINO_AVRDUDE_CONF) -p$(MCU) -carduino -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(ARD1_OUT):i |
87 |
|