-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
129 lines (90 loc) · 4.48 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
ARDLIB_DIR = arduino
ARDLIB_SOURCEDIR = $(ARDLIB_DIR)/src
ARDLIB_BUILDDIR = $(ARDLIB_DIR)/build
ARDLIB_INCLUDEDIR = $(ARDLIB_DIR)/include
ARDLIB_SOURCE_FILES = abi.cpp CDC.cpp HardwareSerial0.cpp HardwareSerial1.cpp HardwareSerial2.cpp HardwareSerial3.cpp HardwareSerial.cpp HID.cpp hooks.c IPAddress.cpp new.cpp Print.cpp Stream.cpp Tone.cpp USBCore.cpp WInterrupts.c wiring_analog.c wiring.c wiring_digital.c wiring_pulse.c wiring_pulse.S wiring_shift.c WMath.cpp WString.cpp EEPROM.cpp
ARDLIB_SOURCES = $(patsubst %,$(ARDLIB_SOURCEDIR)/%,$(ARDLIB_SOURCE_FILES))
ARDLIB_OBJECTS = $(patsubst $(ARDLIB_SOURCEDIR)/%,$(ARDLIB_BUILDDIR)/%.o,$(ARDLIB_SOURCES))
SOURCEDIR = src
BUILDDIR = build
EXE = control
CXX = g++
CXXFLAGS = -ggdb -c -std=c++11 -I$(SOURCEDIR) $(CPPFLAGS)
CC = gcc
CFLAGS = -g -c -std=c11 -I$(SOURCEDIR) $(CPPFLAGS)
CPPFLAGS = -DIEEE754
LDFLAGS =
SOURCE_FILES = control.cpp pid.cpp io_cpu.cpp config.cpp rotation.c
SOURCES = $(patsubst %,$(SOURCEDIR)/%,$(SOURCE_FILES))
OBJECTS = $(patsubst $(SOURCEDIR)/%,$(BUILDDIR)/%.o,$(SOURCES))
EXE_PC = control_pc
SOURCE_FILES_PC = control.cpp pid.cpp io.cpp ahrs.c crc_xmodem_generic.c io_ahrs_pc.c io_pc.cpp io_depth_pc.cpp io_m5_pc.c m5.c crc32.c io_relay_pc.c config.cpp rotation.c
SOURCES_PC = $(patsubst %,$(SOURCEDIR)/%,$(SOURCE_FILES_PC))
OBJECTS_PC = $(patsubst $(SOURCEDIR)/%,$(BUILDDIR)/%_pc.o,$(SOURCES_PC))
EXE_ARD = control.bin
CXX_ARD = avr-g++
CXXFLAGS_ARD = -c -std=c++11 -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DIEEE754 -DAVR -I$(SOURCEDIR) -I$(ARDLIB_INCLUDEDIR)
CC_ARD = avr-gcc
CFLAGS_ARD = -c -std=c11 -g -Os -w -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DIEEE754 -DAVR -DNDEBUG -I$(SOURCEDIR) -I$(ARDLIB_INCLUDEDIR)
SFLAGS_ARD = -c -g -x assembler-with-cpp -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR
LDFLAGS_ARD = -w -Os -Wl,--gc-sections,--relax -mmcu=atmega2560 -Wl,-u,vfprintf -lprintf_flt -lm -Wl,-u,vfscanf -lscanf_flt -lm
SOURCE_FILES_ARD = control.cpp pid.cpp io.cpp ahrs.c crc_xmodem_generic.c io_ahrs_avr.c io_arduino.cpp io_depth_arduino.cpp io_kill_arduino.cpp io_m5_avr.c m5.c crc32.c io_relay_avr.c io_millis_arduino.cpp config.cpp rotation.c
SOURCES_ARD = $(patsubst %,$(SOURCEDIR)/%,$(SOURCE_FILES_ARD))
OBJECTS_ARD = $(patsubst $(SOURCEDIR)/%,$(BUILDDIR)/%_ard.o,$(SOURCES_ARD))
all: arduino
arduino: $(BUILDDIR) $(ARDLIB_BUILDDIR) control.bin
cpu: $(BUILDDIR) control
pc : $(BUILDDIR) $(EXE_PC)
$(BUILDDIR):
mkdir -p $(BUILDDIR)
$(ARDLIB_BUILDDIR):
mkdir -p $(ARDLIB_BUILDDIR)
$(EXE): $(OBJECTS)
$(CXX) $^ $(LDFLAGS) -o $@
$(BUILDDIR)/%.cpp.o: $(SOURCEDIR)/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(BUILDDIR)/%.c.o: $(SOURCEDIR)/%.c
$(CC) $(CFLAGS) $< -o $@
$(BUILDDIR)/%.cpp.o: $(SOURCEDIR)/cpu/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(BUILDDIR)/%.c.o: $(SOURCEDIR)/cpu/%.c
$(CC) $(CFLAGS) $< -o $@
$(EXE_PC): $(OBJECTS_PC)
$(CXX) $^ $(LDFLAGS) -pthread -o $@
$(BUILDDIR)/%.cpp_pc.o: $(SOURCEDIR)/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(BUILDDIR)/%.c_pc.o: $(SOURCEDIR)/%.c
$(CC) $(CFLAGS) $< -o $@
$(BUILDDIR)/%.cpp_pc.o: $(SOURCEDIR)/pc/%.cpp
$(CXX) $(CXXFLAGS) $< -o $@
$(BUILDDIR)/%.c_pc.o: $(SOURCEDIR)/pc/%.c
$(CC) $(CFLAGS) $< -o $@
$(EXE_ARD): $(ARDLIB_OBJECTS) $(OBJECTS_ARD)
$(CC_ARD) $(LDFLAGS_ARD) $^ -o $@
$(BUILDDIR)/%.cpp_ard.o: $(SOURCEDIR)/%.cpp
$(CXX_ARD) $(CXXFLAGS_ARD) $< -o $@
$(BUILDDIR)/%.c_ard.o: $(SOURCEDIR)/%.c
$(CC_ARD) $(CFLAGS_ARD) $< -o $@
$(BUILDDIR)/%.cpp_ard.o: $(SOURCEDIR)/arduino/%.cpp
$(CXX_ARD) $(CXXFLAGS_ARD) $< -o $@
$(BUILDDIR)/%.c_ard.o: $(SOURCEDIR)/arduino/%.c
$(CC_ARD) $(CFLAGS_ARD) $< -o $@
$(ARDLIB_BUILDDIR)/%.cpp.o: $(ARDLIB_SOURCEDIR)/%.cpp
$(CC_ARD) $(CFLAGS_ARD) $< -o $@
$(ARDLIB_BUILDDIR)/%.c.o: $(ARDLIB_SOURCEDIR)/%.c
$(CC_ARD) $(CFLAGS_ARD) $< -o $@
$(ARDLIB_BUILDDIR)/%.S.o: $(ARDLIB_SOURCEDIR)/%.S
$(CC_ARD) $(SFLAGS_ARD) $< -o $@
flash: control.bin
avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $<.eep
avr-objcopy -O ihex -R .eeprom $< $<.hex
avrdude -v -patmega2560 -cwiring -P/dev/ttyUSB2 -b115200 -D -Uflash:w:$<.hex:i
.PHONY: clean
clean:
rm -f $(BUILDDIR)/*
rm -f $(EXE)
rm -f $(ARDLIB_BUILDDIR)/*
rm -f $(EXE_ARD)
rm -f $(EXE_PC)
rm -f -d $(BUILDDIR)
rm -f -d $(ARDLIB_BUILDDIR)