#
# Makefile for yampp-3
#
# Jesper Hansen 2001-05-22
# 
# Nikolai Vorontsov 2001-11-01
#
# Romuald Bialy 2003-10-08

# Tools and directories
CC		= avr-gcc
AS		= avr-gcc -x assembler-with-cpp	
RM		= rm -f
RN		= mv
BIN		= avr-objcopy
INCDIR	= .
LIBDIR	= $(AVR)\avr\lib
SHELL   = $(AVR)\bin\sh.exe
FORMAT  = srec


############################################################################################
############################################################################################

	
# CPU type
MCU = atmega161
#MCU = atmega162

# Target
TRG	= yampp3u_CD

# Assembler source files
ASRC    = vs1001.s delay.s

# C-source files
SRC	= remote.c lcd.c iso9660.c atapi.c uart.c $(TRG).c


# Libraries 
LIB = 

# Compiler flags
CPFLAGS	=  -g -Os -fregmove -fforce-addr -Wall -Wstrict-prototypes -Wa,-ahlms=$(<:.c=.lst)

# Assembler flags
ASFLAGS = -Wa,-gstabs

# Linker flags
LDFLAGS = -Wl,--defsym,__init_wdtcr__=0x07,--defsym,__init_mcucr__=0x80,-Map=$(TRG).map,--cref


############################################################################################
############################################################################################

#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).elf $(TRG).hex $(TRG).bin


#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 $< $@

#create bin (ihex, srec) file from elf output file
%rom: %elf
	$(BIN) -O $(FORMAT) $< $@

%hex: %elf
	$(BIN) -O ihex $< $@

%bin: %elf
	$(BIN) -O binary $< $@


	avr-size $(TRG).elf


#make instruction to delete created files
clean:
	$(RM) $(OBJ)
	$(RM) $(TRG).map
	$(RM) $(TRG).elf
	$(RM) $(TRG).obj
	$(RM) $(TRG).hex
	$(RM) $(TRG).bin
	$(RM) *.bak
	$(RM) *.lst
	$(RM) *.?_sym


############################################################################################
############################################################################################

###### dependecies, add any dependencies you need here ###################

vs1001.o	: vs1001.s vs1001.h
remote.o	: remote.c types.h Constants.h delay.h uart.h remote.h
lcd.o		: lcd.c types.h Constants.h delay.h mem.h uart.h lcd.h 
atapi.o		: atapi.c types.h Constants.h delay.h mem.h uart.h atapi.h
iso9660.o	: iso9660.c types.h Constants.h mem.h uart.h atapi.h
uart.o 		: uart.c types.h Constants.h uart.h 
delay.o		: delay.s types.h Constants.h delay.h
usb.o		: usb.c usb.h Constants.h types.h
$(TRG).o	: $(TRG).c types.h Constants.h delay.h mem.h uart.h iso9660.h atapi.h remote.h vs1001.h
