1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
// Copyright (C) ENPC
// Copyright (C) DIGITEO - 2009
// Copyright (C) DIGITEO - 2010-2011 - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//=============================================================================
function libn = ilib_compile(lib_name, ..
makename, ..
files, ..
ldflags, ..
cflags, ..
fflags, ..
cc)
[lhs,rhs] = argn(0);
if rhs < 2 then
error(msprintf(gettext("%s: Wrong number of input argument(s).\n"),"ilib_compile"));
return
end
// The name of the library starts by "lib", strip it
lib_name_orig = strsubst(lib_name,"/^lib/","","r");
libn=""; //** init variable
if getos() == "Windows" & ~haveacompiler() then
error(_("A Fortran or C compiler is required."))
return;
end
[lhs,rhs]=argn(0);
if rhs < 3 then
files = [];
else
if ~isempty(files) & (or(fileext(files)==".o") | or(fileext(files)==".obj")) then
error(999, msprintf(_("%s: A managed file extension for input argument #%d expected."), "ilib_compile", 3));
end
end
if typeof(lib_name)<>"string" then
error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"ilib_compile",1));
return ;
end
oldpath = pwd();
files = files(:)';
[make_command, lib_name_make, lib_name, path, makename, files]= ...
ilib_compile_get_names(lib_name, files);
if isdir(path) then
chdir(path);
end
if getos() == "Windows" then
//** ----------- Windows section -----------------
// Load dynamic_link Internal lib if it's not already loaded
if ~ exists("dynamic_linkwindowslib") then
load("SCI/modules/dynamic_link/macros/windows/lib");
end
dlwCompile(files, make_command, makename);
else
//** ---------- Linux/MacOS/Unix section ---------------------
ScilabTreeFound=%f;
// Source tree version
// Headers are dispatched in the source tree
if isdir(SCI+"/modules/core/includes/") then
defaultModulesCHeader=[ "core", "mexlib","api_scilab","output_stream","localization" ];
defaultModulesFHeader=[ "core" ];
ScilabTreeFound=%t
for x = defaultModulesCHeader(:)';
cflags=" -I"+SCI+"/modules/"+x+"/includes/ "+cflags;
end
for x = defaultModulesFHeader(:)';
fflags=" -I"+SCI+"/modules/"+x+"/includes/ " + fflags;
end
end
// Binary version
if isdir(SCI+"/../../include/scilab/") & ~ScilabTreeFound then
cflags="-I"+SCI+"/../../include/scilab/ -I"+SCI+"/../../include/ " + cflags
fflags="-I"+SCI+"/../../include/scilab/ " + fflags
ScilabTreeFound=%t
end
// System version (ie: /usr/include/scilab/)
if isdir("/usr/include/scilab/") & ~ScilabTreeFound then
cflags="-I/usr/include/scilab/ "+cflags
fflags="-I/usr/include/scilab/ "+fflags
ScilabTreeFound=%t
end
if ( ilib_verbose() <> 0 & ScilabTreeFound <> %t) then
mprintf(gettext("%s: Warning: Scilab has not been able to find where the Scilab sources are. Please submit a bug report on http://bugzilla.scilab.org/\n"),"ilib_compile");
end
oldPath = pwd();
// Switch back to the TMPDIR where the mandatory files are
chdir(TMPDIR+"/"+lib_name_orig);
// Detect the actual path to the libstdc++ library. For the dynamic link
// build, we want to use the same lib as the compiler installed.
// CF bug #7887 for more information.
// Note that, for the configure, the setup is done by compilerDetection.sh
cmdGCC="if test -x ""$(which gcc 2>/dev/null)""; then echo $(LC_ALL=C gcc -print-search-dirs|awk ''$1==""install:""{print $2}''); fi";
[GCClibpath, ierr, stderr] = unix_g(cmdGCC);
if (GCClibpath <> "" & GCClibpath <> [] & ierr == 0 & grep(getenv("LD_LIBRARY_PATH"),GCClibpath) == []) then
setenv("LD_LIBRARY_PATH",GCClibpath+"/../../../:"+getenv("LD_LIBRARY_PATH"));
end
cmd = "make "
cmd = cmd + gencompilationflags_unix(ldflags, cflags, fflags, cc, "build")
//** BEWARE : this function can cause errors if used with "old style" Makefile inside a Scilab 5
//** environment where the Makefile are created from a "./configure"
[msg, ierr, stderr] = unix_g(cmd) ;
if ( ilib_verbose() == 2 ) then
mprintf(gettext("%s: Build command: %s\n"),"ilib_compile",cmd);
mprintf(gettext("Output: %s\n"),msg);
mprintf(gettext("stderr: %s\n"),stderr);
end
if ierr <> 0 then
errMsg = sprintf(gettext("%s: An error occurred during the compilation:\n"), "ilib_compile");
errMsg = [errMsg ; stderr];
errMsg = [errMsg ; sprintf(gettext("%s: The command was:\n"), "ilib_compile")];
errMsg = [errMsg ; cmd];
chdir(oldPath); // Go back to the working dir
error(errMsg);
return ;
end
if stderr <> "" then
if ( ilib_verbose() <> 0 ) then
mprintf(gettext("%s: Warning: No error code returned by the compilation but the error output is not empty:\n"),"ilib_compile");
mprintf(stderr);
end
return ;
end
generatedLibrary=".libs/" + lib_name;
// Copy the produce lib to the working path
if ~isfile(generatedLibrary) then
error(msprintf(gettext("%s: Could not find the built library ''%s''.\n"),"ilib_compile",generatedLibrary));
end
copyfile(generatedLibrary, oldPath);
end
libn = path + lib_name_make ;
chdir(oldpath);
endfunction
//=============================================================================
// function only defined in ilib_compile
//=============================================================================
function [make_command, lib_name_make, lib_name,path, makename, files] = ..
ilib_compile_get_names(lib_name, files)
if getos() <> "Windows" then
path = "";
lib_name = lib_name + getdynlibext();
lib_name_make = lib_name;
make_command = "make ";
if files <> [] then
files = files + ".o";
end
makename = "Makefile";
else // Windows
// Load dynamic_link Internal lib if it"s not already loaded
if ~ exists("dynamic_linkwindowslib") then
load("SCI/modules/dynamic_link/macros/windows/lib");
end
[make_command, lib_name_make, lib_name, path, makename, files] = ..
dlwGetParamsIlibCompil(lib_name, files);
end
endfunction
//=============================================================================
|