Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5bd5375a22275ee4cb3ce1974b0322f4ac9c8eac
[simgrid.git] / tools / gras / 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 /* specific to Borland Compiler */
12 #ifdef __BORLANDDC__
13 #pragma hdrstop
14 #endif
15
16 #include <stdio.h>
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
19 #include "xbt/log.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
22 #include "portable.h" /* Needed for the time of the SIMIX convertion */
23
24 #include <stdarg.h>
25
26
27
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
29
30 #ifdef _WIN32
31
32 /* tabulation level (used to indent the lines of the borland project file */
33 static unsigned int level = 0;
34
35
36
37 /* the gras.h header directory */
38 static char* __gras_path = NULL;
39
40
41 #ifndef MAX_PATH
42 #define MAX_PATH 260
43 #endif
44
45 /*
46  * A structure which represents a borland project file.
47  */
48 typedef struct s_borland_project
49 {
50     const char* xml_version;/* the xml version used to write the borland project file                   */
51     const char* encoding;   /* the encoding used to write the borland project file                      */
52     const char* comment;    /* the xml comment to write at the begining of the borland project file     */
53         char* name;                     /* the name of the borland project file                                                                         */
54         FILE* stream;                   /* the stream to the borland project file                                                                       */
55         const char* version;    /* the builder version of the borland project file                                                      */
56         char* bin_dir;          /* the directory used to store the generated program                                            */
57         char* obj_dir;          /* the directory used to store the generated object files                                       */
58         char* lib_dir;          /* the directory used to store the librairies used in the borland project       */
59         char* src_dir;          /* the directory use to store the source files of the project                           */
60 }s_borland_project_t,* borland_project_t;
61
62
63 /*
64  * A structure which represents a visual C++ project file.
65  */
66 typedef struct s_dsp
67 {
68         FILE* stream;
69         char* lib_dir;
70         char* src_dir;
71         char* name;
72 }s_dsp_t,* dsp_t;
73
74 /*
75  * Write tabs in a borland project file.
76  * @param project The project concerned by the operation.
77  * @param count The count tab to write
78  */
79 void
80 borland_project_write_tabs(borland_project_t project,unsigned int count);
81
82 /*
83  * Write the begin of an xml node in the borland project file.
84  * @param project The borland project concerned by this operation.
85  * @param name The name of the node.
86  */
87 void
88 borland_project_begin_xml_node(borland_project_t project, const char* name);
89
90
91 /*
92  * Write the end of an xml node in the borland project file.
93  * @param project The borland project concerned by this operation.
94  * @param name The name of the node.
95  */
96 void
97 borland_project_end_xml_node(borland_project_t project, const char* name);
98
99 /*
100  * Write an xml element in a borland project file.
101  * @param project The borland project concerned by this operation.
102  * @param name The name of the element to write
103  * @param value The value of the element  
104  */
105 void
106 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
107
108 /*
109  * Write a FILE xml element in the borland project file.
110  * @param project The borland project concerned by this operation.
111  * @param file_name The value of the attribute FILENAME.
112  * @param form_name The value of the attribute FORMNAME.
113  * @param unit_name The value of the attribute UNITNAME.
114  * @param container_id The value of the attribute CONTAINERID.
115  * @param design_claas The value of the attribute DESIGNCLASS.
116  * @param local_command The value of the attribute LOCALCOMMAND.
117  */
118 void
119 borland_project_write_file_element(     borland_project_t project,
120                                                                         const char* file_name,
121                                                                         const char* form_name,
122                                                                         const char* unit_name,
123                                                                         const char* container_id,
124                                                                         const char* design_class,
125                                                                         const char* local_command);
126 /*
127  * Write all options of the IDE of the Borland Builder C++ compiler.
128  * @ param project The project concerned by this operation.
129  */
130
131 void
132 borland_project_write_ide_options(borland_project_t project);
133
134 /*
135  * Write the xml header of the xml document.
136  * @param project The project concerned by the operation.
137  */
138 void
139 borland_project_write_xml_header(borland_project_t project);
140
141 /*
142  * Write an xml comment in a borland project file
143  * @param project The project concerned by this operation.
144  */
145 void
146 borland_project_write_xml_comment(borland_project_t project);
147
148 /*
149  * Create a bpf file used by a borland project file.
150  * @param name The name of the bpf file to create.
151  */
152 void
153 borland_project_create_main_file(const char* name);
154
155 /*
156  * Create a borland project file.
157  * @param project The project concerned by this operation.
158  */
159 void
160 borland_project_create(borland_project_t project);
161
162 /*
163  * Close a borland project file.
164  * @param project the borland project file to close.
165  */
166 void
167 borland_project_close(borland_project_t project);
168
169
170 /*
171  * Generate a borland simulation poject file.
172  * @param name The name of the simulation project
173  */
174 void
175 generate_borland_simulation_project(const char* name);
176
177 /*
178  * Generate a borland project file for real life.
179  * @param name The name of the project to create.
180  */
181 void
182 generate_borland_real_life_project(const char* name);
183
184 /*
185  * Generate a borland project file.
186  * @param project The borland project to generate.
187  */
188 void
189 generate_borland_project(borland_project_t project,int is_rl,const char* name);
190
191 /*
192  * Find the path of a file.
193  * @param file_name The file name to find.
194  * @path path If founded this parameter will contain the path of file.
195  * @return If successful the function returns 1. Otherwise the function
196  *  retruns 0;
197  */
198 int
199 find_file_path(const char* root_dir,const char* file_name,char* path);
200
201
202 /*
203  * Functions used to create a Microsoft Visual C++ project file (*.dsp).
204  */
205
206 /*
207  * Create the Microsoft visual C++ file project for the simulation.
208  */
209 int
210 generate_simulation_dsp_file(const char* project_name);
211
212 /*
213  * Create the Microsoft visual C++ real life project file.
214  */
215 int
216 generate_real_live_dsp_file(const char* project_name);
217
218 /*
219  * generate a Microsoft Visual project file*/
220 void
221 generate_dsp_project(dsp_t project,int is_rl,const char* name);
222
223 #endif
224
225
226
227 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
228 #define SIM_SOURCENAME  "_%s_simulator.c"
229 #define SIM_OBJNAME  "_%s_simulator.o"
230 #define SIM_BINARYNAME  "%s_simulator"
231 #define SIM_SOURCENAME_LDADD  "%s_simulator_LDADD"
232 #define SIM_SOURCENAME_SOURCES  "%s_simulator_SOURCES"
233 #define RL_SOURCENAME  "_%s_%s.c"
234 #define RL_OBJNAME  "_%s_%s.o"
235 #define RL_BINARYNAME  "%s_%s"
236 #define RL_SOURCENAME_LDADD  "%s_%s_LDADD"
237 #define RL_SOURCENAME_SOURCES  "%s_%s_SOURCES"
238 #define MAKEFILE_FILENAME_AM  "%s.Makefile.am"
239 #define MAKEFILE_FILENAME_LOCAL  "%s.mk"
240 #define MAKEFILE_FILENAME_REMOTE  "%s.Makefile.remote"
241 #define DEPLOYMENT  "%s.deploy.sh"
242
243 char *warning = NULL;
244
245 /**********************************************/
246 /**** Generate the file for the simulator *****/
247 /**********************************************/
248
249 const char *SIM_PREEMBULE =
250 "/* specific to Borland Compiler */\n"
251 "#ifdef __BORLANDC__\n"
252 "#pragma hdrstop\n"
253 "#endif\n\n"
254 "#include <stdlib.h>\n"
255 "#include <stdio.h>\n"
256 "#include \"msg/msg.h\"\n"
257 "#include <gras.h>\n"
258 "\n"
259 "char *gras_log=NULL;\n";
260
261
262 #define SIM_LAUNCH_FUNC  \
263 "int launch_%s(int argc, char **argv) {\n" \
264 "  char **myargv=argv;\n" \
265 "  int myargc=argc;\n" \
266 "  int i;\n" \
267 "  int retcode;\n"\
268 "    \n"\
269 "  if (gras_log) {\n"\
270 "    myargv=malloc((argc+1) * sizeof(char**));\n" \
271 "    for (i=0; i<argc; i++)\n" \
272 "      myargv[i] = argv[i];\n" \
273 "    myargv[myargc++] = gras_log;\n" \
274 "  }\n" \
275 "  retcode = %s(myargc,myargv);\n" \
276 "  if (myargv != argv)\n" \
277 "    free(myargv);\n" \
278 "  return retcode;\n" \
279 "}\n"
280
281 const char *SIM_MAIN_POSTEMBULE = "\n"
282 "\n"
283 #ifdef USE_SIMIX
284 "  gras_launch_application(argv[2]);\n"
285 "\n"
286 "  /*  Run the simulation */\n"
287 "  gras_main();\n"
288 "\n"
289 "  /* cleanup the place */\n"
290 "  gras_clean();\n"
291 #else
292 "  MSG_launch_application(argv[2]);\n"
293 "\n"
294 "  /*  Run the simulation */\n"
295 "  MSG_main();\n"
296 "\n"
297 "  /* cleanup the place */\n"
298 "  MSG_clean();\n"
299 #endif  
300 "  if (gras_log)\n"
301 "    free(gras_log);\n"
302 "  return 0;\n"
303 "}\n";
304
305
306
307 /**********************************************/
308 /********* Parse XML deployment file **********/
309 /**********************************************/
310 xbt_dict_t process_function_set = NULL;
311 xbt_dynar_t process_list = NULL;
312 xbt_dict_t machine_set = NULL;
313
314 typedef struct s_process_t {
315   int argc;
316   char **argv;
317   char *host;
318 } s_process_t;
319
320 static void s_process_free(void *process)
321 {
322   int i;
323   for(i=0;i<((s_process_t*)process)->argc; i++)
324     free(((s_process_t*)process)->argv[i]);
325   free(((s_process_t*)process)->host);
326 }
327
328 static s_process_t process;
329
330 /*
331  * Création de deux dictionnaires
332  */
333 static void parse_process_init(void)
334 {
335   xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
336   xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
337   process.argc = 1 ;
338   process.argv = xbt_new(char*,1);
339   process.argv[0] = xbt_strdup(A_surfxml_process_function);
340   process.host=strdup(A_surfxml_process_host);
341   /*VERB1("Function: %s",A_surfxml_process_function);*/
342 }
343
344 static void parse_argument(void)
345 {
346   process.argc++;
347   process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
348   process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
349 }
350
351 static void parse_process_finalize(void)
352 {
353   xbt_dynar_push(process_list,&process);
354   /*VERB1("Function: %s",process.argv[0]);*/
355 }
356
357 static void generate_sim(char *project)
358 {
359         xbt_dict_cursor_t cursor=NULL;
360         char *key = NULL;
361         void *data = NULL;
362         char *filename = NULL;
363         FILE *OUT = NULL;
364         
365         /* 
366          * Creation d'un fichier nommé : <projet>_simulator.c 
367          */
368  
369
370         filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
371         sprintf(filename,SIM_SOURCENAME,project);
372         
373         OUT=fopen(filename,"w");
374         
375         
376         xbt_assert1(OUT, "Unable to open %s for writing",filename);
377         
378         /*
379          * Ecriture du message d'avertissement.
380          */
381         fprintf(OUT, "%s\n",warning);
382         
383         /*
384          * Ecriture du préambule (inclusion de certains fichiers d'en-tête
385          */
386         fprintf(OUT, "%s", SIM_PREEMBULE);
387         
388         /*
389          * Déclaration des fonction int <process>(int argc,char *argv[]);
390          */
391         xbt_dict_foreach(process_function_set,cursor,key,data) {
392                 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
393         }
394         
395         fprintf(OUT,"\n");
396         
397         /*
398          * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
399          */
400         xbt_dict_foreach(process_function_set,cursor,key,data) {
401         fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
402         }
403         
404         /*
405          * Ecriture du message d'avertissement.
406          */
407         fprintf(OUT, "\n%s\n",warning);
408
409         xbt_dict_foreach(process_function_set,cursor,key,data) {
410                 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
411         }
412         fprintf(OUT, "\n%s\n",warning);
413
414     fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
415     "#ifdef __BORLANDDC__\n"
416     "#pragma argsused\n"
417     "#endif\n\n");
418         
419         fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
420         "\n" 
421         "  /*  Simulation setup */\n" 
422 #ifdef USE_SIMIX                
423         "  gras_global_init(&argc,argv);\n"
424 #else           
425         "  MSG_global_init(&argc,argv);\n"
426 #endif          
427         "  if (argc != 3) {\n" 
428         "    fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n" 
429         "    exit(1);\n" 
430         "  }\n"
431         "\n");
432         fprintf(OUT,
433 #ifdef USE_SIMIX                
434         "  gras_create_environment(argv[1]);\n" 
435         "\n" 
436         "  /*  Application deployment */\n"
437         );
438 #else           
439         "  MSG_paje_output(\"%s.trace\");\n" 
440         "  MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n" 
441         "  MSG_create_environment(argv[1]);\n"
442         "\n" 
443         "  /*  Application deployment */\n",
444         project);
445 #endif          
446         xbt_dict_foreach(process_function_set,cursor,key,data) {
447 #ifdef USE_SIMIX           
448                 fprintf(OUT,"  gras_function_register(\"%s\", launch_%s);\n",key,key);
449 #else
450                 fprintf(OUT,"  MSG_function_register(\"%s\", launch_%s);\n",key,key);
451 #endif
452         }
453         fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
454         fclose(OUT);
455         free(filename);
456 }
457
458 /**********************************************/
459 /**** Generate the file for the real life *****/
460 /**********************************************/
461 static void generate_rl(char *project)
462 {
463   xbt_dict_cursor_t cursor=NULL;
464   char *key = NULL;
465   void *data = NULL;
466   char *filename = NULL;
467   FILE *OUT = NULL;
468
469   xbt_dict_foreach(process_function_set,cursor,key,data) {
470     filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
471
472         sprintf(filename,RL_SOURCENAME,project,key);
473
474     OUT=fopen(filename,"w");
475     xbt_assert1(OUT, "Unable to open %s for writing",filename);
476
477     fprintf(OUT, "\n%s\n",warning);
478     fprintf(OUT, "/* specific to Borland Compiler */\n" \
479                  "#ifdef __BORLANDC__\n" \
480                  "#pragma hdrstop\n" \
481                  "#endif\n\n" \
482                  "#include <stdio.h>\n" \
483                  "#include <signal.h>\n" \
484                  "#include <gras.h>\n" \
485                  "\n" \
486                  "extern const char * XBT_PUBLIC_DATA _gras_procname;\n" \
487                  "/* user code */\n" \
488                  "int %s(int argc, char *argv[]);\n" \
489                  "\n" \
490                  "/* specific to Borland Compiler */\n" \
491                 "#ifdef __BORLANDC__\n" \
492                 "#pragma argsused\n" \
493                 "#endif\n\n" \
494                  "int main(int argc, char *argv[]){\n" \
495                  "  int errcode;\n" \
496                  "\n" \
497                  "  _gras_procname = \"%s\";\n" \
498                  "  errcode=%s(argc,argv);\n"\
499                  " \n" \
500                  "  return errcode;\n"\
501                  "}\n",
502             key,key,key);
503     fprintf(OUT, "\n%s\n",warning);
504     fclose(OUT);
505     free(filename);
506   }
507 }
508
509 static void generate_makefile_am(char *project, char *deployment)
510 {
511   xbt_dict_cursor_t cursor=NULL;
512   char *key = NULL;
513   void *data = NULL;
514   char *filename = NULL;
515   FILE *OUT = NULL;
516
517   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
518   sprintf(filename,MAKEFILE_FILENAME_AM, project);
519
520   OUT=fopen(filename,"w");
521   xbt_assert1(OUT, "Unable to open %s for writing",filename);
522
523   fprintf(OUT, "# AUTOMAKE variable definition\n");
524   fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
525   fprintf(OUT, "PROGRAMS=");
526   fprintf(OUT, SIM_BINARYNAME,project);
527
528   xbt_dict_foreach(process_function_set,cursor,key,data) {
529     fprintf(OUT, " ");
530     fprintf(OUT, RL_BINARYNAME, project, key);
531   }
532
533   fprintf(OUT, "\n\n");
534   fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
535   fprintf(OUT, "=\t");
536   fprintf(OUT, SIM_SOURCENAME,project);
537   fprintf(OUT, " %s.c\n", project);
538   fprintf(OUT, SIM_SOURCENAME_LDADD, project);
539   fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
540
541   xbt_dict_foreach(process_function_set,cursor,key,data) {
542     fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
543     fprintf(OUT, "=\t");
544     fprintf(OUT, RL_SOURCENAME, project,key);
545     fprintf(OUT, " %s.c\n", project);
546     fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
547     fprintf(OUT, "=\tpath/to/libgras.a\n\n");
548   }
549
550   fprintf(OUT, "\n# cleanup temps\n");
551   fprintf(OUT, "CLEANFILES= ");
552   fprintf(OUT, SIM_SOURCENAME, project);
553   
554   xbt_dict_foreach(process_function_set,cursor,key,data) {
555     fprintf(OUT, " ");
556     fprintf(OUT, RL_SOURCENAME, project,key);
557   }
558   fprintf(OUT, "\n");
559
560   fprintf(OUT, "\n# generate temps\n");
561   fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
562
563   xbt_dict_foreach(process_function_set,cursor,key,data) {
564     fprintf(OUT, RL_SOURCENAME, project,key);
565     fprintf(OUT, " ");
566   }
567   fprintf(OUT, SIM_SOURCENAME, project);
568   fprintf(OUT, ": %s\n", deployment);
569   fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
570   fclose(OUT);
571 }
572
573 static void generate_makefile_local(char *project, char *deployment)
574 {
575   xbt_dict_cursor_t cursor=NULL;
576   char *key = NULL;
577   void *data = NULL;
578   char *filename = NULL;
579   FILE *OUT = NULL;
580
581   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
582   sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
583   
584   OUT=fopen(filename,"w");
585   xbt_assert1(OUT, "Unable to open %s for writing",filename);
586   free(filename);
587    
588   fprintf(OUT,
589           "\n"
590           "####\n"
591           "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
592           "####\n\n\n");
593
594   fprintf(OUT,"## Variable declarations\n"
595               "PROJECT_NAME=%s\n"
596               "DISTDIR=gras-$(PROJECT_NAME)\n\n"
597           ,project);
598    
599   fprintf(OUT,
600           "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
601           "# Compilation will fail if you don't do so\n" 
602           "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
603           "# You can fiddle the following to make it fit your taste\n"
604           "INCLUDES = -I$(GRAS_ROOT)/include\n"
605           "CFLAGS ?= -O3 -w -g\n"
606           "LIBS_SIM = -lm  -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
607           "LIBS_RL = -lm  -L$(GRAS_ROOT)/lib/ -lgras\n"
608           "LIBS = \n"
609           "\n");
610
611   fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
612
613   fprintf(OUT, "GENERATED_C_FILES = ");
614   fprintf(OUT, SIM_SOURCENAME" ",project);
615   xbt_dict_foreach(process_function_set,cursor,key,data) {
616     fprintf(OUT, RL_SOURCENAME " ",project, key);
617   }
618   fprintf(OUT, "\n");
619
620   fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
621
622   fprintf(OUT, "BIN_FILES = ");
623
624   fprintf(OUT, SIM_BINARYNAME " ",project);
625   xbt_dict_foreach(process_function_set,cursor,key,data) {
626     fprintf(OUT, RL_BINARYNAME " ", project, key);
627   }
628   fprintf(OUT, "\n");
629
630   fprintf(OUT,
631           "\n"
632           "## By default, build all the binaries\n"
633           "all: $(BIN_FILES)\n"
634           "\n");
635    
636   fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
637   xbt_dict_foreach(process_function_set,cursor,key,data) {
638     fprintf(OUT, RL_SOURCENAME, project,key);
639     fprintf(OUT, " ");
640   }
641   fprintf(OUT, SIM_SOURCENAME, project);
642   fprintf(OUT, ": %s\n", deployment);
643   fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
644
645   fprintf(OUT, "\n## Generate the binaries\n");
646   fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
647   fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
648   xbt_dict_foreach(process_function_set,cursor,key,data) {
649     fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
650     fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
651   }  
652   fprintf(OUT, 
653           "\n"
654           "%%: %%.o\n"
655           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
656           "\n"
657           "%%.o: %%.c\n"
658           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
659           "\n");
660    
661   fprintf(OUT,
662           "## Rules for tarballs and cleaning\n"
663           "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
664           "distdir: $(DIST_FILES)\n"
665           "\trm -rf $(DISTDIR)\n"
666           "\tmkdir -p $(DISTDIR)\n"
667           "\tcp $^ $(DISTDIR)\n"
668           "\n"
669           "dist: clean distdir\n"
670           "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
671           "\n", project /*, project*/);
672
673   fprintf(OUT,
674           "clean:\n"
675           "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
676   xbt_dict_foreach(process_function_set,cursor,key,data) {
677      fprintf(OUT, " " RL_OBJNAME, project, key);
678   }
679   fprintf(OUT,   
680           "\n"
681           "\trm -rf $(DISTDIR)\n"
682           "\n"
683           ".SUFFIXES:\n"
684           ".PHONY : clean\n"
685           "\n");
686   /* 
687   fprintf(OUT, "############ REMOTE COMPILING #########\n");
688   fprintf(OUT, 
689           "MACHINES ?= ");
690   xbt_dict_foreach(machine_set,cursor,key,data) {
691     fprintf(OUT, "%s ",key);
692   }
693   fprintf(OUT,"\n");
694
695   fprintf(OUT, 
696           "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
697           "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
698           "SRCDIR ?= ./\n"
699           "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
700           "SIMGRID_VERSION ?=2.92\n"
701           "GRAS_PROJECT ?= %s\n"
702           "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
703           "\n"
704           "remote:\n"
705           "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
706           "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
707           "\t for site in $(MACHINES) ; do \\\n"
708           "\t   machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
709           "\t   machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
710           "\t   cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
711           "\t                        SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
712           "\t                        GRAS_PROJECT_URL=$(GRAS_PROJECT_URL)  mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
713           "\t   cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
714           "\t                        SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
715           "\t                        GRAS_PROJECT_URL=$(GRAS_PROJECT_URL)  make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
716           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
717           "\t     echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
718           "\t   else \\\n"
719           "\t     machine=$$site;\\\n"
720           "\t     echo \"----[ Compile on $$machine ]----\";\\\n"
721           "\t   fi;\\\n"
722           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
723           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
724           "\t     then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
725           "\t   else \\\n"
726           "\t     if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
727           "\t     then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
728           "\t   fi;\\\n"
729           "\t   echo \"-- Copy the data over\"; \\\n"
730           "\t   scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
731           "\t   echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
732           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
733           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
734           "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
735           "\t   else \\\n"
736           "\t     if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
737           "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
738           "\t   fi;\\\n"
739           "\t done;\n",project,project,project);
740 */
741   fclose(OUT);
742 }
743
744 static void generate_makefile_remote(char *project, char *deployment)
745 {
746   char *filename = NULL;
747   FILE *OUT = NULL;
748
749   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
750   sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
751   
752   OUT=fopen(filename,"w");
753   xbt_assert1(OUT, "Unable to open %s for writing",filename);
754
755   fprintf(OUT, 
756           "INSTALL_PATH ?= $(shell pwd)\n"
757           "\n"
758           "compile-simgrid:\n"
759           "\tcd $$GRAS_ROOT ; \\\n"
760           "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
761           "\techo $$retrieved; \\\n"
762           "\tif test \"x$$retrieved\" = x; then \\\n"
763           "\t  tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
764           "\t  cd simgrid-$(SIMGRID_VERSION)/; \\\n"
765           "\t  ./configure --prefix=$$GRAS_ROOT ; \\\n"
766           "\t  make all install ;\\\n"
767            "\tfi\n"
768           "\n"
769           "compile-gras: compile-simgrid\n"
770           "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
771           "\techo $$not_retrieved; \\\n"
772           "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
773           "\t  tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
774           "\t  make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
775           "\tfi\n"
776           "\n"
777           "clean-simgrid:\n"
778           "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
779           "clean-gras clean-gras-$(GRAS_PROJECT):\n"
780           "\trm -rf gras-$(GRAS_PROJECT)*\n"
781           "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
782           "\n"
783           ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
784           "        compile-simgrid compile-gras\n"
785           );
786   fclose(OUT);
787 }
788
789
790 static void generate_deployment(char *project, char *deployment)
791 {
792   xbt_dict_cursor_t cursor=NULL;
793   char *key = NULL;
794   void *data = NULL;
795   char *filename = NULL;
796   FILE *OUT = NULL;
797
798   int cpt,i;
799   s_process_t proc;
800
801   filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
802   sprintf(filename,DEPLOYMENT, project);
803   
804   OUT=fopen(filename,"w");
805   xbt_assert1(OUT, "Unable to open %s for writing",filename);
806
807   fprintf(OUT, "#!/bin/sh\n");
808   fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
809   fprintf(OUT,
810           "if test \"${MACHINES+set}\" != set; then \n"
811           "    export MACHINES='");
812   xbt_dict_foreach(machine_set,cursor,key,data) {
813     fprintf(OUT, "%s ",key);
814   }
815   fprintf(OUT,  
816           "';\n"
817           "fi\n"
818           "if test \"${INSTALL_PATH+set}\" != set; then \n"
819           "    export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
820           "fi\n"
821           "if test \"${GRAS_ROOT+set}\" != set; then \n"
822           "    export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
823           "fi\n"
824           "if test \"${SRCDIR+set}\" != set; then \n"
825           "    export SRCDIR=./\n"
826           "fi\n"
827           "if test \"${SIMGRID_URL+set}\" != set; then \n"
828           "    export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
829           "fi\n"
830           "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
831           "    export SIMGRID_VERSION=2.91\n"
832           "fi\n"
833           "if test \"${GRAS_PROJECT+set}\" != set; then \n"
834           "    export GRAS_PROJECT=%s\n"
835           "fi\n"
836           "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
837           "    export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
838           "fi\n"
839           "\n"
840           "test -e runlogs/ || mkdir -p runlogs/\n",
841           project);
842
843   fprintf(OUT,  
844           "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
845           "                 SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
846           "                 GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
847
848   xbt_dynar_foreach (process_list,cpt,proc) {
849     fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
850     for(i=1;i<proc.argc;i++) {
851       fprintf(OUT,"%s ",proc.argv[i]);
852     }
853     fprintf(OUT,"\";\n");
854     fprintf(OUT,"ssh %s \"$cmd_prolog 'export LD_LIBRARY_PATH=\\$INSTALL_PATH/lib:\\$LD_LIBRARY_PATH; echo \\\"$cmd\\\" ; $cmd 2>&1'\" > runlogs/%s_%d.log &\n",proc.host,proc.host,cpt);
855   }
856
857   fclose(OUT);
858 }
859
860 static void print(void *p)
861 {
862   printf("%p",p);
863 }
864
865
866 #ifdef _WIN32
867 #include <windows.h>
868 #endif
869
870 /* specific to Borland Compiler */
871 #ifdef __BORLANDDC__
872 #pragma argsused
873 #endif
874
875 int main(int argc, char *argv[])
876 {
877   char *project_name = NULL;
878   char *deployment_file = NULL;
879   int i;
880    
881   surf_init(&argc, argv);
882
883   xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
884
885   project_name = argv[1];
886
887   process_function_set = xbt_dict_new();
888   process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
889   machine_set = xbt_dict_new();
890
891   STag_surfxml_process_fun = parse_process_init;
892   ETag_surfxml_argument_fun = parse_argument;
893   ETag_surfxml_process_fun = parse_process_finalize;
894   
895   for(i=2; i<argc; i++) {
896      deployment_file = argv[i];
897      surf_parse_open(deployment_file);
898      if(surf_parse()) 
899         xbt_assert1(0,"Parse error in %s",deployment_file);
900      
901      surf_parse_close();
902   }
903
904
905   warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
906   sprintf(warning,WARN,deployment_file);
907
908   /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
909     xbt_dict_cursor_t cursor=NULL;
910     char *key = NULL;
911     void *data = NULL;
912
913     for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
914          xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
915          xbt_dict_cursor_step(cursor) ) {
916       DEBUG1("Function %s", key);      
917     }
918     
919     xbt_dict_dump(process_function_set,print);
920   }*/
921
922   generate_sim(project_name);
923   generate_rl(project_name);
924   generate_makefile_local(project_name, deployment_file);
925   #ifdef _WIN32
926   generate_borland_simulation_project(project_name);
927   generate_borland_real_life_project(project_name);
928   generate_simulation_dsp_file(project_name);
929   generate_real_live_dsp_file(project_name);
930
931   if(__gras_path)
932     xbt_free(__gras_path);
933   
934
935   #endif
936 //  generate_makefile_remote(project_name, deployment_file);
937 //  generate_deployment(project_name, deployment_file);
938
939   free(warning);
940   surf_exit();
941   return 0;
942 }
943 #ifdef _WIN32
944 void
945 generate_borland_project(borland_project_t project,int is_rl,const char* name)
946 {
947         char* binary_path;      /* the path of the generated binary file                                */
948         char* obj_path;         /* the path of the generated object file                                */
949         char* lib_files;        /* a list of the libraries used in the borland project  */
950         char* main_source;      /* the name of the bpf file used by the borland project */
951         char* file_name;        /* the file name of the main source file                                */
952     char* include_path; /* the include path                                     */
953         char* buffer;
954
955     /* create the borland project file */
956     borland_project_create(project);
957
958     /* write the xml document header */
959     borland_project_write_xml_header(project);
960
961     /* write the xml comment to identify a borland project file */
962     borland_project_write_xml_comment(project);
963         
964         /* write the begin of the node PROJECT */
965         borland_project_begin_xml_node(project,"PROJECT");
966         
967         /* write the begin of node MACROS */
968         borland_project_begin_xml_node(project,"MACROS");
969         
970         /* write the borland project version */
971         borland_project_write_xml_element(project,"VERSION",project->version);
972         
973         /* construct and write the borland project binary path */
974         binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
975         sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
976         borland_project_write_xml_element(project,"PROJECT",binary_path);
977         xbt_free(binary_path);
978         
979         /* construct an write the object files to generate by the compiler */
980         obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
981         sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
982         borland_project_write_xml_element(project,"OBJFILES",obj_path);
983         xbt_free(obj_path);
984         
985         /* write the resource files used by the compiler (no resource file used) */
986         borland_project_write_xml_element(project,"RESFILES","");
987         
988         /* write the IDL files of the project (no IDL files used) */
989         borland_project_write_xml_element(project,"IDLFILES","");
990         
991         /* write the IDLGENFILES element (not used) */
992         borland_project_write_xml_element(project,"IDLGENFILES","");
993         
994         /* write the DEFFILE element (not used) */
995         borland_project_write_xml_element(project,"DEFFILE","");
996         
997         /* write the RESDEPEN element (not used, no resource file used) */
998         borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
999
1000         /* construct and write the list of libraries used by the project */
1001         /*
1002     lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
1003         sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
1004     */
1005         
1006         if(is_rl){
1007                 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
1008                 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);  
1009         }else{
1010         lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
1011                 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
1012         }
1013
1014         borland_project_write_xml_element(project,"LIBFILES",lib_files);
1015         xbt_free(lib_files);
1016         
1017         /* write the SPARELIBS element (not used) */
1018         borland_project_write_xml_element(project,"SPARELIBS","");
1019         
1020         /* write the PACKAGES element (no package used) */
1021         borland_project_write_xml_element(project,"PACKAGES","");
1022         
1023         /* write the PATHCPP element (the path of the source files of the project)*/
1024         borland_project_write_xml_element(project,"PATHCPP",".;");
1025         
1026         /* write the PATHPAS element (not used) */
1027         borland_project_write_xml_element(project,"PATHPAS","");
1028         
1029         /* write the PATHRC element (not used) */
1030         borland_project_write_xml_element(project,"PATHRC","");
1031         
1032         /* write the PATHASM element (not used) */
1033         borland_project_write_xml_element(project,"PATHASM","");
1034         
1035         /* write the DEBUGLIBPATH element (the path for debug) */
1036         borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
1037         
1038         /* write the RELEASELIBPATH element (the path for release) */
1039         borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
1040         
1041         /* specify the linker to use */
1042         borland_project_write_xml_element(project,"LINKER","ilink32");
1043         
1044         /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
1045         borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
1046         
1047         /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
1048         borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
1049
1050         /* construct and write the MAINSOURCE element */
1051         main_source = xbt_new0(char,strlen(project->name) + 5);
1052         sprintf(main_source,"%s.bpf",project->name);
1053     /* write the main source file to use in the borland project file */
1054         borland_project_write_xml_element(project,"MAINSOURCE",main_source);
1055
1056         /* create the bpf file used by the borland project */
1057         borland_project_create_main_file(main_source);
1058
1059         /* FIXME resolve the include path */
1060         /* write the INCLUDEPATH element  */
1061
1062     if(!__gras_path){
1063         buffer =xbt_new0(char,MAX_PATH);
1064         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1065         
1066                 __gras_path = xbt_new0(char,MAX_PATH);
1067                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1068                 free(buffer);
1069
1070         /*find_file_path("C:\\","gras.h",__gras_path);*/
1071     }
1072
1073     include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1074     sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1075
1076         borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1077
1078     xbt_free(include_path);
1079
1080         /* write the LIBPATH element (no librarie paths specified)*/
1081         borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1082
1083         /*
1084      * write the WARNINGS element :
1085      *  -w-sus (-w-8075) disabled the suspect conversion pointer warning
1086      *  -w-rvl (-w-8070) disabled the function must return warning
1087      *  -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1088      *  -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1089      *  -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1090      *  -w-par (-w-8057) disabled the warning that detect an unused variable
1091      *  -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1092      *  -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1093      *  -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1094      */
1095         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");
1096
1097         /* write the OTHERFILES element (no other files used used) */
1098         borland_project_write_xml_element(project,"OTHERFILES","");
1099
1100         /* write the end of the node MACROS */
1101         borland_project_end_xml_node(project,"MACROS");
1102
1103         /* write the begin of the node OPTIONS */
1104         borland_project_begin_xml_node(project,"OPTIONS");
1105
1106         /* FIXME check the idlcflags */
1107         /* write the IDLCFLAGS element */
1108         borland_project_write_xml_element(project,"IDLCFLAGS","");
1109
1110         /*
1111      * write the CFLAG1 element (compiler options ) :
1112      *
1113      *  -Od     this flag disable all compiler optimisation
1114      *  -H      this flag specify the name of the file which will contain the precompiled header
1115      *  -Hc     this flag specify to the compiler to cach the precompiled header
1116      *  -Vx     this flag specify to the compiler to allow the empty structures
1117      *  -Ve     this flag specify to the compiler to allow the empty base classes
1118      *  -X-     this flag activate the auto-depend informations of the compiler
1119      *  -r-     this flag disabled the use of the processor register
1120      *  -a1     this flag specify that the data must be aligned on one byte
1121      *  -b-     this flag specify that the enums are the smallest size of the integer
1122      *  -k      (used during debug)
1123      *  -y      this flag generate the line number for debug
1124      *  -v      this flag enabled the debugging of the source files
1125      *  -vi     check the expansion of the inline functions
1126      *  -tWC    specify that it's a console application
1127      *  -tWM-   specify that the application is not multithread
1128      *  -c      generate the object file, no link
1129      */
1130         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");
1131
1132         /* write the PFLAGS element */
1133         borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1134
1135         /* write the RFLAGS element */
1136         borland_project_write_xml_element(project,"RFLAGS","");
1137
1138         /* write the AFLAGS element (assembler flags) :
1139      *
1140      *  /mx (not documented)
1141      *  /w2 (not documented)
1142      *  /zd (not documented)
1143      *
1144      */
1145         borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1146
1147         /* write the LFLAGS element (linker flags) :
1148      *
1149      *  -I      specify the output directory for object files
1150      *  -D      register the specified description (no description "")
1151      *  -ap     build a win32 console application
1152      *  -Tpe    generate a exe file
1153      *  -x      do not create the map file
1154      *  -Gn     do not generate the state file
1155      *  -v      include the complete debug informations  
1156      */
1157         borland_project_write_xml_element(project,"LFLAGS","-Iobj -D&quot;&quot; -ap -Tpe -x -Gn -v");
1158
1159         /* write the OTHERFILES element (not used)*/
1160         borland_project_write_xml_element(project,"OTHERFILES","");
1161
1162         /* write the end of the node OPTIONS */
1163         borland_project_end_xml_node(project,"OPTIONS");
1164
1165         /* write the begin of the node LINKER */
1166         borland_project_begin_xml_node(project,"LINKER");
1167
1168         /* write the ALLOBJ element */
1169         borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1170
1171         /* write the ALLRES element (not used) */
1172         borland_project_write_xml_element(project,"ALLRES","");
1173
1174         /* write the ALLLIB element */
1175         borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1176
1177         /* write the OTHERFILES element (not used) */
1178         borland_project_write_xml_element(project,"OTHERFILES","");
1179
1180         /* write the end of the node LINKER */
1181         borland_project_end_xml_node(project,"LINKER");
1182
1183         /* write the begin of the node FILELIST */
1184         borland_project_begin_xml_node(project,"FILELIST");
1185         
1186         /* construct and write the list of file elements */
1187         
1188         /* add the bpf file to the list */
1189         borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1190         xbt_free(main_source);
1191         
1192         /* FIXME : check the source file directory */
1193         /* add the generated source file to the list */
1194         
1195         file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1196         sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1197         borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1198
1199         memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1200         sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1201         borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1202
1203         xbt_free(file_name);
1204
1205         /* FIXME : check the libraries directory */
1206         /* add the simgrid library to the list */
1207         
1208         if(is_rl){
1209                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1210                 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1211                 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1212         }else
1213         {
1214                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1215                 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1216                 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1217         }
1218         
1219         
1220         xbt_free(file_name);
1221
1222         /* write the end of the node FILELIST */
1223         borland_project_end_xml_node(project,"FILELIST");
1224         
1225         /* write the begin of the node BUILDTOOLS (not used)*/
1226         borland_project_begin_xml_node(project,"BUILDTOOLS");
1227         
1228         /* write the end of the node BUILDTOOLS (not used)*/
1229         borland_project_end_xml_node(project,"BUILDTOOLS");
1230         
1231         /* write the begin of the node IDEOPTIONS */
1232         borland_project_begin_xml_node(project,"IDEOPTIONS");
1233         
1234         /* write all of the option of the IDE of Borland C++ Builder */
1235         borland_project_write_ide_options(project);
1236         
1237         /* write the end of the node IDEOPTIONS */
1238         borland_project_end_xml_node(project,"IDEOPTIONS");
1239
1240     /* write the end of the node PROJECT */
1241         borland_project_end_xml_node(project,"PROJECT");
1242
1243     /* close the borland project file */
1244     borland_project_close(project);
1245 }
1246
1247 void
1248 borland_project_write_tabs(borland_project_t project,unsigned int count)
1249 {
1250         unsigned int pos;
1251         
1252         for(pos = 0; pos < count; pos++)
1253                 fprintf(project->stream,"\t");          
1254 }
1255
1256 void
1257 borland_project_begin_xml_node(borland_project_t project, const char* name)
1258 {
1259         if(level)
1260                 borland_project_write_tabs(project,level);
1261                 
1262         fprintf(project->stream,"<%s>\n",name);
1263         
1264         level++;
1265 }
1266
1267 void
1268 borland_project_end_xml_node(borland_project_t project, const char* name)
1269 {
1270         level--;
1271         
1272         if(level)
1273                 borland_project_write_tabs(project,level);
1274         
1275         fprintf(project->stream,"</%s>\n",name);        
1276 }
1277
1278
1279 void
1280 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1281 {
1282         borland_project_write_tabs(project,level);
1283         fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1284 }
1285
1286 void
1287 borland_project_write_xml_header(borland_project_t project)
1288 {
1289     fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1290 }
1291
1292 void
1293 borland_project_create_main_file(const char* name)
1294 {
1295         FILE* stream = fopen(name,"w+");
1296
1297         fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit Ãªtre traité comme le fichier projet\n\n\nmain\n");
1298
1299         fclose(stream);
1300 }
1301
1302 void
1303 borland_project_create(borland_project_t project)
1304 {
1305     char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1306     sprintf(file_name,"%s.bpr",project->name);
1307     project->stream = fopen(file_name,"w+");
1308     xbt_free(file_name);
1309 }
1310
1311 void
1312 borland_project_write_xml_comment(borland_project_t project)
1313 {
1314     fprintf(project->stream,"<!-- %s -->\n",project->comment);
1315 }
1316 void
1317 borland_project_write_file_element(     borland_project_t project,
1318                                                                         const char* file_name,
1319                                                                         const char* form_name,
1320                                                                         const char* unit_name,
1321                                                                         const char* container_id,
1322                                                                         const char* design_class,
1323                                                                         const char* local_command)
1324 {
1325         borland_project_write_tabs(project,level);
1326
1327         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);
1328 }
1329
1330 void
1331 borland_project_write_ide_options(borland_project_t project)
1332 {
1333
1334         const char* ide_options =
1335         "[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"  \
1336         "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1337         "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1338         "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1339         "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1340         "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1341         "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1342         "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1343         "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1344         "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1345         "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1346         "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1347         "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1348         "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1349         "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1350
1351         fprintf(project->stream,ide_options);
1352 }
1353
1354 void
1355 borland_project_close(borland_project_t project)
1356 {
1357     fclose(project->stream);
1358 }
1359
1360 void
1361 generate_borland_simulation_project(const char* name)
1362 {
1363     char buffer[MAX_PATH] = {0};
1364
1365     HANDLE hDir;
1366     WIN32_FIND_DATA wfd = {0};
1367
1368     s_borland_project_t borland_project = {0};
1369     borland_project.xml_version = "1.0";
1370     borland_project.encoding ="utf-8";
1371     borland_project.comment ="C++Builder XML Project";
1372     borland_project.version = "BCB.06.00";
1373
1374     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1375
1376     
1377     GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1378                 
1379
1380     GetCurrentDirectory(MAX_PATH,buffer);
1381
1382     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1383
1384     strcpy(borland_project.src_dir,buffer);
1385
1386     borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1387     sprintf(borland_project.name,"%s_simulator",name);
1388
1389     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1390     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1391
1392     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1393
1394     if(!hDir)
1395         CreateDirectory(borland_project.bin_dir,NULL);
1396
1397     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1398     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1399
1400     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1401
1402     if(INVALID_HANDLE_VALUE == hDir)
1403         CreateDirectory(borland_project.obj_dir,NULL);
1404
1405     generate_borland_project(&borland_project,0,name);
1406
1407     xbt_free(borland_project.name);
1408     xbt_free(borland_project.src_dir);
1409     xbt_free(borland_project.bin_dir);
1410     xbt_free(borland_project.obj_dir);
1411     xbt_free(borland_project.lib_dir);
1412 }
1413
1414 void
1415 generate_borland_real_life_project(const char* name)
1416 {
1417     HANDLE hDir;
1418     WIN32_FIND_DATA wfd = {0};
1419     char buffer[MAX_PATH] = {0};
1420     xbt_dict_cursor_t cursor = NULL;
1421     char *key = NULL;
1422     void *data = NULL;
1423         s_borland_project_t borland_project = {0};
1424
1425         borland_project.xml_version = "1.0";
1426     borland_project.encoding ="utf-8";
1427     borland_project.comment ="C++Builder XML Project";
1428     borland_project.version = "BCB.06.00";
1429     borland_project.lib_dir = " ";
1430
1431     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1432
1433     GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1434        
1435     GetCurrentDirectory(MAX_PATH,buffer);
1436
1437     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1438
1439     strcpy(borland_project.src_dir,buffer);
1440
1441     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1442     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1443
1444     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1445
1446     if(INVALID_HANDLE_VALUE == hDir)
1447         CreateDirectory(borland_project.bin_dir,NULL);
1448
1449     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1450     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1451
1452     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1453
1454     if(!hDir)
1455         CreateDirectory(borland_project.obj_dir,NULL);
1456
1457
1458         xbt_dict_foreach(process_function_set,cursor,key,data) {
1459         borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1460
1461         sprintf(borland_project.name,"%s_%s",name,key);
1462
1463         generate_borland_project(&borland_project,1,name);
1464         xbt_free(borland_project.name);
1465     }
1466
1467     xbt_free(borland_project.src_dir);
1468     xbt_free(borland_project.bin_dir);
1469     xbt_free(borland_project.obj_dir);
1470     xbt_free(borland_project.lib_dir);
1471 }
1472 int
1473 find_file_path(const char* root_dir,const char* file_name,char* path)
1474 {
1475         HANDLE hFind;
1476         WIN32_FIND_DATA wfd;
1477         char* prev_dir = xbt_new(char,MAX_PATH);
1478         GetCurrentDirectory(MAX_PATH,prev_dir);
1479         SetCurrentDirectory(root_dir);
1480         
1481         // begining of the scan
1482         hFind=FindFirstFile ("*.*", &wfd);
1483         
1484         if(hFind!=INVALID_HANDLE_VALUE){
1485         
1486                 /* it's a file */
1487                 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1488                 
1489                         if(!strcmp(file_name,wfd.cFileName)){
1490                                 GetCurrentDirectory(MAX_PATH,path);
1491                                 SetCurrentDirectory(prev_dir);
1492                                 xbt_free(prev_dir);
1493                                 FindClose(hFind);
1494                                 return 1;
1495                         }
1496                 
1497                 }
1498                 /* it's a directory, scan it*/
1499                 else {
1500                 
1501                         if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1502                                 if(find_file_path(wfd.cFileName,file_name,path)){
1503                                         FindClose(hFind);
1504                                         SetCurrentDirectory(prev_dir);
1505                                         return 1;
1506                                 }
1507                         }
1508                 }
1509                 
1510                 /* next file or directory */
1511                 while(FindNextFile(hFind,&wfd))
1512                 {
1513                         /* it's a file */
1514                         if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1515                         {
1516                                 if(!strcmp(file_name,wfd.cFileName)){
1517                                         GetCurrentDirectory(MAX_PATH,path);
1518                                         SetCurrentDirectory(prev_dir);
1519                                         xbt_free(prev_dir);
1520                                         FindClose(hFind);
1521                                         return 1;
1522                                 }
1523                         }
1524                         /* it's a file scan it */
1525                         else {
1526                 
1527                                 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1528                 
1529                                         if(find_file_path(wfd.cFileName,file_name,path)){
1530                                                 SetCurrentDirectory(prev_dir);
1531                                                 FindClose(hFind);
1532                                                 return 1;
1533                                         }
1534                 
1535                                 }
1536                 
1537                         }
1538                 }
1539         }
1540         
1541         SetCurrentDirectory(prev_dir);
1542         xbt_free(prev_dir);
1543         FindClose (hFind);
1544         return 0;
1545 }
1546
1547 /* Implementation of the functions used to create a Visual C++ project.*/
1548
1549 int
1550 generate_simulation_dsp_file(const char* name)
1551 {
1552         char buffer[MAX_PATH] = {0};
1553     s_dsp_t dsp = {0};
1554     dsp.lib_dir = xbt_new0(char,MAX_PATH);
1555
1556     GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1557     GetCurrentDirectory(MAX_PATH,buffer);
1558
1559     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1560     strcpy(dsp.src_dir,buffer);
1561         dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1562         sprintf(dsp.name,"%s_simulator",name);
1563
1564     generate_dsp_project(&dsp,0,name);
1565
1566     xbt_free(dsp.name);
1567     xbt_free(dsp.src_dir);
1568         xbt_free(dsp.lib_dir);
1569     
1570     return 0;           
1571 }
1572
1573 /*
1574  * Create the Microsoft visual C++ real life project file.
1575  */
1576 int
1577 generate_real_live_dsp_file(const char* name)
1578 {
1579         
1580     char buffer[MAX_PATH] = {0};
1581     xbt_dict_cursor_t cursor = NULL;
1582     char *key = NULL;
1583     void *data = NULL;
1584         s_dsp_t dsp = {0};
1585
1586         
1587     dsp.lib_dir = xbt_new0(char,MAX_PATH);
1588
1589     GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1590        
1591     GetCurrentDirectory(MAX_PATH,buffer);
1592
1593     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1594
1595     strcpy(dsp.src_dir,buffer);
1596
1597
1598         xbt_dict_foreach(process_function_set,cursor,key,data) {
1599         dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1600
1601         sprintf(dsp.name,"%s_%s",name,key);
1602
1603         generate_dsp_project(&dsp,1,name);
1604         xbt_free(dsp.name);
1605     }
1606
1607     xbt_free(dsp.src_dir);
1608     xbt_free(dsp.lib_dir);
1609         return 0;
1610 }
1611
1612 void
1613 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1614 {
1615         /* create the visual C++ project file */
1616         char* buffer;
1617         char* file_name = xbt_new0(char,strlen(project->name) + 5);
1618     sprintf(file_name,"%s.dsp",project->name);
1619     project->stream = fopen(file_name,"w+");
1620     xbt_free(file_name);
1621     
1622     if(!__gras_path)
1623         {
1624         buffer =xbt_new0(char,MAX_PATH);
1625         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1626         
1627                 __gras_path = xbt_new0(char,MAX_PATH);
1628                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1629                 free(buffer);
1630     }
1631     
1632     /* dsp file header */
1633     fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1634         fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1635         fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1636         
1637         /* target type is a win32 x86 console application */
1638         fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1639         
1640         /* the current config is win32-debug */
1641         fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1642         
1643         /* warning */
1644         fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1645         
1646         /* NMAKE usage */
1647         fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1648         fprintf(project->stream,"!MESSAGE\n");
1649         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1650         fprintf(project->stream,"!MESSAGE\n");
1651         fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1652         fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1653         fprintf(project->stream,"!MESSAGE\n"); 
1654         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1655         fprintf(project->stream,"!MESSAGE\n");
1656         fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1657         fprintf(project->stream,"!MESSAGE\n"); 
1658         fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1659         fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1660         fprintf(project->stream,"!MESSAGE\n\n"); 
1661         
1662         fprintf(project->stream,"# Begin Project\n\n");
1663         fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1664         fprintf(project->stream,"# PROP Scc_ProjName\n");
1665         fprintf(project->stream,"# PROP Scc_LocalPath\n");
1666         fprintf(project->stream,"CPP=cl.exe\n");
1667         fprintf(project->stream,"RSC=rc.exe\n\n");
1668         
1669         fprintf(project->stream,"!IF  \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1670         
1671         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1672         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1673         fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1674         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1675         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1676         fprintf(project->stream,"# PROP Use_MFC 0\n");
1677         fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1678         fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1679         fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1680         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1681         /* TODO : the include directory */
1682         /*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);*/
1683         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);
1684         fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1685         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1686         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1687         fprintf(project->stream,"BSC32=bscmake.exe\n");
1688         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1689         fprintf(project->stream,"# ADD BSC32 /nologo\n");
1690         fprintf(project->stream,"LINK32=link.exe\n");
1691         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");
1692         
1693         if(is_rl)
1694                 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");
1695         else
1696                 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");
1697                         
1698         fprintf(project->stream,"!ELSEIF  \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1699
1700         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1701         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1702         fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1703         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1704         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1705         fprintf(project->stream,"# PROP Use_MFC 0\n");
1706         fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1707         fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1708         fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1709         fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1710         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1711         /* TODO : the include directory */
1712         /*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);*/
1713         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);
1714         fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n");
1715         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1716         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1717         fprintf(project->stream,"BSC32=bscmake.exe\n");
1718         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1719         fprintf(project->stream,"# ADD BSC32 /nologo\n");
1720         fprintf(project->stream,"LINK32=link.exe\n");
1721         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");
1722         
1723         if(is_rl)
1724                 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");
1725         else
1726                 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");
1727                         
1728         fprintf(project->stream,"!ENDIF\n\n");
1729         
1730         fprintf(project->stream,"# Begin Target\n\n");
1731         fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1732         fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1733         fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1734         fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1735         
1736         fprintf(project->stream,"# Begin Source File\n");
1737         fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1738         fprintf(project->stream,"# End Source File\n\n");
1739         
1740         fprintf(project->stream,"# Begin Source File\n");
1741         fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1742         fprintf(project->stream,"# End Source File\n\n");
1743         
1744         fprintf(project->stream,"# End Group\n");
1745         fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1746         fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1747         fprintf(project->stream,"# End Group\n");
1748         fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1749         fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1750         fprintf(project->stream,"# End Group\n");
1751         fprintf(project->stream,"# End Target\n");
1752         fprintf(project->stream,"# End Project\n");
1753         
1754 }
1755
1756 #endif
1757
1758
1759
1760
1761