VPATH  = @srcdir@
srcdir = @srcdir@

top_srcdir   = @top_srcdir@
top_builddir = @top_builddir@

SAS = $(top_builddir)/bin/asx8051
SCC = $(top_builddir)/bin/sdcc

OBJ = crtstart.rel crtxinit.rel crtxclear.rel crtclear.rel crtxstack.rel \
      crtpagesfr.rel crtbank.rel crtcall.rel

LIB = mcs51.lib

CC = $(SCC)
AS = $(SAS)
ASFLAGS = -plosgff

CFLAGS = -I$(top_srcdir)/include --std-c89

all: $(LIB)

$(LIB): $(OBJ) Makefile
	rm -f $(LIB)
	for i in $(OBJ); do echo $$i >> $(LIB); done

%.rel: %.c
	$(CC) $(CFLAGS) -c $<

%.rel: %.asm
	@# TODO: asx8051 should place it's output in the current dir
	test $(srcdir) = . || cp $< .
	-$(AS) $(ASFLAGS) $(notdir $<)
	test $(srcdir) = . || rm $(notdir $<)

clean:
	rm -f *.rel *.sym *.lst *~ $(CLEANSPEC) *.dump* *.lib

distclean: clean
	rm -r Makefile
