# Make sure that TinyOS Makerules has been included *before* including
# this Makefile, because it expands the PLATFORM variable, which we need

TKN154_PLATFORM_INCLUDE ?= $(TOSDIR)/platforms/$(PLATFORM)/mac/tkn154/Makefile.include
TKN154_EXTRAS += $(wildcard $(TOSDIR)/lib/mac/tkn154/extras/*.extra)
CFLAGS += -I$(TOSDIR)/lib/mac/tkn154 \
	-I$(TOSDIR)/lib/mac/tkn154/dummies \
	-I$(TOSDIR)/lib/mac/tkn154/interfaces/MCPS \
	-I$(TOSDIR)/lib/mac/tkn154/interfaces/MLME \
	-I$(TOSDIR)/lib/mac/tkn154/interfaces/private \
	-I$(TOSDIR)/lib/mac/tkn154/interfaces/public


# Whenever platforms have identical configuration we don't need to put copies of
# Makefile.include under "platforms/$(PLATFORM)/mac/tkn154/", intead we make a
# redirect to the Makefile.include here:

# The shimmer2 platform configuration is identical to telosb
ifeq ($(findstring $(PLATFORM),shimmer2), shimmer2)
  TKN154_PLATFORM_INCLUDE = $(TOSDIR)/platforms/telosb/mac/tkn154/Makefile.include
endif

# The shimmer2r platform configuration is identical to telosb
ifeq ($(findstring $(PLATFORM),shimmer2r), shimmer2r)
  TKN154_PLATFORM_INCLUDE = $(TOSDIR)/platforms/telosb/mac/tkn154/Makefile.include
endif

#################################### Extras ####################################

# legacy
ifdef IEEE154_EXTENDED_ADDRESS
  $(error To set the extended address of a device to X pass 'extaddr,X' to the make system (e.g. "make telosb extaddr,0x012345"))
endif

# legacy
ifdef TKN154_DEBUG
  $(error To enable debug mode pass 'tkn154debug' to the make system (e.g. "make telosb tkn154debug"))
endif

# Pull in our extras (note we cannot use TOSMAKE_PATH, because it has already
# been parsed), so we do it "manually" ourselves now
$(foreach file,$(TKN154_EXTRAS),$(if $(filter $(call names,$(file)),$(GOALS)),$(eval include $(file))))


############################### Platform include ###############################

# 1. check whether target is "clean"
ifneq ($(strip $(foreach g,$(GOALS),$(findstring $(g),clean))),)
  # do nothing (Makerules' default clean branch will be executed)

# 2. check whether the platform is supported, by testing if file
# TKN154_PLATFORM_INCLUDE exists
else ifeq ($(strip $(wildcard $(TKN154_PLATFORM_INCLUDE))),)
  $(error The target platform is not supported by the TKN15.4 MAC)
else

# 3. platform is supported: now include the platform-specific
# TKN15.4 Makefile
  include $(TKN154_PLATFORM_INCLUDE)
endif

