1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 // Copyright (C) DIGITEO - 2009
5 // Copyright (C) DIGITEO - 2010-2011 - Allan CORNET
7 // This file must be used under the terms of the CeCILL.
8 // This source file is licensed as described in the file COPYING, which
9 // you should have received as part of this distribution. The terms
10 // are also available at
11 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 //=============================================================================
14 function libn = ilib_compile(lib_name, ..
24 error(msprintf(gettext("%s: Wrong number of input argument(s).\n"),"ilib_compile"));
28 // The name of the library starts by "lib", strip it
29 lib_name_orig = strsubst(lib_name,"/^lib/","","r");
31 libn=""; //** init variable
33 if ~haveacompiler() then
34 error(_("A Fortran or C compiler is required."))
43 if ~isempty(files) & (or(fileext(files)==".o") | or(fileext(files)==".obj")) then
44 error(999, msprintf(_("%s: A managed file extension for input argument #%d expected."), "ilib_compile", 3));
48 if typeof(lib_name)<>"string" then
49 error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"ilib_compile",1));
56 [make_command, lib_name_make, lib_name, path, makename, files]= ...
57 ilib_compile_get_names(lib_name, makename, files);
63 if getos() == "Windows" then
64 //** ----------- Windows section -----------------
69 if ( ilib_verbose() <> 0 ) then
70 mprintf(_(" Compilation of ") + string(files(i)) +"\n");
74 // then the shared library
75 if ( ilib_verbose() <> 0 ) then
76 mprintf(_(" Building shared library (be patient)\n"));
79 [msg, stat] = unix_g(make_command + makename + " all 2>&0");
81 // more feedback when compilation fails
82 [msg, stat, stderr] = unix_g(make_command + makename + " all 1>&2");
84 error(msprintf(gettext("%s: Error while executing %s.\n"), "ilib_compile", makename));
86 if ilib_verbose() > 1 then
92 //** ---------- Linux/MacOS/Unix section ---------------------
96 // Source tree version
97 // Headers are dispatched in the source tree
98 if isdir(SCI+"/modules/core/includes/") then
99 defaultModulesCHeader=[ "core", "mexlib","api_scilab","output_stream","localization" ];
100 defaultModulesFHeader=[ "core" ];
103 for x = defaultModulesCHeader(:)';
104 cflags=" -I"+SCI+"/modules/"+x+"/includes/ "+cflags;
106 cflags=" -I"+SCI+"/libs/MALLOC/includes/ " + cflags;
108 for x = defaultModulesFHeader(:)';
109 fflags=" -I"+SCI+"/modules/"+x+"/includes/ " + fflags;
114 if isdir(SCI+"/../../include/scilab/") & ~ScilabTreeFound then
115 cflags="-I"+SCI+"/../../include/scilab/ " + cflags
116 fflags="-I"+SCI+"/../../include/scilab/ " + fflags
120 // System version (ie: /usr/include/scilab/)
121 if isdir("/usr/include/scilab/") & ~ScilabTreeFound then
122 cflags="-I/usr/include/scilab/ "+cflags
123 fflags="-I/usr/include/scilab/ "+fflags
127 if ( ilib_verbose() <> 0 & ScilabTreeFound <> %t) then
128 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");
133 // Switch back to the TMPDIR where the mandatory files are
135 chdir(TMPDIR+"/"+lib_name_orig);
137 // Detect the actual path to the libstdc++ library. For the dynamic link
138 // build, we want to use the same lib as the compiler installed.
139 // CF bug #7887 for more information.
140 // Note that, for the configure, the setup is done by compilerDetection.sh
141 cmdGCC="if test -x ""$(which gcc 2>/dev/null)""; then echo $(LC_ALL=C gcc -print-search-dirs|awk ''$1==""install:""{print $2}''); fi";
142 [GCClibpath, ierr, stderr] = unix_g(cmdGCC);
143 if (GCClibpath <> "" & ierr == 0 & grep(getenv("LD_LIBRARY_PATH"),GCClibpath) == []) then
144 setenv("LD_LIBRARY_PATH",GCClibpath+"/../../../:"+getenv("LD_LIBRARY_PATH"));
149 cmd = cmd + gencompilationflags_unix(ldflags, cflags, fflags, cc, "build")
151 //** BEWARE : this function can cause errors if used with "old style" Makefile inside a Scilab 5
152 //** environment where the Makefile are created from a "./configure"
153 [msg, ierr, stderr] = unix_g(cmd) ;
155 if ( ilib_verbose() == 2 ) then
156 mprintf(gettext("%s: Build command: %s\n"),"ilib_compile",cmd);
157 mprintf(gettext("Output: %s\n"),msg);
158 mprintf(gettext("stderr: %s\n"),stderr);
162 mprintf(gettext("%s: An error occurred during the compilation:\n"),"ilib_compile");
166 mprintf(gettext("%s: The command was:\n"),"ilib_compile");
169 chdir(oldPath); // Go back to the working dir
174 if ( ilib_verbose() <> 0 ) then
175 mprintf(gettext("%s: Warning: No error code returned by the compilation but the error output is not empty:\n"),"ilib_compile");
181 generatedLibrary=".libs/" + lib_name;
182 // Copy the produce lib to the working path
183 if ~isfile(generatedLibrary) then
184 error(msprintf(gettext("%s: Could not find the built library ''%s''.\n"),"ilib_compile",generatedLibrary));
186 copyfile(generatedLibrary, oldPath);
190 libn = path + lib_name_make ;
194 //=============================================================================
195 // function only defined in ilib_compile
196 //=============================================================================
197 function [make_command,lib_name_make,lib_name,path,makename,files] = ..
198 ilib_compile_get_names(lib_name, makename, files)
200 if getos() <> "Windows" then
202 k = strindex(makename,["/","\"]);
205 path = part(makename,1:k($));
206 makename = part(makename,k($)+1:length(makename));
211 lib_name = lib_name + getdynlibext();
212 lib_name_make = lib_name;
214 make_command = "make ";
216 files = files + ".o";
220 // Load dynamic_link Internal lib if it"s not already loaded
221 if ~ exists("dynamic_linkwindowslib") then
222 load("SCI/modules/dynamic_link/macros/windows/lib");
225 [make_command, lib_name_make, lib_name, path, makename, files] = ..
226 dlwGetParamsIlibCompil(lib_name, makename, files);
230 //=============================================================================