-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
118 lines (100 loc) · 4.85 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
###############################################################################
# Makefile for Arduino Duemilanove/Uno #
# Copyright (C) 2011 Álvaro Justen <[email protected]> #
# http://twitter.com/turicas #
# #
# This project is hosted at GitHub: http://github.com/turicas/arduinoMakefile #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, please read the license at: #
# http://www.gnu.org/licenses/gpl-2.0.html #
###############################################################################
#Sketch, board and IDE path configuration (in general change only this section)
# Sketch filename (should be in the same directory of Makefile)
SKETCH_NAME=max7219.ino
# The port Arduino is connected
# Uno, in GNU/linux: generally /dev/ttyACM0
# Duemilanove, in GNU/linux: generally /dev/ttyUSB0
PORT=/dev/ttyACM0
# The path of Arduino IDE
ARDUINO_DIR=/cygdrive/d/Program/arduino-1.5.2-windows/arduino-1.5.2
# Boardy type: use "arduino" for Uno or "stk500v1" for Duemilanove
BOARD_TYPE=arduino
# Baud-rate: use "115200" for Uno or "19200" for Duemilanove
BAUD_RATE=115200
#Compiler and uploader configuration
ARDUINO_CORE=$(ARDUINO_DIR)/hardware/arduino/cores/arduino
INCLUDE=-I. -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino
TMP_DIR=/tmp/build_arduino
MCU=atmega328p
DF_CPU=16000000
CC=avr-gcc
CPP=avr-g++
AVR_OBJCOPY=avr-objcopy
AVRDUDE=avrdude
CC_FLAGS=-g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions \
-std=gnu99
CPP_FLAGS=-g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions
AVRDUDE_CONF=/etc/avrdude.conf
CORE_C_FILES=pins_arduino WInterrupts wiring_analog wiring wiring_digital \
wiring_pulse wiring_shift
CORE_CPP_FILES=HardwareSerial main Print Tone WMath WString
all: clean compile upload
clean:
@echo '# *** Cleaning...'
rm -rf "$(TMP_DIR)"
compile:
@echo '# *** Compiling...'
mkdir $(TMP_DIR)
echo '#include "WProgram.h"' > "$(TMP_DIR)/$(SKETCH_NAME).cpp"
cat $(SKETCH_NAME) >> "$(TMP_DIR)/$(SKETCH_NAME).cpp"
@#$(CPP) -MM -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \
# $(CPP_FLAGS) "$(TMP_DIR)/$(SKETCH_NAME).cpp" \
# -MF "$(TMP_DIR)/$(SKETCH_NAME).d" \
# -MT "$(TMP_DIR)/$(SKETCH_NAME).o"
@#Compiling the sketch file:
$(CPP) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \
$(CPP_FLAGS) "$(TMP_DIR)/$(SKETCH_NAME).cpp" \
-o "$(TMP_DIR)/$(SKETCH_NAME).o"
@#Compiling Arduino core .c dependecies:
for core_c_file in ${CORE_C_FILES}; do \
$(CC) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \
$(CC_FLAGS) $(ARDUINO_CORE)/$$core_c_file.c \
-o $(TMP_DIR)/$$core_c_file.o; \
done
@#Compiling Arduino core .cpp dependecies:
for core_cpp_file in ${CORE_CPP_FILES}; do \
$(CPP) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \
$(CPP_FLAGS) $(ARDUINO_CORE)/$$core_cpp_file.cpp \
-o $(TMP_DIR)/$$core_cpp_file.o; \
done
@#TODO: compile external libraries here
@#TODO: use .d files to track dependencies and compile them
@# change .c by -MM and use -MF to generate .d
$(CC) -mmcu=$(MCU) -lm -Wl,--gc-sections -Os \
-o $(TMP_DIR)/$(SKETCH_NAME).elf $(TMP_DIR)/*.o
$(AVR_OBJCOPY) -O ihex -R .eeprom \
$(TMP_DIR)/$(SKETCH_NAME).elf \
$(TMP_DIR)/$(SKETCH_NAME).hex
@echo '# *** Compiled successfully! \o/'
reset:
@echo '# *** Resetting...'
stty --file $(PORT) hupcl
sleep 0.1
stty --file $(PORT) -hupcl
upload:
@echo '# *** Uploading...'
$(AVRDUDE) -q -V -p $(MCU) -C $(AVRDUDE_CONF) -c $(BOARD_TYPE) \
-b $(BAUD_RATE) -P $(PORT) \
-U flash:w:$(TMP_DIR)/$(SKETCH_NAME).hex:i
@echo '# *** Done - enjoy your sketch!'