#*************************************************************************
# Copyright (c) 2002 The University of Chicago, 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 Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in 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)))))

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

.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
