blob: 4730672b299825825aecd4cef6dcfb55746de814 [file] [log] [blame]
Luigi Santivetti69972f92019-11-12 22:55:40 +00001# Part of Grbl
2#
3# Copyright (c) 2009-2011 Simen Svale Skogsrud
4# Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
5#
6# Grbl is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# Grbl is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Grbl. If not, see <http://www.gnu.org/licenses/>.
18
19
20# This is a prototype Makefile. Modify it according to your needs.
21# You should at least check the settings for
22# DEVICE ....... The AVR device you compile for
23# CLOCK ........ Target AVR clock rate in Hertz
24# OBJECTS ...... The object files created from your source files. This list is
25# usually the same as the list of source files with suffix ".o".
26# PROGRAMMER ... Options to avrdude which define the hardware you use for
27# uploading to the AVR and the interface where this hardware
28# is connected.
29# FUSES ........ Parameters for avrdude to flash the fuses appropriately.
30
31DEVICE ?= atmega328p
32CLOCK = 16000000
33PROGRAMMER ?= -c avrisp2 -P usb
34SOURCE = main.c motion_control.c gcode.c spindle_control.c coolant_control.c serial.c \
35 protocol.c stepper.c eeprom.c settings.c planner.c nuts_bolts.c limits.c jog.c\
36 print.c probe.c report.c system.c
Luigi Santivetti42a1b332019-11-17 22:31:46 +000037ifeq ($(USE_ADC), 1)
38 CPPFLAGS += -DUSE_ADC
39 SOURCE += adc.c
40endif
Luigi Santivetti69972f92019-11-12 22:55:40 +000041BUILDDIR = build
42SOURCEDIR = grbl
43# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
44FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m
45
46# Tune the lines below only if you know what you are doing:
47
48AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F
49
50# Compile flags for avr-gcc v4.8.1. Does not produce -flto warnings.
51# COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections
52
53# Compile flags for avr-gcc v4.9.2 compatible with the IDE. Or if you don't care about the warnings.
Luigi Santivetti42a1b332019-11-17 22:31:46 +000054COMPILE = avr-gcc -Wall -Os $(CPPFLAGS) -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections -flto
Luigi Santivetti69972f92019-11-12 22:55:40 +000055
56
57OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(SOURCE:.c=.o)))
58
59# symbolic targets:
60all: grbl.hex
61
62$(BUILDDIR)/%.o: $(SOURCEDIR)/%.c
63 $(COMPILE) -MMD -MP -c $< -o $@
64
65.S.o:
66 $(COMPILE) -x assembler-with-cpp -c $< -o $(BUILDDIR)/$@
67# "-x assembler-with-cpp" should not be necessary since this is the default
68# file type for the .S (with capital S) extension. However, upper case
69# characters are not always preserved on Windows. To ensure WinAVR
70# compatibility define the file type manually.
71
72#.c.s:
73 $(COMPILE) -S $< -o $(BUILDDIR)/$@
74
75flash: all
76 $(AVRDUDE) -U flash:w:grbl.hex:i
77
78fuse:
79 $(AVRDUDE) $(FUSES)
80
81# Xcode uses the Makefile targets "", "clean" and "install"
82install: flash fuse
83
84# if you use a bootloader, change the command below appropriately:
85load: all
86 bootloadHID grbl.hex
87
88clean:
89 rm -f grbl.hex $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(BUILDDIR)/*.elf
90
91# file targets:
92$(BUILDDIR)/main.elf: $(OBJECTS)
93 $(COMPILE) -o $(BUILDDIR)/main.elf $(OBJECTS) -lm -Wl,--gc-sections
94
95grbl.hex: $(BUILDDIR)/main.elf
96 rm -f grbl.hex
97 avr-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.elf grbl.hex
98 avr-size --format=berkeley $(BUILDDIR)/main.elf
99# If you have an EEPROM section, you must also create a hex file for the
100# EEPROM and add it to the "flash" target.
101
102# Targets for code debugging and analysis:
103disasm: main.elf
104 avr-objdump -d $(BUILDDIR)/main.elf
105
106cpp:
107 $(COMPILE) -E $(SOURCEDIR)/main.c
108
109# include generated header dependencies
110-include $(BUILDDIR)/$(OBJECTS:.o=.d)