# Copyright (C) 2005 Thor Andreassen <ta@imada.sdu.dk> 
#                    Anders Dubgaard <anders@dubgaard.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

CLOCK = 7.3728e6
MCU = atmega128

CFLAGS  = -mmcu=$(MCU) -Wall -Os -DBASE=1 -DF_CPU=$(CLOCK) -I./
# CFLAGS can also use -Wstrict-prototypes

LDFLAGS = -lm -mmcu=$(MCU) -Wl,-Map=$(TARGET).map,--cref  # Tor's
#LDFLAGS = -Wl,-u,vfprintf -lprintf_min    # simplest printf
#LDFLAGS = -Wl,-u,vfprintf -lprintf_flt -lm # with floating point conversion
#LDFLAGS = -Wl,-u,vfprintf -lprintf_flt -lm -Map=$(TARGET).map,--cref
#LDFLAGS = -Wl,-u,vfprintf -lprintf_min -Map=$(TARGET).map,--cref
#LDFLAGS += -lm -mmcu=$(MCU)

#C_FILES = $(wildcard *.c
#C_FILES = base.c uart.c $(wildcard radio/*.c)
C_FILES = base.c uart.c radio/cc1000.c radio/crc.c radio/protocol.c \
					psx.c timer.c radio/radio_rx.c  #radio/radio_rx.c  radio/radio_tx.c

include Makefile.common  # depends on C_FILES ...

.PHONY: all clean erase load

all: clean $(TARGET).hex

$(TARGET).hex: $(TARGET).elf
	$(OBJCOPY) -R .eeprom -O ihex $(TARGET).elf $(TARGET).hex

$(TARGET).elf: $(OBJS)
	$(CC) $(LDFLAGS) $^ -o $@

load: $(TARGET).hex erase
	$(AVRDUDE) -D -V $(AVRDUDEOPTS) -U flash:w:$(TARGET).hex

erase:
	$(AVRDUDE) $(AVRDUDEOPTS) -y -e

clean:
	$(RM) $(OBJS) $(ASMS) $(TARGET).map $(TARGET).elf $(TARGET).hex
