# This makefile is a combination of Weddington's and the sample makefile # supplied with WinAvr. Each have interesting results and I want them all. # Sample makefile by Todd G. Batzler # Released to the Public Domain # Define the stuff the casual user needs to change. PRG_TARGET = gcctest9 OBJ = gcctest9.o SRC = gcctest9.c ASRC = MCU_TARGET = at90s8535 OPTIMIZE = -O0 #-O0, -Os, -O1, -O2, -03 DEFS = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums LIBS = ###### dependecies, add any dependencies you need here ################### FILE_1 = gcctest9.o : gcctest9.c FILE_2 = FILE_3 = FILE_4 = FILE_5 = FILE_6 = FILE_7 = ############################################################################### ## Below this line, is generally set up just once and doesn't need to change. # Define directories. DIRAVR = c:/avr/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=ihex $(PRG_TARGET).hex ELFSIZE = @avr-size $(PRG_TARGET).elf FINISH = @echo Errors: none BEGIN = @echo -------- begin -------- END = @echo -------- end -------- DEPENDS = $(PRG_TARGET).o : $(PRG_TARGET).c # Compiler flags. CPFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -Wstrict-prototypes -Wa,-ahlmsd=$(<:.c=.lst) # Assembler flags. ASFLAGS = -Wa,-ahlmsd=$(<:.s=.lst), -gstabs # Linker flags (passed via GCC). LDFLAGS = -Wl,-Map=$(PRG_TARGET).map,--cref # Additional library flags (-lm = math library). LIBFLAGS = -lm $(LIBS) # 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_TARGET) ASFLAGS += -mmcu=$(MCU_TARGET) LDFLAGS += -mmcu=$(MCU_TARGET) # Default target. .PHONY : all all: begin gccversion sizebefore $(PRG_TARGET).elf text eeprom $(PRG_TARGET).lss \ $(PRG_TARGET).cof sizeafter finished depends end # Eye candy. .PHONY : begin begin: $(BEGIN) .PHONY : depends $(DEPENDS) $(FILE_1) $(FILE_2) $(FILE_3) $(FILE_4) $(FILE_5) $(FILE_6) $(FILE_7) .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 $@ # Rules for building the .text rom images text: hex bin srec hex: $(PRG_TARGET).hex bin: $(PRG_TARGET).bin srec: $(PRG_TARGET).srec %.hex: %.elf $(OBJCOPY) -j .text -j .data -O ihex $< $@ %.srec: %.elf $(OBJCOPY) -j .text -j .data -O srec $< $@ %.bin: %.elf $(OBJCOPY) -j .text -j .data -O binary $< $@ # Rules for building the .eeprom rom images eeprom: ehex ebin esrec ehex: $(PRG_TARGET)_eeprom.hex ebin: $(PRG_TARGET)_eeprom.bin esrec: $(PRG_TARGET)_eeprom.srec %_eeprom.hex: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ %_eeprom.srec: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ %_eeprom.bin: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ # 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 $(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) $(PRG_TARGET).hex $(REMOVE) $(PRG_TARGET).eep $(REMOVE) $(PRG_TARGET).obj $(REMOVE) $(PRG_TARGET).cof $(REMOVE) $(PRG_TARGET).elf $(REMOVE) $(PRG_TARGET).map $(REMOVE) $(PRG_TARGET).obj $(REMOVE) $(PRG_TARGET).a90 $(REMOVE) $(PRG_TARGET).sym $(REMOVE) $(PRG_TARGET).lnk $(REMOVE) $(PRG_TARGET).lss $(REMOVE) $(PRG_TARGET).rom $(REMOVE) $(OBJ) $(REMOVE) $(LST) $(REMOVE) $(SRC:.c=.s)