#GameSpy.net PS2 Makefile
#Included from sample-specific Makefiles

SHELL       = /bin/sh
SCE         = /usr/local/sce
LIBDIR      = $(SCE)/ee/lib
SYSINC      = -I$(SCE)/ee/include -I$(SCE)/common/include
INCDIR      = $(STACKINC) $(SYSINC)

#the samples need this for EENet
ENTCNFDIR   = $(SCE)/iop/sample/libeenet/ent_cnf
ENTCNF      = $(ENTCNFDIR)/ent_cnf.irx

LCFILE      = $(LIBDIR)/app.cmd
LIBS        = $(STACKLIB) \
              $(LIBDIR)/libdev.a \
              $(LIBDIR)/libgraph.a \
              $(LIBDIR)/libdma.a \
              $(LIBDIR)/libpkt.a \
              $(LIBDIR)/libcdvd.a \
              $(SDK_LIBS)

snsystems: STACKLIB = $(LIBDIR)/sneetcp.a

snsystems: STACKDEF = SN_SYSTEMS

snsytems: STACKINC =

eenet: STACKLIB = $(LIBDIR)/libeenet.a\
                  $(LIBDIR)/eenetctl.a\
                  $(LIBDIR)/ent_smap.a\
                  $(LIBDIR)/ent_eth.a\
                  $(LIBDIR)/ent_ppp.a\
                  $(LIBDIR)/libscf.a

eenet: STACKDEF = EENET

eenet: STACKINC = -I$(SCE)/ee/include/libeenet/

PREFIX      = ee
AS          = $(PREFIX)-gcc
CC          = $(PREFIX)-gcc
LD          = $(PREFIX)-gcc
RUN         = dsedb -r run
RM          = /bin/rm -f

CFLAGS      = -g -O0 -Wall -Werror -Wa,-al -fno-common $(SDK_CFLAGS)
ASFLAGS     = -c -xassembler-with-cpp -Wa,-al
LDFLAGS     = -Wl,-Map,$(TARGET).map -mno-crt0 -L$(LIBDIR) -lm

.SUFFIXES: .c .s

all: FORCE
	@echo type either make eenet or make snsystems

$(TARGET).elf: $(OBJS) $(LIBS)
	$(LD) -o $@ -T $(LCFILE) $(OBJS) $(STACKLIB) $(LIBS) $(LDFLAGS)

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

.s.o:
	$(AS) $(ASFLAGS) $(INCDIR) -o $@ $< > $*.lst

.c.o:
	$(CC) $(CFLAGS) -D$(STACKDEF) $(INCDIR) -c $< -o $*.o > $*.lst

run: $(TARGET).elf
	$(RUN) $(TARGET).elf

snsystems: $(TARGET).elf

$(ENTCNF):
	cd $(ENTCNFDIR) ; make

eenet: $(ENTCNF) $(TARGET).elf

clean:
	$(RM) $(OBJS) *.o *.map *.lst core *.dis *.elf

FORCE:
