Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Keep working during the SIMIX convertion
[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 #else           
436         "  MSG_paje_output(\"%s.trace\");\n" 
437         "  MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n" 
438         "  MSG_create_environment(argv[1]);\n"
439 #endif          
440         "\n" 
441         "  /*  Application deployment */\n",
442         project);
443         xbt_dict_foreach(process_function_set,cursor,key,data) {
444 #ifdef USE_SIMIX           
445                 fprintf(OUT,"  gras_function_register(\"%s\", launch_%s);\n",key,key);
446 #else
447                 fprintf(OUT,"  MSG_function_register(\"%s\", launch_%s);\n",key,key);
448 #endif
449         }
450         fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
451         fclose(OUT);
452         free(filename);
453 }
454
455 /**********************************************/
456 /**** Generate the file for the real life *****/
457 /**********************************************/
458 static void generate_rl(char *project)
459 {
460   xbt_dict_cursor_t cursor=NULL;
461   char *key = NULL;
462   void *data = NULL;
463   char *filename = NULL;
464   FILE *OUT = NULL;
465
466   xbt_dict_foreach(process_function_set,cursor,key,data) {
467     filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
468
469         sprintf(filename,RL_SOURCENAME,project,key);
470
471     OUT=fopen(filename,"w");
472     xbt_assert1(OUT, "Unable to open %s for writing",filename);
473
474     fprintf(OUT, "\n%s\n",warning);
475     fprintf(OUT, "/* specific to Borland Compiler */\n" \
476                  "#ifdef __BORLANDC__\n" \
477                  "#pragma hdrstop\n" \
478                  "#endif\n\n" \
479                  "#include <stdio.h>\n" \
480                  "#include <signal.h>\n" \
481                  "#include <gras.h>\n" \
482                  "\n" \
483                  "extern const char * XBT_PUBLIC_DATA _gras_procname;\n" \
484                  "/* user code */\n" \
485                  "int %s(int argc, char *argv[]);\n" \
486                  "\n" \
487                  "/* specific to Borland Compiler */\n" \
488                 "#ifdef __BORLANDC__\n" \
489                 "#pragma argsused\n" \
490                 "#endif\n\n" \
491                  "int main(int argc, char *argv[]){\n" \
492                  "  int errcode;\n" \
493                  "\n" \
494                  "  _gras_procname = \"%s\";\n" \
495                  "  errcode=%s(argc,argv);\n"\
496                  " \n" \
497                  "  return errcode;\n"\
498                  "}\n",
499             key,key,key);
500     fprintf(OUT, "\n%s\n",warning);
501     fclose(OUT);
502     free(filename);
503   }
504 }
505
506 static void generate_makefile_am(char *project, char *deployment)
507 {
508   xbt_dict_cursor_t cursor=NULL;
509   char *key = NULL;
510   void *data = NULL;
511   char *filename = NULL;
512   FILE *OUT = NULL;
513
514   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
515   sprintf(filename,MAKEFILE_FILENAME_AM, project);
516
517   OUT=fopen(filename,"w");
518   xbt_assert1(OUT, "Unable to open %s for writing",filename);
519
520   fprintf(OUT, "# AUTOMAKE variable definition\n");
521   fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
522   fprintf(OUT, "PROGRAMS=");
523   fprintf(OUT, SIM_BINARYNAME,project);
524
525   xbt_dict_foreach(process_function_set,cursor,key,data) {
526     fprintf(OUT, " ");
527     fprintf(OUT, RL_BINARYNAME, project, key);
528   }
529
530   fprintf(OUT, "\n\n");
531   fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
532   fprintf(OUT, "=\t");
533   fprintf(OUT, SIM_SOURCENAME,project);
534   fprintf(OUT, " %s.c\n", project);
535   fprintf(OUT, SIM_SOURCENAME_LDADD, project);
536   fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
537
538   xbt_dict_foreach(process_function_set,cursor,key,data) {
539     fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
540     fprintf(OUT, "=\t");
541     fprintf(OUT, RL_SOURCENAME, project,key);
542     fprintf(OUT, " %s.c\n", project);
543     fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
544     fprintf(OUT, "=\tpath/to/libgras.a\n\n");
545   }
546
547   fprintf(OUT, "\n# cleanup temps\n");
548   fprintf(OUT, "CLEANFILES= ");
549   fprintf(OUT, SIM_SOURCENAME, project);
550   
551   xbt_dict_foreach(process_function_set,cursor,key,data) {
552     fprintf(OUT, " ");
553     fprintf(OUT, RL_SOURCENAME, project,key);
554   }
555   fprintf(OUT, "\n");
556
557   fprintf(OUT, "\n# generate temps\n");
558   fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
559
560   xbt_dict_foreach(process_function_set,cursor,key,data) {
561     fprintf(OUT, RL_SOURCENAME, project,key);
562     fprintf(OUT, " ");
563   }
564   fprintf(OUT, SIM_SOURCENAME, project);
565   fprintf(OUT, ": %s\n", deployment);
566   fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
567   fclose(OUT);
568 }
569
570 static void generate_makefile_local(char *project, char *deployment)
571 {
572   xbt_dict_cursor_t cursor=NULL;
573   char *key = NULL;
574   void *data = NULL;
575   char *filename = NULL;
576   FILE *OUT = NULL;
577
578   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
579   sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
580   
581   OUT=fopen(filename,"w");
582   xbt_assert1(OUT, "Unable to open %s for writing",filename);
583   free(filename);
584    
585   fprintf(OUT,
586           "\n"
587           "####\n"
588           "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
589           "####\n\n\n");
590
591   fprintf(OUT,"## Variable declarations\n"
592               "PROJECT_NAME=%s\n"
593               "DISTDIR=gras-$(PROJECT_NAME)\n\n"
594           ,project);
595    
596   fprintf(OUT,
597           "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
598           "# Compilation will fail if you don't do so\n" 
599           "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
600           "# You can fiddle the following to make it fit your taste\n"
601           "INCLUDES = -I$(GRAS_ROOT)/include\n"
602           "CFLAGS ?= -O3 -w -g\n"
603           "LIBS_SIM = -lm  -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
604           "LIBS_RL = -lm  -L$(GRAS_ROOT)/lib/ -lgras\n"
605           "LIBS = \n"
606           "\n");
607
608   fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
609
610   fprintf(OUT, "GENERATED_C_FILES = ");
611   fprintf(OUT, SIM_SOURCENAME" ",project);
612   xbt_dict_foreach(process_function_set,cursor,key,data) {
613     fprintf(OUT, RL_SOURCENAME " ",project, key);
614   }
615   fprintf(OUT, "\n");
616
617   fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
618
619   fprintf(OUT, "BIN_FILES = ");
620
621   fprintf(OUT, SIM_BINARYNAME " ",project);
622   xbt_dict_foreach(process_function_set,cursor,key,data) {
623     fprintf(OUT, RL_BINARYNAME " ", project, key);
624   }
625   fprintf(OUT, "\n");
626
627   fprintf(OUT,
628           "\n"
629           "## By default, build all the binaries\n"
630           "all: $(BIN_FILES)\n"
631           "\n");
632    
633   fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
634   xbt_dict_foreach(process_function_set,cursor,key,data) {
635     fprintf(OUT, RL_SOURCENAME, project,key);
636     fprintf(OUT, " ");
637   }
638   fprintf(OUT, SIM_SOURCENAME, project);
639   fprintf(OUT, ": %s\n", deployment);
640   fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
641
642   fprintf(OUT, "\n## Generate the binaries\n");
643   fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
644   fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
645   xbt_dict_foreach(process_function_set,cursor,key,data) {
646     fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
647     fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
648   }  
649   fprintf(OUT, 
650           "\n"
651           "%%: %%.o\n"
652           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
653           "\n"
654           "%%.o: %%.c\n"
655           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
656           "\n");
657    
658   fprintf(OUT,
659           "## Rules for tarballs and cleaning\n"
660           "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
661           "distdir: $(DIST_FILES)\n"
662           "\trm -rf $(DISTDIR)\n"
663           "\tmkdir -p $(DISTDIR)\n"
664           "\tcp $^ $(DISTDIR)\n"
665           "\n"
666           "dist: clean distdir\n"
667           "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
668           "\n", project /*, project*/);
669
670   fprintf(OUT,
671           "clean:\n"
672           "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
673   xbt_dict_foreach(process_function_set,cursor,key,data) {
674      fprintf(OUT, " " RL_OBJNAME, project, key);
675   }
676   fprintf(OUT,   
677           "\n"
678           "\trm -rf $(DISTDIR)\n"
679           "\n"
680           ".SUFFIXES:\n"
681           ".PHONY : clean\n"
682           "\n");
683   /* 
684   fprintf(OUT, "############ REMOTE COMPILING #########\n");
685   fprintf(OUT, 
686           "MACHINES ?= ");
687   xbt_dict_foreach(machine_set,cursor,key,data) {
688     fprintf(OUT, "%s ",key);
689   }
690   fprintf(OUT,"\n");
691
692   fprintf(OUT, 
693           "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
694           "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
695           "SRCDIR ?= ./\n"
696           "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
697           "SIMGRID_VERSION ?=2.92\n"
698           "GRAS_PROJECT ?= %s\n"
699           "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
700           "\n"
701           "remote:\n"
702           "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
703           "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
704           "\t for site in $(MACHINES) ; do \\\n"
705           "\t   machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
706           "\t   machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
707           "\t   cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
708           "\t                        SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
709           "\t                        GRAS_PROJECT_URL=$(GRAS_PROJECT_URL)  mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
710           "\t   cmd_make=\"\\\"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)  make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
713           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
714           "\t     echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
715           "\t   else \\\n"
716           "\t     machine=$$site;\\\n"
717           "\t     echo \"----[ Compile on $$machine ]----\";\\\n"
718           "\t   fi;\\\n"
719           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
720           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
721           "\t     then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
722           "\t   else \\\n"
723           "\t     if ssh $$machine \"eval $$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   fi;\\\n"
726           "\t   echo \"-- Copy the data over\"; \\\n"
727           "\t   scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
728           "\t   echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
729           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
730           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
731           "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
732           "\t   else \\\n"
733           "\t     if ssh $$machine \"eval $$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   fi;\\\n"
736           "\t done;\n",project,project,project);
737 */
738   fclose(OUT);
739 }
740
741 static void generate_makefile_remote(char *project, char *deployment)
742 {
743   char *filename = NULL;
744   FILE *OUT = NULL;
745
746   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
747   sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
748   
749   OUT=fopen(filename,"w");
750   xbt_assert1(OUT, "Unable to open %s for writing",filename);
751
752   fprintf(OUT, 
753           "INSTALL_PATH ?= $(shell pwd)\n"
754           "\n"
755           "compile-simgrid:\n"
756           "\tcd $$GRAS_ROOT ; \\\n"
757           "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
758           "\techo $$retrieved; \\\n"
759           "\tif test \"x$$retrieved\" = x; then \\\n"
760           "\t  tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
761           "\t  cd simgrid-$(SIMGRID_VERSION)/; \\\n"
762           "\t  ./configure --prefix=$$GRAS_ROOT ; \\\n"
763           "\t  make all install ;\\\n"
764            "\tfi\n"
765           "\n"
766           "compile-gras: compile-simgrid\n"
767           "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
768           "\techo $$not_retrieved; \\\n"
769           "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
770           "\t  tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
771           "\t  make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
772           "\tfi\n"
773           "\n"
774           "clean-simgrid:\n"
775           "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
776           "clean-gras clean-gras-$(GRAS_PROJECT):\n"
777           "\trm -rf gras-$(GRAS_PROJECT)*\n"
778           "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
779           "\n"
780           ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
781           "        compile-simgrid compile-gras\n"
782           );
783   fclose(OUT);
784 }
785
786
787 static void generate_deployment(char *project, char *deployment)
788 {
789   xbt_dict_cursor_t cursor=NULL;
790   char *key = NULL;
791   void *data = NULL;
792   char *filename = NULL;
793   FILE *OUT = NULL;
794
795   int cpt,i;
796   s_process_t proc;
797
798   filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
799   sprintf(filename,DEPLOYMENT, project);
800   
801   OUT=fopen(filename,"w");
802   xbt_assert1(OUT, "Unable to open %s for writing",filename);
803
804   fprintf(OUT, "#!/bin/sh\n");
805   fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
806   fprintf(OUT,
807           "if test \"${MACHINES+set}\" != set; then \n"
808           "    export MACHINES='");
809   xbt_dict_foreach(machine_set,cursor,key,data) {
810     fprintf(OUT, "%s ",key);
811   }
812   fprintf(OUT,  
813           "';\n"
814           "fi\n"
815           "if test \"${INSTALL_PATH+set}\" != set; then \n"
816           "    export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
817           "fi\n"
818           "if test \"${GRAS_ROOT+set}\" != set; then \n"
819           "    export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
820           "fi\n"
821           "if test \"${SRCDIR+set}\" != set; then \n"
822           "    export SRCDIR=./\n"
823           "fi\n"
824           "if test \"${SIMGRID_URL+set}\" != set; then \n"
825           "    export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
826           "fi\n"
827           "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
828           "    export SIMGRID_VERSION=2.91\n"
829           "fi\n"
830           "if test \"${GRAS_PROJECT+set}\" != set; then \n"
831           "    export GRAS_PROJECT=%s\n"
832           "fi\n"
833           "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
834           "    export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
835           "fi\n"
836           "\n"
837           "test -e runlogs/ || mkdir -p runlogs/\n",
838           project);
839
840   fprintf(OUT,  
841           "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
842           "                 SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
843           "                 GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
844
845   xbt_dynar_foreach (process_list,cpt,proc) {
846     fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
847     for(i=1;i<proc.argc;i++) {
848       fprintf(OUT,"%s ",proc.argv[i]);
849     }
850     fprintf(OUT,"\";\n");
851     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);
852   }
853
854   fclose(OUT);
855 }
856
857 static void print(void *p)
858 {
859   printf("%p",p);
860 }
861
862
863 #ifdef _WIN32
864 #include <windows.h>
865 #endif
866
867 /* specific to Borland Compiler */
868 #ifdef __BORLANDDC__
869 #pragma argsused
870 #endif
871
872 int main(int argc, char *argv[])
873 {
874   char *project_name = NULL;
875   char *deployment_file = NULL;
876   int i;
877    
878   surf_init(&argc, argv);
879
880   xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
881
882   project_name = argv[1];
883
884   process_function_set = xbt_dict_new();
885   process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
886   machine_set = xbt_dict_new();
887
888   STag_surfxml_process_fun = parse_process_init;
889   ETag_surfxml_argument_fun = parse_argument;
890   ETag_surfxml_process_fun = parse_process_finalize;
891   
892   for(i=2; i<argc; i++) {
893      deployment_file = argv[i];
894      surf_parse_open(deployment_file);
895      if(surf_parse()) 
896         xbt_assert1(0,"Parse error in %s",deployment_file);
897      
898      surf_parse_close();
899   }
900
901
902   warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
903   sprintf(warning,WARN,deployment_file);
904
905   /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
906     xbt_dict_cursor_t cursor=NULL;
907     char *key = NULL;
908     void *data = NULL;
909
910     for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
911          xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
912          xbt_dict_cursor_step(cursor) ) {
913       DEBUG1("Function %s", key);      
914     }
915     
916     xbt_dict_dump(process_function_set,print);
917   }*/
918
919   generate_sim(project_name);
920   generate_rl(project_name);
921   generate_makefile_local(project_name, deployment_file);
922   #ifdef _WIN32
923   generate_borland_simulation_project(project_name);
924   generate_borland_real_life_project(project_name);
925   generate_simulation_dsp_file(project_name);
926   generate_real_live_dsp_file(project_name);
927
928   if(__gras_path)
929     xbt_free(__gras_path);
930   
931
932   #endif
933 //  generate_makefile_remote(project_name, deployment_file);
934 //  generate_deployment(project_name, deployment_file);
935
936   free(warning);
937   surf_exit();
938   return 0;
939 }
940 #ifdef _WIN32
941 void
942 generate_borland_project(borland_project_t project,int is_rl,const char* name)
943 {
944         char* binary_path;      /* the path of the generated binary file                                */
945         char* obj_path;         /* the path of the generated object file                                */
946         char* lib_files;        /* a list of the libraries used in the borland project  */
947         char* main_source;      /* the name of the bpf file used by the borland project */
948         char* file_name;        /* the file name of the main source file                                */
949     char* include_path; /* the include path                                     */
950         char* buffer;
951
952     /* create the borland project file */
953     borland_project_create(project);
954
955     /* write the xml document header */
956     borland_project_write_xml_header(project);
957
958     /* write the xml comment to identify a borland project file */
959     borland_project_write_xml_comment(project);
960         
961         /* write the begin of the node PROJECT */
962         borland_project_begin_xml_node(project,"PROJECT");
963         
964         /* write the begin of node MACROS */
965         borland_project_begin_xml_node(project,"MACROS");
966         
967         /* write the borland project version */
968         borland_project_write_xml_element(project,"VERSION",project->version);
969         
970         /* construct and write the borland project binary path */
971         binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
972         sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
973         borland_project_write_xml_element(project,"PROJECT",binary_path);
974         xbt_free(binary_path);
975         
976         /* construct an write the object files to generate by the compiler */
977         obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
978         sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
979         borland_project_write_xml_element(project,"OBJFILES",obj_path);
980         xbt_free(obj_path);
981         
982         /* write the resource files used by the compiler (no resource file used) */
983         borland_project_write_xml_element(project,"RESFILES","");
984         
985         /* write the IDL files of the project (no IDL files used) */
986         borland_project_write_xml_element(project,"IDLFILES","");
987         
988         /* write the IDLGENFILES element (not used) */
989         borland_project_write_xml_element(project,"IDLGENFILES","");
990         
991         /* write the DEFFILE element (not used) */
992         borland_project_write_xml_element(project,"DEFFILE","");
993         
994         /* write the RESDEPEN element (not used, no resource file used) */
995         borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
996
997         /* construct and write the list of libraries used by the project */
998         /*
999     lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
1000         sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
1001     */
1002         
1003         if(is_rl){
1004                 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
1005                 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);  
1006         }else{
1007         lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
1008                 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
1009         }
1010
1011         borland_project_write_xml_element(project,"LIBFILES",lib_files);
1012         xbt_free(lib_files);
1013         
1014         /* write the SPARELIBS element (not used) */
1015         borland_project_write_xml_element(project,"SPARELIBS","");
1016         
1017         /* write the PACKAGES element (no package used) */
1018         borland_project_write_xml_element(project,"PACKAGES","");
1019         
1020         /* write the PATHCPP element (the path of the source files of the project)*/
1021         borland_project_write_xml_element(project,"PATHCPP",".;");
1022         
1023         /* write the PATHPAS element (not used) */
1024         borland_project_write_xml_element(project,"PATHPAS","");
1025         
1026         /* write the PATHRC element (not used) */
1027         borland_project_write_xml_element(project,"PATHRC","");
1028         
1029         /* write the PATHASM element (not used) */
1030         borland_project_write_xml_element(project,"PATHASM","");
1031         
1032         /* write the DEBUGLIBPATH element (the path for debug) */
1033         borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
1034         
1035         /* write the RELEASELIBPATH element (the path for release) */
1036         borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
1037         
1038         /* specify the linker to use */
1039         borland_project_write_xml_element(project,"LINKER","ilink32");
1040         
1041         /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
1042         borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
1043         
1044         /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
1045         borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
1046
1047         /* construct and write the MAINSOURCE element */
1048         main_source = xbt_new0(char,strlen(project->name) + 5);
1049         sprintf(main_source,"%s.bpf",project->name);
1050     /* write the main source file to use in the borland project file */
1051         borland_project_write_xml_element(project,"MAINSOURCE",main_source);
1052
1053         /* create the bpf file used by the borland project */
1054         borland_project_create_main_file(main_source);
1055
1056         /* FIXME resolve the include path */
1057         /* write the INCLUDEPATH element  */
1058
1059     if(!__gras_path){
1060         buffer =xbt_new0(char,MAX_PATH);
1061         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1062         
1063                 __gras_path = xbt_new0(char,MAX_PATH);
1064                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1065                 free(buffer);
1066
1067         /*find_file_path("C:\\","gras.h",__gras_path);*/
1068     }
1069
1070     include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1071     sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1072
1073         borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1074
1075     xbt_free(include_path);
1076
1077         /* write the LIBPATH element (no librarie paths specified)*/
1078         borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1079
1080         /*
1081      * write the WARNINGS element :
1082      *  -w-sus (-w-8075) disabled the suspect conversion pointer warning
1083      *  -w-rvl (-w-8070) disabled the function must return warning
1084      *  -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1085      *  -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1086      *  -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1087      *  -w-par (-w-8057) disabled the warning that detect an unused variable
1088      *  -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1089      *  -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1090      *  -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1091      */
1092         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");
1093
1094         /* write the OTHERFILES element (no other files used used) */
1095         borland_project_write_xml_element(project,"OTHERFILES","");
1096
1097         /* write the end of the node MACROS */
1098         borland_project_end_xml_node(project,"MACROS");
1099
1100         /* write the begin of the node OPTIONS */
1101         borland_project_begin_xml_node(project,"OPTIONS");
1102
1103         /* FIXME check the idlcflags */
1104         /* write the IDLCFLAGS element */
1105         borland_project_write_xml_element(project,"IDLCFLAGS","");
1106
1107         /*
1108      * write the CFLAG1 element (compiler options ) :
1109      *
1110      *  -Od     this flag disable all compiler optimisation
1111      *  -H      this flag specify the name of the file which will contain the precompiled header
1112      *  -Hc     this flag specify to the compiler to cach the precompiled header
1113      *  -Vx     this flag specify to the compiler to allow the empty structures
1114      *  -Ve     this flag specify to the compiler to allow the empty base classes
1115      *  -X-     this flag activate the auto-depend informations of the compiler
1116      *  -r-     this flag disabled the use of the processor register
1117      *  -a1     this flag specify that the data must be aligned on one byte
1118      *  -b-     this flag specify that the enums are the smallest size of the integer
1119      *  -k      (used during debug)
1120      *  -y      this flag generate the line number for debug
1121      *  -v      this flag enabled the debugging of the source files
1122      *  -vi     check the expansion of the inline functions
1123      *  -tWC    specify that it's a console application
1124      *  -tWM-   specify that the application is not multithread
1125      *  -c      generate the object file, no link
1126      */
1127         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");
1128
1129         /* write the PFLAGS element */
1130         borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1131
1132         /* write the RFLAGS element */
1133         borland_project_write_xml_element(project,"RFLAGS","");
1134
1135         /* write the AFLAGS element (assembler flags) :
1136      *
1137      *  /mx (not documented)
1138      *  /w2 (not documented)
1139      *  /zd (not documented)
1140      *
1141      */
1142         borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1143
1144         /* write the LFLAGS element (linker flags) :
1145      *
1146      *  -I      specify the output directory for object files
1147      *  -D      register the specified description (no description "")
1148      *  -ap     build a win32 console application
1149      *  -Tpe    generate a exe file
1150      *  -x      do not create the map file
1151      *  -Gn     do not generate the state file
1152      *  -v      include the complete debug informations  
1153      */
1154         borland_project_write_xml_element(project,"LFLAGS","-Iobj -D&quot;&quot; -ap -Tpe -x -Gn -v");
1155
1156         /* write the OTHERFILES element (not used)*/
1157         borland_project_write_xml_element(project,"OTHERFILES","");
1158
1159         /* write the end of the node OPTIONS */
1160         borland_project_end_xml_node(project,"OPTIONS");
1161
1162         /* write the begin of the node LINKER */
1163         borland_project_begin_xml_node(project,"LINKER");
1164
1165         /* write the ALLOBJ element */
1166         borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1167
1168         /* write the ALLRES element (not used) */
1169         borland_project_write_xml_element(project,"ALLRES","");
1170
1171         /* write the ALLLIB element */
1172         borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1173
1174         /* write the OTHERFILES element (not used) */
1175         borland_project_write_xml_element(project,"OTHERFILES","");
1176
1177         /* write the end of the node LINKER */
1178         borland_project_end_xml_node(project,"LINKER");
1179
1180         /* write the begin of the node FILELIST */
1181         borland_project_begin_xml_node(project,"FILELIST");
1182         
1183         /* construct and write the list of file elements */
1184         
1185         /* add the bpf file to the list */
1186         borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1187         xbt_free(main_source);
1188         
1189         /* FIXME : check the source file directory */
1190         /* add the generated source file to the list */
1191         
1192         file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1193         sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1194         borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1195
1196         memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1197         sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1198         borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1199
1200         xbt_free(file_name);
1201
1202         /* FIXME : check the libraries directory */
1203         /* add the simgrid library to the list */
1204         
1205         if(is_rl){
1206                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1207                 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1208                 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1209         }else
1210         {
1211                 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1212                 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1213                 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1214         }
1215         
1216         
1217         xbt_free(file_name);
1218
1219         /* write the end of the node FILELIST */
1220         borland_project_end_xml_node(project,"FILELIST");
1221         
1222         /* write the begin of the node BUILDTOOLS (not used)*/
1223         borland_project_begin_xml_node(project,"BUILDTOOLS");
1224         
1225         /* write the end of the node BUILDTOOLS (not used)*/
1226         borland_project_end_xml_node(project,"BUILDTOOLS");
1227         
1228         /* write the begin of the node IDEOPTIONS */
1229         borland_project_begin_xml_node(project,"IDEOPTIONS");
1230         
1231         /* write all of the option of the IDE of Borland C++ Builder */
1232         borland_project_write_ide_options(project);
1233         
1234         /* write the end of the node IDEOPTIONS */
1235         borland_project_end_xml_node(project,"IDEOPTIONS");
1236
1237     /* write the end of the node PROJECT */
1238         borland_project_end_xml_node(project,"PROJECT");
1239
1240     /* close the borland project file */
1241     borland_project_close(project);
1242 }
1243
1244 void
1245 borland_project_write_tabs(borland_project_t project,unsigned int count)
1246 {
1247         unsigned int pos;
1248         
1249         for(pos = 0; pos < count; pos++)
1250                 fprintf(project->stream,"\t");          
1251 }
1252
1253 void
1254 borland_project_begin_xml_node(borland_project_t project, const char* name)
1255 {
1256         if(level)
1257                 borland_project_write_tabs(project,level);
1258                 
1259         fprintf(project->stream,"<%s>\n",name);
1260         
1261         level++;
1262 }
1263
1264 void
1265 borland_project_end_xml_node(borland_project_t project, const char* name)
1266 {
1267         level--;
1268         
1269         if(level)
1270                 borland_project_write_tabs(project,level);
1271         
1272         fprintf(project->stream,"</%s>\n",name);        
1273 }
1274
1275
1276 void
1277 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1278 {
1279         borland_project_write_tabs(project,level);
1280         fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1281 }
1282
1283 void
1284 borland_project_write_xml_header(borland_project_t project)
1285 {
1286     fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1287 }
1288
1289 void
1290 borland_project_create_main_file(const char* name)
1291 {
1292         FILE* stream = fopen(name,"w+");
1293
1294         fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit Ãªtre traité comme le fichier projet\n\n\nmain\n");
1295
1296         fclose(stream);
1297 }
1298
1299 void
1300 borland_project_create(borland_project_t project)
1301 {
1302     char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1303     sprintf(file_name,"%s.bpr",project->name);
1304     project->stream = fopen(file_name,"w+");
1305     xbt_free(file_name);
1306 }
1307
1308 void
1309 borland_project_write_xml_comment(borland_project_t project)
1310 {
1311     fprintf(project->stream,"<!-- %s -->\n",project->comment);
1312 }
1313 void
1314 borland_project_write_file_element(     borland_project_t project,
1315                                                                         const char* file_name,
1316                                                                         const char* form_name,
1317                                                                         const char* unit_name,
1318                                                                         const char* container_id,
1319                                                                         const char* design_class,
1320                                                                         const char* local_command)
1321 {
1322         borland_project_write_tabs(project,level);
1323
1324         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);
1325 }
1326
1327 void
1328 borland_project_write_ide_options(borland_project_t project)
1329 {
1330
1331         const char* ide_options =
1332         "[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"  \
1333         "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1334         "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1335         "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1336         "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1337         "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1338         "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1339         "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1340         "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1341         "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1342         "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1343         "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1344         "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1345         "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1346         "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1347
1348         fprintf(project->stream,ide_options);
1349 }
1350
1351 void
1352 borland_project_close(borland_project_t project)
1353 {
1354     fclose(project->stream);
1355 }
1356
1357 void
1358 generate_borland_simulation_project(const char* name)
1359 {
1360     char buffer[MAX_PATH] = {0};
1361
1362     HANDLE hDir;
1363     WIN32_FIND_DATA wfd = {0};
1364
1365     s_borland_project_t borland_project = {0};
1366     borland_project.xml_version = "1.0";
1367     borland_project.encoding ="utf-8";
1368     borland_project.comment ="C++Builder XML Project";
1369     borland_project.version = "BCB.06.00";
1370
1371     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1372
1373     
1374     GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1375                 
1376
1377     GetCurrentDirectory(MAX_PATH,buffer);
1378
1379     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1380
1381     strcpy(borland_project.src_dir,buffer);
1382
1383     borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1384     sprintf(borland_project.name,"%s_simulator",name);
1385
1386     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1387     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1388
1389     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1390
1391     if(!hDir)
1392         CreateDirectory(borland_project.bin_dir,NULL);
1393
1394     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1395     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1396
1397     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1398
1399     if(INVALID_HANDLE_VALUE == hDir)
1400         CreateDirectory(borland_project.obj_dir,NULL);
1401
1402     generate_borland_project(&borland_project,0,name);
1403
1404     xbt_free(borland_project.name);
1405     xbt_free(borland_project.src_dir);
1406     xbt_free(borland_project.bin_dir);
1407     xbt_free(borland_project.obj_dir);
1408     xbt_free(borland_project.lib_dir);
1409 }
1410
1411 void
1412 generate_borland_real_life_project(const char* name)
1413 {
1414     HANDLE hDir;
1415     WIN32_FIND_DATA wfd = {0};
1416     char buffer[MAX_PATH] = {0};
1417     xbt_dict_cursor_t cursor = NULL;
1418     char *key = NULL;
1419     void *data = NULL;
1420         s_borland_project_t borland_project = {0};
1421
1422         borland_project.xml_version = "1.0";
1423     borland_project.encoding ="utf-8";
1424     borland_project.comment ="C++Builder XML Project";
1425     borland_project.version = "BCB.06.00";
1426     borland_project.lib_dir = " ";
1427
1428     borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1429
1430     GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1431        
1432     GetCurrentDirectory(MAX_PATH,buffer);
1433
1434     borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1435
1436     strcpy(borland_project.src_dir,buffer);
1437
1438     borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1439     sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1440
1441     hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1442
1443     if(INVALID_HANDLE_VALUE == hDir)
1444         CreateDirectory(borland_project.bin_dir,NULL);
1445
1446     borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1447     sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1448
1449     hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1450
1451     if(!hDir)
1452         CreateDirectory(borland_project.obj_dir,NULL);
1453
1454
1455         xbt_dict_foreach(process_function_set,cursor,key,data) {
1456         borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1457
1458         sprintf(borland_project.name,"%s_%s",name,key);
1459
1460         generate_borland_project(&borland_project,1,name);
1461         xbt_free(borland_project.name);
1462     }
1463
1464     xbt_free(borland_project.src_dir);
1465     xbt_free(borland_project.bin_dir);
1466     xbt_free(borland_project.obj_dir);
1467     xbt_free(borland_project.lib_dir);
1468 }
1469 int
1470 find_file_path(const char* root_dir,const char* file_name,char* path)
1471 {
1472         HANDLE hFind;
1473         WIN32_FIND_DATA wfd;
1474         char* prev_dir = xbt_new(char,MAX_PATH);
1475         GetCurrentDirectory(MAX_PATH,prev_dir);
1476         SetCurrentDirectory(root_dir);
1477         
1478         // begining of the scan
1479         hFind=FindFirstFile ("*.*", &wfd);
1480         
1481         if(hFind!=INVALID_HANDLE_VALUE){
1482         
1483                 /* it's a file */
1484                 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1485                 
1486                         if(!strcmp(file_name,wfd.cFileName)){
1487                                 GetCurrentDirectory(MAX_PATH,path);
1488                                 SetCurrentDirectory(prev_dir);
1489                                 xbt_free(prev_dir);
1490                                 FindClose(hFind);
1491                                 return 1;
1492                         }
1493                 
1494                 }
1495                 /* it's a directory, scan it*/
1496                 else {
1497                 
1498                         if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1499                                 if(find_file_path(wfd.cFileName,file_name,path)){
1500                                         FindClose(hFind);
1501                                         SetCurrentDirectory(prev_dir);
1502                                         return 1;
1503                                 }
1504                         }
1505                 }
1506                 
1507                 /* next file or directory */
1508                 while(FindNextFile(hFind,&wfd))
1509                 {
1510                         /* it's a file */
1511                         if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1512                         {
1513                                 if(!strcmp(file_name,wfd.cFileName)){
1514                                         GetCurrentDirectory(MAX_PATH,path);
1515                                         SetCurrentDirectory(prev_dir);
1516                                         xbt_free(prev_dir);
1517                                         FindClose(hFind);
1518                                         return 1;
1519                                 }
1520                         }
1521                         /* it's a file scan it */
1522                         else {
1523                 
1524                                 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1525                 
1526                                         if(find_file_path(wfd.cFileName,file_name,path)){
1527                                                 SetCurrentDirectory(prev_dir);
1528                                                 FindClose(hFind);
1529                                                 return 1;
1530                                         }
1531                 
1532                                 }
1533                 
1534                         }
1535                 }
1536         }
1537         
1538         SetCurrentDirectory(prev_dir);
1539         xbt_free(prev_dir);
1540         FindClose (hFind);
1541         return 0;
1542 }
1543
1544 /* Implementation of the functions used to create a Visual C++ project.*/
1545
1546 int
1547 generate_simulation_dsp_file(const char* name)
1548 {
1549         char buffer[MAX_PATH] = {0};
1550     s_dsp_t dsp = {0};
1551     dsp.lib_dir = xbt_new0(char,MAX_PATH);
1552
1553     GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1554     GetCurrentDirectory(MAX_PATH,buffer);
1555
1556     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1557     strcpy(dsp.src_dir,buffer);
1558         dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1559         sprintf(dsp.name,"%s_simulator",name);
1560
1561     generate_dsp_project(&dsp,0,name);
1562
1563     xbt_free(dsp.name);
1564     xbt_free(dsp.src_dir);
1565         xbt_free(dsp.lib_dir);
1566     
1567     return 0;           
1568 }
1569
1570 /*
1571  * Create the Microsoft visual C++ real life project file.
1572  */
1573 int
1574 generate_real_live_dsp_file(const char* name)
1575 {
1576         
1577     char buffer[MAX_PATH] = {0};
1578     xbt_dict_cursor_t cursor = NULL;
1579     char *key = NULL;
1580     void *data = NULL;
1581         s_dsp_t dsp = {0};
1582
1583         
1584     dsp.lib_dir = xbt_new0(char,MAX_PATH);
1585
1586     GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1587        
1588     GetCurrentDirectory(MAX_PATH,buffer);
1589
1590     dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1591
1592     strcpy(dsp.src_dir,buffer);
1593
1594
1595         xbt_dict_foreach(process_function_set,cursor,key,data) {
1596         dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1597
1598         sprintf(dsp.name,"%s_%s",name,key);
1599
1600         generate_dsp_project(&dsp,1,name);
1601         xbt_free(dsp.name);
1602     }
1603
1604     xbt_free(dsp.src_dir);
1605     xbt_free(dsp.lib_dir);
1606         return 0;
1607 }
1608
1609 void
1610 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1611 {
1612         /* create the visual C++ project file */
1613         char* buffer;
1614         char* file_name = xbt_new0(char,strlen(project->name) + 5);
1615     sprintf(file_name,"%s.dsp",project->name);
1616     project->stream = fopen(file_name,"w+");
1617     xbt_free(file_name);
1618     
1619     if(!__gras_path)
1620         {
1621         buffer =xbt_new0(char,MAX_PATH);
1622         GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1623         
1624                 __gras_path = xbt_new0(char,MAX_PATH);
1625                 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1626                 free(buffer);
1627     }
1628     
1629     /* dsp file header */
1630     fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1631         fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1632         fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1633         
1634         /* target type is a win32 x86 console application */
1635         fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1636         
1637         /* the current config is win32-debug */
1638         fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1639         
1640         /* warning */
1641         fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1642         
1643         /* NMAKE usage */
1644         fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1645         fprintf(project->stream,"!MESSAGE\n");
1646         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1647         fprintf(project->stream,"!MESSAGE\n");
1648         fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1649         fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1650         fprintf(project->stream,"!MESSAGE\n"); 
1651         fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1652         fprintf(project->stream,"!MESSAGE\n");
1653         fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1654         fprintf(project->stream,"!MESSAGE\n"); 
1655         fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1656         fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1657         fprintf(project->stream,"!MESSAGE\n\n"); 
1658         
1659         fprintf(project->stream,"# Begin Project\n\n");
1660         fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1661         fprintf(project->stream,"# PROP Scc_ProjName\n");
1662         fprintf(project->stream,"# PROP Scc_LocalPath\n");
1663         fprintf(project->stream,"CPP=cl.exe\n");
1664         fprintf(project->stream,"RSC=rc.exe\n\n");
1665         
1666         fprintf(project->stream,"!IF  \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1667         
1668         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1669         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1670         fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1671         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1672         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1673         fprintf(project->stream,"# PROP Use_MFC 0\n");
1674         fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1675         fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1676         fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1677         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1678         /* TODO : the include directory */
1679         /*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);*/
1680         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);
1681         fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1682         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1683         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1684         fprintf(project->stream,"BSC32=bscmake.exe\n");
1685         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1686         fprintf(project->stream,"# ADD BSC32 /nologo\n");
1687         fprintf(project->stream,"LINK32=link.exe\n");
1688         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");
1689         
1690         if(is_rl)
1691                 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");
1692         else
1693                 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");
1694                         
1695         fprintf(project->stream,"!ELSEIF  \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1696
1697         fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1698         fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1699         fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1700         fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1701         fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1702         fprintf(project->stream,"# PROP Use_MFC 0\n");
1703         fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1704         fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1705         fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1706         fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1707         fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1708         /* TODO : the include directory */
1709         /*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);*/
1710         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);
1711         fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ  /c\n");
1712         fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1713         fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1714         fprintf(project->stream,"BSC32=bscmake.exe\n");
1715         fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1716         fprintf(project->stream,"# ADD BSC32 /nologo\n");
1717         fprintf(project->stream,"LINK32=link.exe\n");
1718         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");
1719         
1720         if(is_rl)
1721                 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");
1722         else
1723                 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");
1724                         
1725         fprintf(project->stream,"!ENDIF\n\n");
1726         
1727         fprintf(project->stream,"# Begin Target\n\n");
1728         fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1729         fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1730         fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1731         fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1732         
1733         fprintf(project->stream,"# Begin Source File\n");
1734         fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1735         fprintf(project->stream,"# End Source File\n\n");
1736         
1737         fprintf(project->stream,"# Begin Source File\n");
1738         fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1739         fprintf(project->stream,"# End Source File\n\n");
1740         
1741         fprintf(project->stream,"# End Group\n");
1742         fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1743         fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1744         fprintf(project->stream,"# End Group\n");
1745         fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1746         fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1747         fprintf(project->stream,"# End Group\n");
1748         fprintf(project->stream,"# End Target\n");
1749         fprintf(project->stream,"# End Project\n");
1750         
1751 }
1752
1753 #endif
1754
1755
1756
1757
1758