-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
75 lines (56 loc) · 1.67 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
##
# Makefile for Arduino feauturing the ATmega328P microcontroller.
#
# Notes for Makefile Noobs:
#
# All makefile rules are structured like this:
# target: prerequisites
# <TAB> recipe
#
# $@ means target
# $^ means all prerequesites
#
##
# specify compiler
CC = avr-gcc
# specify programmer
PROGRAMMER = arduino
# overriding baudrate
BAUDRATE = 57600 # Arduino Nano
# BAUDRATE = 115200 # Arduino Uno
# specify mcu
MCU_MODEL = ATmega328P
# specify compiler flags
CFLAGS ?= -Os -DF_APU=16000000UL -mmcu=atmega328p -Wall -Wextra -Werror -std=c99
# specify linker flags
LDFLAGS ?= -mmcu=atmega328p
# specify USB path to Arduino
#ARDUINO_USB ?= /dev/ttyACM0
ARDUINO_USB ?= /dev/ttyUSB0
all: main.hex ioexample.run
main.hex: main.run
@echo "generating hexfile .."
avr-objcopy -O ihex -R .eeprom main.run main.hex
main.run: main.o hal/pin.o hal/serial.o
@echo "linking compiled files to main.run .."
$(CC) $(LDFLAGS) -o $@ $^
main.o: main.c
@echo "compiling main.c .."
$(CC) $(CFLAGS) -c -o $@ $<
hal/pin.o: hal/pin.c hal/pin.h
@echo "compiling pin.c .."
$(CC) $(CFLAGS) -c -o $@ $<
hal/serial.o: hal/serial.c hal/serial.h
@echo "compiling serial.c .."
$(CC) $(CFLAGS) -c -o $@ $<
upload: main.hex
@echo "flashing hex file to microcontroller .."
avrdude -F -V -c ${PROGRAMMER} -p ${MCU_MODEL} -P ${ARDUINO_USB} -b ${BAUDRATE} -U flash:w:main.hex
ioexample.run: linuxSerialClient/ioexample.cpp
@echo "compiling linux serial client as 'ioexample' .."
g++ -std=c++17 -Wall -Wextra linuxSerialClient/ioexample.cpp -o ioexample.run
clean:
@echo "cleaning up .."
rm -rf *.o **/*.o *.run **/*.run *.hex **/*.hex
# specify all targets that are not files
.PHONY: clean upload all