#makefile variables PRG = count OBJ = $(PRG).o MCU_TARGET = atmega128 OPTIMIZE = -O0 # options are 1, 2, 3, s OBJCOPY = avr-objcopy OBJDUMP = avr-objdump CC = avr-gcc #compiler and linker/loader flags override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) override LDFLAGS = -Wl,-Map,$(PRG).map #The automatic variables make recognizes: # $@ file name of target, i.e., left hand side of : # $< name of first prerequisite # $? name of all the prerequisites that are newer than the target # $^, $+ Names of all the prerequisites # all: $(PRG).elf lst text eeprom ####################################################################### # The dependency for 'all" is the program.elf and three other rules. # The target "all" is known as a "phony target" as it is not a file # but a name used to have "make" do something for you. If no argument # is given to make, it processes the first rule. ####################################################################### $(PRG).elf: $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ ########################################################### # Make understands that to make an .obj you compile a .c # Thus we only need to say we want a .elf from an .obj # $@ is make shorthand for left hand side of ":" (think "bulls eye") # $^ is make shorthand for right hand side of ":" (all the prereqs) ########################################################### clean: rm -rf *.o $(PRG).elf *.lst *.map ########################################################## # The target "clean" is another phony target that cleans # up all the extra files we make at each compile. ########################################################## program: $(PRG).hex uisp -dprog=stk200 -dpart=atmega128 -dlpt=/dev/parport0 --erase --upload if=$(PRG).hex ########################################################## # Target "program" depends on the .hex file which it # downloads to the target board using the parallel port. ########################################################## lst: $(PRG).lst %.lst: %.elf $(OBJDUMP) -h -S $< > $@ ############################################################ # The target "lst" is another phony target. Its depends # on the .lst (list) file. The list file shows the # assembly language output of the compiler intermixed # with the C code so it is easier to debug and follow. # avr-objdump ($OBJDUMP) is the avr binutil tool we us to # get information from the .elf file. # # $@ is the file name of the target, i.e., left hand side of : # $< is shorthand for source file for the single dependency ############################################################ ############################################################ # Following are rules for building the .text rom images # This is the stuff that will be put in flash. ############################################################ #.text section holds code and read only data text: hex bin srec hex: $(PRG).hex bin: $(PRG).bin srec: $(PRG).srec %.hex: %.elf $(OBJCOPY) -j .text -j .data -O ihex $< $@ ########################################################## # This rule is very general in that it can take any .elf # file and build the .hex file from it using avr-objcopy. # avr-objcopy is used to extract the downloadable portion # of the .elf file to build the flash image. ########################################################## %.srec: %.elf $(OBJCOPY) -j .text -j .data -O srec $< $@ ########################################################## # Very similiar to above line except it is building # Motorols S-records which are a ASCII representation # of the binary flash file. ########################################################## %.bin: %.elf $(OBJCOPY) -j .text -j .data -O binary $< $@ ########################################################## # Once again extracting the .bin from the .elf file. ########################################################## ########################################################## # Following are rules for building the .eeprom images # This is the stuff that will be put in EEPROM. ########################################################## eeprom: ehex ebin esrec ehex: $(PRG)_eeprom.hex ebin: $(PRG)_eeprom.bin esrec: $(PRG)_eeprom.srec %_eeprom.hex: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ ################################################################# #This builds the EEPROM image from the .elf file for downloading. ################################################################# %_eeprom.srec: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@ ################################################################ #This builds the S-record image from the .elf file if necessary. ################################################################ %_eeprom.bin: %.elf $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ ############################################################ #This builds a binary image from the .elf file if necessary. ############################################################