x_message => messagebox(,'modal')
[scilab.git] / scilab / modules / scicos / macros / scicos_scicos / link_olibs.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //                      - Alan Layec <alan.layec@inria.fr>   - 2007
5 //                      - Allan CORNET - 2008
6 //                      - Rachid Djenidi
7 //                      - Simone Mannori
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 //
23 // See the file ../license.txt
24 //
25 //**
26 //------------------------------------------------------------------------
27 //** link_olibs   : links otherlibs in scilab
28 //                  for scicos C generated block
29 //
30 // Input : libs   : a matrix of string containing path+name
31 //                 of the libraries
32 //
33 //         rpat   : a target directory for temporary generated files
34 //
35 // Output : ok    : a boolean variable to say if job has succed
36 //          libs  : a matrix of string containing path+name
37 //                  of the libraries
38 //          for_link : a vector of strings with link cmd
39 //                     for exec or for loader.sce
40 //
41 // Author : Alan Layec, 1 Jul 2007
42 //
43 function [ok,libs,for_link] = link_olibs(libs,rpat)
44
45   //** get lhs,rhs nb paramaters
46   [lhs,rhs]=argn(0);
47
48   //** decl and set local variables
49   ok=%t
50   x=''
51   xlibs=[]
52   for_link=[]
53
54   //** get out from this function if
55   //   there is nothing to do
56   if libs=='' | libs==[] then return, end
57
58   //** LCC
59   if with_lcc()==%T then
60     //** add lcc.lib
61     //   for compatibility with dll of
62     //   msvc
63     libs=libs(:)';
64     for x=libs
65       //** extract path, name and extension of libs
66       [path,fname,extension]=fileparts(x);
67       if rhs <= 1 then
68         rpat = path
69       end
70       if (extension == '') then
71         //** search dll
72         if fileinfo(x+'.dll')<>[] then
73           if fileinfo(x+'lcc.lib')==[] then
74             //** export lcc.lib
75             messagebox(['I will try to export a '+x+'lcc.lib'],"modal","info");
76             ok=exportlibforlcc(x,rpat)
77             if ~ok then
78               messagebox(['Can''t export a '+path+fname+'lcc.lib';
79                          'Please try to do your own lcc.lib file with';
80                          'the xx scilab function or change the path';
81                          'of your library '+x+'.dll'],"modal","error");
82               ok=%f;
83               return
84             end
85           end
86           for_link=[for_link;x+'.dll']
87           link(for_link($));
88           xlibs=[xlibs;x+'lcc.lib']
89
90         //** search DLL
91         elseif fileinfo(x+'.DLL')<>[] then
92           if fileinfo(x+'lcc.lib')==[] then
93             //** export lcc.lib
94             messagebox(['I will try to export a '+x+'lcc.lib'],"modal","info");
95             ok=exportlibforlcc(x,rpat)
96             if ~ok then
97               messagebox(['Can''t export a '+path+fname+'lcc.lib';
98                          'Please try to do your own lcc.lib file with';
99                          'the xx scilab function or change the path';
100                          'of your library '+x+'.dll'],"modal","error");
101               ok=%f;
102               return
103             end
104           end
105           for_link=[for_link;x+'.DLL']
106           link(for_link($));
107           xlibs=[xlibs;x+'lcc.lib']
108
109         else
110           //** no extension
111           //   no .dll exists
112           //   do something here please ?
113           ok=%f
114           pause
115         end
116       elseif fileinfo(x)==[] then
117         messagebox(['Can''t include '+x;
118                    'That file doesn''t exist';
119                    lasterror()],"modal","error");
120         ok=%f
121         return
122       //** extension assume that user know what he does
123       else
124         //** compiled object (.obj)
125         //** compiled object doesn't need to be linked
126         if extension=='.obj' | extension=='.OBJ'  then
127           xlibs=[xlibs;x]
128         //** library (.dll)
129         elseif extension=='.dll' | extension=='.DLL' then
130           for_link=[for_link;x]
131           link(for_link($));
132           if fileinfo(x+'lcc.lib')==[] then
133             //** export lcc.lib
134             messagebox(['I will try to export a '+x+'lcc.lib'],"modal","info");
135             ok=exportlibforlcc(path+fname,rpat)
136             if ~ok then
137               messagebox(['Can''t export a '+path+fname+'lcc.lib';
138                          'Please try to do your own lcc.lib file with';
139                          'the xx scilab function or change the path';
140                          'of your library '+x+'.dll'],"modal","error");
141               ok=%f;
142               return
143             end
144           end
145           xlibs=[xlibs;path+fname+'lcc.lib']
146
147         //** library (.lib)
148         elseif extension=='.lib' | extension=='.ilib' then
149           if fileinfo(path+fname+'.dll')<>[] then
150             for_link=[for_link;path+fname+'.dll']
151             link(for_link($));
152           elseif fileinfo(path+fname+'.DLL')<>[] then
153             for_link=[for_link;path+fname+'.DLL']
154             link(for_link($));
155           else
156             //link(x);
157             messagebox(['I don''t know what to do !';
158                       'Please, report this through the Scilab bug tracker.'],"modal","error");
159             ok=%f
160             pause
161           end
162           xlibs=[xlibs;x]
163         else
164           //link(x);
165           messagebox(['I don''t know what to do !';
166                      'Please, report this through the Scilab bug tracker.'],"modal","error");
167           ok=%f
168           pause
169         end
170       end
171     end
172
173   //** MSVC
174   elseif getenv('WIN32','NO')=='OK' then
175     //** add .lib or .ilib
176     libs=libs(:)';
177     for x=libs
178       [path,fname,extension]=fileparts(x);
179       if (extension == '') then
180         //** search ilib
181         if fileinfo(x+'.ilib')<>[] then
182           //** search dll
183           if fileinfo(x+'.dll')<>[] then
184             for_link=[for_link;x+'.dll']
185             link(for_link($));
186           //** search DLL
187           elseif fileinfo(x+'.DLL')<>[] then
188             for_link=[for_link;x+'.DLL']
189             link(for_link($));
190           //** no .dll, .DLL
191           else
192             messagebox(['I cant''t find a dll !';
193                        'Please, report this through the Scilab bug tracker.'],"modal","error");
194             ok=%f
195             pause
196           end
197           xlibs=[xlibs;x+'.ilib']
198         //** search lib
199         elseif fileinfo(x+'.lib')<>[] then
200           //** search dll
201           if fileinfo(x+'.dll')<>[] then
202             for_link=[for_link;x+'.dll']
203             link(for_link($));
204           //** search DLL
205           elseif fileinfo(x+'.DLL')<>[] then
206             for_link=[for_link;x+'.DLL']
207             link(for_link($));
208           //** no .dll, .DLL
209           else
210             messagebox(['I cant''t find a dll !';
211                        'Please, report this through the Scilab bug tracker.'],"modal","error");
212             ok=%f
213             pause
214           end
215           xlibs=[xlibs;x+'.lib']
216         else
217           //** no extension
218           //   no .lib, no .ilib exists
219           //   do something here please ?
220           messagebox(['I don''t know what to do !';
221                      'Please, report this through the Scilab bug tracker.';],"modal","error");
222           ok=%f
223           pause
224         end
225       elseif fileinfo(x)==[] then
226         messagebox(['Can''t include '+x;
227                    'That file doesn''t exist';
228                    lasterror()],"modal","error");
229         ok=%f
230         return
231       //** extension assume that user know what he does
232       else
233         //** compiled object (.obj)
234         //** compiled object doesn't need to be linked
235         if extension=='.obj' | extension=='.OBJ'  then
236           xlibs=[xlibs;x]
237         //** library (.dll)
238         elseif extension=='.dll' | extension=='.DLL' then
239           for_link=[for_link;x]
240           link(for_link($));
241           if fileinfo(path+fname+'.ilib')<> [] then
242             xlibs=[xlibs;path+fname+'.ilib']
243           elseif fileinfo(path+fname+'.lib')<> [] then
244             xlibs=[xlibs;path+fname+'.lib']
245           else
246             //link(x);
247             messagebox(['I don''t know what to do !';
248                       'Please, report this through the Scilab bug tracker.'],"modal","error");
249             ok=%f
250             pause
251           end
252         //** library (.lib)
253         elseif extension=='.lib' | extension=='.ilib' then
254           if fileinfo(path+fname+'.dll')<>[] then
255             for_link=[for_link;path+fname+'.dll']
256             link(for_link($));
257           elseif fileinfo(path+fname+'.DLL')<>[] then
258             for_link=[for_link;path+fname+'.DLL']
259             link(for_link($));
260           else
261             //link(x);
262             messagebox(['I don''t know what to do !';
263                       'Please, report this through the Scilab bug tracker.'],"modal","error");
264             ok=%f
265             pause
266           end
267           xlibs=[xlibs;x]
268         else
269           //link(x);
270           messagebox(['I don''t know what to do !';
271                      'Please, report this through the Scilab bug tracker.'],"modal","error");
272           ok=%f
273           pause
274         end
275       end
276     end
277
278   //** Unix
279   else
280     //** add .a
281     //   for compatibility test if we have already a .a
282     libs=libs(:)';
283     for x=libs
284       [path,fname,extension]=fileparts(x);
285       //** no extension. Assume that's a so library
286       if (extension == '') then
287        if fileinfo(path+fname+'.so')<>[] then
288         for_link=[for_link;x+'.so']
289         link(for_link($));
290        elseif fileinfo(path+fname+'.SO')<>[] then
291         for_link=[for_link;x+'.SO']
292         link(for_link($));
293        else
294          //link(x);
295          messagebox(['I don''t know what to do !';
296                     'Please, report this through the Scilab bug tracker.'],"modal","error");
297          ok=%f
298          pause
299        end
300        if fileinfo(x+'.a')<>[] then
301          xlibs=[xlibs;x+'.a']
302        elseif fileinfo(x+'.A')<>[] then
303          xlibs=[xlibs;x+'.A']
304        else
305          //link(x);
306          messagebox(['I don''t know what to do !';
307                     'Please, report this through the Scilab bug tracker.'],"modal","error");
308          ok=%f
309          pause
310        end
311       elseif fileinfo(x)==[] then
312         messagebox(['Can''t include '+x;
313                    'That file doesn''t exist';
314                    lasterror()],"modal","error");
315         ok=%f
316         return
317       //** extension assume that user know what he does
318       else
319         //** compiled object (.o)
320         //** compiled object doesn't need to be linked
321         if extension=='.o' | extension=='.O'  then
322           xlibs=[xlibs;x]
323         //** library (.so)
324         elseif extension=='.so' | extension=='.SO' then
325           for_link=[for_link;x]
326           link(for_link($));
327           if fileinfo(path+fname+'.a')<> [] then
328             xlibs=[xlibs;path+fname+'.a']
329           elseif fileinfo(path+fname+'.A')<> [] then
330             xlibs=[xlibs;path+fname+'.A']
331           else
332             //link(x);
333             messagebox(['I don''t know what to do !';
334                       'Please, report this through the Scilab bug tracker.'],"modal","error");
335             ok=%f
336             pause
337           end
338         //** library (.a)
339         elseif extension=='.a' | extension=='.A' then
340           if fileinfo(path+fname+'.so')<>[] then
341             for_link=[for_link;path+fname+'.so']
342             link(for_link($));
343           elseif fileinfo(path+fname+'.SO')<>[] then
344             for_link=[for_link;path+fname+'.SO']
345             link(for_link($));
346           else
347             //link(x);
348             messagebox(['I don''t know what to do !';
349                     'Please, report this through the Scilab bug tracker.'],"modal","error");
350             ok=%f
351             pause
352           end
353           xlibs=[xlibs;x]
354         else
355           //link(x);
356           messagebox(['I don''t know what to do !';
357                     'Please, report this through the Scilab bug tracker.'],"modal","error");
358           ok=%f
359           pause
360         end
361       end
362     end
363   end
364
365   //** add double quote for include in
366   //   Makefile
367   libs=xlibs
368   if MSDOS then
369       libs='""'+libs+'""'
370    else
371      libs=''''+libs+''''
372    end
373
374   //** return link cmd for for_link
375   if for_link <> [] then
376     for_link = 'link(""'+for_link+'"");';
377   end
378
379   //** concatenate libs for Makefile
380   if size(libs,1)<>1 then
381     libs = strcat(libs,' ')
382   end
383
384 endfunction