###########################################################################
# 
# Path to MODEL should be specified.
# 
# Ex: 
# $ make MODEL=../../examples/bistab/bistab
# 
#
###########################################################################

ifeq ($(URDME_ROOT),)
    $(error URDME_ROOT is not set, run 'urdme_init' to correct)
endif

###########################################################################

ifeq ($(URDME_MODEL),)
  ifneq ($(MODEL),)
  	URDME_MODEL = $(MODEL)
  else
    URDME_MODEL = $(shell basename `pwd`)
  endif
endif

#ifeq ($(wildcard $(URDME_MODEL).m),)
#    $(error model '.m' file not found, please make sure the model is setup correctly)
#endif

ifeq ($(wildcard $(URDME_MODEL).c),)
    $(error model '.c' file not found, please make sure the model is setup correctly)
endif

###########################################################################

URDME=$(URDME_ROOT)
ARGS=URDME_MODEL=$(URDME_MODEL) URDME_ROOT=$(URDME_ROOT)

###########################################################################
ifneq ($(SOLVER),)
ALL_SOLVERS = $(shell find $(URDME_ROOT)/build -maxdepth 1 -name Makefile.\* | grep Makefile.$(SOLVER)$ )
else
ALL_SOLVERS = $(shell find $(URDME_ROOT)/build -maxdepth 1 -name Makefile.\* )
endif
###########################################################################
###########################################################################
#ifneq ($(MAKECMDGOALS),)
#
#$(MAKECMDGOALS): $(addsuffix .__build,$(ALL_SOLVERS))
#	@echo  "Finished building solvers"
#
#endif

#####

all: $(addsuffix .__build,$(ALL_SOLVERS))
	@echo  "Finished building solvers"

clean: $(addsuffix .__build,$(ALL_SOLVERS))
	@echo  "Finished cleaning"

%.__build: 
	make -f $* $(ARGS) $(MAKECMDGOALS)


test: 
	@echo $(MAKECMDGOALS)

############################################################################
############################################################################
#LIB = $(URDME)/lib
#BIN = $(URDME)/bin
#INCLUDE = $(URDME)/include
#SRC = $(URDME)/src
#
#OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
#DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
###
#ifneq ($(DARWIN),)  # Adreas OSX
#MATLAB = /Applications/Matlab_R2009b.app
#else  #Brian linux
#MATLAB = /usr/local/matlab.2008a
#endif
#MATLAB_EXT = $(MATLAB)/extern
#MATLAB_INC=$(MATLAB_EXT)/include
#MATLAB_LIB=$(MATLAB)/bin/$(MATLAB_ARCH)
