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
32 if getos() == "Windows" & ~haveacompiler() then
33 error(_("A Fortran or C compiler is required."))
42 if ~isempty(files) & (or(fileext(files)==".o") | or(fileext(files)==".obj")) then
43 error(999, msprintf(_("%s: A managed file extension for input argument #%d expected."), "ilib_compile", 3));
47 if typeof(lib_name)<>"string" then
48 error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"ilib_compile",1));
55 [make_command, lib_name_make, lib_name, path, makename, files]= ...
56 ilib_compile_get_names(lib_name, files);
62 if getos() == "Windows" then
63 //** ----------- Windows section -----------------
65 // Load dynamic_link Internal lib if it"s not already loaded
66 if ~ exists("dynamic_linkwindowslib") then
67 load("SCI/modules/dynamic_link/macros/windows/lib");
70 dlwCompile(files, make_command, makename);
73 //** ---------- Linux/MacOS/Unix section ---------------------
77 // Source tree version
78 // Headers are dispatched in the source tree
79 if isdir(SCI+"/modules/core/includes/") then
80 defaultModulesCHeader=[ "core", "mexlib","api_scilab","output_stream","localization" ];
81 defaultModulesFHeader=[ "core" ];
84 for x = defaultModulesCHeader(:)';
85 cflags=" -I"+SCI+"/modules/"+x+"/includes/ "+cflags;
88 for x = defaultModulesFHeader(:)';
89 fflags=" -I"+SCI+"/modules/"+x+"/includes/ " + fflags;
94 if isdir(SCI+"/../../include/scilab/") & ~ScilabTreeFound then
95 cflags="-I"+SCI+"/../../include/scilab/ " + cflags
96 fflags="-I"+SCI+"/../../include/scilab/ " + fflags
100 // System version (ie: /usr/include/scilab/)
101 if isdir("/usr/include/scilab/") & ~ScilabTreeFound then
102 cflags="-I/usr/include/scilab/ "+cflags
103 fflags="-I/usr/include/scilab/ "+fflags
107 if ( ilib_verbose() <> 0 & ScilabTreeFound <> %t) then
108 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");
113 // Switch back to the TMPDIR where the mandatory files are
115 chdir(TMPDIR+"/"+lib_name_orig);
117 // Detect the actual path to the libstdc++ library. For the dynamic link
118 // build, we want to use the same lib as the compiler installed.
119 // CF bug #7887 for more information.
120 // Note that, for the configure, the setup is done by compilerDetection.sh
121 cmdGCC="if test -x ""$(which gcc 2>/dev/null)""; then echo $(LC_ALL=C gcc -print-search-dirs|awk ''$1==""install:""{print $2}''); fi";
122 [GCClibpath, ierr, stderr] = unix_g(cmdGCC);
123 if (GCClibpath <> "" & ierr == 0 & grep(getenv("LD_LIBRARY_PATH"),GCClibpath) == []) then
124 setenv("LD_LIBRARY_PATH",GCClibpath+"/../../../:"+getenv("LD_LIBRARY_PATH"));
129 cmd = cmd + gencompilationflags_unix(ldflags, cflags, fflags, cc, "build")
131 //** BEWARE : this function can cause errors if used with "old style" Makefile inside a Scilab 5
132 //** environment where the Makefile are created from a "./configure"
133 [msg, ierr, stderr] = unix_g(cmd) ;
135 if ( ilib_verbose() == 2 ) then
136 mprintf(gettext("%s: Build command: %s\n"),"ilib_compile",cmd);
137 mprintf(gettext("Output: %s\n"),msg);
138 mprintf(gettext("stderr: %s\n"),stderr);
142 errMsg = sprintf(gettext("%s: An error occurred during the compilation:\n"), "ilib_compile");
143 errMsg = [errMsg ; stderr];
144 errMsg = [errMsg ; sprintf(gettext("%s: The command was:\n"), "ilib_compile")];
145 errMsg = [errMsg ; cmd];
146 chdir(oldPath); // Go back to the working dir
152 if ( ilib_verbose() <> 0 ) then
153 mprintf(gettext("%s: Warning: No error code returned by the compilation but the error output is not empty:\n"),"ilib_compile");
159 generatedLibrary=".libs/" + lib_name;
160 // Copy the produce lib to the working path
161 if ~isfile(generatedLibrary) then
162 error(msprintf(gettext("%s: Could not find the built library ''%s''.\n"),"ilib_compile",generatedLibrary));
164 copyfile(generatedLibrary, oldPath);
168 libn = path + lib_name_make ;
172 //=============================================================================
173 // function only defined in ilib_compile
174 //=============================================================================
175 function [make_command, lib_name_make, lib_name,path, makename, files] = ..
176 ilib_compile_get_names(lib_name, files)
178 if getos() <> "Windows" then
181 lib_name = lib_name + getdynlibext();
182 lib_name_make = lib_name;
184 make_command = "make ";
186 files = files + ".o";
189 makename = 'Makefile';
192 // Load dynamic_link Internal lib if it"s not already loaded
193 if ~ exists("dynamic_linkwindowslib") then
194 load("SCI/modules/dynamic_link/macros/windows/lib");
197 [make_command, lib_name_make, lib_name, path, makename, files] = ..
198 dlwGetParamsIlibCompil(lib_name, files);
202 //=============================================================================