2016-09-06 22:34:10 +03:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Simple Makefile for Arduino MEGA 2560 C projects
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
CC = avr-gcc
|
|
|
|
OBJCOPY = avr-objcopy
|
|
|
|
AVRDUDE = avrdude
|
|
|
|
CODE_FORMATTER = tooling/format-code.sh
|
2016-10-11 12:08:53 +03:00
|
|
|
AVRSIZE = avr-size
|
2016-09-06 22:34:10 +03:00
|
|
|
|
|
|
|
BOARD = atmega2560
|
|
|
|
|
|
|
|
# Use shell command export to define it
|
|
|
|
# Example: export ARDUINO=/dev/ttyACM0
|
|
|
|
DEVICE = $(ARDUINO)
|
|
|
|
|
|
|
|
# Build artifacts
|
|
|
|
BINDIR = bin
|
|
|
|
TARGET = $(BINDIR)/$(BOARD)-user-code.ihx
|
|
|
|
ELF = $(BINDIR)/$(BOARD)-user-code.elf
|
|
|
|
|
|
|
|
# Source files. wildard "uses" all .c files in src directory
|
|
|
|
SRCDIR = src
|
2016-10-04 21:56:44 +03:00
|
|
|
BUILD_LIBS_DIR = lib
|
|
|
|
SRC = $(wildcard $(SRCDIR)/*.c $(BUILD_LIBS_DIR)/*/*.c)
|
2016-09-06 22:34:10 +03:00
|
|
|
|
|
|
|
# Define object files from .c files defined above
|
|
|
|
OBJ=$(SRC:.c=.o)
|
|
|
|
|
|
|
|
# Compiler flags
|
|
|
|
# Note that those beginning with -D are acctually pre-processor macros
|
|
|
|
# -Wall ... -Wfatal-errors All possible warning options
|
|
|
|
# -Os Optimize code. The special option -Os is meant to turn on all -O2
|
|
|
|
# optimizations that are not expected to increase code size.
|
|
|
|
# -std=c11 use C11 standard
|
|
|
|
CFLAGS = -Wall \
|
|
|
|
-Wextra \
|
|
|
|
-Wpedantic \
|
|
|
|
-Wformat \
|
|
|
|
-pedantic-errors \
|
|
|
|
-Werror \
|
|
|
|
-Wfatal-errors \
|
|
|
|
-Os \
|
2016-10-21 13:40:53 +03:00
|
|
|
-flto \
|
|
|
|
-fdata-sections \
|
|
|
|
-ffunction-sections \
|
2016-09-06 22:34:10 +03:00
|
|
|
-mmcu=$(BOARD) \
|
|
|
|
-DF_CPU=16000000UL \
|
2016-09-08 13:12:20 +03:00
|
|
|
-DGIT_DESCR=\"$(shell git describe --abbrev=6 --dirty --always --tags --long)\" \
|
2016-10-31 19:52:30 +02:00
|
|
|
-ffreestanding \
|
2016-09-06 22:34:10 +03:00
|
|
|
-std=c11
|
|
|
|
|
|
|
|
# Linker flags
|
2016-10-21 13:40:53 +03:00
|
|
|
LDFLAGS = -mmcu=$(BOARD) \
|
|
|
|
-flto \
|
|
|
|
-Wl,-gc-sections
|
2016-09-06 22:34:10 +03:00
|
|
|
|
|
|
|
OBJCOPYARGS = -O ihex \
|
|
|
|
-R .eeprom
|
|
|
|
|
2016-09-08 12:40:53 +03:00
|
|
|
# FIXME Find out why some Arduinos require -D to write code
|
2016-09-06 22:34:10 +03:00
|
|
|
AVRDUDEARGS = -p $(BOARD) \
|
|
|
|
-c wiring \
|
|
|
|
-F \
|
|
|
|
-P $(DEVICE) \
|
|
|
|
-b 115200 \
|
2016-09-08 12:40:53 +03:00
|
|
|
-V \
|
|
|
|
-D
|
2016-09-06 22:34:10 +03:00
|
|
|
|
2016-10-11 12:08:53 +03:00
|
|
|
AVRSIZEARGS = -C \
|
|
|
|
--mcu=$(BOARD)
|
|
|
|
|
2016-09-06 22:34:10 +03:00
|
|
|
all: $(ELF) $(TARGET)
|
|
|
|
|
|
|
|
%.o : %.c
|
|
|
|
$(CC) -c $(CFLAGS) -o $*.o $<
|
|
|
|
|
|
|
|
$(ELF): $(OBJ)
|
|
|
|
$(CC) $(LDFLAGS) $^ -o $@
|
|
|
|
|
|
|
|
$(TARGET):
|
|
|
|
$(OBJCOPY) $(OBJCOPYARGS) $(ELF) $(TARGET)
|
|
|
|
|
|
|
|
clean:
|
2016-09-08 09:36:00 +03:00
|
|
|
#Do not remove .placeholder in BINDIR
|
|
|
|
find $(BINDIR) -type f -not -name '.placeholder' -print0 | xargs -0 rm -f --
|
|
|
|
rm -f $(SRCDIR)/*.o
|
2016-10-04 21:56:44 +03:00
|
|
|
rm -fr $(BUILD_LIBS_DIR)/*/*.o
|
2016-09-06 22:34:10 +03:00
|
|
|
|
|
|
|
install:
|
2016-11-06 20:37:15 +02:00
|
|
|
@if [ ! -c "$(ARDUINO)" ]; then \
|
|
|
|
echo -e "\n\nEnvironment variable ARDUINO is \"$(ARDUINO)\" and that is invalid."\
|
|
|
|
"\nDid you do \"export ARDUINO=/dev/ttyACM0\" before running make install?"\
|
|
|
|
"\nAlso make sure that ARDUINO env var points to a valid tty device\n\n"; \
|
|
|
|
exit 1;\
|
|
|
|
fi
|
|
|
|
|
2016-09-06 22:34:10 +03:00
|
|
|
$(AVRDUDE) $(AVRDUDEARGS) -U flash:w:$(TARGET)
|
|
|
|
|
|
|
|
format:
|
2016-10-21 13:48:22 +03:00
|
|
|
$(CODE_FORMATTER) $(SRCDIR)/*.c
|
2016-09-06 22:34:10 +03:00
|
|
|
|
2016-10-11 12:08:53 +03:00
|
|
|
size:
|
|
|
|
$(AVRSIZE) $(AVRSIZEARGS) $(ELF)
|
|
|
|
|
|
|
|
.PHONY: clean install format size
|