#*************************************************************************
# Copyright (c) 2006 UChicago Argonne LLC, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in the file LICENSE that is included with this distribution.
#*************************************************************************

# Octave definitions and rules

ifeq ($(findstring Host,$(VALID_BUILDS)),Host)

FILE_TYPE += OCTAVE
INSTALL_OCTAVE = $(INSTALL_LOCATION_LIB)/octave
DIRECTORY_TARGETS += $(INSTALL_OCTAVE)

ifdef T_A

MKOCTFILE_FLAGS += --mex --verbose -DOCTAVE
MKOCTFILE_FLAGS += $(RELEASE_INCLUDES) $(addprefix -L,$(SHRLIB_SEARCH_DIRS))

vpath %.mex $(USR_VPATH) $(ALL_SRC_DIRS)
vpath %.m $(USR_VPATH) $(ALL_SRC_DIRS)

define OCTAVES_template
$(1) : $$($(1)_SRCS)
endef
$(foreach file, $(OCTAVES),$(eval $(call OCTAVES_template,$(strip $(file)))))

clean: octave_clean

#This clean works from O.* dirs.
octave_clean: 
	@$(RM) *.mex *.m

.PHONY: octave_clean

.PRECIOUS: *.m *.mex

%.mex:
	mkoctfile $(MKOCTFILE_FLAGS) $($*_LIBS:%=-l%) $($*_SRCS)

endif
endif


# Makefile usage:
#  OCTAVES +=  abc.mex def.mex
#  abc_SRCS = a1.c a2.c
#  abc_LIBS = ca Com
#  def_SRCS = a3.c a4.c
#  def_LIBS = ca Com
