# Mostly written by Jonathan Larmour, Cygnus Solutions
# This file is in the public domain and may be used for any purpose

# PKG_INSTALL_DIR might need to be edited.  Right now it is set
# assuming that a user ran pkgconf.tcl in //c/ecos-work on Windows NT,
# or used the Configuration Tool with C:\ecos-work as a build-tree.
#
# You can also override it on the make command-line, e.g.:
#   make PKG_INSTALL_DIR=/myecc/install
# or you can set it in your environment

ECOS_SRC=/home/tgi2/tgi/eCos/ecos

ECOS_DIR=./bcm93310
PKG_INSTALL_DIR = $(ECOS_DIR)/install

# You must also set XCC to the name of your cross-compiler, including any
# options it needs.

# Uncomment one of the below, or invoke make with the name of the compiler
# you want, e.g.:
#   make XCC=mn10300-elf-gcc
# You can also set XCC in your environment

XCC = mips-unknown-elf-gcc

###### VARIABLES
# Any of these can be overriden on the command-line or in your environment

CFLAGS        = -O -Ilibnetworking -Wmissing-prototypes -Wstrict-prototypes

CXXFLAGS      = $(CFLAGS)

EXTRACFLAGS   = -Wall -I$(PKG_INSTALL_DIR)/include

LDFLAGS       = -nostartfiles -L$(PKG_INSTALL_DIR)/lib
LIBS          = -Ttarget.ld -nostdlib -Wl,-Map,map

LD            = $(XCC)

ECOS_CFG=--target=bcm3310 --platform=bcm93310 --startup=ram \
	--disable-watchdog --disable-uitron --disable-libm --disable-libc

###### RULES

.PHONY: all clean force

all: test # twothreads simple-alarm serial

clean:
	$(MAKE) -C libnetworking clean
	-rm -f test booter netboot/*.o *.o *~
	-rm -rf $(ECOS_DIR) bcm93310.orig booter.srec libnet.a

%.o: %.c
	$(XCC) -c -o $*.o $(CFLAGS) $(EXTRACFLAGS) $<

%.i: %.c
	$(XCC) -E -o $*.i $(CFLAGS) $(EXTRACFLAGS) $<

KERN_PIECES=kern_subr uipc_domain uipc_mbuf uipc_socket uipc_socket2
C_FILES=$(C_PIECES:%=%.c)
KERN_O_FILES=$(C_PIECES:%=%.o)

KERN_PIECES=
#OBJS = head.o lib.o 
OBJS=test.o

test: $(PKG_INSTALL_DIR) $(OBJS) libnet.a
	$(LD) $(LDFLAGS) -o $@ $(OBJS) libnet.a $(LIBS) -lc
	cp $@ /var/exports/bcm/

libnet.a: force
	$(MAKE) -C libnetworking

bcm93310.orig:
	mkdir $(ECOS_DIR)
	cd $(ECOS_DIR) && tclsh $(ECOS_SRC)/packages/pkgconf.tcl $(ECOS_CFG)
	mv $(ECOS_DIR) $@

$(ECOS_DIR):
	mkdir $@
	cd $(ECOS_DIR) && \
	tclsh $(ECOS_SRC)/packages/pkgconf.tcl $(ECOS_CFG) && \
	patch -p1 < ../pkgconf.diffs

$(PKG_INSTALL_DIR): $(ECOS_DIR)
	make -C $(ECOS_DIR)

pkgdiffs: bcm93310.orig $(ECOS_DIR)
	diff -rc bcm93310.orig/pkgconf $(ECOS_DIR)/pkgconf

force:
