SDCC_BASE = ../../../..
INSTALL_DIR = ../bin

VPATH  = @srcdir@
srcdir = @srcdir@

CC = $(SDCC_BASE)/bin/sdcc
LIB = @GPLIB@
CP = @CP@
RM = @RM@
RMDIR = @RMDIR@

CPPFLAGS = -I$(srcdir)/../../../include/pic

C_SRC = $(notdir $(wildcard $(srcdir)/pic1*.c))
OBJS = $(C_SRC:.c=.o)
LIBS = $(addprefix $(INSTALL_DIR)/,$(OBJS:.o=.lib))

all : $(LIBS)

ifeq (0,1)
# useful while fixing .inc files
GPUTILS = /opt/modules/gputils-0.13.3/share/gputils
pic%.c : $(GPUTILS)/header/p%.inc
	-$(SDCC_BASE)/support/scripts/inc2h.pl $* $(GPUTILS);
	-mv pic$*.h $(SDCC_BASE)/device/include/pic/pic$*.h;
endif

pic%.o : pic%.c
ifndef SILENT
	@echo "[  CC   ] ==> $(patsubst $(top_builddir)/%,%,$@)"
endif
	@-$(CC) $(CPPFLAGS) $(CFLAGS) -mpic14 -p$* -o "$@" -c "$<"

$(INSTALL_DIR)/%.lib : %.o
	@-$(LIB) -c "$@" "$<";

install : all

clean : clean-intermediate
	@-$(RM) *.asm
	@-$(RM) $(OBJS) $(LIBS)
	@-$(RMDIR) ../build/libdev

distclean: clean
	@-$(RM) Makefile

clean-intermediate :
	@-$(RM) *.lst *.d *.adb

