# Simple Makefile
# Volker Oth (c) 1999


########### change this lines according to your project ##################

#put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603 etc.)
    MCU = at90s8535

#put the name of the target file here (without extension)
	TRG	= steuerung

#put your C sourcefiles here 
	SRC	= $(TRG).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 -O2 -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)

#linker flags
	LDFLAGS = -Wl,-Map=$(TRG).map,--cref

###### dependecies, add any dependencies you need here ###################

#$(TRG).o: $(TRG).c 


########### you should not need to change the following line #############
#include $(AVR)/avrfreaks/avr_make

# GCC-AVR standard Makefile part 3
# Based on Volker Oth's makefiles of jan.2000
# Modified and merged by AVRfreaks.net for smoother integration with AVR Studio,
# and easier comprehension for the average user (nov.2001). Minor errors corrected.

# ---------- Included from make1 !!! -----------
###### 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
	BIN	= avr-objcopy
	SIZE	= avr-size
	INCDIR	= .
	LIBDIR	= $(AVR)/avr/lib
	SHELL   = $(AVR)/bin/sh.exe
	ISPEXE  = C:\Programme\PonyProg2000\PONYPROG2000 
	
###### output format can be srec, ihex (avrobj is always created) #######
	FORMAT = ihex	
# ------------------------------------------	

#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 $(TRG).ok 
all:	$(TRG).hex $(TRG).elf $(TRG).rom $(TRG).eep $(TRG).ok 


# --- 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 $< $@		RR: funktioniert auf dem neuen WinAVR-compiler nicht 

# --- create bin (.rom and .eep) files from elf output file ---
%.rom: %.elf
	$(BIN) -O $(FORMAT) -R .eeprom $< $@

%.eep: %.elf
	$(BIN) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O $(FORMAT) $< $@

%.hex: %.elf
	$(BIN) -O $(FORMAT) -R .eeprom $< $@


# --- If all other steps compile ok then echo "Errors: none" ---
# --- Necessary for AVR Studio to understand that everything went ok ---
%ok:
	@echo "Errors: none" 

# --- make instruction to delete created files ---
clean:
	$(RM) *.o
	$(RM) $(OBJ)
	$(RM) $(SRC:.c=.s)
	$(RM) $(SRC:.c=.lst)
	$(RM) $(TRG).map
	$(RM) $(TRG).elf
	$(RM) $(TRG).eep
	$(RM) $(TRG).rom

	$(RM) $(TRG).obj
#	$(RM) $(TRG).a90
	$(RM) $(TRG).hex	
#	$(RM) *.bak
#	$(RM) *.log
	
size:
	$(SIZE) $(TRG).elf
	


isp: $(TRG).hex $(TRG).eep
	echo -e "SELECTDEVICE $(MCU)\nLOAD-PROG $(TRG).hex \nWRITE-PROG" > isp.e2s
	$(ISPEXE) isp.e2s

