Logo AND Algorithmique Numérique Distribuée

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