SHELL       = /bin/sh

ifdef SCETOP
TOP	    = $(SCETOP)
else
TOP	    = /usr/local/sce
endif
LIBDIR      = $(TOP)/ee/lib
INCDIR      = $(TOP)/ee/include
INST_DIR    = ../target

TARGET      = atwinmon
CRT0        = crt0.o
CONFIG      = config.o

LCFILE      = ./app.cmd
LIBS        = -L$(LIBDIR) \
	      -lgraph -ldma -ldev -lpkt -lcdvd -lpad -lmc -lkernl
INCOPTS     = -I../../include -I../include \
		-I$(TOP)/ee/include -I$(TOP)/common/include

PREFIX      = ee
AS          = $(PREFIX)-gcc
CC          = $(PREFIX)-gcc
LD          = $(PREFIX)-gcc
ASFLAGS     = -c -xassembler-with-cpp -Wa,-al
CFLAGS      = -O2 -g -Wall -Wa,-al -fno-common 
LDFLAGS     = -Wl,-Map,$(TARGET).map -nostartfiles -L$(LIBDIR) -lm
EM          = /bin/rm -f

.SUFFIXES: .c

.c.o:
	$(CC) $(CFLAGS) $(TMPFLAGS) -I$(INCDIR) -c $< -o $*.o > $*.lst

all:	$(TARGET).elf

$(TARGET).elf: $(CRT0) $(CONFIG) $(TARGET).a
	$(LD) -o $@ -T $(LCFILE)           $(CONFIG) $(CRT0) $(TARGET).a $(LIBS) $(LDFLAGS)

$(CRT0): $(LIBDIR)/crt0.s
	$(AS) $(ASFLAGS) $(TMPFLAGS) -o $@ $< > $*.lst

install:	all
	cp $(TARGET).elf $(INST_DIR)/.

clean:
	$(RM) $(TARGET).elf *.map *.lst
	$(RM) $(CRT0) $(CONFIG)
