1
////////////////////////////////////////////////////////////////////////////////
3
// Matlab S-Function project wizard
5
////////////////////////////////////////////////////////////////////////////////
10
function BeginWizard()
12
local intro_msg = _T("Welcome to the new Matlab C-S-Function project wizard!\n\n" +
13
"This wizard will guide you to create a new project\n" +
14
"creating a Matlab C-S-Function using the GCC\n" +
15
"or Matlab LCC compiler.\n\n" +
16
"For GCC you must have converted the Matlab DLL's into\n" +
17
"GCC compatible libraries using the DLLTOOL before.\n" +
18
"This wizard expects the GCC libraries at the location:\n" +
19
"[MATLAB]/extern/lib/win32/gcc\n\n" +
20
"When you're ready to proceed, please click \"Next\"...");
22
local matlabpath_descr = _T("Please select the location of Matlab on your computer.\n" +
23
"This is the top-level folder where Matlab was installed.");
25
Wizard.AddInfoPage(_T("MatlabCSFIntro"), intro_msg); // intro
26
Wizard.AddProjectPathPage();
27
Wizard.AddCompilerPage(_T(""), _T("gcc;lcc"), true, false); // compiler selection but no path selection
28
Wizard.AddGenericSelectPathPage(_T("MatlabPath"), matlabpath_descr, _T("Please select Matlab's location:"), _T("$(#matlab)"));
29
Wizard.AddPage(_T("MatlabHint"));
32
////////////////////////////////////////////////////////////////////////////////
34
////////////////////////////////////////////////////////////////////////////////
36
function OnLeave_MatlabPath(fwd)
40
local dir = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
41
local dir_nomacro = ReplaceMacros(dir, true);
42
if (!IO.DirectoryExists(dir_nomacro))
44
ShowError(_T("Please select a valid path to Matlab..."));
47
// Verify Matlab extern includes
48
if (!IO.DirectoryExists(dir_nomacro + _T("/extern/include")))
50
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
51
"can't locate the Matlab extern include path in the sub-directory /extern/include"));
54
// Verify Matlab extern tmwtypes.h (Simulink types)
55
if (!IO.FileExists(dir_nomacro + _T("/extern/include/tmwtypes.h")))
57
ShowError(_T("The Matlab extern path seems valid, but this wizard\n" +
58
"can't locate the Matlab twmtypes.h in it."));
61
// Verify Simulink includes
62
if (!IO.DirectoryExists(dir_nomacro + _T("/simulink/include")))
64
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
65
"can't locate the Simulink include path in the sub-directory\n"
66
"/simulink/include"));
69
// Verify Matlab extern tmwtypes.h (Simulink types)
70
if (!IO.FileExists(dir_nomacro + _T("/simulink/include/simstruc.h")))
72
ShowError(_T("The Matlab-Simulink include path seems valid, but this wizard\n" +
73
"can't locate the Matlab simstruc.h in it."));
77
if (Wizard.GetCompilerID().Matches(_T("lcc")))
79
// Verify LCC includes
80
if (!IO.DirectoryExists(dir_nomacro + _T("/sys/lcc/include")))
82
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
83
"can't locate the LCC include path in the sub-directory\n" +
87
// Verify LCC libraries
88
if (!IO.DirectoryExists(dir_nomacro + _T("/extern/lib/win32/lcc")))
90
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
91
"can't locate the LCC library path in the sub-directory\n" +
92
"/extern/lib/win32/lcc"));
96
else if (Wizard.GetCompilerID().Matches(_T("gcc")))
98
// Verify GCC libraries
99
if (!IO.DirectoryExists(dir_nomacro + _T("/extern/lib/win32/gcc")))
101
ShowError(_T("The Matlab path you entered seems valid, but this wizard\n" +
102
"can't locate the GCC library path in the sub-directory\n" +
103
"/extern/lib/win32/gcc"));
113
// return the files this project contains
114
function GetFilesDir()
116
local result = _T("matlab_csf/files");
117
if (Wizard.GetCompilerID().Matches(_T("lcc")))
118
result += _T(";matlab_csf/lccstub");
123
// setup the already created project
124
function SetupProject(project)
126
// enable compiler warnings (project-wide)
127
if (Wizard.GetCompilerID().Matches(_T("lcc")))
129
if (!CompilerFactory.IsValidCompilerID(_T("lcc")))
131
ShowError(_T("The wizard has detected that your version of Code::Blocks does not\n" +
132
"support the LCC compiler which is required for this project.\n" +
133
"The wizard cannot continue. Please update Code::Blocks."));
137
// set project options for LCC
138
project.SetModeForPCH(pchSourceDir);
139
project.AddCompilerOption(_T("-Zp8")); // 8 byte alignment
140
project.AddCompilerOption(_T("-noregistrylookup")); // do not query the registry for libpath
142
project.AddLinkerOption(_T("-s"));
143
project.AddLinkerOption(_T("-tmpdir \".\""));
144
project.AddLinkerOption(_T("-libpath ") + MatlabPath + _T("\\extern\\lib\\win32\\lcc"));
145
project.AddLinkerOption(MatlabPath + _T("\\extern\\lib\\win32\\lcc\\mexFunction.def"));
147
else if (Wizard.GetCompilerID().Matches(_T("gcc")))
149
// set project options for GCC
150
project.SetModeForPCH(pchSourceDir);
151
project.AddCompilerOption(_T("-malign-double")); // 8 byte alignment
152
project.AddCompilerOption(_T("-fno-exceptions")); // exception free code
154
project.AddLinkerOption(_T("-shared"));
155
project.AddLinkerOption(_T("-Wl,--out-implib=sfuntmpl")+DOT_EXT_STATICLIB);
156
project.AddLibDir(MatlabPath + _T("/extern/lib/win32/gcc"));
160
ShowError(_T("The selected compiler is not compatible with Matlab.\n" +
161
"The wizard cannot continue."));
165
// set common project options (the same for both compilers)
166
project.AddCompilerOption(_T("-DNDEBUG"));
167
project.AddCompilerOption(_T("-DMATLAB_MEX_FILE"));
169
project.AddIncludeDir(MatlabPath + _T("\\extern\\include"));
170
project.AddIncludeDir(MatlabPath + _T("\\simulink\\include"));
172
project.AddLinkLib(_T("libmx"));
173
project.AddLinkLib(_T("libmex"));
174
project.AddLinkLib(_T("libmatlb"));
175
project.AddLinkLib(_T("libmat"));
178
local target = project.GetBuildTarget(Wizard.GetDebugName());
181
target.SetTargetType(ttDynamicLib);
182
// the s-function DLL must have the same name as the file/function
183
target.SetOutputFilename(_T("sfuntmpl") + DOT_EXT_DYNAMICLIB);
184
target.SetWorkingDir(_T("."));
186
if (Wizard.GetCompilerID().Matches(_T("lcc")))
188
// It only works that way because the LCC resource compiler does not
189
// support creating it's "object files" (*.res) in any sub-directory
190
target.SetObjectOutput(_T(".")); //
195
target = project.GetBuildTarget(Wizard.GetReleaseName());
198
target.SetTargetType(ttDynamicLib);
199
// the s-function DLL must have the same name as the file/function
200
target.SetOutputFilename(_T("sfuntmpl") + DOT_EXT_DYNAMICLIB);
201
target.SetWorkingDir(_T("."));
203
if (Wizard.GetCompilerID().Matches(_T("lcc")))
205
// It only works that way because the LCC resource compiler does not
206
// support creating it's "object files" (*.res) in any sub-directory
207
target.SetObjectOutput(_T(".")); //