209 lines
5.6 KiB
Makefile
209 lines
5.6 KiB
Makefile
# Name of the project
|
|
PROJ_NAME = video
|
|
|
|
## Directories ##
|
|
# This is where the source files are located,
|
|
# which are not in the current directory
|
|
SRC_DIR = ./src
|
|
|
|
# The header files we use are located here
|
|
INC_DIR = ./inc
|
|
INC_DIR += ./src
|
|
INC_DIR += .
|
|
|
|
BUILD_DIR = build
|
|
OUTPUT_DIR = output
|
|
|
|
######################################################################
|
|
# SOURCES #
|
|
######################################################################
|
|
|
|
## FILES ##
|
|
# c files
|
|
# SRCS =
|
|
SRCS += main.c
|
|
|
|
# asm files
|
|
# S maiuscola! Invoca prima il compilatore gcc che interpreta macro e altro
|
|
ASRC += main.S
|
|
ASRC += frame.S
|
|
|
|
# header files
|
|
# Specify here libraries! Makefile will check existance before launching
|
|
# DEPS = $(notdir $(wildcard $(INC_DIR)/*.h))
|
|
# DEPS += Makefile
|
|
# DEPS += $(ENUMSTRING)
|
|
|
|
# Object files
|
|
# Automatically declares object file names
|
|
OBJS = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(filter %.c,$(SRCS)) )
|
|
OBJS += $(patsubst %.cpp, $(BUILD_DIR)/%.cpp.o,$(filter %.cpp,$(SRCS)) )
|
|
|
|
# Dependencies from .h/.hpp files, but exclude asm files
|
|
DEPS := $(patsubst %.o, %.d, $(OBJS))
|
|
|
|
OBJS += $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(filter %.s,$(ASRC)) )
|
|
OBJS += $(patsubst %.S, $(BUILD_DIR)/%.S.o, $(filter %.S,$(ASRC)) )
|
|
|
|
|
|
# Virtual Paths
|
|
# Tell make to look in that folder if it cannot find a source
|
|
# in the current directory
|
|
vpath %.c $(SRC_DIR)
|
|
vpath %.cpp $(SRC_DIR)
|
|
vpath %.S $(SRC_DIR)
|
|
vpath %.h $(INC_DIR)
|
|
|
|
######################################################################
|
|
# SETUP TOOLS #
|
|
######################################################################
|
|
ECHO := /bin/echo
|
|
|
|
# GCC/programming Tools
|
|
CC = avr-gcc
|
|
CXX = avr-g++
|
|
OBJCOPY = avr-objcopy
|
|
OBJDUMP = avr-objdump
|
|
GDB = avr-gdb
|
|
AS = avr-as
|
|
SIZE = avr-size
|
|
AVRDUDE = avrdude
|
|
# Custom script for enum parsing
|
|
# PACK2STRING = python3 bin/enum2string.py
|
|
|
|
# Microcontroller
|
|
MCU = atmega328p
|
|
F_CPU = 16000000
|
|
# Fuses -- www.engbedded.com/fusecalc/
|
|
LFUSE = 0xfd
|
|
HFUSE = 0xde
|
|
|
|
### GCC options ###
|
|
|
|
## Compiler flags ##
|
|
# Do not run the linker
|
|
CFLAGS += -c
|
|
# Debug informations
|
|
CFLAGS += -g
|
|
# Auto optimisation
|
|
CFLAGS += -Os
|
|
# All warning messages
|
|
CFLAGS += -Wall -Wextra
|
|
# Puts functions and data into its own section - remove thread-safe things
|
|
CFLAGS += -fno-exceptions -fstack-usage -fdump-tree-optimized -ffunction-sections -fdata-sections -fno-threadsafe-statics
|
|
# Use smallest size for enums
|
|
CFLAGS += -fshort-enums
|
|
# Microcontroller
|
|
CFLAGS += -mmcu=$(MCU)
|
|
# Clock speed
|
|
CFLAGS += -DF_CPU=$(F_CPU)L
|
|
# Header files
|
|
CFLAGS += $(addprefix -I,$(INC_DIR))
|
|
CFLAGS += -flto
|
|
# CFLAGS += -DAVR
|
|
# Debug Flag
|
|
# CFLAGS += -DDEBUG
|
|
|
|
## CXX flags are the same as CC ones here!
|
|
CXXFLAGS = $(CFLAGS)
|
|
CXXFLAGS += -std=c++11
|
|
|
|
# Linker flags
|
|
LFLAGS = -mmcu=$(MCU)
|
|
LFLAGS += $(addprefix -I,$(INC_DIR))
|
|
|
|
######################################################################
|
|
# PROGRAMMING TOOLS #
|
|
######################################################################
|
|
# To match MCU with BOARD, see link
|
|
# http://www.nongnu.org/avr-libc/user-manual/using_tools.html
|
|
#PROGRAMMER = avrispmkii
|
|
PROGRAMMER = usbasp
|
|
# verbose
|
|
# PROGRAM_FLAGS = -v
|
|
# erase
|
|
# PROGRAM_FLAGS = -e
|
|
# choose programmer
|
|
PROGRAM_FLAGS += -c $(PROGRAMMER)
|
|
# target cpu
|
|
PROGRAM_FLAGS += -p $(MCU)
|
|
# USB port and baudrate
|
|
# PROGRAM_FLAGS += -P /dev/ttyACM0
|
|
|
|
######################################################################
|
|
# TARGETS #
|
|
######################################################################
|
|
.PHONY: clean
|
|
|
|
all: $(OUTPUT_DIR)/$(PROJ_NAME).hex
|
|
|
|
-include $(DEPS)
|
|
|
|
# invokes CC compiler before assemblying
|
|
$(BUILD_DIR)/%.S.o : %.S
|
|
@echo -e "\033[1;33m[Assembling ]\033[0m AS $<"
|
|
@mkdir -p `dirname $@`
|
|
$(CC) $(CFLAGS) $< -o $@
|
|
|
|
# pure asm
|
|
$(BUILD_DIR)/%.s.o : %.s
|
|
@echo -e "\033[1;33m[Assembling ]\033[0m AS $<"
|
|
@mkdir -p `dirname $@`
|
|
$(CC) $(CFLAGS) $< -o $@
|
|
|
|
# .cxx files
|
|
$(BUILD_DIR)/%.cpp.o: %.cpp
|
|
@echo -e "\033[1;33m[Compiling ]\033[0m CX $<"
|
|
@mkdir -p `dirname $@`
|
|
$(CXX) $(CXXFLAGS) $< -o $@
|
|
|
|
# .c files
|
|
$(BUILD_DIR)/%.c.o: %.c
|
|
@echo -e "\033[1;33m[Compiling ]\033[0m CC $<"
|
|
@mkdir -p `dirname $@`
|
|
$(CC) $(CFLAGS) $< -o $@
|
|
|
|
.DELETE_ON_ERROR:
|
|
$(BUILD_DIR)/%.c.d: %.c
|
|
@mkdir -p `dirname $@`
|
|
@$(ECHO) -n "$@ " > $@
|
|
@$(CC) -MM -MT '$(@D)/$(<F).o' $(CFLAGS) $< >> $@
|
|
|
|
.DELETE_ON_ERROR:
|
|
$(BUILD_DIR)/%.cpp.d: %.cpp
|
|
@mkdir -p `dirname $@`
|
|
@$(ECHO) -n "$@ " > $@
|
|
@$(CC) -MM -MT '$(@D)/$(<F).o' $(CFLAGS) $< >> $@
|
|
|
|
# $(ENUMSTRING): $(STRINGFILES)
|
|
# $(PACK2STRING) $^ > $(ENUMSTRING)
|
|
|
|
$(OUTPUT_DIR)/$(PROJ_NAME).elf: $(OBJS)
|
|
@echo -e "\033[1;34m[Linking ]\033[0m $@"
|
|
@mkdir -p ${OUTPUT_DIR}
|
|
$(CC) $(LFLAGS) -o $@ $(foreach file, $^, $(file)) -lm
|
|
@echo -e "\033[1;35m[Disasm... ]\033[0m $^"
|
|
$(OBJDUMP) -h -S $@ > $(OUTPUT_DIR)/$(PROJ_NAME).lss
|
|
|
|
$(OUTPUT_DIR)/$(PROJ_NAME).hex: $(OUTPUT_DIR)/$(PROJ_NAME).elf
|
|
@echo -e "\033[1;36m[Binary ]\033[0m $^"
|
|
$(OBJCOPY) -O ihex -R .eeprom $^ $@
|
|
|
|
size: $(OUTPUT_DIR)/$(PROJ_NAME).elf
|
|
$(SIZE) -C --mcu=$(MCU) $(OUTPUT_DIR)/$(PROJ_NAME).elf
|
|
|
|
flash: $(OUTPUT_DIR)/$(PROJ_NAME).hex
|
|
$(AVRDUDE) $(PROGRAM_FLAGS) -U flash:w:$(OUTPUT_DIR)/$(PROJ_NAME).hex
|
|
|
|
fuse: $(OUTPUT_DIR)/$(PROJ_NAME).hex
|
|
$(AVRDUDE) $(PROGRAM_FLAGS) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
|
|
|
|
test:
|
|
$(AVRDUDE) $(PROGRAM_FLAGS)
|
|
|
|
clean:
|
|
@echo -e "\033[1;33m[Cleaning ]\033[0m"
|
|
@rm -rf $(BUILD_DIR)/*
|
|
@rm -rf $(OUTPUT_DIR)/*
|
|
|