move makefile.incl.mak
[scilab.git] / scilab / modules / dynamic_link / macros / ilib_gen_Make.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ENPC
3 // 
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at    
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function Makename=ilib_gen_Make(name,tables,files,libs,makename,with_gateway,ldflags,cflags,fflags,cc)
11 // flag 'c' or 'f' used with lcc 
12 //------------------------------------
13 // generate a Makefile for gateway
14
15   if argn(2)<6 then with_gateway=%t,ldflags='',cflags='',fflags='', cc='';end
16   for i=1:size(files,'*') // compatibility scilab 4.x
17     [path_f, file_f, ext_f] = fileparts(files(i));
18     if or(ext_f == ['.o','.obj']) then
19       files(i) = path_f + file_f;
20     else
21       files(i) = path_f + file_f + ext_f;
22     end
23   end
24   
25   // change table if necessary 
26   if typeof(tables)<>'list' then 
27     tables= list(tables)
28   end
29   L=length(tables); 
30   for it = 1:L 
31     table = tables(it);
32     [mt,nt]=size(table);
33         
34         if nt==2 then 
35           col= "csci";  // @TODO what is csci
36           table = [table, col(ones(mt,1))];
37           nt=3; 
38         end 
39         
40         if nt<>3 then 
41           error(msprintf(gettext("%s: Wrong size for input argument #%d.\n"),"ilib_gen_Make",2));
42         end 
43         
44         tables(it)=table;
45   end
46       
47   comp_target = COMPILER;
48   if with_lcc() == %T then
49         Makename = makename+'.lcc'
50         ilib_gen_Make_lcc(name,tables,files,libs,Makename,with_gateway,ldflags,cflags,fflags,'c')
51   else if getenv('WIN32','NO')=='OK' then
52     select comp_target
53      case 'VC++'   then Makename = makename+'.mak'
54       ilib_gen_Make_win32(name,tables,files,libs,Makename,with_gateway,ldflags,cflags,fflags)
55      case 'gcc' then 
56       Makename = makename;
57       ilib_gen_Make_unix(name,tables,files,libs,Makename,with_gateway,ldflags,cflags,fflags,cc)
58     else
59        Makename = makename;
60        ilib_gen_Make_win32(name,tables,files,libs,Makename,with_gateway,ldflags,cflags,fflags)
61     end
62   else
63      Makename = makename;
64      ilib_gen_Make_unix(name,files,libs,name,ldflags,cflags,fflags,cc)
65   end
66   end
67 endfunction
68
69
70 function ilib_gen_Make_win32(name,table,files,libs,Makename,with_gateway,ldflags,cflags,fflags)
71
72   managed_ext = ['.f90','.cxx','.cpp','.c','.f'];
73   for i=1:size(files,'*') // compatibility scilab 4.x
74     [path_f, file_f, ext_f] = fileparts(files(i));
75     if or(managed_ext == ext_f) then
76       files(i) = path_f + file_f;
77     else
78       files(i) = path_f + file_f + ext_f;
79     end
80   end
81
82   fd=mopen(Makename,"w");
83   mfprintf(fd,"# generated by builder.sce: Please do not edit this file\n");
84   mfprintf(fd,"# ------------------------------------------------------\n");
85   mfprintf(fd,"SHELL = /bin/sh\n");
86   mfprintf(fd,"SCIDIR =%s\n",SCI);
87   mfprintf(fd,"SCIDIR1 =%s\n",pathconvert(SCI,%f,%f,'w'));
88   mfprintf(fd,"# name of the dll to be built\n"); 
89   mfprintf(fd,"LIBRARY = %s\n",name);
90   mfprintf(fd,"# list of objects file\n");
91   mfprintf(fd,"OBJS =");
92   for x=files(:)' ; mfprintf(fd," %s.obj",x);end
93
94   if typeof(tables)<>'list' then 
95     tables= list(tables)
96   end
97   L=length(tables); 
98
99   if with_gateway then 
100     if L==1 then 
101       mfprintf(fd," %s.obj",name);
102     else
103        for i=1:L , mfprintf(fd," %s.obj",name+string(i));end 
104     end
105   end
106   
107   for it=1:L 
108     table = tables(it)
109     [mt,nt]=size(table);
110  
111     for i=1:mt ; 
112       // mex files to be added 
113       if table(i,3)=='cmex' | table(i,3)=='fmex' | table(i,3)=='Fmex' 
114         mfprintf(fd," %s.obj",table(i,2));
115       end
116     end
117   end
118   mfprintf(fd,"\n# added libraries \n");
119   mfprintf(fd,"OTHERLIBS = ");
120   for x=libs(:)' ; mfprintf(fd," %s.lib",x);end
121   mfprintf(fd,"\n");
122   mfprintf(fd,"!include $(SCIDIR1)\\modules\\dynamic_link\\src\\scripts\\Makefile.incl.mak\n");
123   
124   mexcflags = ' ';
125   mexfflags = ' ';
126   
127   if table(i,3)=='cmex' | table(i,3)=='fmex' | table(i,3)=='Fmex' then
128     if findmsvccompiler() <>'msvc90express' then
129       mexcflags = " -Dmexfunction_=mex$*_  -DmexFunction=mex_$* ";
130       mexfflags = " -Dmexfunction=mex$* ";
131     end
132   end
133   mfprintf(fd,"CFLAGS = $(CC_OPTIONS) -DFORDLL -I\""$(SCIDIR)/modules/core/includes\"""+...
134            mexcflags + cflags +" \n"); 
135   mfprintf(fd,"FFLAGS = $(FC_OPTIONS) -DFORDLL -I\""$(SCIDIR)/modules/core/includes\"""+...
136            mexfflags + fflags +"\n"); 
137   mfprintf(fd,"EXTRA_LDFLAGS = "+ ldflags+"\n");
138   mfprintf(fd,"!include $(SCIDIR1)\\modules\\dynamic_link\\src\\scripts\\Makedll.incl \n");
139   mclose(fd);
140 endfunction
141 //---------------------------------------------------------------------------------------
142          
143 function ilib_gen_Make_lcc(name,table,files,libs,Makename,with_gateway,ldflags,cflags,fflags,flag)
144 // Allan CORNET
145 //INRIA 2004
146
147   managed_ext = ['.cxx','.cpp','.c','.f'];
148   for i=1:size(files,'*') // compatibility scilab 4.x
149     [path_f, file_f, ext_f] = fileparts(files(i));
150     if or(managed_ext == ext_f) then
151       files(i) = path_f + file_f;
152     else
153       files(i) = path_f + file_f + ext_f;
154     end
155   end
156   
157   if with_module('scicos') then
158     scicoslib = '$(LCCLIBDIR)\\scicoslcc.lib $(LCCLIBDIR)\\scicos_flcc.lib $(LCCLIBDIR)\\scicos_blockslcc.lib  $(LCCLIBDIR)\\scicos_blocks_flcc.lib';
159   else
160     scicoslib = '';
161   end
162
163   fd=mopen(Makename,"w");
164   mfprintf(fd,"# ------------------------------------------------------------\n");
165   mfprintf(fd,"# generated by builder.sce (lcc 1): Please do not edit this file\n");
166   mfprintf(fd,"# ------------------------------------------------------------\n\n");
167   mfprintf(fd,"SCIDIR =%s\n",SCI);
168   mfprintf(fd,"LCCLIBDIR =%s\n",getshortpathname(SCIHOME+filesep()+'lcclib'));
169   mfprintf(fd,"SCIDIR1 =%s\n",pathconvert(SCI,%f,%f,'w'));
170   mfprintf(fd,"DUMPEXTS=""$(SCIDIR1)\\bin\\dumpexts""\n");
171         mfprintf(fd,"SCIIMPLIB=$(LCCLIBDIR)\\LibScilablcc.lib $(LCCLIBDIR)\\blaspluslcc.lib $(LCCLIBDIR)\\libf2clcc.lib $(LCCLIBDIR)\\interscilcc.lib $(LCCLIBDIR)\\lapacklcc.lib " + scicoslib +"\n\n");
172   mfprintf(fd,"CC=lcc\n");
173   mfprintf(fd,"LINKER=lcclnk\n");
174   mfprintf(fd,"CFLAGS= -ansic msvcrt.lib -I""$(SCIDIR)/modules/core/includes"" -I""$(SCIDIR)/modules/output_stream/includes"" -I""$(SCIDIR)/libs/f2c"" -I""$(SCIDIR)/modules/mexlib/includes"" -Dmexfunction_=mex$*_ -DmexFunction=mex_$* -DWIN32 -DSTRICT -DFORDLL -D__STDC__ "+ cflags +" \n"); 
175   mfprintf(fd,"LINKER_FLAGS=-dll -nounderscores\n");
176   mfprintf(fd,"EXTRA_LDFLAGS = "+ ldflags+"\n");
177   mfprintf(fd,"O=.obj\n");
178  
179   mfprintf(fd,"# name of the dll to be built\n"); 
180   mfprintf(fd,"LIBRARY = %s\n",name);
181   mfprintf(fd,"# list of objects file\n");
182   mfprintf(fd,"OBJS =");
183   for x=files(:)' ; mfprintf(fd," %s$(O)",x);end
184
185   if typeof(table)<>'list' then 
186     tables= list(table)
187   end
188   
189   L=length(table); 
190
191   if with_gateway then 
192     if L==1 then 
193       mfprintf(fd," %s$(O)",name);
194     else
195        for i=1:L , mfprintf(fd," %s$(O)",name+string(i));end 
196     end
197   end
198   
199   for it=1:L 
200     table = tables(it)
201     [mt,nt]=size(table);
202  
203     for i=1:mt ; 
204       // mex files to be added 
205       if table(i,3)=='cmex' | table(i,3)=='fmex' | table(i,3)=='Fmex' 
206         mfprintf(fd," %s$(O)",table(i,2));
207       end
208     end
209   end
210   
211   
212   mfprintf(fd,"\n\n# added libraries \n");
213   mfprintf(fd,"OTHERLIBS =");
214   
215   for x=libs(:)' ; mfprintf(fd," %s.lib",x);end
216   mfprintf(fd,"\n");
217   
218   mfprintf(fd,"\n");
219   
220   mfprintf(fd,"\nall :: $(LIBRARY).dll\n");
221   mfprintf(fd,"\n$(LIBRARY).dll: $(OBJS)\n");
222   mfprintf(fd,"\t"+"$(DUMPEXTS) -o ""$(LIBRARY).def"" ""$*"" $(OBJS)\n");
223   mfprintf(fd,"\t"+"$(LINKER) $(LINKER_FLAGS) $(OBJS) $(OTHERLIBS) $(SCIIMPLIB) $(XLIBSBIN) $(TERMCAPLIB) $(EXTRA_LDFLAGS) $*.def -o $(LIBRARY).dll\n\n");
224
225   for x=files(:)' ;
226     managed_ext_obj = ['.obj','.o'];
227     [path_f, file_f, ext_f] = fileparts(x);
228     if or(managed_ext == ext_f) then
229       files(i) = path_f + file_f;
230     else
231       files(i) = path_f + file_f + ext_f;
232     end
233         mfprintf(fd,"%s$(O):\n",x);
234         mfprintf(fd,"\t"+"$(CC) $(CFLAGS) $*.c\n\n");
235   end
236
237   if with_gateway then 
238     if L==1 then 
239       mfprintf(fd,"\n%s$(O):\n",name);
240       mfprintf(fd,"\t"+"$(CC) $(CFLAGS) $*.c\n");
241     else
242        for i=1:L ;
243        mfprintf(fd,"\n%s$(O):\n",name+string(i));
244        mfprintf(fd,"\t"+"$(CC) $(CFLAGS) $*.c\n");
245        end 
246     end
247   end
248   
249   mfprintf(fd,"\nclean:\n");
250   mfprintf(fd,"\t"+"del *.obj\n");
251   mfprintf(fd,"\t"+"del *.dll\n");
252   mfprintf(fd,"\t"+"del *.lib\n");
253   mfprintf(fd,"\t"+"del *.def\n");
254  
255  mclose(fd);
256
257 endfunction
258 //---------------------------------------------------------------------------------------