Logo AND Algorithmique Numérique Distribuée

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