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;
87 cflags=" -I"+SCI+"/libs/MALLOC/includes/ " + cflags;
89 for x = defaultModulesFHeader(:)';
90 fflags=" -I"+SCI+"/modules/"+x+"/includes/ " + fflags;
95 if isdir(SCI+"/../../include/scilab/") & ~ScilabTreeFound then
96 cflags="-I"+SCI+"/../../include/scilab/ " + cflags
97 fflags="-I"+SCI+"/../../include/scilab/ " + fflags
101 // System version (ie: /usr/include/scilab/)
102 if isdir("/usr/include/scilab/") & ~ScilabTreeFound then
103 cflags="-I/usr/include/scilab/ "+cflags
104 fflags="-I/usr/include/scilab/ "+fflags
108 if ( ilib_verbose() <> 0 & ScilabTreeFound <> %t) then
109 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");
114 // Switch back to the TMPDIR where the mandatory files are
116 chdir(TMPDIR+"/"+lib_name_orig);
118 // Detect the actual path to the libstdc++ library. For the dynamic link
119 // build, we want to use the same lib as the compiler installed.
120 // CF bug #7887 for more information.
121 // Note that, for the configure, the setup is done by compilerDetection.sh
122 cmdGCC="if test -x ""$(which gcc 2>/dev/null)""; then echo $(LC_ALL=C gcc -print-search-dirs|awk ''$1==""install:""{print $2}''); fi";
123 [GCClibpath, ierr, stderr] = unix_g(cmdGCC);
124 if (GCClibpath <> "" & ierr == 0 & grep(getenv("LD_LIBRARY_PATH"),GCClibpath) == []) then
125 setenv("LD_LIBRARY_PATH",GCClibpath+"/../../../:"+getenv("LD_LIBRARY_PATH"));
130 cmd = cmd + gencompilationflags_unix(ldflags, cflags, fflags, cc, "build")
132 //** BEWARE : this function can cause errors if used with "old style" Makefile inside a Scilab 5
133 //** environment where the Makefile are created from a "./configure"
134 [msg, ierr, stderr] = unix_g(cmd) ;
136 if ( ilib_verbose() == 2 ) then
137 mprintf(gettext("%s: Build command: %s\n"),"ilib_compile",cmd);
138 mprintf(gettext("Output: %s\n"),msg);
139 mprintf(gettext("stderr: %s\n"),stderr);
143 errMsg = sprintf(gettext("%s: An error occurred during the compilation:\n"), "ilib_compile");
144 errMsg = [errMsg ; stderr];
145 errMsg = [errMsg ; sprintf(gettext("%s: The command was:\n"), "ilib_compile")];
146 errMsg = [errMsg ; cmd];
147 chdir(oldPath); // Go back to the working dir
153 if ( ilib_verbose() <> 0 ) then
154 mprintf(gettext("%s: Warning: No error code returned by the compilation but the error output is not empty:\n"),"ilib_compile");
160 generatedLibrary=".libs/" + lib_name;
161 // Copy the produce lib to the working path
162 if ~isfile(generatedLibrary) then
163 error(msprintf(gettext("%s: Could not find the built library ''%s''.\n"),"ilib_compile",generatedLibrary));
165 copyfile(generatedLibrary, oldPath);
169 libn = path + lib_name_make ;
173 //=============================================================================
174 // function only defined in ilib_compile
175 //=============================================================================
176 function [make_command, lib_name_make, lib_name,path, makename, files] = ..
177 ilib_compile_get_names(lib_name, files)
179 if getos() <> "Windows" then
182 lib_name = lib_name + getdynlibext();
183 lib_name_make = lib_name;
185 make_command = "make ";
187 files = files + ".o";
190 makename = 'Makefile';
193 // Load dynamic_link Internal lib if it"s not already loaded
194 if ~ exists("dynamic_linkwindowslib") then
195 load("SCI/modules/dynamic_link/macros/windows/lib");
198 [make_command, lib_name_make, lib_name, path, makename, files] = ..
199 dlwGetParamsIlibCompil(lib_name, files);
203 //=============================================================================