-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (105 loc) · 3.3 KB
/
Copy pathMakefile
File metadata and controls
147 lines (105 loc) · 3.3 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Freecut: open firmware for Cricut Personal devices.
#
#
# MCU name
MCU = atmega128
# Output format. (can be srec, ihex)
FORMAT = ihex
# Target file name (without extension).
TARGET = freecut
# Speed
FCLK = 16000000UL
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c usb.c lcd.c keypad.c timer.c stepper.c cli.c flash.c dial.c
# Assembler sources
ASRC =
# Optional compiler flags.
CFLAGS = -D$(MCU) $(TEST) $(CE) -Os -DFCLK=$(FCLK) -fpack-struct
CFLAGS += -fshort-enums -Wall -Werror -Wstrict-prototypes
# Optional assembler flags.
ASFLAGS = -Wa,-ahlms=$(<:.S=.lst),-gstabs
# Optional linker flags.
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Additional libraries
#
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
#
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
#
# -lm = math library
LDFLAGS += -lm
# ---------------------------------------------------------------------------
# Define directories, if needed.
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
# Define all object files.
OBJ = $(ASRC:.S=.o) $(SRC:.c=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags. Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: $(TARGET).elf $(TARGET).hex $(TARGET).lss tags
.PHONY: prog
prog: all
avrdude -pm128 -cstk500v2 -b115200 -P/dev/ttyUSB0 -u -V -U flash:w:$(TARGET).hex:i
# Create final output files (.hex) from ELF output file.
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
# Disassembly listing
%.dis: %.elf
$(OBJDUMP) -d $< > $@
# Create extended listing file from ELF output file.
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean :
rm -f *.hex
rm -f *.obj
rm -f *.elf
rm -f *.map
rm -f *.obj
rm -f *.sym
rm -f *.ssm
rm -f *.lnk
rm -f *.lss
rm -f *.lst
rm -f $(OBJ)
rm -f $(LST)
rm -f $(SRC:.c=.s)
rm -f $(SRC:.c=.d)
rm -f logfile
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified (See README.txt Credits).)
# Note that this will work with sh (bash) and sed that is shipped with WinAVR (see the SHELL variable defined above).
# This may not work with other shells or other seds.
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed -e 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' \
> $@; [ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all clean
tags: *.[hc]
ctags *.[hc]