AM_CPPFLAGS = $(shell $(MKOCTFILE) -p CPPFLAGS)
AM_CPPFLAGS += $(shell $(MKOCTFILE) -p INCFLAGS)
AM_CPPFLAGS += -I$(top_srcdir)/../../sources

DEFS += -DOCTAVE_MEX_FILE
DEFS += -DMEXEXT=\".mex\"

AM_CFLAGS = $(shell $(MKOCTFILE) -p CPICFLAG)
AM_FFLAGS = $(shell $(MKOCTFILE) -p FPICFLAG)
AM_CXXFLAGS = $(shell $(MKOCTFILE) -p CXXPICFLAG)
AM_LDFLAGS = $(shell $(MKOCTFILE) -p DL_LDFLAGS) -L"$(shell $(MKOCTFILE) -p OCTLIBDIR)"

LIBS += $(shell $(MKOCTFILE) -p OCTAVE_LIBS)
LIBS += $(shell $(MKOCTFILE) -p BLAS_LIBS)
LIBS += $(shell $(MKOCTFILE) -p LAPACK_LIBS)
LIBS += $(shell $(MKOCTFILE) -p FFTW_LIBS)
LIBS += $(shell $(MKOCTFILE) -p LIBS)
LIBS += $(shell $(MKOCTFILE) -p FLIBS)

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

all-local: $(PROGRAMS)
## Create symlinks in mex/octave/, 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)/../../octave && \
		cd $(top_srcdir)/../../octave && \
		for p in $(PROGRAMS); do \
			$(LN_S) -f $(abs_builddir)/$$p $$p; \
		done; \
	fi

clean-local:
	if test -d $(top_srcdir)/../../octave; then \
		cd $(top_srcdir)/../../octave && rm -f $(PROGRAMS); \
	fi
