aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Makefile
blob: 8fe680986681cec0034a878cc3b5e637e119b206 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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