lline: Makefile: compile seperately
[avr_work.git] / lline / Makefile
blobea19807e8a34ff55445f000d12c7b8896f0638fb
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)
8 MCU = attiny861
9 ADMCU = attiny861
10 F_CPU = 8000000
11 FORMAT = ihex
12 TARGET = main
13 SRC = main.c
14 SRC += spi_io.c ../common/queue.c
15 SRC += adc.c
16 SRC += motor.c
18 ASRC =
19 OPT = s
21 # Name of this Makefile (used for "make depend").
22 MAKEFILE = Makefile
24 # Debugging format.
25 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
26 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
27 DEBUG = stabs
29 # Compiler flag to set the C Standard level.
30 # c89 - "ANSI" C
31 # gnu89 - c89 plus GCC extensions
32 # c99 - ISO C99 standard (not yet fully implemented)
33 # gnu99 - c99 plus GCC extensions
34 CSTANDARD = -std=gnu99
36 # Place -D or -U options here
37 CDEFS =
39 # Place -I options here
40 CINCS = -I../common
41 CLINK =
43 CDEBUG = -g$(DEBUG)
44 CWARN = -Wall -Wstrict-prototypes -Wextra -Wno-main
45 CWARN += -Wunknown-pragmas -Wfloat-equal -Wundef -Wbad-function-cast
46 CWARN += -Wstrict-overflow -Wmissing-format-attribute
47 CWARN += -Wunsafe-loop-optimizations -Wstrict-prototypes
48 CWARN += -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion
49 CWARN += -Wpacked
50 CTUNING = -funsigned-char -funsigned-bitfields -fshort-enums
51 CTUNING += -fmerge-all-constants -funsafe-loop-optimizations
52 CTUNING += -fstrict-overflow
53 #CTUNING += -fpack-struct
55 #CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
56 CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) $(CLINK) $(CTUNING)
59 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
62 #Additional libraries.
64 # Minimalistic printf version
65 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
67 # Floating point printf version (requires MATH_LIB = -lm below)
68 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
70 #PRINTF_LIB = $(PRINTF_LIB_MIN)
71 PRINTF_LIB =
74 # Minimalistic scanf version
75 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
77 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
78 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
80 SCANF_LIB =
81 #SCANF_LIB = $(SCANF_LIB_MIN)
83 #MATH_LIB = -lm
84 MATH_LIB =
86 # External memory options
88 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
89 # used for variables (.data/.bss) and heap (malloc()).
90 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
92 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
93 # only used for heap (malloc()).
94 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
96 EXTMEMOPTS =
98 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
99 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
102 # Programming support using avrdude. Settings and variables.
104 AVRDUDE_PROGRAMMER = usbtiny
105 #AVRDUDE_PORT = "-P /dev/ttyUSB0"
107 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
108 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
111 # Uncomment the following if you want avrdude's erase cycle counter.
112 # Note that this counter needs to be initialized first using -Yn,
113 # see avrdude manual.
114 #AVRDUDE_ERASE_COUNTER = -y
116 # Uncomment the following if you do /not/ wish a verification to be
117 # performed after programming the device.
118 #AVRDUDE_NO_VERIFY = -V
120 # Increase verbosity level. Please use this when submitting bug
121 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
122 # to submit bug reports.
123 #AVRDUDE_VERBOSE = -v -v
125 AVRDUDE_BASIC = -p $(ADMCU) $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
126 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
127 AVRDUDE_POWER = -t -p $(ADMCU) -c $(AVRDUDE_PROGRAMMER)
129 CC = avr-gcc
130 OBJCOPY = avr-objcopy
131 OBJDUMP = avr-objdump
132 SIZE = avr-size
133 NM = avr-nm
134 AVRDUDE = avrdude
135 REMOVE = rm -f
136 MV = mv -f
138 # Define all object files.
139 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
141 # Define all listing files.
142 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
144 # Combine all necessary flags and optional flags.
145 # Add target processor to flags.
146 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
147 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
148 ALL_CFLAGS += -DF_CPU=$(F_CPU)
149 ALL_ASFLAGS += -DF_CPU=$(F_CPU)
152 # Default target.
153 all: build
155 size: elf
156 $(SIZE) -C --mcu=$(MCU) $(TARGET).elf
159 build: elf hex eep
161 elf: $(TARGET).elf
162 hex: $(TARGET).hex
163 eep: $(TARGET).eep
164 lss: $(TARGET).lss
165 sym: $(TARGET).sym
168 # Program the device.
169 program: $(TARGET).hex $(TARGET).eep
170 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
173 power:
174 $(AVRDUDE) $(AVRDUDE_POWER)
176 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
177 COFFCONVERT=$(OBJCOPY) --debugging \
178 --change-section-address .data-0x800000 \
179 --change-section-address .bss-0x800000 \
180 --change-section-address .noinit-0x800000 \
181 --change-section-address .eeprom-0x810000
184 coff: $(TARGET).elf
185 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
188 extcoff: $(TARGET).elf
189 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
192 .SUFFIXES: .elf .hex .eep .lss .sym
194 .elf.hex:
195 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
197 .elf.eep:
198 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
199 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
201 # Create extended listing file from ELF output file.
202 .elf.lss:
203 $(OBJDUMP) -h -S $< > $@
205 # Create a symbol table from ELF output file.
206 .elf.sym:
207 $(NM) -n $< > $@
211 # Link: create ELF output file from object files.
212 $(TARGET).elf: $(OBJ)
213 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
214 #$(CC) $(ALL_CFLAGS) $(SRC) --combine -fwhole-program --output $@ $(LDFLAGS)
216 # Compile: create object files from C source files.
217 .c.o:
218 $(CC) -c $(ALL_CFLAGS) $< -o $@
221 # Compile: create assembler files from C source files.
222 .c.s:
223 $(CC) -S $(ALL_CFLAGS) $< -o $@
226 # Assemble: create object files from assembler source files.
227 .S.o:
228 $(CC) -c $(ALL_ASFLAGS) $< -o $@
232 # Target: clean project.
233 clean:
234 $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
235 $(TARGET).map $(TARGET).sym $(TARGET).lss \
236 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
238 depend:
239 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
240 then \
241 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
242 $(MAKEFILE).$$$$ && \
243 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
245 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
246 >> $(MAKEFILE); \
247 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
249 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
250 # DO NOT DELETE THIS LINE -- make depend depends on it.