Index: mttroot/mtt/lib/rep/sfun_rep/Makefile
==================================================================
--- mttroot/mtt/lib/rep/sfun_rep/Makefile
+++ mttroot/mtt/lib/rep/sfun_rep/Makefile
@@ -5,21 +5,23 @@
 $(MTT_SYS)_sfun.mexglx: $(MTT_SYS)_sfun.c sfun_debug.h useful-functions.hh $(MTT_SYS)_def.h $(MTT_SYS)_sympar.h $(MTT_SYS)_cr.h $(MTT_SYS)_numpar.c $(MTT_SYS)_ode.c $(MTT_SYS)_odeo.c $(MTT_SYS)_state.c $(MTT_SYS)_sfun_ae.mexglx $(MTT_SYS)_sfun_input.mexglx $(MTT_SYS)_sfun_interface.mexglx $(MTT_SYS).mdl
 	echo Creating $@
 	mex $(MTT_SYS)_sfun.c
 	cp *_sfun*mexglx $(MTT_SYS).mdl ..
 
-$(MTT_SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
+$(MTT_SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl $(MTT_SYS)_def.r
 	echo Creating $@
-	cat $^ | sed 's/<mtt_model_name>/$(MTT_SYS)/g' > $@
+	cat $< | sed 's/<mtt_model_name>/$(MTT_SYS)/g' |\
+	sed s/\<have_algebraic_equations\>/`mtt_getsize $(MTT_SYS) yz`/ > $@
 
 $(MTT_SYS)_sfun_ae.mexglx: $(MTT_SYS)_sfun_ae.c sfun_debug.h useful-functions.hh $(MTT_SYS)_def.h $(MTT_SYS)_sympar.h $(MTT_SYS)_cr.h $(MTT_SYS)_ae.c
 	echo Creating $@
 	mex $(MTT_SYS)_sfun_ae.c
 
-$(MTT_SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl
+$(MTT_SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl $(MTT_SYS)_def.r
 	echo Creating $@
-	cat $^ | sed 's/<mtt_model_name>/$(MTT_SYS)/g' > $@
+	cat $< | sed 's/<mtt_model_name>/$(MTT_SYS)/g' |\
+	sed s/\<have_algebraic_equations\>/`mtt_getsize $(MTT_SYS) yz`/ > $@
 
 $(MTT_SYS)_sfun_input.mexglx: $(MTT_SYS)_sfun_input.c sfun_debug.h useful-functions.hh $(MTT_SYS)_def.h $(MTT_SYS)_sympar.h $(MTT_SYS)_cr.h $(MTT_SYS)_input.c $(MTT_SYS)_numpar.c
 	echo Creating $@
 	mex $(MTT_SYS)_sfun_input.c
 

Index: mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl
==================================================================
--- mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl
+++ mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl
@@ -1,10 +1,12 @@
 /* -*-c-*-	Put emacs into c-mode
  * <mtt_model_name>_sfun_ae.c:
  * Matlab mex algebraic equations for <mtt_model_name>
  */
 
+#if <have_algebraic_equations> /* have_algebraic_equations */
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <mex.h>
 #include "sfun_debug.h"
@@ -114,5 +116,7 @@
 }
 
 #ifdef __cplusplus
 }
 #endif
+
+#endif /* have_algebraic_equations */

Index: mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl
==================================================================
--- mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl
+++ mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl
@@ -111,10 +111,11 @@
 }
 
 static void
 update_inputs_from_solver (void)
 {
+#if <have_algebraic_equations> /* have_algebraic_equations */
   mxArray *MTT_MATLAB_P;
   mxArray *MTT_MATLAB_T;
   mxArray *MTT_MATLAB_U;
   mxArray *MTT_MATLAB_Ui;
   mxArray *MTT_MATLAB_X;
@@ -176,10 +177,12 @@
   mxDestroyArray (MTT_MATLAB_U);
   mxDestroyArray (MTT_MATLAB_Ui);
   mxDestroyArray (MTT_MATLAB_X);
 
   PRINT_LEAVE;
+#endif /* have_algebraic_equations */
+  ;
 }
 
 static void
 update_simtime_from_simulink (SimStruct *S)
 {