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)
11 SRC = ../common/I2C/BMP280.c ../common/I2C/MAX1164x.c ../common/I2C/SHT2x.c ../common/I2C/USI_TWI_Master.c DS2450_VOC_SHT_BMP.c
12 ASRC = ../common/OWDS2450.S
14 # Name of this Makefile (used for "make depend").
18 CFLAGS = -x c -funsigned-char -funsigned-bitfields -I. -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -Wall -std=gnu99 -MD -MP
20 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
23 #Additional libraries.
25 # Minimalistic printf version
26 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
28 # Floating point printf version (requires MATH_LIB = -lm below)
29 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
33 # Minimalistic scanf version
34 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
36 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
37 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
43 # External memory options
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
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
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)
59 # Programming support using avrdude. Settings and variables.
61 #AVRDUDE_PROGRAMMER = stk500
62 #AVRDUDE_PORT = /dev/term/a
64 #AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
65 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
68 # Uncomment the following if you want avrdude's erase cycle counter.
69 # Note that this counter needs to be initialized first using -Yn,
71 #AVRDUDE_ERASE_COUNTER = -y
73 # Uncomment the following if you do /not/ wish a verification to be
74 # performed after programming the device.
75 #AVRDUDE_NO_VERIFY = -V
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
82 #AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
83 #AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
95 # Define all object files.
96 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
98 # Define all listing files.
99 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
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)
119 # Program the device.
120 program: $(TARGET).hex $(TARGET).eep
121 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
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
135 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
138 extcoff: $(TARGET).elf
139 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
142 .SUFFIXES: .elf .hex .eep .lss .sym
145 $(OBJCOPY) -O $(FORMAT) $< $@
146 # $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
149 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
150 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
152 # Create extended listing file from ELF output file.
154 $(OBJDUMP) -h -S $< > $@
156 # Create a symbol table from ELF output file.
162 # Link: create ELF output file from object files.
163 $(TARGET).elf: $(OBJ)
164 $(CC) $(OBJ) --output $@ $(LDFLAGS)
167 # Compile: create object files from C source files.
169 $(CC) -c $(ALL_CFLAGS) $< -o $@
172 # Compile: create assembler files from C source files.
174 $(CC) -S $(ALL_CFLAGS) $< -o $@
177 # Assemble: create object files from assembler source files.
179 $(CC) -c $(ALL_ASFLAGS) $< -o $@
183 # Target: clean project.
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)
190 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
192 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
193 $(MAKEFILE).$$$$ && \
194 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
196 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
198 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
200 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend