EXEEXT = $(MEXEXT)

AM_CPPFLAGS = $(MATLAB_CPPFLAGS)
AM_CPPFLAGS += -I$(top_srcdir)/../../sources

DEFS += $(MATLAB_DEFS)
DEFS += -DMATLAB_MEX_FILE
DEFS += -DMEXEXT=\"$(MEXEXT)\"

AM_CFLAGS = $(MATLAB_CFLAGS) -Wall -Wno-parentheses
AM_FCFLAGS = $(MATLAB_FCFLAGS) -Wall -Wimplicit-interface
AM_CXXFLAGS = $(MATLAB_CXXFLAGS) -Wall -Wno-parentheses -Wold-style-cast
AM_LDFLAGS = $(MATLAB_LDFLAGS)
LIBS += $(MATLAB_LIBS)

mexdir = $(libdir)/dynare/mex/matlab

all-local: $(PROGRAMS)
## Create symlinks in mex/matlab/, but only if the build is not
## out-of-tree (because of the Windows installer)
	if [ "$(abs_srcdir)" = "$(abs_builddir)" ]; then \
		$(MKDIR_P) $(top_srcdir)/../../matlab && \
		cd $(top_srcdir)/../../matlab && \
		for p in $(PROGRAMS); do \
			$(LN_S) -f $(abs_builddir)/$$p $$p; \
		done; \
	fi

clean-local:
	rm -f *.mod # Fortran modules
	if test -d $(top_srcdir)/../../matlab; then \
		cd $(top_srcdir)/../../matlab && rm -f $(PROGRAMS); \
	fi

# Rules for the Fortran 2008 interface to MEX, BLAS/LAPACK and pthread functions
matlab_mat.mod: matlab_mex.o
matlab_mex.mod: matlab_mex.o

matlab_mex.F08: $(top_srcdir)/../../sources/matlab_mex.F08
	$(LN_S) -f $< $@

blas.mod: blas_lapack.o
lapack.mod: blas_lapack.o

blas_lapack.F08: $(top_srcdir)/../../sources/blas_lapack.F08
	$(LN_S) -f $< $@

pthread.mod: pthread.o

pthread.F08: $(top_srcdir)/../../sources/pthread.F08
	$(LN_S) -f $< $@
