forked from ashelly/grbl
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
130 lines (101 loc) · 3.99 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
# Part of Grbl
#
# Copyright (c) 2009-2011 Simen Svale Skogsrud
# Copyright (c) 2012 Sungeun K. Jeon
#
# Grbl 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 3 of the License, or
# (at your option) any later version.
#
# Grbl 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 Grbl. If not, see <http://www.gnu.org/licenses/>.
# This is a prototype Makefile. Modify it according to your needs.
# You should at least check the settings for
# DEVICE ....... The AVR device you compile for
# CLOCK ........ Target AVR clock rate in Hertz
# OBJECTS ...... The object files created from your source files. This list is
# usually the same as the list of source files with suffix ".o".
# PROGRAMMER ... Options to avrdude which define the hardware you use for
# uploading to the AVR and the interface where this hardware
# is connected.
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.
VERSION = 0.4.6
DEVICE ?= atmega2560
CLOCK = 16000000
PORT ?= /dev/ttyUSB0
PROGRAMMER ?= -c wiring -P $(PORT) -v -v
OBJECTS = main.o motion_control.o gcode.o spindle_control.o serial.o \
protocol.o stepper.o eeprom.o settings.o planner.o magazine.o \
nuts_bolts.o limits.o print.o probe.o report.o system.o \
counters.o gqueue.o adc.o spi.o signals.o systick.o \
motor_driver.o ad5121.o sram.o
# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
FUSES = -U hfuse:w:0xd8:m -U lfuse:w:0xff:m
# update that line with this when programmer is back up:
# FUSES = -U hfuse:w:0xd7:m -U lfuse:w:0xff:m
# Tune the lines below only if you know what you are doing:
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F -D
CFLAGS = -Wall -Werror -Wextra -Os -fstack-usage --std=c11 \
-DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -DGRBL_VERSION=$(VERSION)
COMPILE = avr-gcc $(CFLAGS) -I. -ffunction-sections
ifneq ($(SPI),)
CFLAGS += -DSPI_STEPPER_DRIVER
endif
ifneq ($(USE_CAROUSEL_LOSS),)
CFLAGS += -DUSE_CAROUSEL_LOSS
endif
# symbolic targets:
all debug: grbl.hex
debug: CFLAGS += -g
.c.o:
$(COMPILE) -c $< -o $@
@$(COMPILE) -MM $< > $*.d
.S.o:
$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.
.c.s:
$(COMPILE) -S $< -o $@
flash: all
$(AVRDUDE) -U flash:w:grbl.hex:i
fuse:
$(AVRDUDE) $(FUSES)
# Xcode uses the Makefile targets "", "clean" and "install"
install: flash fuse
# Using a USB bootloader for ARM microcontrollers
load: all
bootloadHID grbl.hex
clean:
rm -f grbl.hex main.elf $(OBJECTS) $(OBJECTS:.o=.d) grbl.stack *.su grbl.cflow grbl_callgraph.pdf
# file targets:
main.elf: $(OBJECTS)
$(COMPILE) -o main.elf $(OBJECTS) -lm -Wl,--gc-sections
grbl.stack: main.elf
cat $(OBJECTS:.o=.su) > $@
grbl.cflow: main.elf
cflow $(OBJECTS:.o=.c) -o $@
grbl_callgraph.pdf: grbl.cflow grbl.stack
./script/stackusage.py -s grbl.stack -f grbl.cflow -c grbl_callgraph.pdf
stack_analysis: grbl.stack grbl.cflow
./script/stackusage.py -s grbl.stack -f grbl.cflow -a
grbl.hex: main.elf
rm -f grbl.hex
avr-objcopy -j .text -j .data -O ihex main.elf grbl.hex
avr-size --format=berkeley main.elf
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.
# Targets for code debugging and analysis:
disasm: main.elf
avr-objdump -d main.elf
cpp:
$(COMPILE) -E main.c
# include generated header dependencies
-include $(OBJECTS:.o=.d)