Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split too long file, various cleanups
[simgrid.git] / tools / gras / windows_stub_generator.c
1 /*      $Id$     */
2
3 /* gras_stub_generator - creates the main() to use a GRAS program           */
4
5 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier.   */
6 /* All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "gras_stub_generator.h"
12
13 /* specific to Borland Compiler */
14 #ifdef __BORLANDDC__
15 #pragma hdrstop
16 #endif
17
18 #include <stdio.h>
19 #include "xbt/sysdep.h"
20 #include "xbt/function_types.h"
21 #include "xbt/log.h"
22 #include "surf/surfxml_parse.h"
23 #include "surf/surf.h"
24 #include "portable.h" /* Needed for the time of the SIMIX convertion */
25
26 #include <stdarg.h>
27
28
29
30 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(stubgen);
31
32 #ifdef _WIN32
33
34 /* tabulation level (used to indent the lines of the borland project file */
35 static unsigned int level = 0;
36
37
38
39 /* the gras.h header directory */
40 static char* __gras_path = NULL;
41
42
43 #ifndef MAX_PATH
44 #define MAX_PATH 260
45 #endif
46
47 /*
48  * A structure which represents a borland project file.
49  */
50 typedef struct s_borland_project
51 {
52     const char* xml_version;/* the xml version used to write the borland project file                   */
53     const char* encoding;   /* the encoding used to write the borland project file                      */
54     const char* comment;    /* the xml comment to write at the begining of the borland project file     */
55         char* name;                     /* the name of the borland project file                                                                         */
56         FILE* stream;                   /* the stream to the borland project file                                                                       */
57         const char* version;    /* the builder version of the borland project file                                                      */
58         char* bin_dir;          /* the directory used to store the generated program                                            */
59         char* obj_dir;          /* the directory used to store the generated object files                                       */
60         char* lib_dir;          /* the directory used to store the librairies used in the borland project       */
61         char* src_dir;          /* the directory use to store the source files of the project                           */
62 }s_borland_project_t,* borland_project_t;
63
64
65 /*
66  * A structure which represents a visual C++ project file.
67  */
68 typedef struct s_dsp
69 {
70         FILE* stream;
71         char* lib_dir;
72         char* src_dir;
73         char* name;
74 }s_dsp_t,* dsp_t;
75
76 /*
77  * Write tabs in a borland project file.
78  * @param project The project concerned by the operation.
79  * @param count The count tab to write
80  */
81 static void
82 borland_project_write_tabs(borland_project_t project,unsigned int count);
83
84 /*
85  * Write the begin of an xml node in the borland project file.
86  * @param project The borland project concerned by this operation.
87  * @param name The name of the node.
88  */
89 static void
90 borland_project_begin_xml_node(borland_project_t project, const char* name);
91
92
93 /*
94  * Write the end of an xml node in the borland project file.
95  * @param project The borland project concerned by this operation.
96  * @param name The name of the node.
97  */
98 static void
99 borland_project_end_xml_node(borland_project_t project, const char* name);
100
101 /*
102  * Write an xml element in a borland project file.
103  * @param project The borland project concerned by this operation.
104  * @param name The name of the element to write
105  * @param value The value of the element  
106  */
107 static void
108 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
109
110 /*
111  * Write a FILE xml element in the borland project file.
112  * @param project The borland project concerned by this operation.
113  * @param file_name The value of the attribute FILENAME.
114  * @param form_name The value of the attribute FORMNAME.
115  * @param unit_name The value of the attribute UNITNAME.
116  * @param container_id The value of the attribute CONTAINERID.
117  * @param design_claas The value of the attribute DESIGNCLASS.
118  * @param local_command The value of the attribute LOCALCOMMAND.
119  */
120 static void
121 borland_project_write_file_element(     borland_project_t project,
122                                                                         const char* file_name,
123                                                                         const char* form_name,
124                                                                         const char* unit_name,
125                                                                         const char* container_id,
126                                                                         const char* design_class,
127                                                                         const char* local_command);
128 /*
129  * Write all options of the IDE of the Borland Builder C++ compiler.
130  * @ param project The project concerned by this operation.
131  */
132
133 static void
134 borland_project_write_ide_options(borland_project_t project);
135
136 /*
137  * Write the xml header of the xml document.
138  * @param project The project concerned by the operation.
139  */
140 static void
141 borland_project_write_xml_header(borland_project_t project);
142
143 /*
144  * Write an xml comment in a borland project file
145  * @param project The project concerned by this operation.
146  */
147 static void
148 borland_project_write_xml_comment(borland_project_t project);
149
150 /*
151  * Create a bpf file used by a borland project file.
152  * @param name The name of the bpf file to create.
153  */
154 static void
155 borland_project_create_main_file(const char* name);
156
157 /*
158  * Create a borland project file.
159  * @param project The project concerned by this operation.
160  */
161 static void
162 borland_project_create(borland_project_t project);
163
164 /*
165  * Close a borland project file.
166  * @param project the borland project file to close.
167  */
168 static void
169 borland_project_close(borland_project_t project);
170
171
172 /*
173  * Generate a borland project file.
174  * @param project The borland project to generate.
175  */
176 static void
177 generate_borland_project(borland_project_t project,int is_rl,const char* name);
178
179 /*
180  * Find the path of a file.
181  * @param file_name The file name to find.
182  * @path path If founded this parameter will contain the path of file.
183  * @return If successful the function returns 1. Otherwise the function
184  *  retruns 0;
185  */
186 static int
187 find_file_path(const char* root_dir,const char* file_name,char* path);
188
189
190 /*
191  * Functions used to create a Microsoft Visual C++ project file (*.dsp).
192  */
193
194 /*
195  * generate a Microsoft Visual project file*/
196 static void
197 generate_dsp_project(dsp_t project,int is_rl,const char* name);
198
199 static void
200 generate_borland_project(borland_project_t project,int is_rl,const char* name)
201 {
202         char* binary_path;      /* the path of the generated binary file                                */
203         char* obj_path;         /* the path of the generated object file                                */
204         char* lib_files;        /* a list of the libraries used in the borland project  */
205         char* main_source;      /* the name of the bpf file used by the borland project */
206         char* file_name;        /* the file name of the main source file                                */
207     char* include_path; /* the include path                                     */
208         char* buffer;
209
210     /* create the borland project file */
211     borland_project_create(project);
212
213     /* write the xml document header */
214     borland_project_write_xml_header(project);
215
216     /* write the xml comment to identify a borland project file */
217     borland_project_write_xml_comment(project);
218         
219         /* write the begin of the node PROJECT */
220         borland_project_begin_xml_node(project,"PROJECT");
221         
222         /* write the begin of node MACROS */
223         borland_project_begin_xml_node(project,"MACROS");
224         
225         /* write the borland project version */
226         borland_project_write_xml_element(project,"VERSION",project->version);
227         
228         /* construct and write the borland project binary path */
229         binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
230         sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
231         borland_project_write_xml_element(project,"PROJECT",binary_path);
232         xbt_free(binary_path);
233         
234         /* construct an write the object files to generate by the compiler */
235         obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
236         sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
237         borland_project_write_xml_element(project,"OBJFILES",obj_path);
238         xbt_free(obj_path);
239         
240         /* write the resource files used by the compiler (no resource file used) */
241         borland_project_write_xml_element(project,"RESFILES","");
242         
243         /* write the IDL files of the project (no IDL files used) */
244         borland_project_write_xml_element(project,"IDLFILES","");
245         
246         /* write the IDLGENFILES element (not used) */
247         borland_project_write_xml_element(project,"IDLGENFILES","");
248         
249         /* write the DEFFILE element (not used) */
250         borland_project_write_xml_element(project,"DEFFILE","");
251         
252         /* write the RESDEPEN element (not used, no resource file used) */
253         borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
254
255         /* construct and write the list of libraries used by the project */
256         /*
257     lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
258         sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
259     */
260         
261         if(is_rl){
262                 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
263                 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);  
264         }else{
265         lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
266                 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
267         }
268
269         borland_project_write_xml_element(project,"LIBFILES",lib_files);
270         xbt_free(lib_files);
271         
272         /* write the SPARELIBS element (not used) */
273         borland_project_write_xml_element(project,"SPARELIBS","");
274         
275         /* write the PACKAGES element (no package used) */
276         borland_project_write_xml_element(project,"PACKAGES","");
277         
278         /* write the PATHCPP element (the path of the source files of the project)*/
279         borland_project_write_xml_element(project,"PATHCPP",".;");
280         
281         /* write the PATHPAS element (not used) */
282         borland_project_write_xml_element(project,"PATHPAS","");
283         
284         /* write the PATHRC element (not used) */
285         borland_project_write_xml_element(project,"PATHRC","");
286         
287         /* write the PATHASM element (not used) */
288         borland_project_write_xml_element(project,"PATHASM","");
289         
290         /* write the DEBUGLIBPATH element (the path for debug) */
291         borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
292         
293         /* write the RELEASELIBPATH element (the path for release) */
294         borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
295         
296         /* specify the linker to use */
297         borland_project_write_xml_element(project,"LINKER","ilink32");
298         
299         /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
300         borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
301         
302         /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
303         borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
304
305         /* construct and write the MAINSOURCE element */
306         main_source = xbt_new0(char,strlen(project->name) + 5);
307         sprintf(main_source,"%s.bpf",project->name);
308     /* write the main source file to use in the borland project file */
309         borland_project_write_xml_element(project,"MAINSOURCE",main_source);
310
311         /* create the bpf file used by the borland project */
312         borland_project_create_main_file(main_source);
313
314         /* FIXME resolve the include path */
315         /* write the INCLUDEPATH element  */
316
317     if(!__gras_path){
318         buffer =xbt_new0(char,MAX_PATH);
319         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
320         
321                 __gras_path = xbt_new0(char,MAX_PATH);
322                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
323                 free(buffer);
324
325         /*find_file_path("C:\\","gras.h",__gras_path);*/
326     }
327
328     include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
329     sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
330
331         borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
332
333     xbt_free(include_path);
334
335         /* write the LIBPATH element (no librarie paths specified)*/
336         borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
337
338         /*
339      * write the WARNINGS element :
340      *  -w-sus (-w-8075) disabled the suspect conversion pointer warning
341      *  -w-rvl (-w-8070) disabled the function must return warning
342      *  -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
343      *  -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
344      *  -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
345      *  -w-par (-w-8057) disabled the warning that detect an unused variable
346      *  -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
347      *  -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
348      *  -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
349      */
350         borland_project_write_xml_element(project,"WARNINGS","-w-sus -w-rvl -w-rch -w-pia -w-pch -w-par -w-csu -w-ccc -w-aus");
351
352         /* write the OTHERFILES element (no other files used used) */
353         borland_project_write_xml_element(project,"OTHERFILES","");
354
355         /* write the end of the node MACROS */
356         borland_project_end_xml_node(project,"MACROS");
357
358         /* write the begin of the node OPTIONS */
359         borland_project_begin_xml_node(project,"OPTIONS");
360
361         /* FIXME check the idlcflags */
362         /* write the IDLCFLAGS element */
363         borland_project_write_xml_element(project,"IDLCFLAGS","");
364
365         /*
366      * write the CFLAG1 element (compiler options ) :
367      *
368      *  -Od     this flag disable all compiler optimisation
369      *  -H      this flag specify the name of the file which will contain the precompiled header
370      *  -Hc     this flag specify to the compiler to cach the precompiled header
371      *  -Vx     this flag specify to the compiler to allow the empty structures
372      *  -Ve     this flag specify to the compiler to allow the empty base classes
373      *  -X-     this flag activate the auto-depend informations of the compiler
374      *  -r-     this flag disabled the use of the processor register
375      *  -a1     this flag specify that the data must be aligned on one byte
376      *  -b-     this flag specify that the enums are the smallest size of the integer
377      *  -k      (used during debug)
378      *  -y      this flag generate the line number for debug
379      *  -v      this flag enabled the debugging of the source files
380      *  -vi     check the expansion of the inline functions
381      *  -tWC    specify that it's a console application
382      *  -tWM-   specify that the application is not multithread
383      *  -c      generate the object file, no link
384      */
385         borland_project_write_xml_element(project,"CFLAG1","-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
386
387         /* write the PFLAGS element */
388         borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
389
390         /* write the RFLAGS element */
391         borland_project_write_xml_element(project,"RFLAGS","");
392
393         /* write the AFLAGS element (assembler flags) :
394      *
395      *  /mx (not documented)
396      *  /w2 (not documented)
397      *  /zd (not documented)
398      *
399      */
400         borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
401
402         /* write the LFLAGS element (linker flags) :
403      *
404      *  -I      specify the output directory for object files
405      *  -D      register the specified description (no description "")
406      *  -ap     build a win32 console application
407      *  -Tpe    generate a exe file
408      *  -x      do not create the map file
409      *  -Gn     do not generate the state file
410      *  -v      include the complete debug informations  
411      */
412         borland_project_write_xml_element(project,"LFLAGS","-Iobj -D&quot;&quot; -ap -Tpe -x -Gn -v");
413
414         /* write the OTHERFILES element (not used)*/
415         borland_project_write_xml_element(project,"OTHERFILES","");
416
417         /* write the end of the node OPTIONS */
418         borland_project_end_xml_node(project,"OPTIONS");
419
420         /* write the begin of the node LINKER */
421         borland_project_begin_xml_node(project,"LINKER");
422
423         /* write the ALLOBJ element */
424         borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
425
426         /* write the ALLRES element (not used) */
427         borland_project_write_xml_element(project,"ALLRES","");
428
429         /* write the ALLLIB element */
430         borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
431
432         /* write the OTHERFILES element (not used) */
433         borland_project_write_xml_element(project,"OTHERFILES","");
434
435         /* write the end of the node LINKER */
436         borland_project_end_xml_node(project,"LINKER");
437
438         /* write the begin of the node FILELIST */
439         borland_project_begin_xml_node(project,"FILELIST");
440         
441         /* construct and write the list of file elements */
442         
443         /* add the bpf file to the list */
444         borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
445         xbt_free(main_source);
446         
447         /* FIXME : check the source file directory */
448         /* add the generated source file to the list */
449         
450         file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
451         sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
452         borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
453
454         memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
455         sprintf(file_name,"%s\\%s.c",project->src_dir,name);
456         borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
457
458         xbt_free(file_name);
459
460         /* FIXME : check the libraries directory */
461         /* add the simgrid library to the list */
462         
463         if(is_rl){
464                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
465                 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
466                 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
467         }else
468         {
469                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
470                 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
471                 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
472         }
473         
474         
475         xbt_free(file_name);
476
477         /* write the end of the node FILELIST */
478         borland_project_end_xml_node(project,"FILELIST");
479         
480         /* write the begin of the node BUILDTOOLS (not used)*/
481         borland_project_begin_xml_node(project,"BUILDTOOLS");
482         
483         /* write the end of the node BUILDTOOLS (not used)*/
484         borland_project_end_xml_node(project,"BUILDTOOLS");
485         
486         /* write the begin of the node IDEOPTIONS */
487         borland_project_begin_xml_node(project,"IDEOPTIONS");
488         
489         /* write all of the option of the IDE of Borland C++ Builder */
490         borland_project_write_ide_options(project);
491         
492         /* write the end of the node IDEOPTIONS */
493         borland_project_end_xml_node(project,"IDEOPTIONS");
494
495     /* write the end of the node PROJECT */
496         borland_project_end_xml_node(project,"PROJECT");
497
498     /* close the borland project file */
499     borland_project_close(project);
500 }
501
502 void
503 borland_project_write_tabs(borland_project_t project,unsigned int count)
504 {
505         unsigned int pos;
506         
507         for(pos = 0; pos < count; pos++)
508                 fprintf(project->stream,"\t");          
509 }
510
511 void
512 borland_project_begin_xml_node(borland_project_t project, const char* name)
513 {
514         if(level)
515                 borland_project_write_tabs(project,level);
516                 
517         fprintf(project->stream,"<%s>\n",name);
518         
519         level++;
520 }
521
522 void
523 borland_project_end_xml_node(borland_project_t project, const char* name)
524 {
525         level--;
526         
527         if(level)
528                 borland_project_write_tabs(project,level);
529         
530         fprintf(project->stream,"</%s>\n",name);        
531 }
532
533
534 void
535 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
536 {
537         borland_project_write_tabs(project,level);
538         fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
539 }
540
541 void
542 borland_project_write_xml_header(borland_project_t project)
543 {
544     fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
545 }
546
547 void
548 borland_project_create_main_file(const char* name)
549 {
550         FILE* stream = fopen(name,"w+");
551
552         fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit Ãªtre traité comme le fichier projet\n\n\nmain\n");
553
554         fclose(stream);
555 }
556
557 void
558 borland_project_create(borland_project_t project)
559 {
560     char* file_name = xbt_new0(char,strlen(project->name ) + 5);
561     sprintf(file_name,"%s.bpr",project->name);
562     project->stream = fopen(file_name,"w+");
563     xbt_free(file_name);
564 }
565
566 void
567 borland_project_write_xml_comment(borland_project_t project)
568 {
569     fprintf(project->stream,"<!-- %s -->\n",project->comment);
570 }
571 void
572 borland_project_write_file_element(     borland_project_t project,
573                                                                         const char* file_name,
574                                                                         const char* form_name,
575                                                                         const char* unit_name,
576                                                                         const char* container_id,
577                                                                         const char* design_class,
578                                                                         const char* local_command)
579 {
580         borland_project_write_tabs(project,level);
581
582         fprintf(project->stream,"<FILE FILENAME=\"%s\" FORMNAME=\"%s\" UNITNAME=\"%s\" CONTAINERID=\"%s\" DESIGNCLASS=\"%s\" LOCALCOMMAND=\"%s\"/>\n",file_name,form_name,unit_name,container_id,design_class,local_command);
583 }
584
585 void
586 borland_project_write_ide_options(borland_project_t project)
587 {
588
589         const char* ide_options =
590         "[Version Info]\nIncludeVerInfo=0\nAutoIncBuild=0\nMajorVer=1\nMinorVer=0\nRelease=0\nBuild=0\nDebug=0\nPreRelease=0\nSpecial=0\nPrivate=0\nDLL=0\nLocale=1036\nCodePage=1252\n\n"  \
591         "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
592         "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
593         "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
594         "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
595         "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
596         "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
597         "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
598         "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
599         "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
600         "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
601         "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
602         "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
603         "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
604         "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
605
606         fprintf(project->stream,ide_options);
607 }
608
609 void
610 borland_project_close(borland_project_t project)
611 {
612     fclose(project->stream);
613 }
614
615 void
616 generate_borland_simulation_project(const char* name)
617 {
618     char buffer[MAX_PATH] = {0};
619
620     HANDLE hDir;
621     WIN32_FIND_DATA wfd = {0};
622
623     s_borland_project_t borland_project = {0};
624     borland_project.xml_version = "1.0";
625     borland_project.encoding ="utf-8";
626     borland_project.comment ="C++Builder XML Project";
627     borland_project.version = "BCB.06.00";
628
629     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
630
631     
632     GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
633                 
634
635     GetCurrentDirectory(MAX_PATH,buffer);
636
637     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
638
639     strcpy(borland_project.src_dir,buffer);
640
641     borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
642     sprintf(borland_project.name,"%s_simulator",name);
643
644     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
645     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
646
647     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
648
649     if(!hDir)
650         CreateDirectory(borland_project.bin_dir,NULL);
651
652     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
653     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
654
655     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
656
657     if(INVALID_HANDLE_VALUE == hDir)
658         CreateDirectory(borland_project.obj_dir,NULL);
659
660     generate_borland_project(&borland_project,0,name);
661
662     xbt_free(borland_project.name);
663     xbt_free(borland_project.src_dir);
664     xbt_free(borland_project.bin_dir);
665     xbt_free(borland_project.obj_dir);
666     xbt_free(borland_project.lib_dir);
667 }
668
669 void
670 generate_borland_real_life_project(const char* name)
671 {
672     HANDLE hDir;
673     WIN32_FIND_DATA wfd = {0};
674     char buffer[MAX_PATH] = {0};
675     xbt_dict_cursor_t cursor = NULL;
676     char *key = NULL;
677     void *data = NULL;
678         s_borland_project_t borland_project = {0};
679
680         borland_project.xml_version = "1.0";
681     borland_project.encoding ="utf-8";
682     borland_project.comment ="C++Builder XML Project";
683     borland_project.version = "BCB.06.00";
684     borland_project.lib_dir = " ";
685
686     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
687
688     GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
689        
690     GetCurrentDirectory(MAX_PATH,buffer);
691
692     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
693
694     strcpy(borland_project.src_dir,buffer);
695
696     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
697     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
698
699     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
700
701     if(INVALID_HANDLE_VALUE == hDir)
702         CreateDirectory(borland_project.bin_dir,NULL);
703
704     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
705     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
706
707     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
708
709     if(!hDir)
710         CreateDirectory(borland_project.obj_dir,NULL);
711
712
713         xbt_dict_foreach(process_function_set,cursor,key,data) {
714         borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
715
716         sprintf(borland_project.name,"%s_%s",name,key);
717
718         generate_borland_project(&borland_project,1,name);
719         xbt_free(borland_project.name);
720     }
721
722     xbt_free(borland_project.src_dir);
723     xbt_free(borland_project.bin_dir);
724     xbt_free(borland_project.obj_dir);
725     xbt_free(borland_project.lib_dir);
726 }
727 int
728 find_file_path(const char* root_dir,const char* file_name,char* path)
729 {
730         HANDLE hFind;
731         WIN32_FIND_DATA wfd;
732         char* prev_dir = xbt_new(char,MAX_PATH);
733         GetCurrentDirectory(MAX_PATH,prev_dir);
734         SetCurrentDirectory(root_dir);
735         
736         // begining of the scan
737         hFind=FindFirstFile ("*.*", &wfd);
738         
739         if(hFind!=INVALID_HANDLE_VALUE){
740         
741                 /* it's a file */
742                 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
743                 
744                         if(!strcmp(file_name,wfd.cFileName)){
745                                 GetCurrentDirectory(MAX_PATH,path);
746                                 SetCurrentDirectory(prev_dir);
747                                 xbt_free(prev_dir);
748                                 FindClose(hFind);
749                                 return 1;
750                         }
751                 
752                 }
753                 /* it's a directory, scan it*/
754                 else {
755                 
756                         if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
757                                 if(find_file_path(wfd.cFileName,file_name,path)){
758                                         FindClose(hFind);
759                                         SetCurrentDirectory(prev_dir);
760                                         return 1;
761                                 }
762                         }
763                 }
764                 
765                 /* next file or directory */
766                 while(FindNextFile(hFind,&wfd))
767                 {
768                         /* it's a file */
769                         if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
770                         {
771                                 if(!strcmp(file_name,wfd.cFileName)){
772                                         GetCurrentDirectory(MAX_PATH,path);
773                                         SetCurrentDirectory(prev_dir);
774                                         xbt_free(prev_dir);
775                                         FindClose(hFind);
776                                         return 1;
777                                 }
778                         }
779                         /* it's a file scan it */
780                         else {
781                 
782                                 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
783                 
784                                         if(find_file_path(wfd.cFileName,file_name,path)){
785                                                 SetCurrentDirectory(prev_dir);
786                                                 FindClose(hFind);
787                                                 return 1;
788                                         }
789                 
790                                 }
791                 
792                         }
793                 }
794         }
795         
796         SetCurrentDirectory(prev_dir);
797         xbt_free(prev_dir);
798         FindClose (hFind);
799         return 0;
800 }
801
802 /* Implementation of the functions used to create a Visual C++ project.*/
803
804 int
805 generate_simulation_dsp_file(const char* name)
806 {
807         char buffer[MAX_PATH] = {0};
808     s_dsp_t dsp = {0};
809     dsp.lib_dir = xbt_new0(char,MAX_PATH);
810
811     GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
812     GetCurrentDirectory(MAX_PATH,buffer);
813
814     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
815     strcpy(dsp.src_dir,buffer);
816         dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
817         sprintf(dsp.name,"%s_simulator",name);
818
819     generate_dsp_project(&dsp,0,name);
820
821     xbt_free(dsp.name);
822     xbt_free(dsp.src_dir);
823         xbt_free(dsp.lib_dir);
824     
825     return 0;           
826 }
827
828 /*
829  * Create the Microsoft visual C++ real life project file.
830  */
831 int
832 generate_real_live_dsp_file(const char* name)
833 {
834         
835     char buffer[MAX_PATH] = {0};
836     xbt_dict_cursor_t cursor = NULL;
837     char *key = NULL;
838     void *data = NULL;
839         s_dsp_t dsp = {0};
840
841         
842     dsp.lib_dir = xbt_new0(char,MAX_PATH);
843
844     GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
845        
846     GetCurrentDirectory(MAX_PATH,buffer);
847
848     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
849
850     strcpy(dsp.src_dir,buffer);
851
852
853         xbt_dict_foreach(process_function_set,cursor,key,data) {
854         dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
855
856         sprintf(dsp.name,"%s_%s",name,key);
857
858         generate_dsp_project(&dsp,1,name);
859         xbt_free(dsp.name);
860     }
861
862     xbt_free(dsp.src_dir);
863     xbt_free(dsp.lib_dir);
864         return 0;
865 }
866
867 void
868 generate_dsp_project(dsp_t project,int is_rl,const char* name)
869 {
870         /* create the visual C++ project file */
871         char* buffer;
872         char* file_name = xbt_new0(char,strlen(project->name) + 5);
873     sprintf(file_name,"%s.dsp",project->name);
874     project->stream = fopen(file_name,"w+");
875     xbt_free(file_name);
876     
877     if(!__gras_path)
878         {
879         buffer =xbt_new0(char,MAX_PATH);
880         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
881         
882                 __gras_path = xbt_new0(char,MAX_PATH);
883                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
884                 free(buffer);
885     }
886     
887     /* dsp file header */
888     fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
889         fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
890         fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
891         
892         /* target type is a win32 x86 console application */
893         fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
894         
895         /* the current config is win32-debug */
896         fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
897         
898         /* warning */
899         fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
900         
901         /* NMAKE usage */
902         fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
903         fprintf(project->stream,"!MESSAGE\n");
904         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
905         fprintf(project->stream,"!MESSAGE\n");
906         fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
907         fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
908         fprintf(project->stream,"!MESSAGE\n"); 
909         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
910         fprintf(project->stream,"!MESSAGE\n");
911         fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
912         fprintf(project->stream,"!MESSAGE\n"); 
913         fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
914         fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
915         fprintf(project->stream,"!MESSAGE\n\n"); 
916         
917         fprintf(project->stream,"# Begin Project\n\n");
918         fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
919         fprintf(project->stream,"# PROP Scc_ProjName\n");
920         fprintf(project->stream,"# PROP Scc_LocalPath\n");
921         fprintf(project->stream,"CPP=cl.exe\n");
922         fprintf(project->stream,"RSC=rc.exe\n\n");
923         
924         fprintf(project->stream,"!IF  \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
925         
926         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
927         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
928         fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
929         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
930         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
931         fprintf(project->stream,"# PROP Use_MFC 0\n");
932         fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
933         fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
934         fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
935         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
936         /* TODO : the include directory */
937         /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"./%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);*/
938         fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);
939         fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
940         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
941         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
942         fprintf(project->stream,"BSC32=bscmake.exe\n");
943         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
944         fprintf(project->stream,"# ADD BSC32 /nologo\n");
945         fprintf(project->stream,"LINK32=link.exe\n");
946         fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n");
947         
948         if(is_rl)
949                 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libgras.lib /nologo /subsystem:console /machine:I386\n\n");
950         else
951                 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib /nologo /subsystem:console /machine:I386\n\n");
952                         
953         fprintf(project->stream,"!ELSEIF  \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
954
955         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
956         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
957         fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
958         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
959         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
960         fprintf(project->stream,"# PROP Use_MFC 0\n");
961         fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
962         fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
963         fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
964         fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
965         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
966         /* TODO : the include directory */
967         /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od  /I \"./%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n",__gras_path);*/
968         fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od  /I \"%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n",__gras_path);
969         fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n");
970         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
971         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
972         fprintf(project->stream,"BSC32=bscmake.exe\n");
973         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
974         fprintf(project->stream,"# ADD BSC32 /nologo\n");
975         fprintf(project->stream,"LINK32=link.exe\n");
976         fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n");
977         
978         if(is_rl)
979                 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib  libgras.lib  /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
980         else
981                 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib  simgrid.lib  /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
982                         
983         fprintf(project->stream,"!ENDIF\n\n");
984         
985         fprintf(project->stream,"# Begin Target\n\n");
986         fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
987         fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
988         fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
989         fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
990         
991         fprintf(project->stream,"# Begin Source File\n");
992         fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
993         fprintf(project->stream,"# End Source File\n\n");
994         
995         fprintf(project->stream,"# Begin Source File\n");
996         fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
997         fprintf(project->stream,"# End Source File\n\n");
998         
999         fprintf(project->stream,"# End Group\n");
1000         fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1001         fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1002         fprintf(project->stream,"# End Group\n");
1003         fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1004         fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1005         fprintf(project->stream,"# End Group\n");
1006         fprintf(project->stream,"# End Target\n");
1007         fprintf(project->stream,"# End Project\n");
1008         
1009 }
1010
1011 #endif
1012
1013
1014
1015
1016