# Simple Makefile based on work by Volker Oth # Ron Kreymborg # # Define some variables based on the AVR base path in $(AVR) AVR = c:/avrgcc CC = avr-gcc AS = avr-gcc -x assembler-with-cpp RM = rm -f BIN = $(AVR)/bin/avr-objcopy INCDIR = . # Output format can be srec, ihex (avrobj is always created) FORMAT = srec # Default compiler flags CPFLAGS = -g -O -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst) # Default assembler flags ASFLAGS = -Wa,-gstabs # Default linker flags LDFLAGS = -Wl,-Map=$(TRG).map,--cref # Put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603 etc.) MCU = atmega103 # Put the name of the target file here (without extension) TRG = main # List your C sourcefiles here SRC=$(TRG).c taskr.c # Put additional assembler source file here ASRC = # Additional libraries and object files to link LIB = # Additional includes to compile INC = # Compiler flags CPFLAGS = -g -O -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst) -fverbose-asm -save-temps # Assembler flags ASFLAGS = -gstabs # Linker flags LDFLAGS = -Wl,-Map=$(TRG).map,--cref -lm # Define all project specific object files OBJ = $(ASRC:.s=.o) $(SRC:.c=.o) CPFLAGS += -mmcu=$(MCU) ASFLAGS += -mmcu=$(MCU) LDFLAGS += -mmcu=$(MCU) # This defines the aims of the make process all: $(TRG).obj $(TRG).elf $(TRG).rom $(TRG).eep # Compile: instructions to create assembler and/or object files from C source %o : %c $(CC) -c $(CPFLAGS) -I$(INCDIR) $< -o $@ %s : %c $(CC) -S $(CPFLAGS) -I$(INCDIR) $< -o $@ # Assemble: instructions to create object file from assembler files %o : %s $(AS) -c $(ASFLAGS) -I$(INCDIR) $< -o $@ # Link: instructions to create elf output file from object files %elf: $(OBJ) $(CC) $(OBJ) $(LIB) $(LDFLAGS) -o $@ # Create avrobj file from elf output file %obj: %elf $(BIN) -O avrobj -R .eeprom $< $@ # Create bin (ihex, srec) file from elf output file %rom: %elf $(BIN) -O $(FORMAT) -R .eeprom $< $@ # Create eeprom load module from elf %eep: %elf $(BIN) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ # Make instruction to delete created files clean: $(RM) $(OBJ) $(RM) $(SRC:.c=.s) $(RM) $(SRC:.c=.lst) $(RM) $(TRG).map $(RM) $(TRG).elf $(RM) $(TRG).obj $(RM) $(TRG).eep $(RM) $(TRG).rom $(RM) *.bak $(RM) *.log # Dependecies, add any dependencies you need here... $(TRG).o : $(TRG).c taskr.h taskr.o : taskr.c taskr.h critical.h