-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
147 lines (120 loc) · 4.41 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Builds Arduino library.
#
# FIXME: Build directories are created every time you run make.
# FIXME: Library rebuild every time.
# FIXME: ar must not update the library but rebuild it.
# FIXME: Have to specify ARCH even for make clean-all.
#
# TODO: Add autodependency generation.
# TODO: Automatic source search.
# TODO: Refactor variables.
ARDUINO_LIB_SRC := $(wildcard \
src/EEPROM/*.cpp \
src/Ethernet/*.cpp \
src/Ethernet/utility/*.cpp \
src/Firmata/*.cpp \
src/LiquidCrystal/*.cpp \
src/Matrix/*.cpp \
src/SD/*.cpp \
src/SD/utility/*.cpp \
src/Sprite/*.cpp \
src/SPI/*.cpp \
src/CAN_BUS_Shield/*.cpp \
src/Servo/*.cpp \
src/Stepper/*.cpp \
src/SoftwareSerial/*.cpp \
src/Wire/*.cpp \
src/Wire/utility/*.c \
src/MsTimer2/*.cpp \
src/*.c \
src/*.cpp)
ARDUINO_LIB_INC = -Iinclude/EEPROM \
-Iinclude/Ethernet \
-Iinclude/Ethernet/utility \
-Iinclude/Firmata \
-Iinclude/LiquidCrystal \
-Iinclude/Matrix \
-Iinclude/SD \
-Iinclude/SD/utility \
-Iinclude/SPI \
-Iinclude/CAN_BUS_Shield \
-Iinclude/Servo \
-Iinclude/Sprite \
-Iinclude/Stepper \
-Iinclude/SoftwareSerial \
-Iinclude/Wire \
-Iinclude/Wire/utility \
-Iinclude/MsTimer2 \
-Iinclude
ifeq ($(ARCH),nano)
MCU = atmega328p
else ifeq ($(ARCH),mini)
MCU = atmega328p
else ifeq ($(ARCH),uno)
MCU = atmega328p
else ifeq ($(ARCH),mega)
MCU = atmega1280
else ifeq ($(ARCH),mega2560)
MCU = atmega2560
else ifeq ($(strip $(ARCH)),)
$(error Please specify for which Arduino board you build the library, for example ARCH=nano)
else
$(error Unknown Arduino board: $(ARCH))
endif
BUILD_DIR = build
ARCH_BUILD_DIR = $(BUILD_DIR)/$(ARCH)
SRC_DIR = src
LIB_NAME = arduino
OBJS := $(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(patsubst $(SRC_DIR)/%,$(ARCH_BUILD_DIR)/%,$(ARDUINO_LIB_SRC))))
TARGET = $(ARCH_BUILD_DIR)/lib$(LIB_NAME).a
# Tools.
AR = avr-ar
ARFLAGS = rcs
CC = avr-gcc
CXX = $(CC)
CFLAGS = -c -mmcu=$(MCU) -DF_CPU=16000000L -Os $(ARDUINO_LIB_INC) $(PROJECT_CFLAGS)
CXXFLAGS = $(CFLAGS)
all: $(TARGET)
new-project: $(DESTDIR)/.git $(DESTDIR)/lib/arduino bootloaders $(SUBMODULES)
@printf "\n\n==============================================\n"
@printf "Read README.developer\n"
@printf "To start work do:\ncd $(DESTDIR)\nmake\n"
$(SUBMODULES):
@echo added $@
bootloaders: $(DESTDIR)/contrib/bootloaders
canopen: $(DESTDIR)/lib/canopen
$(DESTDIR)/.git:
@if [ -z "$(DESTDIR)" ]; then printf 'run:\n\tmake new-project ARCH=<arch> DESTDIR=/dir/to/new-project\n'; exit 1; fi
mkdir -p $(DESTDIR)
cp skel/* skel/.??* $(DESTDIR)
sed -i -e 's/^ARCH.*/ARCH = $(ARCH)/' $(DESTDIR)/Makefile
sed -i -e 's/^SUBMODULES =.*/SUBMODULES = $(SUBMODULES)/' $(DESTDIR)/Makefile
cd $(DESTDIR) && \
git init . && \
git add * .??* && \
git commit -m init
$(DESTDIR)/lib/arduino:
cd $(DESTDIR) && mkdir -p lib && \
git submodule add https://github.com/ramok/arduino-lib.git lib/arduino && \
git commit -m 'add submodule arduino-lib'
$(DESTDIR)/contrib/bootloaders:
cd $(DESTDIR) && mkdir -p contrib && \
git submodule add https://github.com/ramok/bootloaders.git contrib/bootloaders && \
git commit -m 'add submodule bootloaders'
$(DESTDIR)/lib/canopen:
cd $(DESTDIR) && mkdir -p lib && \
git submodule add https://github.com/ramok/libcanopen.git lib/canopen && \
git commit -m 'add submodule arduino-lib'
$(TARGET): $(OBJS)
$(AR) $(ARFLAGS) $(TARGET) $(OBJS)
$(ARCH_BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
+[ -d $(dir $@) ] || mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $< -o $@
$(ARCH_BUILD_DIR)/%.o: $(SRC_DIR)/%.c
+[ -d $(dir $@) ] || mkdir -p $(dir $@)
$(CC) $(CFLAGS) $< -o $@
clean:
-rm -rf $(ARCH_BUILD_DIR) 2>/dev/null
clean-all:
-rm -rf $(BUILD_DIR)
.PHONY: clean clean-all