# Makefile
#
#  Copyright (C) 2006,2007 Nuno Sucena Almeida
#
#  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

#sources = $(wildcard *.asm)
sources=dcf13.asm
#sources+=i2c.asm i2c_eeprom.asm i2c_expander.asm setup.asm main.asm
includes = $(wildcard *.inc)
objects = $(patsubst %.asm,%.o,$(sources))
name = dcf

#sources1 = bootloader.asm
#objects1 = $(patsubst %.asm,%.o,$(sources1))
#name1 = bootloader

# processor
PROC=16f628
#PROC=16f648a
#PROC=16f88

# assembler
AS=gpasm
ASFLAGS=-p $(PROC) -e ON -a inhx16
INCFLAGS=

# linker
LINK=gplink
LINKFLAGS=-m -c -a inhx16 -s /usr/share/gputils/lkr/$(PROC).lkr

# Simulator
SIM=gpsim

allobjects=$(objects) $(objects1)

all: $(objects) $(name)

$(allobjects): %.o: %.asm
	@echo compiling $<
	$(AS) $(ASFLAGS) $(INCFLAGS) -c $< -o $@

$(name): $(sources) $(includes)
	@echo creating $(name)
	$(LINK) $(LINKFLAGS) -o $(name) $(objects)

burn:
	picprog --slow --rdtsc --erase --burn --pic /dev/ttyS0 --ihx16 --input $(name).hex 

clean:
	rm -f *~ *.o *.lst *.cod *.hex *.cof *.map a.out gmon.out $(name)

sim:	all
	$(SIM) -pp${PROC} -s $(name).cod
