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_NASM = nasm |
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_INCLUDE = "include/arduino/" |
23 |
|
24 | ARDUINO_CORE_CXX_SRC = $(shell find include/arduino -name '*.cpp') |
25 | ARDUINO_CORE_C_SRC = $(shell find include/arduino -name '*.c') |
26 | ARDUINO_CORE_ASM_SRC = $(shell find include/arduino -name '*.S') |
27 |
|
28 | ARD1_SOURCES = $(shell find src/ard1 -name '*.cpp') |
29 |
|
30 | ARDUINO_CORE_C = $(ARDUINO_CORE_C_SRC:%.c=%.o) |
31 | ARDUINO_CORE_CXX = $(ARDUINO_CORE_CXX_SRC:%.cpp=%.o) |
32 | ARDUINO_CORE_ASM = $(ARDUINO_CORE_ASM_SRC:%.S=%.o) |
33 |
|
34 | ARD1_OBJECTS = $(ARD1_SOURCES:%.cpp=%.o) |
35 |
|
36 | ARD1_OUT = bin/ard1.hex |
37 |
|
38 |
|
39 |
|
40 | .PHONY: all ard1-build |
41 |
|
42 | all: $(OUT) |
43 |
|
44 | $(OUT): $(OBJECTS) |
45 | $(CC) $(CFLAGS) $(OBJECTS) -o $(OUT) |
46 |
|
47 | $(OBJECTS): $(SOURCES) |
48 | $(CC) -c $(CFLAGS) $(SOURCES) |
49 |
|
50 |
|
51 | ard1-build: $(ARD1_OUT) |
52 |
|
53 | %.o: %.c |
54 | @echo |
55 | @echo Compiling Arduino C file: $< to $@ |
56 | $(ARDUINO_CC) $(ARDUINO_CFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
57 |
|
58 | %.o: %.cpp |
59 | @echo |
60 | @echo Compiling Arduino C++ file: $< to $@ |
61 | $(ARDUINO_CXX) $(ARDUINO_CXXFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
62 |
|
63 | %.o: %.S |
64 | @echo |
65 | @echo Compiling Arduino Assembly file: $< to $@ |
66 | $(ARDUINO_CC) $(ARDUINO_CFLAGS) -I $(ARDUINO_INCLUDE) $< -o $@ |
67 |
|
68 |
|
69 | $(ARD1_OUT): $(ARD1_OBJECTS) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_C) $(ARDUINO_CORE_ASM) |
70 | @echo |
71 | @echo Compiling Arduino objects to hex file |
72 | $(ARDUINO_CC) -Os -Wl,-Map,bin/main.map --gc-sections -mmcu=$(MCU) $(ARD1_OBJECTS) $(ARDUINO_CORE_CXX) $(ARDUINO_CORE_C) $(ARDUINO_CORE_ASM) -o bin/main.elf |
73 | $(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 |
74 | $(ARDUINO_OBJCOPY) -O ihex -R .eeprom bin/main.elf $@ |
75 |
|