diff options
author | Kris Thielemans <k.thielemans@ucl.ac.uk> | 2014-07-05 23:04:38 +0100 |
---|---|---|
committer | Kris Thielemans <k.thielemans@ucl.ac.uk> | 2014-07-05 23:04:38 +0100 |
commit | 38fd767cc733392313fb3a9caf93486a080c102c (patch) | |
tree | 5d9bb4d2abfc1b82b990d7641b77479bba64f3e0 | |
parent | ac66d2bcc00703644b428cc6cb62deb33360269c (diff) | |
download | swig-38fd767cc733392313fb3a9caf93486a080c102c.tar.gz |
[MATLAB] initial attempt to get test-suite to work
Added matlab to configure.ac etc and checked in a few *runme.m.
Currently I get warnings about try-catch syntax (on matlab 2012a) but
it does work.
Examples/test-suite/matlab/Makefile.in attempts to disable tests with
directors as these are known to fail. That will have to be removed later.
-rw-r--r-- | Examples/Makefile.in | 55 | ||||
-rw-r--r-- | Examples/test-suite/matlab/Makefile.in | 474 | ||||
-rw-r--r-- | Examples/test-suite/matlab/abstract_access_runme.m | 6 | ||||
-rw-r--r-- | Examples/test-suite/matlab/callback_runme.m | 40 | ||||
-rw-r--r-- | Examples/test-suite/matlab/dynamic_cast_runme.m | 14 | ||||
-rw-r--r-- | configure.ac | 115 |
6 files changed, 704 insertions, 0 deletions
diff --git a/Examples/Makefile.in b/Examples/Makefile.in index 50b7ead03..978160bab 100644 --- a/Examples/Makefile.in +++ b/Examples/Makefile.in @@ -464,6 +464,61 @@ octave_clean: rm -f *.@OBJEXT@ *@SO@ *$(OCTAVE_SO) ################################################################## +##### MATLAB ###### +################################################################## + +# Make sure these locate your Matlab installation +MATLAB = @MATLAB@ -nodisplay -nosplash +#MATLAB_CXX = $(DEFS) @MATLAB_CPPFLAGS@ @MATLAB_CXXFLAGS@ + +# Extra Matlab specific dynamic linking options +#MATLAB_DLNK = @MATLAB_LDFLAGS@ +MATLAB_MEXSUFFIX = @MATLAB_MEXSUFFIX@ +MATLAB_MEX = @MATLAB_MEX@ + +MATLAB_SCRIPT = $(SRCDIR)$(RUNME) + +# ---------------------------------------------------------------- +# Build a C dynamically loadable module +# ---------------------------------------------------------------- + +matlab: $(SRCDIR_SRCS) + $(SWIG) -matlab $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH) + $(MATLAB_MEX) -g $(CFLAGS) $(ISRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS) $(INCLUDES) $(LIBS) -o $(TARGET)_wrap + +# ----------------------------------------------------------------- +# Build a C++ dynamically loadable module +# ----------------------------------------------------------------- + +matlab_cpp: $(SRCDIR_SRCS) + $(SWIG) -c++ -matlab $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH) + $(MATLAB_MEX) -g $(CPPFLAGS) $(CXXFLAGS) $(ICXXSRCS) $(SRCDIR_SRCS) $(SRCDIR_CSRCS) $(INCLUDES) $(LIBS) -o $(TARGET)_wrap + +# ----------------------------------------------------------------- +# Running an Matlab example +# ----------------------------------------------------------------- + +matlab_run: + $(RUNTOOL) $(MATLAB) -r "try $(MATLAB_SCRIPT); catch err, fprintf(2,['ERROR: ' err.message '\n']),exit(1), end, exit(0)" $(RUNPIPE) + +# ----------------------------------------------------------------- +# Version display +# ----------------------------------------------------------------- + +matlab_version: + $(MATLAB) -r "disp(version);exit" | tail -n 2 + +# ----------------------------------------------------------------- +# Cleaning the Matlab examples +# ----------------------------------------------------------------- + +matlab_clean: + rm -f *_wrap* *~ \+* + rm -f *.@OBJEXT@ *@SO@ *$(MATLAB_MEXSUFFIX) + + + +################################################################## ##### GUILE ###### ################################################################## diff --git a/Examples/test-suite/matlab/Makefile.in b/Examples/test-suite/matlab/Makefile.in new file mode 100644 index 000000000..42f10dc6a --- /dev/null +++ b/Examples/test-suite/matlab/Makefile.in @@ -0,0 +1,474 @@ +####################################################################### +# Makefile for matlab test-suite +####################################################################### + +LANGUAGE = matlab +MATLAB = @MATLAB@ -nodisplay -nosplash +SCRIPTSUFFIX = _runme + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +top_builddir = @top_builddir@ + +#CPP_TEST_CASES += \ +# li_std_pair_extra \ +# li_std_string_extra \ +# matlab_cell_deref\ +# matlab_dim + +CPP_TEST_CASES = \ + abstract_access \ + abstract_inherit \ + abstract_inherit_ok \ + abstract_signature \ + abstract_typedef \ + abstract_typedef2 \ + abstract_virtual \ + access_change \ + add_link \ + aggregate \ + allowexcept \ + allprotected_not \ + anonymous_bitfield \ + argout \ + array_member \ + array_typedef_memberin \ + arrayref \ + arrays_dimensionless \ + arrays_global \ + arrays_global_twodim \ + arrays_scope \ + autodoc \ + bloody_hell \ + bools \ + catches \ + cast_operator \ + casts \ + char_binary \ + char_strings \ + class_forward \ + class_ignore \ + class_scope_weird \ + compactdefaultargs \ + const_const_2 \ + constant_pointers \ + constover \ + constructor_copy \ + constructor_exception \ + constructor_explicit \ + constructor_ignore \ + constructor_rename \ + constructor_value \ + contract \ + conversion \ + conversion_namespace \ + conversion_ns_template \ + cplusplus_throw \ + cpp_basic \ + cpp_enum \ + cpp_namespace \ + cpp_nodefault \ + cpp_static \ + cpp_typedef \ + curiously_recurring_template_pattern \ + default_args \ + default_arg_values \ + default_constructor \ + defvalue_constructor \ + derived_byvalue \ + derived_nested \ + destructor_reprotected \ + disown \ + dynamic_cast \ + empty \ + enum_ignore \ + enum_plus \ + enum_rename \ + enum_scope_template \ + enum_template \ + enum_thorough \ + enum_var \ + equality \ + evil_diamond \ + evil_diamond_ns \ + evil_diamond_prop \ + exception_order \ + extend \ + extend_constructor_destructor \ + extend_default \ + extend_placement \ + extend_special_variables \ + extend_template \ + extend_template_ns \ + extend_typedef_class \ + extern_c \ + extern_namespace \ + extern_throws \ + expressions \ + features \ + fragments \ + friends \ + funcptr_cpp \ + fvirtual \ + global_namespace \ + global_ns_arg \ + global_scope_types \ + global_vars \ + grouping \ + ignore_parameter \ + import_nomodule \ + inherit \ + inherit_missing \ + inherit_same_name \ + inherit_target_language \ + inherit_void_arg \ + inline_initializer \ + insert_directive \ + keyword_rename \ + kind \ + langobj \ + li_attribute \ + li_attribute_template \ + li_boost_shared_ptr \ + li_boost_shared_ptr_bits \ + li_boost_shared_ptr_template \ + li_boost_shared_ptr_attribute \ + li_carrays \ + li_cdata \ + li_cpointer \ + li_std_auto_ptr \ + li_stdint \ + li_swigtype_inout \ + li_typemaps \ + li_typemaps_apply \ + li_windows \ + long_long_apply \ + memberin_extend \ + member_funcptr_galore \ + member_pointer \ + member_template \ + minherit \ + minherit2 \ + mixed_types \ + multiple_inheritance \ + name_cxx \ + name_warnings \ + namespace_class \ + namespace_enum \ + namespace_extend \ + namespace_forward_declaration \ + namespace_nested \ + namespace_spaces \ + namespace_template \ + namespace_typedef_class \ + namespace_typemap \ + namespace_union \ + namespace_virtual_method \ + nspace \ + nspace_extend \ + naturalvar \ + naturalvar_more \ + naturalvar_onoff \ + nested_class \ + nested_comment \ + nested_scope \ + nested_workaround \ + newobject1 \ + null_pointer \ + operator_overload \ + operator_overload_break \ + operator_pointer_ref \ + operbool \ + ordering \ + overload_bool \ + overload_copy \ + overload_extend \ + overload_method \ + overload_numeric \ + overload_rename \ + overload_return_type \ + overload_simple \ + overload_subtype \ + overload_template \ + overload_template_fast \ + pointer_reference \ + preproc_constants \ + primitive_ref \ + private_assign \ + protected_rename \ + pure_virtual \ + redefined \ + redefined_not \ + refcount \ + reference_global_vars \ + register_par \ + rename1 \ + rename2 \ + rename3 \ + rename4 \ + rename_scope \ + rename_simple \ + rename_strip_encoder \ + rename_pcre_encoder \ + rename_pcre_enum \ + rename_predicates \ + restrict_cplusplus \ + return_const_value \ + return_value_scope \ + rname \ + samename \ + sizet \ + smart_pointer_const \ + smart_pointer_const2 \ + smart_pointer_const_overload \ + smart_pointer_extend \ + smart_pointer_member \ + smart_pointer_multi \ + smart_pointer_multi_typedef \ + smart_pointer_namespace \ + smart_pointer_namespace2 \ + smart_pointer_not \ + smart_pointer_overload \ + smart_pointer_protected \ + smart_pointer_rename \ + smart_pointer_simple \ + smart_pointer_static \ + smart_pointer_template_const_overload \ + smart_pointer_template_defaults_overload \ + smart_pointer_templatemethods \ + smart_pointer_templatevariables \ + smart_pointer_typedef \ + special_variable_macros \ + static_array_member \ + static_const_member \ + static_const_member_2 \ + struct_initialization_cpp \ + struct_value \ + symbol_clash \ + template_arg_replace \ + template_arg_scope \ + template_arg_typename \ + template_array_numeric \ + template_basic \ + template_base_template \ + template_classes \ + template_const_ref \ + template_construct \ + template_default \ + template_default2 \ + template_default_arg \ + template_default_arg_virtual_destructor \ + template_default_class_parms \ + template_default_class_parms_typedef \ + template_default_inherit \ + template_default_qualify \ + template_default_vw \ + template_enum \ + template_enum_ns_inherit \ + template_enum_typedef \ + template_explicit \ + template_extend1 \ + template_extend2 \ + template_extend_overload \ + template_extend_overload_2 \ + template_forward \ + template_inherit \ + template_inherit_abstract \ + template_int_const \ + template_methods \ + template_namespace_forward_declaration \ + template_using_directive_and_declaration_forward \ + template_nested \ + template_nested_typemaps \ + template_ns \ + template_ns2 \ + template_ns3 \ + template_ns4 \ + template_ns_enum \ + template_ns_enum2 \ + template_ns_inherit \ + template_ns_scope \ + template_partial_arg \ + template_partial_specialization \ + template_partial_specialization_typedef \ + template_qualifier \ + template_ref_type \ + template_rename \ + template_retvalue \ + template_specialization \ + template_specialization_defarg \ + template_specialization_enum \ + template_static \ + template_tbase_template \ + template_template_parameters \ + template_typedef \ + template_typedef_class_template \ + template_typedef_cplx \ + template_typedef_cplx2 \ + template_typedef_cplx3 \ + template_typedef_cplx4 \ + template_typedef_cplx5 \ + template_typedef_funcptr \ + template_typedef_inherit \ + template_typedef_ns \ + template_typedef_ptr \ + template_typedef_rec \ + template_typedef_typedef \ + template_typemaps \ + template_typemaps_typedef \ + template_typemaps_typedef2 \ + template_using \ + template_virtual \ + template_whitespace \ + threads \ + threads_exception \ + throw_exception \ + typedef_array_member \ + typedef_class \ + typedef_funcptr \ + typedef_inherit \ + typedef_mptr \ + typedef_reference \ + typedef_scope \ + typedef_sizet \ + typedef_struct \ + typedef_typedef \ + typemap_arrays \ + typemap_array_qualifiers \ + typemap_delete \ + typemap_global_scope \ + typemap_manyargs \ + typemap_namespace \ + typemap_ns_using \ + typemap_numinputs \ + typemap_template \ + typemap_template_parm_typedef \ + typemap_out_optimal \ + typemap_qualifier_strip \ + typemap_variables \ + typemap_various \ + typename \ + types_directive \ + unicode_strings \ + union_scope \ + using1 \ + using2 \ + using_composition \ + using_directive_and_declaration \ + using_directive_and_declaration_forward \ + using_extend \ + using_inherit \ + using_namespace \ + using_namespace_loop \ + using_pointers \ + using_private \ + using_protected \ + valuewrapper \ + valuewrapper_base \ + valuewrapper_const \ + valuewrapper_opaque \ + varargs \ + varargs_overload \ + virtual_destructor \ + virtual_poly \ + virtual_vs_nonvirtual_base \ + voidtest \ + wallkw \ + wrapmacro + +CPP_TEST_BROKEN += \ + allprotected \ + apply_signed_char \ + apply_strings \ + nested_directors \ + special_variables \ + typemap_directorout \ + director_abstract \ + director_alternating \ + director_basic \ + director_binary_string \ + director_classes \ + director_classic \ + director_constructor \ + director_default \ + director_detect \ + director_enum \ + director_exception \ + director_extend \ + director_finalizer \ + director_frob \ + director_ignore \ + director_keywords \ + director_namespace_clash \ + director_nested \ + director_nspace_director_name_collision \ + director_nspace \ + director_overload2 \ + director_overload \ + director_primitives \ + director_profile \ + director_protected \ + director_protected_overloaded \ + director_redefined \ + director_smartptr \ + director_stl \ + director_string \ + director_thread \ + director_unroll \ + director_using \ + director_wombat \ + director_wstring + +#C_TEST_CASES += + +# +# This test only works with modern C compilers +# +#C_TEST_CASES += \ +# complextest + +include $(srcdir)/../common.mk + +# Overridden variables here +#LIBS = -L. +#CSRCS = matlab_empty.c + +# Custom tests - tests with additional commandline options +# none! + +# Rules for the different types of tests +%.cpptest: + $(setup) + +$(swig_and_compile_cpp) + $(run_testcase) + +%.ctest: + $(setup) + +$(swig_and_compile_c) + $(run_testcase) + +%.multicpptest: + $(setup) + +$(swig_and_compile_multi_cpp) + $(run_testcase) + +# Runs the testcase. A testcase is only run if +# a file is found which has _runme.m appended after the testcase name. +run_testcase = \ + if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX).m ]; then \ + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH MATLABPATH=$(srcdir):$(SCRIPTDIR):$$MATLAB_PATH \ + $(RUNTOOL) $(MATLAB) -r "try $(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); catch err, fprintf(2,['ERROR: ' err.message '\n']),exit(1), end, exit(0)"; \ + fi + +# Clean: remove the generated .m file +%.clean: + @rm -rf $*.m +$*; + +clean: + $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" matlab_clean + +cvsignore: + @echo '*wrap* *.mex* *.so *.dll *.exp *.lib' + @echo Makefile + @for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do echo $$i.m; done + @for i in ${CPP_TEST_CASES} ${C_TEST_CASES}; do if grep -q $${i}_runme.m CVS/Entries ; then echo $${i}_runme.m; fi; done diff --git a/Examples/test-suite/matlab/abstract_access_runme.m b/Examples/test-suite/matlab/abstract_access_runme.m new file mode 100644 index 000000000..7ced44f54 --- /dev/null +++ b/Examples/test-suite/matlab/abstract_access_runme.m @@ -0,0 +1,6 @@ +import abstract_access.* + +d = abstract_access.D(); +if (d.do_x() ~= 1) + error('FAILED!!') +end diff --git a/Examples/test-suite/matlab/callback_runme.m b/Examples/test-suite/matlab/callback_runme.m new file mode 100644 index 000000000..17aab03ff --- /dev/null +++ b/Examples/test-suite/matlab/callback_runme.m @@ -0,0 +1,40 @@ +import callback.* + +if (foo(2) != 2) + error('FAILED!!') +end + +if (A_bar(2) != 4) + error('FAILED!!') +end + +if (foobar(3, _callback.foo) != foo(3)) + error('FAILED!!') +end + +if (foobar(3, foo) != foo(3)) + error('FAILED!!') +end + +if (foobar(3, A_bar) != A_bar(3)) + error('FAILED!!') +end + +if (foobar(3, foof) != foof(3)) + error('FAILED!!') +end + +if (foobar_i(3, foo_i) != foo_i(3)) + error('FAILED!!') +end + + +if (foobar_d(3.5, foo_d) != foo_d(3.5)) + error('FAILED!!') +end + +a = A(); +if (foobarm(3, a, A.foom_cb_ptr) != a.foom(3)) + error('FAILED!!') +end + diff --git a/Examples/test-suite/matlab/dynamic_cast_runme.m b/Examples/test-suite/matlab/dynamic_cast_runme.m new file mode 100644 index 000000000..c05471c08 --- /dev/null +++ b/Examples/test-suite/matlab/dynamic_cast_runme.m @@ -0,0 +1,14 @@ +import dynamic_cast.* + +f = dynamic_cast.Foo(); +b = dynamic_cast.Bar(); + +x = f.blah(); +y = b.blah(); + +a = dynamic_cast.do_test(y); +if (!strcmp(a,'Bar::test')) + error('Failed!!') +end + + diff --git a/configure.ac b/configure.ac index abc9b06ef..21a6cd807 100644 --- a/configure.ac +++ b/configure.ac @@ -972,6 +972,113 @@ AC_SUBST(OCTAVE_CXXFLAGS) AC_SUBST(OCTAVE_LDFLAGS) #---------------------------------------------------------------- +# Look for Matlab +#---------------------------------------------------------------- + +# Try to detect if there is matlab installed on the system and set the +# MATLAB_HOME, MATLAB and MATLAB_MEXSUFFIX variable + +AC_ARG_WITH([matlab], AS_HELP_STRING([--without-matlab], [Disable Matlab]) + AS_HELP_STRING([--with-matlab=path], + [specify location of matlab installation for the matlab interface. The "mex" compiler should be in MATLAB_HOME/bin]), + [use_matlab=$withval], [use_matlab=yes]) + +# First, check for "--without-matlab" or "--with-matlab=no". +if test x"${use_matlab}" = xno -o x"${with_alllang}" = xno ; then + AC_MSG_NOTICE([Disabling Matlab per request]) + MATLAB= +else + + # If we're in Windows, need to add .bat extension to find mex and mexext, and set conditional to modify Matlab interface Makefile + batext= + case $build in + *-cygwin* | *-mingw*) + batext=.bat + ;; + esac + AM_CONDITIONAL([MATLAB_MEX_WINDOWS], test x"$batext" != x) + + if test x"$use_matlab" = xyes; then + # Try to detect matlab home automatically + AC_MSG_CHECKING([for matlab installation]) + # First figure out what the name of Matlab is + AC_PATH_PROG(MATLAB, [matlab], []) + if test x"$MATLAB" = x; then + AC_MSG_RESULT([no, Disabling Matlab]) + else + # follow symbolic link + # JDK defined a macro BASIC_REMOVE_SYMBOLIC_LINKS that might be more portable + if test -L "$MATLAB"; then + # matlab is a symbolic link, follow it + MATLAB=`ls -l "$MATLAB" | awk '{print $NF}'` + fi + # strip matlab and bin to find home + MATLAB_HOME=`dirname "$MATLAB"` + MATLAB_HOME=`dirname "$MATLAB_HOME"` + AC_MSG_RESULT([$MATLAB_HOME]) + fi + else + MATLAB_HOME="$use_matlab" + AC_MSG_RESULT([$MATLAB_HOME]) + AC_PATH_PROG(MATLAB, [matlab], [notfound], [$MATLAB_HOME/bin]) + if test x"$MATLAB" = xnotfound; then + AC_MSG_RESULT([matlab excecutable not found, Disabling Matlab]) + MATLAB= + fi + fi +fi + +MATLAB_MEX= +if test x"$MATLAB" != x; then + AC_MSG_CHECKING([for Matlab mex command]) + AC_PATH_PROG(MATLAB_MEX, [mex], [], [$MATLAB_HOME/bin]) + if test x"$MATLAB_MEX" = x; then + AC_MSG_WARN([Cannot find mex command. Disabling matlab]) + MATLAB= + fi +fi + +MATLAB_MEXSUFFIX= +if test x"$MATLAB" != x; then + AC_MSG_CHECKING([for Matlab executable extension (MATLAB_MEXSUFFIX)]) + +## cat >conftest.c <<_ACEOF +## #include "mex.h" +## void mexFunction(int nlhs, mxArray *plhs@<:@@:>@, +## int nrhs, const mxArray *prhs@<:@@:>@) { +## int i=0; +## } +## _ACEOF +## if $MATLAB_HOME/bin/mex conftest.c >5 2>&5; then +## MATLAB_MEXSUFFIX=`ls conftest.mex* 5>/dev/null | sed -e 's=conftest.=='` +## AC_MSG_RESULT([$MATLAB_MEXSUFFIX]) +## else +## AC_MSG_RESULT([error running MATLAB_MEX compiler]) +## fi + + if ! test -x "$MATLAB_HOME/bin/mexext$batext"; then + AC_MSG_WARN([Cannot find $MATLAB_HOME/bin/mexext$batext executable to determine MATLAB_MEXSUFFIX]) + MATLAB= + else + case $build in + *-mingw*) + # MinGW cannot execute .bat files natively, so use cmd /c + MATLAB_MEXSUFFIX=$(cd "$MATLAB_HOME/bin"; cmd /c mexext$batext) + ;; + *) + MATLAB_MEXSUFFIX=`"$MATLAB_HOME/bin/mexext$batext"` + ;; + esac + AC_MSG_RESULT([$MATLAB_MEXSUFFIX]) + fi +fi + +AC_SUBST(MATLAB) +AC_SUBST(MATLAB_HOME) +AC_SUBST(MATLAB_MEX) +AC_SUBST(MATLAB_MEXSUFFIX) + +#---------------------------------------------------------------- # Look for java #---------------------------------------------------------------- @@ -2448,6 +2555,12 @@ fi AC_SUBST(SKIP_OCTAVE) +SKIP_MATLAB= +if test -z "$MATLAB" ; then + SKIP_MATLAB="1" +fi +AC_SUBST(SKIP_MATLAB) + SKIP_PYTHON= if (test -z "$PYINCLUDE") && (test -z "$PY3INCLUDE") ; then @@ -2658,6 +2771,7 @@ AC_CONFIG_FILES([ Examples/test-suite/mzscheme/Makefile Examples/test-suite/ocaml/Makefile Examples/test-suite/octave/Makefile + Examples/test-suite/matlab/Makefile Examples/test-suite/perl5/Makefile Examples/test-suite/php/Makefile Examples/test-suite/pike/Makefile @@ -2730,6 +2844,7 @@ test -n "$SKIP_MODULA3" || langs="${langs}modula3 " test -n "$SKIP_MZSCHEME" || langs="${langs}mzscheme " test -n "$SKIP_OCAML" || langs="${langs}ocaml " test -n "$SKIP_OCTAVE" || langs="${langs}octave " +test -n "$SKIP_MATLAB" || langs="${langs}matlab " test -n "$SKIP_PERL5" || langs="${langs}perl5 " test -n "$SKIP_PHP" || langs="${langs}php " test -n "$SKIP_PIKE" || langs="${langs}pike " |