Luigi Santivetti | 69972f9 | 2019-11-12 22:55:40 +0000 | [diff] [blame^] | 1 | # 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 | |
| 31 | DEVICE ?= atmega328p |
| 32 | CLOCK = 16000000 |
| 33 | PROGRAMMER ?= -c avrisp2 -P usb |
| 34 | SOURCE = 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 |
| 37 | BUILDDIR = build |
| 38 | SOURCEDIR = grbl |
| 39 | # FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m |
| 40 | FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m |
| 41 | |
| 42 | # Tune the lines below only if you know what you are doing: |
| 43 | |
| 44 | AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F |
| 45 | |
| 46 | # Compile flags for avr-gcc v4.8.1. Does not produce -flto warnings. |
| 47 | # COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections |
| 48 | |
| 49 | # Compile flags for avr-gcc v4.9.2 compatible with the IDE. Or if you don't care about the warnings. |
| 50 | COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections -flto |
| 51 | |
| 52 | |
| 53 | OBJECTS = $(addprefix $(BUILDDIR)/,$(notdir $(SOURCE:.c=.o))) |
| 54 | |
| 55 | # symbolic targets: |
| 56 | all: grbl.hex |
| 57 | |
| 58 | $(BUILDDIR)/%.o: $(SOURCEDIR)/%.c |
| 59 | $(COMPILE) -MMD -MP -c $< -o $@ |
| 60 | |
| 61 | .S.o: |
| 62 | $(COMPILE) -x assembler-with-cpp -c $< -o $(BUILDDIR)/$@ |
| 63 | # "-x assembler-with-cpp" should not be necessary since this is the default |
| 64 | # file type for the .S (with capital S) extension. However, upper case |
| 65 | # characters are not always preserved on Windows. To ensure WinAVR |
| 66 | # compatibility define the file type manually. |
| 67 | |
| 68 | #.c.s: |
| 69 | $(COMPILE) -S $< -o $(BUILDDIR)/$@ |
| 70 | |
| 71 | flash: all |
| 72 | $(AVRDUDE) -U flash:w:grbl.hex:i |
| 73 | |
| 74 | fuse: |
| 75 | $(AVRDUDE) $(FUSES) |
| 76 | |
| 77 | # Xcode uses the Makefile targets "", "clean" and "install" |
| 78 | install: flash fuse |
| 79 | |
| 80 | # if you use a bootloader, change the command below appropriately: |
| 81 | load: all |
| 82 | bootloadHID grbl.hex |
| 83 | |
| 84 | clean: |
| 85 | rm -f grbl.hex $(BUILDDIR)/*.o $(BUILDDIR)/*.d $(BUILDDIR)/*.elf |
| 86 | |
| 87 | # file targets: |
| 88 | $(BUILDDIR)/main.elf: $(OBJECTS) |
| 89 | $(COMPILE) -o $(BUILDDIR)/main.elf $(OBJECTS) -lm -Wl,--gc-sections |
| 90 | |
| 91 | grbl.hex: $(BUILDDIR)/main.elf |
| 92 | rm -f grbl.hex |
| 93 | avr-objcopy -j .text -j .data -O ihex $(BUILDDIR)/main.elf grbl.hex |
| 94 | avr-size --format=berkeley $(BUILDDIR)/main.elf |
| 95 | # If you have an EEPROM section, you must also create a hex file for the |
| 96 | # EEPROM and add it to the "flash" target. |
| 97 | |
| 98 | # Targets for code debugging and analysis: |
| 99 | disasm: main.elf |
| 100 | avr-objdump -d $(BUILDDIR)/main.elf |
| 101 | |
| 102 | cpp: |
| 103 | $(COMPILE) -E $(SOURCEDIR)/main.c |
| 104 | |
| 105 | # include generated header dependencies |
| 106 | -include $(BUILDDIR)/$(OBJECTS:.o=.d) |