-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (46 loc) · 1.32 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
##
# @file Makefile
# @author Jack Duignan (JackpDuigna@gmail.com)
# #date 2024-06-11
# @brief the make file for the embedded-terminal project
# https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
# User params
USBDEVICE = /dev/ttyUSB0
TARGET = main
# Flags
CFLAGS = -Os -DF_CPU=16000000UL -mmcu=atmega328p -Wall -Wstrict-prototypes -Wextra
MCU = -mmcu=atmega328p
# Commands
CC = avr-gcc
OBJCOPY = avr-objcopy
SIZE = avr-size
DEL = rm
MKDIR_P = mkdir -p
# Locations
SRCDIR = ./src
BUILDDIR = ./build
# Use all c files in directory
SRCS := $(shell cd $(SRCDIR) && find * -name '*.cpp' -or -name '*.c' -or -name '*.s')
OBJS := $(SRCS:%=$(BUILDDIR)/%.o)
all: $(BUILDDIR)/$(TARGET).out
# Create out file
$(BUILDDIR)/$(TARGET).out: $(OBJS)
$(CC) $(OBJS) $(MCU) -o $@
# Create object files
$(BUILDDIR)/%.c.o: $(SRCDIR)/%.c
@$(MKDIR_P) $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Flash to the MCC
.PHONY: flash
flash: $(BUILDDIR)/$(TARGET).out
$(OBJCOPY) -O ihex -R .eeprom $(BUILDDIR)/$(TARGET).out $(BUILDDIR)/$(TARGET).hex
avrdude -F -V -c arduino -p ATMEGA328P -P $(USBDEVICE) -b 115200 -U flash:w:$(BUILDDIR)/$(TARGET).hex
$(SIZE) $(BUILDDIR)/$(TARGET).hex
# Launch a serial prompt
.PHONY: serial
serial:
putty -serial $(USBDEVICE) -sercfg 8,'2',57600,'n' -fn "Monospace 13"
# Clean
.PHONY: clean
clean:
$(DEL) -rf $(BUILDDIR)