CC = sh4-linux-gcc
OBJCOPY = sh4-linux-objcopy
OCFLAGS = -O binary -R .note -R .comment -S

PROGRAMS = blob-elf32 blob

# WARNING: start.S *must* be the first file, otherwise the target will
# be linked in the wrong order!
blob_elf32_SOURCES = start.S main.c command.c serial.c util.c uucodec.c yaffs.c \
					 nand.c mmc.c memcommands.c crctab.c
blob_elf32_OBJECTS = start.o main.o command.o serial.o util.o uucodec.o yaffs.o \
					 nand.o mmc.o memcommands.o crctab.o
blob_elf32_LDFLAGS = -Wl,-T,ld-script
blob_elf32_LDADD = -lgcc

INCLUDES = -Iinclude -I.

DEFS =
LDFLAGS = -static -nostdlib 
LIBS = 
CFLAGS = -O2 -Wall -nostdinc -fomit-frame-pointer -fPIC \
	-m4-nofpu
CPPFLAGS = $(INCLUDES)


COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@

SOURCES = $(blob_elf32_SOURCES)
OBJECTS = $(blob_elf32_OBJECTS)

all: Makefile.dep $(PROGRAMS)

rz.o:
	cp rz/rz.o .

.SUFFIXES: .S .c .o

.c.o:
	$(COMPILE) -c $<

.S.o:
	$(COMPILE) -c $<


blob-elf32: $(blob_elf32_OBJECTS) $(blob_elf32_DEPENDENCIES)
	@rm -f blob-elf32
	$(LINK) $(blob_elf32_LDFLAGS) $(blob_elf32_OBJECTS) $(blob_elf32_LDADD) $(LIBS)

blob: blob-elf32
	$(OBJCOPY) $(OCFLAGS) $< $@

CLEANFILES = *~ *.bak

clean:
	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
	-rm -f *.tab.c *.o core *.core Makefile.dep
	-test -z "$(PROGRAMS)" || rm -f $(PROGRAMS)

Makefile.dep:
	$(CC) $(CPPFLAGS) -MM $(blob_elf32_SOURCES) >Makefile.dep

include Makefile.dep

