1 # Hey Emacs, this is a -*- makefile -*-
3 # AVR-GCC Makefile template, derived from the WinAVR template (which
4 # is public domain), believed to be neutral to any flavor of "make"
5 # (GNU make, BSD make, SysV make)
10 TARGET = keyboard-i2c-slave
20 # Programming support using avrdude. Settings and variables.
22 AVRDUDE_PROGRAMMER = arduino
23 AVRDUDE_PORT = /dev/ttyACM0
25 # Name of this Makefile (used for "make depend").
29 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
30 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
33 # Compiler flag to set the C Standard level.
35 # gnu89 - c89 plus GCC extensions
36 # c99 - ISO C99 standard (not yet fully implemented)
37 # gnu99 - c99 plus GCC extensions
38 CSTANDARD = -std=gnu99
40 # Place -D or -U options here
43 # Place -I options here
48 CWARN = -Wall -Wstrict-prototypes
49 CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
50 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
51 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) \
52 -fno-aggressive-loop-optimizations
54 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
57 #Additional libraries.
59 # Minimalistic printf version
60 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
62 # Floating point printf version (requires MATH_LIB = -lm below)
63 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
67 # Minimalistic scanf version
68 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
70 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
71 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
77 # External memory options
79 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
80 # used for variables (.data/.bss) and heap (malloc()).
81 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
83 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
84 # only used for heap (malloc()).
85 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
89 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
90 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
93 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
94 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
97 # Uncomment the following if you want avrdude's erase cycle counter.
98 # Note that this counter needs to be initialized first using -Yn,
100 #AVRDUDE_ERASE_COUNTER = -y
102 # Uncomment the following if you do /not/ wish a verification to be
103 # performed after programming the device.
104 #AVRDUDE_NO_VERIFY = -V
106 # Increase verbosity level. Please use this when submitting bug
107 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
108 # to submit bug reports.
109 #AVRDUDE_VERBOSE = -v -v
111 AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
112 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
116 OBJCOPY = avr-objcopy
117 OBJDUMP = avr-objdump
124 # Define all object files.
125 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
127 # Define all listing files.
128 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
130 # Combine all necessary flags and optional flags.
131 # Add target processor to flags.
132 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
133 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
148 # Program the device.
149 program: $(TARGET).hex $(TARGET).eep
150 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
153 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
154 COFFCONVERT=$(OBJCOPY) --debugging \
155 --change-section-address .data-0x800000 \
156 --change-section-address .bss-0x800000 \
157 --change-section-address .noinit-0x800000 \
158 --change-section-address .eeprom-0x810000
162 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
165 extcoff: $(TARGET).elf
166 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
169 .SUFFIXES: .elf .hex .eep .lss .sym
172 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
175 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
176 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
178 # Create extended listing file from ELF output file.
180 $(OBJDUMP) -h -S $< > $@
182 # Create a symbol table from ELF output file.
188 # Link: create ELF output file from object files.
189 $(TARGET).elf: $(OBJ)
190 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
193 # Compile: create object files from C source files.
195 $(CC) -c $(ALL_CFLAGS) $< -o $@
198 # Compile: create assembler files from C source files.
200 $(CC) -S $(ALL_CFLAGS) $< -o $@
203 # Assemble: create object files from assembler source files.
205 $(CC) -c $(ALL_ASFLAGS) $< -o $@
209 # Target: clean project.
211 $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
212 $(TARGET).map $(TARGET).sym $(TARGET).lss \
213 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
216 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
218 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
219 $(MAKEFILE).$$$$ && \
220 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
222 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
224 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
226 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend