Makefiles for Linux
[owSlave2.git] / DS2450 / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2
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)
6
7
8 MCU = attiny84
9 FORMAT = ihex
10 TARGET =DS2450
11 SRC = DS2450.c
12 ASRC = OWDS2450.S
13
14 # Name of this Makefile (used for "make depend").
15 MAKEFILE = Makefile
16
17
18 CFLAGS = -x c -funsigned-char -funsigned-bitfields -I. -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall   -std=gnu99 -MD -MP 
19
20 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
21
22
23 #Additional libraries.
24
25 # Minimalistic printf version
26 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
27
28 # Floating point printf version (requires MATH_LIB = -lm below)
29 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
30
31 PRINTF_LIB = 
32
33 # Minimalistic scanf version
34 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
35
36 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
37 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
38
39 SCANF_LIB = 
40
41 MATH_LIB = -lm
42
43 # External memory options
44
45 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
46 # used for variables (.data/.bss) and heap (malloc()).
47 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
48
49 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
50 # only used for heap (malloc()).
51 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
52
53 EXTMEMOPTS =
54
55 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
56 #LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
57 LDFLAGS = -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=$(MCU)
58
59 # Programming support using avrdude. Settings and variables.
60
61 #AVRDUDE_PROGRAMMER = stk500
62 #AVRDUDE_PORT = /dev/term/a
63
64 #AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
65 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
66
67
68 # Uncomment the following if you want avrdude's erase cycle counter.
69 # Note that this counter needs to be initialized first using -Yn,
70 # see avrdude manual.
71 #AVRDUDE_ERASE_COUNTER = -y
72
73 # Uncomment the following if you do /not/ wish a verification to be
74 # performed after programming the device.
75 #AVRDUDE_NO_VERIFY = -V
76
77 # Increase verbosity level.  Please use this when submitting bug
78 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
79 # to submit bug reports.
80 #AVRDUDE_VERBOSE = -v -v
81
82 #AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
83 #AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
84
85
86 CC = avr-gcc
87 OBJCOPY = avr-objcopy
88 OBJDUMP = avr-objdump
89 SIZE = avr-size
90 NM = avr-nm
91 #AVRDUDE = avrdude
92 REMOVE = rm -f
93 MV = mv -f
94
95 # Define all object files.
96 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
97
98 # Define all listing files.
99 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
100
101 # Combine all necessary flags and optional flags.
102 # Add target processor to flags.
103 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
104 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
105
106
107 # Default target.
108 all: build
109
110 build: elf hex eep
111
112 elf: $(TARGET).elf
113 hex: $(TARGET).hex
114 #eep: $(TARGET).eep
115 lss: $(TARGET).lss 
116 sym: $(TARGET).sym
117
118
119 # Program the device.  
120 program: $(TARGET).hex $(TARGET).eep
121         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
122
123
124
125
126 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
127 COFFCONVERT=$(OBJCOPY) --debugging \
128 --change-section-address .data-0x800000 \
129 --change-section-address .bss-0x800000 \
130 --change-section-address .noinit-0x800000 \
131 --change-section-address .eeprom-0x810000 
132
133
134 coff: $(TARGET).elf
135         $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
136
137
138 extcoff: $(TARGET).elf
139         $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
140
141
142 .SUFFIXES: .elf .hex .eep .lss .sym
143
144 .elf.hex:
145         $(OBJCOPY) -O $(FORMAT) $< $@
146 #       $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
147
148 .elf.eep:
149         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
150         --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
151
152 # Create extended listing file from ELF output file.
153 .elf.lss:
154         $(OBJDUMP) -h -S $< > $@
155
156 # Create a symbol table from ELF output file.
157 .elf.sym:
158         $(NM) -n $< > $@
159
160
161
162 # Link: create ELF output file from object files.
163 $(TARGET).elf: $(OBJ)
164         $(CC)  $(OBJ) --output $@ $(LDFLAGS)
165
166
167 # Compile: create object files from C source files.
168 .c.o:
169         $(CC) -c $(ALL_CFLAGS) $< -o $@ 
170
171
172 # Compile: create assembler files from C source files.
173 .c.s:
174         $(CC) -S $(ALL_CFLAGS) $< -o $@
175
176
177 # Assemble: create object files from assembler source files.
178 .S.o:
179         $(CC) -c $(ALL_ASFLAGS) $< -o $@
180
181
182
183 # Target: clean project.
184 clean:
185         $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
186         $(TARGET).map $(TARGET).sym $(TARGET).lss \
187         $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
188
189 depend:
190         if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
191         then \
192                 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
193                         $(MAKEFILE).$$$$ && \
194                 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
195         fi
196         echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
197                 >> $(MAKEFILE); \
198         $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
199
200 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
201
202