forked from marcmerlin/ArduinoOnPc-FastLED-GFX-LEDMatrix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeNativeArduino.mk
135 lines (108 loc) · 4.25 KB
/
makeNativeArduino.mk
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
129
130
131
132
133
134
135
# To get memory debugging:
# unset LD_PRELOAD ; export ASAN=yes; make
# https://github.com/google/sanitizers/wiki/AddressSanitizer
ifneq ($(ASAN),)
CFLAGS += -fsanitize=address
CXXFLAGS += -fsanitize=address
LDFLAGS += -fsanitize=address
endif
penultimateword = $(wordlist $(words $1),$(words $1), x $1)
SKETCH_ROOT := $(shell dirname $(abspath $(call penultimateword, $(MAKEFILE_LIST))))
NATIVE_ROOT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
#Q ?= @
BUILD_ROOT ?= build
SKETCH ?= $(shell find $(SKETCH_ROOT) -maxdepth 1 -name "*.ino")
TARGET := $(shell basename -s .ino $(SKETCH))
$(shell mkdir -p $(BUILD_ROOT))
CFLAGS += -Wall -Wextra -Wno-unused-parameter -g
CFLAGS += -DARDUINO=101 -DSKETCH_FILE=\"$(SKETCH)\"
CFLAGS += -std=gnu11
CFLAGS += -lm
CFLAGS += -DARDUINOONPC
CXXFLAGS += -Wall -Wextra -Wno-unused-parameter -g
CXXFLAGS += -DARDUINO=101 -DSKETCH_FILE=\"$(SKETCH)\"
#CXXFLAGS += -Wno-class-memaccess # FastLED does some naughty things, not supported by gcc on arm
CXXFLAGS += -std=gnu++11
CXXFLAGS += -DARDUINOONPC
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -L/usr/X11R6/lib -lX11 # include X11 library
LDFLAGS += -pthread # include linux thread library
# comment this out if you arne't using https://github.com/hzeller/rpi-rgb-led-matrix/
# Copy a string like these in this file: M384BY256 M192BY160 M128BY192
CXXFLAGS += -DGFXDISPLAY_$(shell cat /root/NM/gfxdisplay)
ifneq ($(shell uname -m |grep arm),)
CXXFLAGS += -DRPIRGBPANEL
ifneq ($(shell grep 'Raspberry Pi 4' /proc/device-tree/model),)
CXXFLAGS += -DRPI4
else
ifneq ($(shell grep 'Raspberry Pi 3' /proc/device-tree/model),)
CXXFLAGS += -DRPI3
else
CXXFLAGS += -DRPILT3
endif
endif
#pragma message "ARDUINOONPC building on ARM (guessing rPi), will link against rgbmatrix"
LDFLAGS += -L$(NATIVE_ROOT)/rpi-rgb-led-matrix/lib -lrgbmatrix -lrt
else
ifeq ($(LINUX_RENDERER_SDL),yes)
CXXFLAGS += -DFASTLED_SDL $(shell sdl2-config --cflags) -DLINUX_RENDERER_SDL -DLINUX_RENDERER_SDL_MAIN_DELAY=$(LINUX_RENDERER_SDL_MAIN_DELAY)
LDFLAGS += $(shell sdl2-config --libs)
endif
endif
DEPDIR := $(BUILD_ROOT)
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
define add_lib
SRC_C += $(shell find $1 -name '*.c')
SRC_CXX += $(shell find $1 -name '*.cpp')
SRC_USER_C = $(shell find $(SKETCH_ROOT) -name "*.c" | grep -Ev '\.(vscode|git)')
SRC_USER_CXX = $(shell find $(SKETCH_ROOT) -name "*.cpp" | grep -Ev '\.(vscode|git)')
INCLUDES += -I$1
endef
INCLUDES += -I$(SKETCH_ROOT)
INCLUDES += -I$(NATIVE_ROOT)/src/cores/arduino -I$(NATIVE_ROOT)/src/system
# comment this out if you arne't using https://github.com/hzeller/rpi-rgb-led-matrix/
INCLUDES += -I$(NATIVE_ROOT)/rpi-rgb-led-matrix/include
$(eval $(call add_lib,$(NATIVE_ROOT)/src))
$(foreach lib, $(ARDUINO_LIBS), $(eval $(call add_lib,$(NATIVE_ROOT)/libraries/$(lib))))
USER_FOLDERS = $(shell find $(SKETCH_ROOT) -path $(SKETCH_ROOT)/build -prune -o -type d -print | grep -Ev '\.(vscode|git)')
INC_USER_FOLDERS = $(foreach folder, $(USER_FOLDERS), -I$(folder))
OBJECTS += $(SRC_C:%.c=$(BUILD_ROOT)/%.o)
OBJECTS += $(SRC_CXX:%.cpp=$(BUILD_ROOT)/%.o)
OBJECTS += $(SRC_USER_C:%.c=$(BUILD_ROOT)/%.o)
OBJECTS += $(SRC_USER_CXX:%.cpp=$(BUILD_ROOT)/%.o)
SRCS += $(SRC_C)
SRCS += $(SRC_CXX)
SRCS += $(SRC_USER_C)
SRCS += $(SRC_USER_CXX)
$(TARGET): $(OBJECTS)
$(Q)$(CXX) $(INC_USER_FOLDERS) $(INCLUDES) $(OBJECTS) $(LDFLAGS) -o $@
@size $@
clean:
rm -r $(BUILD_ROOT)
rm $(TARGET)
print:
@echo "LINUX_RENDERER_SDL:\t $(LINUX_RENDERER_SDL)"
@echo "BUILD_ROOT:\t $(BUILD_ROOT)"
@echo "INCLUDES:\t $(INCLUDES)"
@echo "OBJECTS:\t $(OBJECTS)"
@echo "SRCS:\t $(SRCS)"
@echo "SKETCH:\t $(SKETCH)"
@echo "ROOT:\t $(NATIVE_ROOT)"
@echo "SRC_C :\t $(SRC_C)"
@echo "SRC_CXX :\t $(SRC_CXX)"
@echo "SRC_USER:\t $(SRC_USER)"
@echo "INC_USER_FOLDERS:\t $(INC_USER_FOLDERS)"
@echo "CXXFLAGS :\t $(CXXFLAGS)"
@echo "LDFLAGS:\t $(LDFLAGS)"
$(BUILD_ROOT)/%.o : %.c $(DEPDIR)/%.d
@mkdir -p `dirname $@`
$(Q)$(CC) $(DEPFLAGS) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(POSTCOMPILE)
$(BUILD_ROOT)/%.o : %.cpp $(DEPDIR)/%.d
@mkdir -p `dirname $@`
$(Q)$(CXX) $(DEPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
$(POSTCOMPILE)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))