forked from ChrisMicro/ArduinoOnPc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
makeNativeArduino.mk
78 lines (55 loc) · 2 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
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
CFLAGS += -DARDUINO=101 -DSKETCH_FILE=\"$(SKETCH)\"
CFLAGS += -DFASTLED_SDL $(shell sdl2-config --cflags)
CXXFLAGS += $(CFLAGS)
CXXFLAGS += -Wno-class-memaccess # FastLED does some naughty things
LDFLAGS += $(shell sdl2-config --libs)
LDFLAGS += -Wl,--gc-sections
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')
INCLUDES += -I$1
endef
INCLUDES += -I$(NATIVE_ROOT)/src/cores/arduino -I$(NATIVE_ROOT)/src/system
$(eval $(call add_lib,$(NATIVE_ROOT)/src))
$(foreach lib, $(ARDUINO_LIBS), $(eval $(call add_lib,$(NATIVE_ROOT)/libraries/$(lib))))
OBJECTS += $(SRC_C:%.c=$(BUILD_ROOT)/%.o)
OBJECTS += $(SRC_CXX:%.cpp=$(BUILD_ROOT)/%.o)
INCLUDES += $(foreach d, $(INC_DIR), -I$d)
SRCS += $(SRC_C)
SRCS += $(SRC_CXX)
$(TARGET): $(OBJECTS)
$(Q)$(CXX) $(OBJECTS) $(LDFLAGS) -o $@
@size $@
clean:
rm -r $(BUILD_ROOT)
rm $(TARGET)
print:
@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)"
$(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))))