Merge branch 'experimental'
[opensid.git] / Makefile
blob0a3117e3eeb7e12404b19a1cfd9cadc681f53f65
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)
7 MCU = atmega32
8 F_CPU = 16000000UL
10 FORMAT = ihex
11 TARGET = main
13 BASEDIR = src
14 SRC = $(BASEDIR)/$(TARGET).c \
15 $(BASEDIR)/lib/fifo.c \
16 $(BASEDIR)/lib/usart.c
17 ASRC =
18 OPT = s
20 # Name of this Makefile (used for "make depend").
21 MAKEFILE = Makefile
23 # Debugging format.
24 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
25 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
26 DEBUG = stabs
28 # Compiler flag to set the C Standard level.
29 # c89 - "ANSI" C
30 # gnu89 - c89 plus GCC extensions
31 # c99 - ISO C99 standard (not yet fully implemented)
32 # gnu99 - c99 plus GCC extensions
33 CSTANDARD = -std=gnu99
35 # Place -D or -U options here
36 CDEFS =
38 # Place -I options here
39 CINCS =
41 CDEBUG = -g$(DEBUG)
42 CWARN = -Wall -Wstrict-prototypes
43 CTUNING = -funsigned-char -funsigned-bitfields \
44 -fpack-struct -fshort-enums -ffreestanding \
45 -ffunction-sections -fdata-sections
47 CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
48 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
50 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
52 #Additional libraries.
54 # Minimalistic printf version
55 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
57 # Floating point printf version (requires MATH_LIB = -lm below)
58 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
60 PRINTF_LIB =
62 # Minimalistic scanf version
63 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
65 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
66 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
68 SCANF_LIB =
70 MATH_LIB = -lm
72 # External memory options
74 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
75 # used for variables (.data/.bss) and heap (malloc()).
76 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
78 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
79 # only used for heap (malloc()).
80 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
82 EXTMEMOPTS =
84 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
85 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
88 # Programming support using avrdude. Settings and variables.
90 AVRDUDE_PROGRAMMER = avrispmkII
91 AVRDUDE_PORT = usb
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,
99 # see avrdude manual.
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)
115 CC = avr-gcc
116 OBJCOPY = avr-objcopy
117 OBJDUMP = avr-objdump
118 SIZE = avr-size
119 NM = avr-nm
120 AVRDUDE = avrdude
121 REMOVE = rm -f
122 MV = mv -f
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) -DF_CPU=$(F_CPU) -Wl,--relax,--gc-sections
133 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) -DF_CPU=$(F_CPU)
136 # Default target.
137 all: build
139 build: elf hex eep
141 elf: $(TARGET).elf
142 hex: $(TARGET).hex
143 eep: $(TARGET).eep
144 lss: $(TARGET).lss
145 sym: $(TARGET).sym
147 # Program the device.
148 program: $(TARGET).hex $(TARGET).eep
149 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
151 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
152 COFFCONVERT=$(OBJCOPY) --debugging \
153 --change-section-address .data-0x800000 \
154 --change-section-address .bss-0x800000 \
155 --change-section-address .noinit-0x800000 \
156 --change-section-address .eeprom-0x810000
158 coff: $(TARGET).elf
159 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
162 extcoff: $(TARGET).elf
163 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
165 .SUFFIXES: .elf .hex .eep .lss .sym
167 .elf.hex:
168 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
170 .elf.eep:
171 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
172 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
174 # Create extended listing file from ELF output file.
175 .elf.lss:
176 $(OBJDUMP) -h -S $< > $@
178 # Create a symbol table from ELF output file.
179 .elf.sym:
180 $(NM) -n $< > $@
183 # Link: create ELF output file from object files.
184 $(TARGET).elf: $(OBJ)
185 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
188 # Compile: create object files from C source files.
189 .c.o:
190 $(CC) -c $(ALL_CFLAGS) $< -o $@
192 # Compile: create assembler files from C source files.
193 .c.s:
194 $(CC) -S $(ALL_CFLAGS) $< -o $@
196 # Assemble: create object files from assembler source files.
197 .S.o:
198 $(CC) -c $(ALL_ASFLAGS) $< -o $@
200 # XXX: Determine free flash
201 size: $(TARGET).elf
202 tools/space.sh $^
204 # XXX: Flash consumption details
205 size-detail: $(TARGET).elf
206 tools/space-detail.sh $^
208 # Target: clean project.
209 clean:
210 $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
211 $(TARGET).map $(TARGET).sym $(TARGET).lss \
212 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
214 depend:
215 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
216 then \
217 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
218 $(MAKEFILE).$$$$ && \
219 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
221 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
222 >> $(MAKEFILE); \
223 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
225 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend size size-detail