# Sample makefile (c) 2002-2003 Eric B. Weddington # Released to the Public Domain # Define directories. DIRAVR = p:/programme/winavr DIRAVRBIN = $(DIRAVR)/bin DIRAVRUTILS = $(DIRAVR)/utils/bin DIRINC = . DIRLIB = $(DIRAVR)/avr/lib # Define programs. SHELL = sh COMPILE = avr-gcc ASSEMBLE = avr-gcc -x assembler-with-cpp REMOVE = rm -f COPY = cp OBJCOPY = avr-objcopy OBJDUMP = avr-objdump ELFCOFF = objtool HEXSIZE = @avr-size --target=$(FORMAT) $(TARGET).hex ELFSIZE = @avr-size $(TARGET).elf FINISH = @echo Errors: none BEGIN = @echo -------- begin -------- END = @echo -------- end -------- # MCU name MCU = at90s8515 # Output format. Can be [srec|ihex]. FORMAT = ihex # Target file name (without extension). TARGET = uart # List C source files here. SRC = $(TARGET).c # List Assembler source files here. ASRC = # Compiler flags. CPFLAGS = -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst) # Assembler flags. ASFLAGS = -Wa,-ahlms=$(<:.s=.lst), -gstabs # Linker flags (passed via GCC). LDFLAGS = -Wl,-Map=$(TARGET).map,--cref # Additional library flags (-lm = math library). LIBFLAGS = -lm # Define all project specific object files. OBJ = $(SRC:.c=.o) $(ASRC:.s=.o) # Define all listing files. LST = $(ASRC:.s=.lst) $(SRC:.c=.lst) # Add target processor to flags. CPFLAGS += -mmcu=$(MCU) ASFLAGS += -mmcu=$(MCU) LDFLAGS += -mmcu=$(MCU) # Default target. .PHONY : all all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).lss $(TARGET).cof sizeafter finished end # Eye candy. .PHONY : begin begin: $(BEGIN) .PHONY : finish finished: $(FINISH) .PHONY : end end: $(END) # Display size of file. .PHONY : sizebefore sizebefore: @echo Size before: -$(HEXSIZE) .PHONY : sizeafter sizeafter: @echo Size after: $(HEXSIZE) # Display compiler version information. .PHONY : gccversion gccversion : $(COMPILE) --version # Create AVROBJ format file from ELF output file. (Future release) #%.obj: %.elf # $(OBJCOPY) -O avrobj -R .eeprom $< $@ # Create COFF format file from ELF output file. %.cof: %.elf $(ELFCOFF) loadelf $< mapfile $*.map writecof $@ # Create final output files (.hex, .eep) from ELF output file. %.hex: %.elf $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ %.eep: %.elf -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ # Create extended listing file from ELF output file. %.lss: %.elf $(OBJDUMP) -h -S $< > $@ # Link: create ELF output file from object files. .SECONDARY : $(TRG).elf .PRECIOUS : $(OBJ) %.elf: $(OBJ) $(COMPILE) $(LDFLAGS) $(OBJ) $(LIBFLAGS) --output $@ # Compile: create object files from C source files. %.o : %.c *.h $(COMPILE) -c $(CPFLAGS) -I$(DIRINC) $< -o $@ # Assemble: create object files from assembler files. %.o : %.s $(ASSEMBLE) -c $(ASFLAGS) -I$(DIRINC) $< -o $@ # Target: clean project. .PHONY : clean clean: begin clean_list finished end .PHONY : clean_list clean_list : $(REMOVE) $(TARGET).hex $(REMOVE) $(TARGET).eep $(REMOVE) $(TARGET).obj $(REMOVE) $(TARGET).cof $(REMOVE) $(TARGET).elf $(REMOVE) $(TARGET).map $(REMOVE) $(TARGET).obj $(REMOVE) $(TARGET).a90 $(REMOVE) $(TARGET).sym $(REMOVE) $(TARGET).lnk $(REMOVE) $(TARGET).lss $(REMOVE) $(OBJ) $(REMOVE) $(LST) $(REMOVE) $(SRC:.c=.s) # Automatically generate C source code dependencies. (Code taken from the GNU make user manual.) # Note that this will work with sh (bash) and sed that is shipped with WinAVR (see the SHELL variable defined above). # This may not work with other shells or other seds. %.d: %.c set -e; $(COMPILE) -MM $(CPFLAGS) $< \ | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \ [ -s $@ ] || rm -f $@ include $(SRC:.c=.d) # List assembly only source file dependencies here: