-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
108 lines (84 loc) · 2.6 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
#
# Makefile for Adruino project
# Author: Matthieu 'Korrigan' Rosinski <[email protected]>
#
# This Makefile provide basic rules to build up an Arduino project for
# C or CPP source files (not using .pde project files).
#
# You should edit this Makefile to add your project source files
#########################################################################
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
# Version 2, December 2004 #
# #
# Copyright (C) 2004 Sam Hocevar <[email protected]> #
# #
# Everyone is permitted to copy and distribute verbatim or modified #
# copies of this license document, and changing it is allowed as long #
# as the name is changed. #
# #
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
# #
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
# #
#########################################################################
NAME = test
# Config for Arduino Duemilanove, hardware specific
PORT = /dev/ttyUSB0
MCU = atmega328p
F_CPU = 16000000
UPLOAD_RATE = 57600
MAX_SIZE = 30720
# Basepath
ARDUINO = ./core
ARD_STDLIB = $(ARDUINO)/libarduino.a
# Source files
CXXSRC = main.cpp
OBJ = $(SRC:.c=.o) \
$(CXXSRC:.cpp=.o)
# Binaries
CC = avr-gcc
CXX = avr-g++
OBJCOPY = avr-objcopy
SIZE = avr-size
AVRDUDE = avrdude
RM = @rm -fv
STTY = stty --file
# Flags
CXXFLAGS += -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
-Os -W -Wall -ffunction-sections -fdata-sections \
-I$(ARDUINO)
CFLAGS += -mmcu=$(MCU) -DF_CPU=$(F_CPU) \
-W -Wall -Wextra \
-std=c99 \
-I$(ARDUINO)
LDFLAGS += -mmcu=$(MCU) -L$(ARDUINO) -larduino -lm -Wl,--gc-sections -Os
AVRDUDE_FLAGS += -V -q -c stk500v1 -b $(UPLOAD_RATE) \
-C /etc/avrdude.conf
# Rulez
$(NAME): $(NAME).elf
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(NAME).elf: $(OBJ) $(ARD_STDLIB)
$(CC) -o $@ $(OBJ) $(LDFLAGS)
$(ARD_STDLIB): $(ARDUINO)
make -C $(ARDUINO)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
all: $(NAME)
upload: reset raw_upload
reset:
$(STTY) $(PORT) hupcl
sleep 0.4
$(STTY) $(PORT) -hupcl
raw_upload: $(NAME)
$(AVRDUDE) $(AVRDUDE_FLAGS) \
-p$(MCU) -P$(PORT) \
-Uflash:w:$<:i
clean:
$(RM) $(OBJ) $(NAME).elf
mrproper: clean
$(RM) $(NAME)
re: mrproper all
.PHONY: all upload reset raw_upload clean mrproper monitor re