# $Id: Makefile.esb,v 1.15 2010/03/02 22:40:39 nifi Exp $

SENSORS    = sensors.c irq.c button-sensor.c pir-sensor.c vib-sensor.c \
             sound-sensor.c radio-sensor.c ctsrts-sensor.c battery-sensor.c \
             temperature-sensor.c
ESB        = ir.c beep.c ds1629.c tr1001-gcr.c gcr.c \
             esb-sensors.c node-id.c eeprom.c \
             uip-driver.c uip-ipchksum.c
CFS_EEPROM = cfs-eeprom.c
CFS_COFFEE = cfs-coffee.c cfs-coffee-arch.c

CONTIKI_TARGET_DIRS = . dev apps net loader
ifndef CONTIKI_TARGET_MAIN
  CONTIKI_TARGET_MAIN = contiki-esb-main.c
endif

CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(ESB) \
        contiki-esb-default-init-lowlevel.c \
        contiki-esb-default-init-apps.c \
	rs232.c rs232-putchar.c fader.c

ifdef WITH_CODEPROP
  CONTIKI_TARGET_DIRS += ../../apps/codeprop
  CONTIKI_TARGET_SOURCEFILES += codeprop-tmp.c
  WITH_UIP=1
endif

ifdef GCC
CFLAGS+=-Os -g
endif

ifdef IAR
CFLAGS += -D__MSP430F149__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32
CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR)
endif


ifdef WITH_UIP
  ifndef WITH_SLIP
    WITH_SLIP=1
  endif
  CFLAGS += -DWITH_UIP=1 -DWITH_SLIP=${WITH_SLIP}
endif

ifeq ($(CFS),coffee)
  CONTIKI_TARGET_SOURCEFILES += $(CFS_COFFEE)
else
  CONTIKI_TARGET_SOURCEFILES += $(CFS_EEPROM)
endif

include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps

MCU=msp430f149
include $(CONTIKI)/cpu/msp430/Makefile.msp430

ifdef IAR
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f149.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif # IAR

contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
#	$(AR) rcf $@ $^

ifndef BASE_IP
BASE_IP := 172.16.1.1
endif

send:	$(CONTIKI)/tools/codeprop.c
	cc -Wall $^ -o send

%.send:	%.cm send
	send $(BASE_IP) $<

### System dependent Makefile

ifeq ($(HOST_OS),FreeBSD)
  # settings for FreeBSD
  -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.freebsd
else
  ifeq ($(HOST_OS),Windows)
    # settings for Windows
    -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win
  else
    # settings for an arbitary unix-like platform
    -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix
  endif
endif