3 /* gras_stub_generator - creates the main() to use a GRAS program */
5 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
6 /* All rights reserved. */
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. */
11 #include "gras_stub_generator.h"
13 /* specific to Borland Compiler */
19 #include "xbt/sysdep.h"
20 #include "xbt/function_types.h"
22 #include "surf/surfxml_parse.h"
23 #include "surf/surf.h"
24 #include "portable.h" /* Needed for the time of the SIMIX convertion */
30 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(stubgen);
34 /* tabulation level (used to indent the lines of the borland project file */
35 static unsigned int level = 0;
39 /* the gras.h header directory */
40 static char* __gras_path = NULL;
48 * A structure which represents a borland project file.
50 typedef struct s_borland_project
52 const char* xml_version;/* the xml version used to write the borland project file */
53 const char* encoding; /* the encoding used to write the borland project file */
54 const char* comment; /* the xml comment to write at the begining of the borland project file */
55 char* name; /* the name of the borland project file */
56 FILE* stream; /* the stream to the borland project file */
57 const char* version; /* the builder version of the borland project file */
58 char* bin_dir; /* the directory used to store the generated program */
59 char* obj_dir; /* the directory used to store the generated object files */
60 char* lib_dir; /* the directory used to store the librairies used in the borland project */
61 char* src_dir; /* the directory use to store the source files of the project */
62 }s_borland_project_t,* borland_project_t;
66 * A structure which represents a visual C++ project file.
77 * Write tabs in a borland project file.
78 * @param project The project concerned by the operation.
79 * @param count The count tab to write
82 borland_project_write_tabs(borland_project_t project,unsigned int count);
85 * Write the begin of an xml node in the borland project file.
86 * @param project The borland project concerned by this operation.
87 * @param name The name of the node.
90 borland_project_begin_xml_node(borland_project_t project, const char* name);
94 * Write the end of an xml node in the borland project file.
95 * @param project The borland project concerned by this operation.
96 * @param name The name of the node.
99 borland_project_end_xml_node(borland_project_t project, const char* name);
102 * Write an xml element in a borland project file.
103 * @param project The borland project concerned by this operation.
104 * @param name The name of the element to write
105 * @param value The value of the element
108 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
111 * Write a FILE xml element in the borland project file.
112 * @param project The borland project concerned by this operation.
113 * @param file_name The value of the attribute FILENAME.
114 * @param form_name The value of the attribute FORMNAME.
115 * @param unit_name The value of the attribute UNITNAME.
116 * @param container_id The value of the attribute CONTAINERID.
117 * @param design_claas The value of the attribute DESIGNCLASS.
118 * @param local_command The value of the attribute LOCALCOMMAND.
121 borland_project_write_file_element( borland_project_t project,
122 const char* file_name,
123 const char* form_name,
124 const char* unit_name,
125 const char* container_id,
126 const char* design_class,
127 const char* local_command);
129 * Write all options of the IDE of the Borland Builder C++ compiler.
130 * @ param project The project concerned by this operation.
134 borland_project_write_ide_options(borland_project_t project);
137 * Write the xml header of the xml document.
138 * @param project The project concerned by the operation.
141 borland_project_write_xml_header(borland_project_t project);
144 * Write an xml comment in a borland project file
145 * @param project The project concerned by this operation.
148 borland_project_write_xml_comment(borland_project_t project);
151 * Create a bpf file used by a borland project file.
152 * @param name The name of the bpf file to create.
155 borland_project_create_main_file(const char* name);
158 * Create a borland project file.
159 * @param project The project concerned by this operation.
162 borland_project_create(borland_project_t project);
165 * Close a borland project file.
166 * @param project the borland project file to close.
169 borland_project_close(borland_project_t project);
173 * Generate a borland project file.
174 * @param project The borland project to generate.
177 generate_borland_project(borland_project_t project,int is_rl,const char* name);
180 * Find the path of a file.
181 * @param file_name The file name to find.
182 * @path path If founded this parameter will contain the path of file.
183 * @return If successful the function returns 1. Otherwise the function
187 find_file_path(const char* root_dir,const char* file_name,char* path);
191 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
195 * generate a Microsoft Visual project file*/
197 generate_dsp_project(dsp_t project,int is_rl,const char* name);
200 generate_borland_project(borland_project_t project,int is_rl,const char* name)
202 char* binary_path; /* the path of the generated binary file */
203 char* obj_path; /* the path of the generated object file */
204 char* lib_files; /* a list of the libraries used in the borland project */
205 char* main_source; /* the name of the bpf file used by the borland project */
206 char* file_name; /* the file name of the main source file */
207 char* include_path; /* the include path */
210 /* create the borland project file */
211 borland_project_create(project);
213 /* write the xml document header */
214 borland_project_write_xml_header(project);
216 /* write the xml comment to identify a borland project file */
217 borland_project_write_xml_comment(project);
219 /* write the begin of the node PROJECT */
220 borland_project_begin_xml_node(project,"PROJECT");
222 /* write the begin of node MACROS */
223 borland_project_begin_xml_node(project,"MACROS");
225 /* write the borland project version */
226 borland_project_write_xml_element(project,"VERSION",project->version);
228 /* construct and write the borland project binary path */
229 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
230 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
231 borland_project_write_xml_element(project,"PROJECT",binary_path);
232 xbt_free(binary_path);
234 /* construct an write the object files to generate by the compiler */
235 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
236 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
237 borland_project_write_xml_element(project,"OBJFILES",obj_path);
240 /* write the resource files used by the compiler (no resource file used) */
241 borland_project_write_xml_element(project,"RESFILES","");
243 /* write the IDL files of the project (no IDL files used) */
244 borland_project_write_xml_element(project,"IDLFILES","");
246 /* write the IDLGENFILES element (not used) */
247 borland_project_write_xml_element(project,"IDLGENFILES","");
249 /* write the DEFFILE element (not used) */
250 borland_project_write_xml_element(project,"DEFFILE","");
252 /* write the RESDEPEN element (not used, no resource file used) */
253 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
255 /* construct and write the list of libraries used by the project */
257 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
258 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
262 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
263 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
265 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
266 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
269 borland_project_write_xml_element(project,"LIBFILES",lib_files);
272 /* write the SPARELIBS element (not used) */
273 borland_project_write_xml_element(project,"SPARELIBS","");
275 /* write the PACKAGES element (no package used) */
276 borland_project_write_xml_element(project,"PACKAGES","");
278 /* write the PATHCPP element (the path of the source files of the project)*/
279 borland_project_write_xml_element(project,"PATHCPP",".;");
281 /* write the PATHPAS element (not used) */
282 borland_project_write_xml_element(project,"PATHPAS","");
284 /* write the PATHRC element (not used) */
285 borland_project_write_xml_element(project,"PATHRC","");
287 /* write the PATHASM element (not used) */
288 borland_project_write_xml_element(project,"PATHASM","");
290 /* write the DEBUGLIBPATH element (the path for debug) */
291 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
293 /* write the RELEASELIBPATH element (the path for release) */
294 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
296 /* specify the linker to use */
297 borland_project_write_xml_element(project,"LINKER","ilink32");
299 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
300 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
302 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
303 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
305 /* construct and write the MAINSOURCE element */
306 main_source = xbt_new0(char,strlen(project->name) + 5);
307 sprintf(main_source,"%s.bpf",project->name);
308 /* write the main source file to use in the borland project file */
309 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
311 /* create the bpf file used by the borland project */
312 borland_project_create_main_file(main_source);
314 /* FIXME resolve the include path */
315 /* write the INCLUDEPATH element */
318 buffer =xbt_new0(char,MAX_PATH);
319 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
321 __gras_path = xbt_new0(char,MAX_PATH);
322 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
325 /*find_file_path("C:\\","gras.h",__gras_path);*/
328 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
329 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
331 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
333 xbt_free(include_path);
335 /* write the LIBPATH element (no librarie paths specified)*/
336 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
339 * write the WARNINGS element :
340 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
341 * -w-rvl (-w-8070) disabled the function must return warning
342 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
343 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
344 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
345 * -w-par (-w-8057) disabled the warning that detect an unused variable
346 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
347 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
348 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
350 borland_project_write_xml_element(project,"WARNINGS","-w-sus -w-rvl -w-rch -w-pia -w-pch -w-par -w-csu -w-ccc -w-aus");
352 /* write the OTHERFILES element (no other files used used) */
353 borland_project_write_xml_element(project,"OTHERFILES","");
355 /* write the end of the node MACROS */
356 borland_project_end_xml_node(project,"MACROS");
358 /* write the begin of the node OPTIONS */
359 borland_project_begin_xml_node(project,"OPTIONS");
361 /* FIXME check the idlcflags */
362 /* write the IDLCFLAGS element */
363 borland_project_write_xml_element(project,"IDLCFLAGS","");
366 * write the CFLAG1 element (compiler options ) :
368 * -Od this flag disable all compiler optimisation
369 * -H this flag specify the name of the file which will contain the precompiled header
370 * -Hc this flag specify to the compiler to cach the precompiled header
371 * -Vx this flag specify to the compiler to allow the empty structures
372 * -Ve this flag specify to the compiler to allow the empty base classes
373 * -X- this flag activate the auto-depend informations of the compiler
374 * -r- this flag disabled the use of the processor register
375 * -a1 this flag specify that the data must be aligned on one byte
376 * -b- this flag specify that the enums are the smallest size of the integer
377 * -k (used during debug)
378 * -y this flag generate the line number for debug
379 * -v this flag enabled the debugging of the source files
380 * -vi check the expansion of the inline functions
381 * -tWC specify that it's a console application
382 * -tWM- specify that the application is not multithread
383 * -c generate the object file, no link
385 borland_project_write_xml_element(project,"CFLAG1","-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
387 /* write the PFLAGS element */
388 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
390 /* write the RFLAGS element */
391 borland_project_write_xml_element(project,"RFLAGS","");
393 /* write the AFLAGS element (assembler flags) :
395 * /mx (not documented)
396 * /w2 (not documented)
397 * /zd (not documented)
400 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
402 /* write the LFLAGS element (linker flags) :
404 * -I specify the output directory for object files
405 * -D register the specified description (no description "")
406 * -ap build a win32 console application
407 * -Tpe generate a exe file
408 * -x do not create the map file
409 * -Gn do not generate the state file
410 * -v include the complete debug informations
412 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
414 /* write the OTHERFILES element (not used)*/
415 borland_project_write_xml_element(project,"OTHERFILES","");
417 /* write the end of the node OPTIONS */
418 borland_project_end_xml_node(project,"OPTIONS");
420 /* write the begin of the node LINKER */
421 borland_project_begin_xml_node(project,"LINKER");
423 /* write the ALLOBJ element */
424 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
426 /* write the ALLRES element (not used) */
427 borland_project_write_xml_element(project,"ALLRES","");
429 /* write the ALLLIB element */
430 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
432 /* write the OTHERFILES element (not used) */
433 borland_project_write_xml_element(project,"OTHERFILES","");
435 /* write the end of the node LINKER */
436 borland_project_end_xml_node(project,"LINKER");
438 /* write the begin of the node FILELIST */
439 borland_project_begin_xml_node(project,"FILELIST");
441 /* construct and write the list of file elements */
443 /* add the bpf file to the list */
444 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
445 xbt_free(main_source);
447 /* FIXME : check the source file directory */
448 /* add the generated source file to the list */
450 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
451 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
452 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
454 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
455 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
456 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
460 /* FIXME : check the libraries directory */
461 /* add the simgrid library to the list */
464 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
465 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
466 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
469 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
470 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
471 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
477 /* write the end of the node FILELIST */
478 borland_project_end_xml_node(project,"FILELIST");
480 /* write the begin of the node BUILDTOOLS (not used)*/
481 borland_project_begin_xml_node(project,"BUILDTOOLS");
483 /* write the end of the node BUILDTOOLS (not used)*/
484 borland_project_end_xml_node(project,"BUILDTOOLS");
486 /* write the begin of the node IDEOPTIONS */
487 borland_project_begin_xml_node(project,"IDEOPTIONS");
489 /* write all of the option of the IDE of Borland C++ Builder */
490 borland_project_write_ide_options(project);
492 /* write the end of the node IDEOPTIONS */
493 borland_project_end_xml_node(project,"IDEOPTIONS");
495 /* write the end of the node PROJECT */
496 borland_project_end_xml_node(project,"PROJECT");
498 /* close the borland project file */
499 borland_project_close(project);
503 borland_project_write_tabs(borland_project_t project,unsigned int count)
507 for(pos = 0; pos < count; pos++)
508 fprintf(project->stream,"\t");
512 borland_project_begin_xml_node(borland_project_t project, const char* name)
515 borland_project_write_tabs(project,level);
517 fprintf(project->stream,"<%s>\n",name);
523 borland_project_end_xml_node(borland_project_t project, const char* name)
528 borland_project_write_tabs(project,level);
530 fprintf(project->stream,"</%s>\n",name);
535 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
537 borland_project_write_tabs(project,level);
538 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
542 borland_project_write_xml_header(borland_project_t project)
544 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
548 borland_project_create_main_file(const char* name)
550 FILE* stream = fopen(name,"w+");
552 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
558 borland_project_create(borland_project_t project)
560 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
561 sprintf(file_name,"%s.bpr",project->name);
562 project->stream = fopen(file_name,"w+");
567 borland_project_write_xml_comment(borland_project_t project)
569 fprintf(project->stream,"<!-- %s -->\n",project->comment);
572 borland_project_write_file_element( borland_project_t project,
573 const char* file_name,
574 const char* form_name,
575 const char* unit_name,
576 const char* container_id,
577 const char* design_class,
578 const char* local_command)
580 borland_project_write_tabs(project,level);
582 fprintf(project->stream,"<FILE FILENAME=\"%s\" FORMNAME=\"%s\" UNITNAME=\"%s\" CONTAINERID=\"%s\" DESIGNCLASS=\"%s\" LOCALCOMMAND=\"%s\"/>\n",file_name,form_name,unit_name,container_id,design_class,local_command);
586 borland_project_write_ide_options(borland_project_t project)
589 const char* ide_options =
590 "[Version Info]\nIncludeVerInfo=0\nAutoIncBuild=0\nMajorVer=1\nMinorVer=0\nRelease=0\nBuild=0\nDebug=0\nPreRelease=0\nSpecial=0\nPrivate=0\nDLL=0\nLocale=1036\nCodePage=1252\n\n" \
591 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
592 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
593 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
594 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
595 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
596 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
597 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
598 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
599 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
600 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
601 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
602 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
603 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
604 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
606 fprintf(project->stream,ide_options);
610 borland_project_close(borland_project_t project)
612 fclose(project->stream);
616 generate_borland_simulation_project(const char* name)
618 char buffer[MAX_PATH] = {0};
621 WIN32_FIND_DATA wfd = {0};
623 s_borland_project_t borland_project = {0};
624 borland_project.xml_version = "1.0";
625 borland_project.encoding ="utf-8";
626 borland_project.comment ="C++Builder XML Project";
627 borland_project.version = "BCB.06.00";
629 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
632 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
635 GetCurrentDirectory(MAX_PATH,buffer);
637 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
639 strcpy(borland_project.src_dir,buffer);
641 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
642 sprintf(borland_project.name,"%s_simulator",name);
644 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
645 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
647 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
650 CreateDirectory(borland_project.bin_dir,NULL);
652 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
653 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
655 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
657 if(INVALID_HANDLE_VALUE == hDir)
658 CreateDirectory(borland_project.obj_dir,NULL);
660 generate_borland_project(&borland_project,0,name);
662 xbt_free(borland_project.name);
663 xbt_free(borland_project.src_dir);
664 xbt_free(borland_project.bin_dir);
665 xbt_free(borland_project.obj_dir);
666 xbt_free(borland_project.lib_dir);
670 generate_borland_real_life_project(const char* name)
673 WIN32_FIND_DATA wfd = {0};
674 char buffer[MAX_PATH] = {0};
675 xbt_dict_cursor_t cursor = NULL;
678 s_borland_project_t borland_project = {0};
680 borland_project.xml_version = "1.0";
681 borland_project.encoding ="utf-8";
682 borland_project.comment ="C++Builder XML Project";
683 borland_project.version = "BCB.06.00";
684 borland_project.lib_dir = " ";
686 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
688 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
690 GetCurrentDirectory(MAX_PATH,buffer);
692 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
694 strcpy(borland_project.src_dir,buffer);
696 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
697 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
699 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
701 if(INVALID_HANDLE_VALUE == hDir)
702 CreateDirectory(borland_project.bin_dir,NULL);
704 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
705 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
707 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
710 CreateDirectory(borland_project.obj_dir,NULL);
713 xbt_dict_foreach(process_function_set,cursor,key,data) {
714 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
716 sprintf(borland_project.name,"%s_%s",name,key);
718 generate_borland_project(&borland_project,1,name);
719 xbt_free(borland_project.name);
722 xbt_free(borland_project.src_dir);
723 xbt_free(borland_project.bin_dir);
724 xbt_free(borland_project.obj_dir);
725 xbt_free(borland_project.lib_dir);
728 find_file_path(const char* root_dir,const char* file_name,char* path)
732 char* prev_dir = xbt_new(char,MAX_PATH);
733 GetCurrentDirectory(MAX_PATH,prev_dir);
734 SetCurrentDirectory(root_dir);
736 // begining of the scan
737 hFind=FindFirstFile ("*.*", &wfd);
739 if(hFind!=INVALID_HANDLE_VALUE){
742 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
744 if(!strcmp(file_name,wfd.cFileName)){
745 GetCurrentDirectory(MAX_PATH,path);
746 SetCurrentDirectory(prev_dir);
753 /* it's a directory, scan it*/
756 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
757 if(find_file_path(wfd.cFileName,file_name,path)){
759 SetCurrentDirectory(prev_dir);
765 /* next file or directory */
766 while(FindNextFile(hFind,&wfd))
769 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
771 if(!strcmp(file_name,wfd.cFileName)){
772 GetCurrentDirectory(MAX_PATH,path);
773 SetCurrentDirectory(prev_dir);
779 /* it's a file scan it */
782 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
784 if(find_file_path(wfd.cFileName,file_name,path)){
785 SetCurrentDirectory(prev_dir);
796 SetCurrentDirectory(prev_dir);
802 /* Implementation of the functions used to create a Visual C++ project.*/
805 generate_simulation_dsp_file(const char* name)
807 char buffer[MAX_PATH] = {0};
809 dsp.lib_dir = xbt_new0(char,MAX_PATH);
811 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
812 GetCurrentDirectory(MAX_PATH,buffer);
814 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
815 strcpy(dsp.src_dir,buffer);
816 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
817 sprintf(dsp.name,"%s_simulator",name);
819 generate_dsp_project(&dsp,0,name);
822 xbt_free(dsp.src_dir);
823 xbt_free(dsp.lib_dir);
829 * Create the Microsoft visual C++ real life project file.
832 generate_real_live_dsp_file(const char* name)
835 char buffer[MAX_PATH] = {0};
836 xbt_dict_cursor_t cursor = NULL;
842 dsp.lib_dir = xbt_new0(char,MAX_PATH);
844 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
846 GetCurrentDirectory(MAX_PATH,buffer);
848 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
850 strcpy(dsp.src_dir,buffer);
853 xbt_dict_foreach(process_function_set,cursor,key,data) {
854 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
856 sprintf(dsp.name,"%s_%s",name,key);
858 generate_dsp_project(&dsp,1,name);
862 xbt_free(dsp.src_dir);
863 xbt_free(dsp.lib_dir);
868 generate_dsp_project(dsp_t project,int is_rl,const char* name)
870 /* create the visual C++ project file */
872 char* file_name = xbt_new0(char,strlen(project->name) + 5);
873 sprintf(file_name,"%s.dsp",project->name);
874 project->stream = fopen(file_name,"w+");
879 buffer =xbt_new0(char,MAX_PATH);
880 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
882 __gras_path = xbt_new0(char,MAX_PATH);
883 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
887 /* dsp file header */
888 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
889 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
890 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
892 /* target type is a win32 x86 console application */
893 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
895 /* the current config is win32-debug */
896 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
899 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
902 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
903 fprintf(project->stream,"!MESSAGE\n");
904 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
905 fprintf(project->stream,"!MESSAGE\n");
906 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
907 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
908 fprintf(project->stream,"!MESSAGE\n");
909 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
910 fprintf(project->stream,"!MESSAGE\n");
911 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
912 fprintf(project->stream,"!MESSAGE\n");
913 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
914 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
915 fprintf(project->stream,"!MESSAGE\n\n");
917 fprintf(project->stream,"# Begin Project\n\n");
918 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
919 fprintf(project->stream,"# PROP Scc_ProjName\n");
920 fprintf(project->stream,"# PROP Scc_LocalPath\n");
921 fprintf(project->stream,"CPP=cl.exe\n");
922 fprintf(project->stream,"RSC=rc.exe\n\n");
924 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
926 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
927 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
928 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
929 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
930 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
931 fprintf(project->stream,"# PROP Use_MFC 0\n");
932 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
933 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
934 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
935 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
936 /* TODO : the include directory */
937 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"./%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);*/
938 fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);
939 fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
940 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
941 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
942 fprintf(project->stream,"BSC32=bscmake.exe\n");
943 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
944 fprintf(project->stream,"# ADD BSC32 /nologo\n");
945 fprintf(project->stream,"LINK32=link.exe\n");
946 fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n");
949 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libgras.lib /nologo /subsystem:console /machine:I386\n\n");
951 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib /nologo /subsystem:console /machine:I386\n\n");
953 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
955 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
956 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
957 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
958 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
959 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
960 fprintf(project->stream,"# PROP Use_MFC 0\n");
961 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
962 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
963 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
964 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
965 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
966 /* TODO : the include directory */
967 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"./%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",__gras_path);*/
968 fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",__gras_path);
969 fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
970 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
971 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
972 fprintf(project->stream,"BSC32=bscmake.exe\n");
973 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
974 fprintf(project->stream,"# ADD BSC32 /nologo\n");
975 fprintf(project->stream,"LINK32=link.exe\n");
976 fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n");
979 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib libgras.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
981 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib simgrid.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
983 fprintf(project->stream,"!ENDIF\n\n");
985 fprintf(project->stream,"# Begin Target\n\n");
986 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
987 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
988 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
989 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
991 fprintf(project->stream,"# Begin Source File\n");
992 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
993 fprintf(project->stream,"# End Source File\n\n");
995 fprintf(project->stream,"# Begin Source File\n");
996 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
997 fprintf(project->stream,"# End Source File\n\n");
999 fprintf(project->stream,"# End Group\n");
1000 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1001 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1002 fprintf(project->stream,"# End Group\n");
1003 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1004 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1005 fprintf(project->stream,"# End Group\n");
1006 fprintf(project->stream,"# End Target\n");
1007 fprintf(project->stream,"# End Project\n");