# AVR-GCC Makefile # # history: # Sept. 2nd 2002 - S. Gauthier - Added '-lm' to linker flags to allow use of math library. # Dec. 31st 2002 - S. Gauthier - Added '-Wl,-u,vfprintf -lprintf_flt' to linker flags to allow use of new printf float library. # #************************************************************** .SUFFIXES: .SUFFIXES: .S .c .o .obj .elf .eep .rom #--- define some variables based on the AVR base path in $(AVR) CC = avr-gcc AS = avr-gcc -x assembler-with-cpp RM = rm -f RN = mv CP = cp BIN = avr-objcopy INCDIR = -I. -I$(AVRX)/avrx -I$(AVR)/avr/inc LIBDIR = $(AVRX)/avrx/avrx.a SHELL = $(AVR)/bin/sh.exe #--- default mcu type MCU = atmega128 #--- default compiler flags -ahlmsn CPFLAGS = -g -Os -Wall -Wstrict-prototypes -Wa,-adhlmsn=$(<:.c=.lst) -mmcu=$(MCU) #--- default assembler flags ASFLAGS = -mmcu=$(MCU) -Wa,-mmcu=$(MCU),-gstabs #--- default linker flags (to get printf w/ floats append this '-Wl,-u,vfprintf -lprintf_flt -lm') LDFLAGS = -Wl,-Map=$(<:.o=.map),--cref -mmcu=$(MCU) -lm #--- output format can be srec, ihex ROMFORMAT = ihex EEPROMFORMAT = ihex #--- compile: instructions to create assembler and/or object files from C source #.c.o: %o : %c $(CC) -c $(CPFLAGS) $(INCDIR) $< -o $@ %s : %c $(CC) -s $(CPFLAGS) $(INCDIR) $< -o $@ #--- assemble: instructions to create object file from assembler source %o : %S $(AS) -x assembler-with-cpp $(ASFLAGS) $(INCDIR) -c $< -o $@ #--- link: instructions to create elf output file from object files %elf: %o $(CC) $^ $(LIBDIR) $(LDFLAGS) -o $@ #--- create avrobj file from elf output file %obj: %elf # $(BIN) -O avrobj -R .eeprom $< $@ $(BIN) -O ihex -R .eeprom $< $@ #--- create flash and eeprom bin file (ihex, srec) from elf output file %hex: %elf $(BIN) -O $(ROMFORMAT) -R .eeprom $< $@ %eep: %elf $(BIN) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(EEPROMFORMAT) $< $(@:.elf=.eep) #*************************** add your projects below ************************************** #--- this defines the aims of the make process all: srx1 avr-size srx1.elf avr-sizex --flash 130048 -m $(MCU) srx1.elf #done with target all clean: $(RM) *.o $(RM) *.elf $(RM) *.obj $(RM) *.eep $(RM) *.hex $(RM) *.o $(RM) *.lst $(RM) *.rom $(RM) *.map $(RM) *.c_sym upload: loadmega -f=srx1.hex -port=2 -speed=38400 -pages=4 -size=256 -delay=8 #-------- project source definitions. srx1: srx1.obj srx1.hex srx1.elf: srx1.o HW_drivers.o serialio.o generalio.o MotorTask.o I2C.o srx1.o: makefile srx1.c hardware.h definitions.h text_strings.h scm\scm_cmds.h #-------- Low-level IO routines (processor dependent) serialio.o: serialio.c serialio.h hardware.h definitions.h #-------- General IO routines (non-processor dependent) generalio.o: generalio.c generalio.h hardware.h definitions.h #-------- General H/W drivers HW_drivers.o: HW_drivers.c HW_drivers.h hardware.h definitions.h #-------- Motor Task MotorTask.o: MotorTask.c MotorTask.h hardware.h definitions.h #-------- I2C high level routines and TWI (I2C) Low-level interface I2C.o: I2C.c I2C.h hardware.h