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 char* __gras_path = NULL;
36 /* tabulation level (used to indent the lines of the borland project file */
37 static unsigned int level = 0;
45 * A structure which represents a borland project file.
47 typedef struct s_borland_project
49 const char* xml_version;/* the xml version used to write the borland project file */
50 const char* encoding; /* the encoding used to write the borland project file */
51 const char* comment; /* the xml comment to write at the begining of the borland project file */
52 char* name; /* the name of the borland project file */
53 FILE* stream; /* the stream to the borland project file */
54 const char* version; /* the builder version of the borland project file */
55 char* bin_dir; /* the directory used to store the generated program */
56 char* obj_dir; /* the directory used to store the generated object files */
57 char* lib_dir; /* the directory used to store the librairies used in the borland project */
58 char* src_dir; /* the directory use to store the source files of the project */
59 }s_borland_project_t,* borland_project_t;
63 * A structure which represents a visual C++ project file.
74 * Write tabs in a borland project file.
75 * @param project The project concerned by the operation.
76 * @param count The count tab to write
79 borland_project_write_tabs(borland_project_t project,unsigned int count);
82 * Write the begin of an xml node in the borland project file.
83 * @param project The borland project concerned by this operation.
84 * @param name The name of the node.
87 borland_project_begin_xml_node(borland_project_t project, const char* name);
91 * Write the end of an xml node in the borland project file.
92 * @param project The borland project concerned by this operation.
93 * @param name The name of the node.
96 borland_project_end_xml_node(borland_project_t project, const char* name);
99 * Write an xml element in a borland project file.
100 * @param project The borland project concerned by this operation.
101 * @param name The name of the element to write
102 * @param value The value of the element
105 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
108 * Write a FILE xml element in the borland project file.
109 * @param project The borland project concerned by this operation.
110 * @param file_name The value of the attribute FILENAME.
111 * @param form_name The value of the attribute FORMNAME.
112 * @param unit_name The value of the attribute UNITNAME.
113 * @param container_id The value of the attribute CONTAINERID.
114 * @param design_claas The value of the attribute DESIGNCLASS.
115 * @param local_command The value of the attribute LOCALCOMMAND.
118 borland_project_write_file_element( borland_project_t project,
119 const char* file_name,
120 const char* form_name,
121 const char* unit_name,
122 const char* container_id,
123 const char* design_class,
124 const char* local_command);
126 * Write all options of the IDE of the Borland Builder C++ compiler.
127 * @ param project The project concerned by this operation.
131 borland_project_write_ide_options(borland_project_t project);
134 * Write the xml header of the xml document.
135 * @param project The project concerned by the operation.
138 borland_project_write_xml_header(borland_project_t project);
141 * Write an xml comment in a borland project file
142 * @param project The project concerned by this operation.
145 borland_project_write_xml_comment(borland_project_t project);
148 * Create a bpf file used by a borland project file.
149 * @param name The name of the bpf file to create.
152 borland_project_create_main_file(const char* name);
155 * Create a borland project file.
156 * @param project The project concerned by this operation.
159 borland_project_create(borland_project_t project);
162 * Close a borland project file.
163 * @param project the borland project file to close.
166 borland_project_close(borland_project_t project);
170 * Generate a borland project file.
171 * @param project The borland project to generate.
174 generate_borland_project(borland_project_t project,int is_rl,const char* name);
177 * Find the path of a file.
178 * @param file_name The file name to find.
179 * @path path If founded this parameter will contain the path of file.
180 * @return If successful the function returns 1. Otherwise the function
184 find_file_path(const char* root_dir,const char* file_name,char* path);
188 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
192 * generate a Microsoft Visual project file*/
194 generate_dsp_project(dsp_t project,int is_rl,const char* name);
197 generate_borland_project(borland_project_t project,int is_rl,const char* name)
199 char* binary_path; /* the path of the generated binary file */
200 char* obj_path; /* the path of the generated object file */
201 char* lib_files; /* a list of the libraries used in the borland project */
202 char* main_source; /* the name of the bpf file used by the borland project */
203 char* file_name; /* the file name of the main source file */
204 char* include_path; /* the include path */
207 /* create the borland project file */
208 borland_project_create(project);
210 /* write the xml document header */
211 borland_project_write_xml_header(project);
213 /* write the xml comment to identify a borland project file */
214 borland_project_write_xml_comment(project);
216 /* write the begin of the node PROJECT */
217 borland_project_begin_xml_node(project,"PROJECT");
219 /* write the begin of node MACROS */
220 borland_project_begin_xml_node(project,"MACROS");
222 /* write the borland project version */
223 borland_project_write_xml_element(project,"VERSION",project->version);
225 /* construct and write the borland project binary path */
226 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
227 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
228 borland_project_write_xml_element(project,"PROJECT",binary_path);
229 xbt_free(binary_path);
231 /* construct an write the object files to generate by the compiler */
232 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
233 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
234 borland_project_write_xml_element(project,"OBJFILES",obj_path);
237 /* write the resource files used by the compiler (no resource file used) */
238 borland_project_write_xml_element(project,"RESFILES","");
240 /* write the IDL files of the project (no IDL files used) */
241 borland_project_write_xml_element(project,"IDLFILES","");
243 /* write the IDLGENFILES element (not used) */
244 borland_project_write_xml_element(project,"IDLGENFILES","");
246 /* write the DEFFILE element (not used) */
247 borland_project_write_xml_element(project,"DEFFILE","");
249 /* write the RESDEPEN element (not used, no resource file used) */
250 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
252 /* construct and write the list of libraries used by the project */
254 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
255 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
259 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
260 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
262 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
263 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
266 borland_project_write_xml_element(project,"LIBFILES",lib_files);
269 /* write the SPARELIBS element (not used) */
270 borland_project_write_xml_element(project,"SPARELIBS","");
272 /* write the PACKAGES element (no package used) */
273 borland_project_write_xml_element(project,"PACKAGES","");
275 /* write the PATHCPP element (the path of the source files of the project)*/
276 borland_project_write_xml_element(project,"PATHCPP",".;");
278 /* write the PATHPAS element (not used) */
279 borland_project_write_xml_element(project,"PATHPAS","");
281 /* write the PATHRC element (not used) */
282 borland_project_write_xml_element(project,"PATHRC","");
284 /* write the PATHASM element (not used) */
285 borland_project_write_xml_element(project,"PATHASM","");
287 /* write the DEBUGLIBPATH element (the path for debug) */
288 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
290 /* write the RELEASELIBPATH element (the path for release) */
291 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
293 /* specify the linker to use */
294 borland_project_write_xml_element(project,"LINKER","ilink32");
296 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
297 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
299 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
300 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
302 /* construct and write the MAINSOURCE element */
303 main_source = xbt_new0(char,strlen(project->name) + 5);
304 sprintf(main_source,"%s.bpf",project->name);
305 /* write the main source file to use in the borland project file */
306 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
308 /* create the bpf file used by the borland project */
309 borland_project_create_main_file(main_source);
311 /* FIXME resolve the include path */
312 /* write the INCLUDEPATH element */
315 buffer =xbt_new0(char,MAX_PATH);
316 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
318 __gras_path = xbt_new0(char,MAX_PATH);
319 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
322 /*find_file_path("C:\\","gras.h",__gras_path);*/
325 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
326 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
328 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
330 xbt_free(include_path);
332 /* write the LIBPATH element (no librarie paths specified)*/
333 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
336 * write the WARNINGS element :
337 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
338 * -w-rvl (-w-8070) disabled the function must return warning
339 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
340 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
341 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
342 * -w-par (-w-8057) disabled the warning that detect an unused variable
343 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
344 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
345 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
347 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");
349 /* write the OTHERFILES element (no other files used used) */
350 borland_project_write_xml_element(project,"OTHERFILES","");
352 /* write the end of the node MACROS */
353 borland_project_end_xml_node(project,"MACROS");
355 /* write the begin of the node OPTIONS */
356 borland_project_begin_xml_node(project,"OPTIONS");
358 /* FIXME check the idlcflags */
359 /* write the IDLCFLAGS element */
360 borland_project_write_xml_element(project,"IDLCFLAGS","");
363 * write the CFLAG1 element (compiler options ) :
365 * -Od this flag disable all compiler optimisation
366 * -H this flag specify the name of the file which will contain the precompiled header
367 * -Hc this flag specify to the compiler to cach the precompiled header
368 * -Vx this flag specify to the compiler to allow the empty structures
369 * -Ve this flag specify to the compiler to allow the empty base classes
370 * -X- this flag activate the auto-depend informations of the compiler
371 * -r- this flag disabled the use of the processor register
372 * -a1 this flag specify that the data must be aligned on one byte
373 * -b- this flag specify that the enums are the smallest size of the integer
374 * -k (used during debug)
375 * -y this flag generate the line number for debug
376 * -v this flag enabled the debugging of the source files
377 * -vi check the expansion of the inline functions
378 * -tWC specify that it's a console application
379 * -tWM- specify that the application is not multithread
380 * -c generate the object file, no link
382 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");
384 /* write the PFLAGS element */
385 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
387 /* write the RFLAGS element */
388 borland_project_write_xml_element(project,"RFLAGS","");
390 /* write the AFLAGS element (assembler flags) :
392 * /mx (not documented)
393 * /w2 (not documented)
394 * /zd (not documented)
397 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
399 /* write the LFLAGS element (linker flags) :
401 * -I specify the output directory for object files
402 * -D register the specified description (no description "")
403 * -ap build a win32 console application
404 * -Tpe generate a exe file
405 * -x do not create the map file
406 * -Gn do not generate the state file
407 * -v include the complete debug informations
409 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
411 /* write the OTHERFILES element (not used)*/
412 borland_project_write_xml_element(project,"OTHERFILES","");
414 /* write the end of the node OPTIONS */
415 borland_project_end_xml_node(project,"OPTIONS");
417 /* write the begin of the node LINKER */
418 borland_project_begin_xml_node(project,"LINKER");
420 /* write the ALLOBJ element */
421 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
423 /* write the ALLRES element (not used) */
424 borland_project_write_xml_element(project,"ALLRES","");
426 /* write the ALLLIB element */
427 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
429 /* write the OTHERFILES element (not used) */
430 borland_project_write_xml_element(project,"OTHERFILES","");
432 /* write the end of the node LINKER */
433 borland_project_end_xml_node(project,"LINKER");
435 /* write the begin of the node FILELIST */
436 borland_project_begin_xml_node(project,"FILELIST");
438 /* construct and write the list of file elements */
440 /* add the bpf file to the list */
441 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
442 xbt_free(main_source);
444 /* FIXME : check the source file directory */
445 /* add the generated source file to the list */
447 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
448 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
449 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
451 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
452 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
453 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
457 /* FIXME : check the libraries directory */
458 /* add the simgrid library to the list */
461 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
462 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
463 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
466 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
467 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
468 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
474 /* write the end of the node FILELIST */
475 borland_project_end_xml_node(project,"FILELIST");
477 /* write the begin of the node BUILDTOOLS (not used)*/
478 borland_project_begin_xml_node(project,"BUILDTOOLS");
480 /* write the end of the node BUILDTOOLS (not used)*/
481 borland_project_end_xml_node(project,"BUILDTOOLS");
483 /* write the begin of the node IDEOPTIONS */
484 borland_project_begin_xml_node(project,"IDEOPTIONS");
486 /* write all of the option of the IDE of Borland C++ Builder */
487 borland_project_write_ide_options(project);
489 /* write the end of the node IDEOPTIONS */
490 borland_project_end_xml_node(project,"IDEOPTIONS");
492 /* write the end of the node PROJECT */
493 borland_project_end_xml_node(project,"PROJECT");
495 /* close the borland project file */
496 borland_project_close(project);
500 borland_project_write_tabs(borland_project_t project,unsigned int count)
504 for(pos = 0; pos < count; pos++)
505 fprintf(project->stream,"\t");
509 borland_project_begin_xml_node(borland_project_t project, const char* name)
512 borland_project_write_tabs(project,level);
514 fprintf(project->stream,"<%s>\n",name);
520 borland_project_end_xml_node(borland_project_t project, const char* name)
525 borland_project_write_tabs(project,level);
527 fprintf(project->stream,"</%s>\n",name);
532 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
534 borland_project_write_tabs(project,level);
535 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
539 borland_project_write_xml_header(borland_project_t project)
541 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
545 borland_project_create_main_file(const char* name)
547 FILE* stream = fopen(name,"w+");
549 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
555 borland_project_create(borland_project_t project)
557 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
558 sprintf(file_name,"%s.bpr",project->name);
559 project->stream = fopen(file_name,"w+");
564 borland_project_write_xml_comment(borland_project_t project)
566 fprintf(project->stream,"<!-- %s -->\n",project->comment);
569 borland_project_write_file_element( borland_project_t project,
570 const char* file_name,
571 const char* form_name,
572 const char* unit_name,
573 const char* container_id,
574 const char* design_class,
575 const char* local_command)
577 borland_project_write_tabs(project,level);
579 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);
583 borland_project_write_ide_options(borland_project_t project)
586 const char* ide_options =
587 "[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" \
588 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
589 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
590 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
591 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
592 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
593 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
594 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
595 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
596 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
597 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
598 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
599 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
600 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
601 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
603 fprintf(project->stream,ide_options);
607 borland_project_close(borland_project_t project)
609 fclose(project->stream);
613 generate_borland_simulation_project(const char* name)
615 char buffer[MAX_PATH] = {0};
618 WIN32_FIND_DATA wfd = {0};
620 s_borland_project_t borland_project = {0};
621 borland_project.xml_version = "1.0";
622 borland_project.encoding ="utf-8";
623 borland_project.comment ="C++Builder XML Project";
624 borland_project.version = "BCB.06.00";
626 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
629 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
632 GetCurrentDirectory(MAX_PATH,buffer);
634 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
636 strcpy(borland_project.src_dir,buffer);
638 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
639 sprintf(borland_project.name,"%s_simulator",name);
641 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
642 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
644 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
647 CreateDirectory(borland_project.bin_dir,NULL);
649 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
650 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
652 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
654 if(INVALID_HANDLE_VALUE == hDir)
655 CreateDirectory(borland_project.obj_dir,NULL);
657 generate_borland_project(&borland_project,0,name);
659 xbt_free(borland_project.name);
660 xbt_free(borland_project.src_dir);
661 xbt_free(borland_project.bin_dir);
662 xbt_free(borland_project.obj_dir);
663 xbt_free(borland_project.lib_dir);
667 generate_borland_real_life_project(const char* name)
670 WIN32_FIND_DATA wfd = {0};
671 char buffer[MAX_PATH] = {0};
672 xbt_dict_cursor_t cursor = NULL;
675 s_borland_project_t borland_project = {0};
677 borland_project.xml_version = "1.0";
678 borland_project.encoding ="utf-8";
679 borland_project.comment ="C++Builder XML Project";
680 borland_project.version = "BCB.06.00";
682 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
684 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
686 GetCurrentDirectory(MAX_PATH,buffer);
688 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
690 strcpy(borland_project.src_dir,buffer);
692 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
693 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
695 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
697 if(INVALID_HANDLE_VALUE == hDir)
698 CreateDirectory(borland_project.bin_dir,NULL);
700 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
701 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
703 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
706 CreateDirectory(borland_project.obj_dir,NULL);
709 xbt_dict_foreach(process_function_set,cursor,key,data) {
710 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
712 sprintf(borland_project.name,"%s_%s",name,key);
714 generate_borland_project(&borland_project,1,name);
715 xbt_free(borland_project.name);
718 xbt_free(borland_project.src_dir);
719 xbt_free(borland_project.bin_dir);
720 xbt_free(borland_project.obj_dir);
721 xbt_free(borland_project.lib_dir);
724 find_file_path(const char* root_dir,const char* file_name,char* path)
728 char* prev_dir = xbt_new(char,MAX_PATH);
729 GetCurrentDirectory(MAX_PATH,prev_dir);
730 SetCurrentDirectory(root_dir);
732 // begining of the scan
733 hFind=FindFirstFile ("*.*", &wfd);
735 if(hFind!=INVALID_HANDLE_VALUE){
738 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
740 if(!strcmp(file_name,wfd.cFileName)){
741 GetCurrentDirectory(MAX_PATH,path);
742 SetCurrentDirectory(prev_dir);
749 /* it's a directory, scan it*/
752 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
753 if(find_file_path(wfd.cFileName,file_name,path)){
755 SetCurrentDirectory(prev_dir);
761 /* next file or directory */
762 while(FindNextFile(hFind,&wfd))
765 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
767 if(!strcmp(file_name,wfd.cFileName)){
768 GetCurrentDirectory(MAX_PATH,path);
769 SetCurrentDirectory(prev_dir);
775 /* it's a file scan it */
778 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
780 if(find_file_path(wfd.cFileName,file_name,path)){
781 SetCurrentDirectory(prev_dir);
792 SetCurrentDirectory(prev_dir);
798 /* Implementation of the functions used to create a Visual C++ project.*/
801 generate_simulation_dsp_file(const char* name)
803 char buffer[MAX_PATH] = {0};
805 dsp.lib_dir = xbt_new0(char,MAX_PATH);
807 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
808 GetCurrentDirectory(MAX_PATH,buffer);
810 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
811 strcpy(dsp.src_dir,buffer);
812 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
813 sprintf(dsp.name,"%s_simulator",name);
815 generate_dsp_project(&dsp,0,name);
818 xbt_free(dsp.src_dir);
819 xbt_free(dsp.lib_dir);
825 * Create the Microsoft visual C++ real life project file.
828 generate_real_live_dsp_file(const char* name)
831 char buffer[MAX_PATH] = {0};
832 xbt_dict_cursor_t cursor = NULL;
838 dsp.lib_dir = xbt_new0(char,MAX_PATH);
840 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
842 GetCurrentDirectory(MAX_PATH,buffer);
844 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
846 strcpy(dsp.src_dir,buffer);
849 xbt_dict_foreach(process_function_set,cursor,key,data) {
850 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
852 sprintf(dsp.name,"%s_%s",name,key);
854 generate_dsp_project(&dsp,1,name);
858 xbt_free(dsp.src_dir);
859 xbt_free(dsp.lib_dir);
864 generate_dsp_project(dsp_t project,int is_rl,const char* name)
866 /* create the visual C++ project file */
868 char* file_name = xbt_new0(char,strlen(project->name) + 5);
869 sprintf(file_name,"%s.dsp",project->name);
870 project->stream = fopen(file_name,"w+");
875 buffer =xbt_new0(char,MAX_PATH);
876 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
878 __gras_path = xbt_new0(char,MAX_PATH);
879 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
883 /* dsp file header */
884 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
885 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
886 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
888 /* target type is a win32 x86 console application */
889 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
891 /* the current config is win32-debug */
892 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
895 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
898 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
899 fprintf(project->stream,"!MESSAGE\n");
900 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
901 fprintf(project->stream,"!MESSAGE\n");
902 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
903 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
904 fprintf(project->stream,"!MESSAGE\n");
905 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
906 fprintf(project->stream,"!MESSAGE\n");
907 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
908 fprintf(project->stream,"!MESSAGE\n");
909 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
910 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
911 fprintf(project->stream,"!MESSAGE\n\n");
913 fprintf(project->stream,"# Begin Project\n\n");
914 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
915 fprintf(project->stream,"# PROP Scc_ProjName\n");
916 fprintf(project->stream,"# PROP Scc_LocalPath\n");
917 fprintf(project->stream,"CPP=cl.exe\n");
918 fprintf(project->stream,"RSC=rc.exe\n\n");
920 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
922 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
923 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
924 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
925 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
926 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
927 fprintf(project->stream,"# PROP Use_MFC 0\n");
928 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
929 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
930 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
931 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
932 /* TODO : the include directory */
933 /*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);*/
934 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);
935 fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
936 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
937 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
938 fprintf(project->stream,"BSC32=bscmake.exe\n");
939 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
940 fprintf(project->stream,"# ADD BSC32 /nologo\n");
941 fprintf(project->stream,"LINK32=link.exe\n");
942 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");
945 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");
947 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");
949 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
951 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
952 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
953 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
954 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
955 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
956 fprintf(project->stream,"# PROP Use_MFC 0\n");
957 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
958 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
959 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
960 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
961 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
962 /* TODO : the include directory */
963 /*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);*/
964 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);
965 fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
966 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
967 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
968 fprintf(project->stream,"BSC32=bscmake.exe\n");
969 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
970 fprintf(project->stream,"# ADD BSC32 /nologo\n");
971 fprintf(project->stream,"LINK32=link.exe\n");
972 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");
975 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");
977 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");
979 fprintf(project->stream,"!ENDIF\n\n");
981 fprintf(project->stream,"# Begin Target\n\n");
982 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
983 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
984 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
985 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
987 fprintf(project->stream,"# Begin Source File\n");
988 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
989 fprintf(project->stream,"# End Source File\n\n");
991 fprintf(project->stream,"# Begin Source File\n");
992 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
993 fprintf(project->stream,"# End Source File\n\n");
995 fprintf(project->stream,"# End Group\n");
996 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
997 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
998 fprintf(project->stream,"# End Group\n");
999 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1000 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1001 fprintf(project->stream,"# End Group\n");
1002 fprintf(project->stream,"# End Target\n");
1003 fprintf(project->stream,"# End Project\n");