diff options
Diffstat (limited to 'src/app/Makefile')
-rw-r--r-- | src/app/Makefile | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/app/Makefile b/src/app/Makefile new file mode 100644 index 0000000..8fe6809 --- /dev/null +++ b/src/app/Makefile @@ -0,0 +1,107 @@ +# Location of build tools +CC=avr-gcc +OBJCOPY=avr-objcopy +SIZE=avr-size +AVRDUDE=avrdude +AVRDUDE_FLAGS=-B 100kHz + +# Modify this to the device name of the UART used for AVRDUDE +AVRDUDE_DEV=usb +PROG = dragon_isp + +# Modify this to the CPU you are using +PART=attiny25 +AVRDUDE_PART=t25 + +# Cpu frequency +# is 3.579545MHz / 8 = 447443.125 +#F_CPU=447443UL +F_CPU="(3579545UL/8)" + +# Directory for built objects +BUILD_DIR=build + +# Port/application object files +APP_NAME = app + +# Application object files +APP_OBJECTS = main.o + +# Library object files to build and use +LIB_OBJECTS = +LIB_ASM_OBJECTS = +LIB_DIR = ../lib + +# Collection of built objects +ALL_OBJECTS = $(LIB_OBJECTS) $(LIB_ASM_OBJECTS) $(APP_OBJECTS) +BUILT_OBJECTS = $(patsubst %,$(BUILD_DIR)/%,$(ALL_OBJECTS)) + +# Target application filenames (.elf and .hex) for each application object +APP_ELF = $(APP_NAME).elf +APP_HEX = $(APP_NAME).hex + +# Search build/output directory for dependencies +vpath %.o ./$(BUILD_DIR) +vpath %.elf ./$(BUILD_DIR) +vpath %.hex ./$(BUILD_DIR) + +# GCC flags +CFLAGS=-g -mmcu=$(PART) -O1 -Wall -Werror -DF_CPU=$(F_CPU) +INCLUDES=-I. -I$(LIB_DIR) + + +################# +# Build targets # +################# + +# All applications +all: $(BUILD_DIR) $(APP_HEX) Makefile + +# Make build/output directory +$(BUILD_DIR): + mkdir $(BUILD_DIR) + +# Application HEX files +$(APP_HEX): %.hex: %.elf + @echo Building $@ + $(OBJCOPY) -j .text -j .data -O ihex $(BUILD_DIR)/$< $(BUILD_DIR)/$@ + +# Application ELF files +$(APP_ELF): %.elf: $(LIB_OBJECTS) $(LIB_ASM_OBJECTS) $(APP_OBJECTS) + $(CC) $(CFLAGS) $(BUILT_OBJECTS) --output $(BUILD_DIR)/$@ -Wl,-Map,$(BUILD_DIR)/$(basename $@).map + +# Application objects builder +$(APP_OBJECTS): %.o: %.c + $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@) + +# Application C objects builder +$(LIB_OBJECTS): %.o: $(LIB_DIR)/%.c + $(CC) -c $(CFLAGS) $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@) + +# Application asm objects builder +$(LIB_ASM_OBJECTS): %.o: $(LIB_DIR)/%.s + $(CC) -c $(CFLAGS) -x assembler-with-cpp $(INCLUDES) $< -o $(BUILD_DIR)/$(notdir $@) + +# .lst file builder +%.lst: %.c + $(CC) $(CFLAGS) $(INCLUDES) -Wa,-al $< > $@ + +# Clean +clean: + rm -f *.o *.elf *.map *.hex *.bin *.lst + rm -rf doxygen-avr + rm -rf build + +# Send to device +program: $(APP_HEX) + $(SIZE) -C $(BUILD_DIR)/$(APP_ELF) + $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U flash:w:$(BUILD_DIR)/$(APP_HEX) -v + +fuse: + $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -U lfuse:w:0x60:m -U hfuse:w:0xdc:m -U efuse:w:0xff:m -v + +interactive: + $(AVRDUDE) $(AVRDUDE_FLAGS) -c $(PROG) -P $(AVRDUDE_DEV) -p $(AVRDUDE_PART) -t -v + +doxygen: + doxygen ./Doxyfile |