1 /* gras_stub_generator - creates the main() to use a GRAS program */
3 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
4 /* All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "gras_stub_generator.h"
11 /* specific to Borland Compiler */
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
22 #include "portable.h" /* Needed for the time of the SIMIX convertion */
28 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(stubgen);
32 char *__gras_path = NULL;
34 /* tabulation level (used to indent the lines of the borland project file */
35 static unsigned int level = 0;
43 * A structure which represents a borland project file.
45 typedef struct s_borland_project {
46 const char *xml_version; /* the xml version used to write the borland project file */
47 const char *encoding; /* the encoding used to write the borland project file */
48 const char *comment; /* the xml comment to write at the begining of the borland project file */
49 char *name; /* the name of the borland project file */
50 FILE *stream; /* the stream to the borland project file */
51 const char *version; /* the builder version of the borland project file */
52 char *bin_dir; /* the directory used to store the generated program */
53 char *obj_dir; /* the directory used to store the generated object files */
54 char *lib_dir; /* the directory used to store the librairies used in the borland project */
55 char *src_dir; /* the directory use to store the source files of the project */
56 } s_borland_project_t, *borland_project_t;
60 * A structure which represents a visual C++ project file.
62 typedef struct s_dsp {
70 * Write tabs in a borland project file.
71 * @param project The project concerned by the operation.
72 * @param count The count tab to write
75 borland_project_write_tabs(borland_project_t project, unsigned int count);
78 * Write the begin of an xml node in the borland project file.
79 * @param project The borland project concerned by this operation.
80 * @param name The name of the node.
83 borland_project_begin_xml_node(borland_project_t project,
88 * Write the end of an xml node in the borland project file.
89 * @param project The borland project concerned by this operation.
90 * @param name The name of the node.
93 borland_project_end_xml_node(borland_project_t project, const char *name);
96 * Write an xml element in a borland project file.
97 * @param project The borland project concerned by this operation.
98 * @param name The name of the element to write
99 * @param value The value of the element
102 borland_project_write_xml_element(borland_project_t project,
103 const char *name, const char *value);
106 * Write a FILE xml element in the borland project file.
107 * @param project The borland project concerned by this operation.
108 * @param file_name The value of the attribute FILENAME.
109 * @param form_name The value of the attribute FORMNAME.
110 * @param unit_name The value of the attribute UNITNAME.
111 * @param container_id The value of the attribute CONTAINERID.
112 * @param design_claas The value of the attribute DESIGNCLASS.
113 * @param local_command The value of the attribute LOCALCOMMAND.
116 borland_project_write_file_element(borland_project_t project,
117 const char *file_name,
118 const char *form_name,
119 const char *unit_name,
120 const char *container_id,
121 const char *design_class,
122 const char *local_command);
124 * Write all options of the IDE of the Borland Builder C++ compiler.
125 * @ param project The project concerned by this operation.
128 static void borland_project_write_ide_options(borland_project_t project);
131 * Write the xml header of the xml document.
132 * @param project The project concerned by the operation.
134 static void borland_project_write_xml_header(borland_project_t project);
137 * Write an xml comment in a borland project file
138 * @param project The project concerned by this operation.
140 static void borland_project_write_xml_comment(borland_project_t project);
143 * Create a bpf file used by a borland project file.
144 * @param name The name of the bpf file to create.
146 static void borland_project_create_main_file(const char *name);
149 * Create a borland project file.
150 * @param project The project concerned by this operation.
152 static void borland_project_create(borland_project_t project);
155 * Close a borland project file.
156 * @param project the borland project file to close.
158 static void borland_project_close(borland_project_t project);
162 * Generate a borland project file.
163 * @param project The borland project to generate.
166 generate_borland_project(borland_project_t project, int is_rl,
170 * Find the path of a file.
171 * @param file_name The file name to find.
172 * @path path If founded this parameter will contain the path of file.
173 * @return If successful the function returns 1. Otherwise the function
177 find_file_path(const char *root_dir, const char *file_name, char *path);
181 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
185 * generate a Microsoft Visual project file*/
186 static void generate_dsp_project(dsp_t project, int is_rl,
190 generate_borland_project(borland_project_t project, int is_rl,
193 char *binary_path; /* the path of the generated binary file */
194 char *obj_path; /* the path of the generated object file */
195 char *lib_files; /* a list of the libraries used in the borland project */
196 char *main_source; /* the name of the bpf file used by the borland project */
197 char *file_name; /* the file name of the main source file */
198 char *include_path; /* the include path */
201 /* create the borland project file */
202 borland_project_create(project);
204 /* write the xml document header */
205 borland_project_write_xml_header(project);
207 /* write the xml comment to identify a borland project file */
208 borland_project_write_xml_comment(project);
210 /* write the begin of the node PROJECT */
211 borland_project_begin_xml_node(project, "PROJECT");
213 /* write the begin of node MACROS */
214 borland_project_begin_xml_node(project, "MACROS");
216 /* write the borland project version */
217 borland_project_write_xml_element(project, "VERSION", project->version);
219 /* construct and write the borland project binary path */
221 xbt_new0(char, strlen(project->name) + strlen(project->bin_dir) + 6);
222 sprintf(binary_path, "%s\\%s.exe", project->bin_dir, project->name);
223 borland_project_write_xml_element(project, "PROJECT", binary_path);
224 xbt_free(binary_path);
226 /* construct an write the object files to generate by the compiler */
229 strlen(project->name) + strlen(name) +
230 (2 * strlen(project->obj_dir)) + 11);
231 sprintf(binary_path, "%s\\%s.obj\n%s\\%s.obj", project->obj_dir,
232 project->name, project->obj_dir, name);
233 borland_project_write_xml_element(project, "OBJFILES", obj_path);
236 /* write the resource files used by the compiler (no resource file used) */
237 borland_project_write_xml_element(project, "RESFILES", "");
239 /* write the IDL files of the project (no IDL files used) */
240 borland_project_write_xml_element(project, "IDLFILES", "");
242 /* write the IDLGENFILES element (not used) */
243 borland_project_write_xml_element(project, "IDLGENFILES", "");
245 /* write the DEFFILE element (not used) */
246 borland_project_write_xml_element(project, "DEFFILE", "");
248 /* write the RESDEPEN element (not used, no resource file used) */
249 borland_project_write_xml_element(project, "RESDEPEN", "$(RESFILES)");
251 /* construct and write the list of libraries used by the project */
253 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
254 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
260 (2 * (strlen(project->lib_dir) + 1)) +
261 strlen("libgras.lib") + 2);
262 sprintf(lib_files, "%s\\libgras.lib", project->lib_dir);
266 (2 * (strlen(project->lib_dir) + 1)) +
267 strlen("simgrid.lib") + 2);
268 sprintf(lib_files, "%s\\simgrid.lib", project->lib_dir);
271 borland_project_write_xml_element(project, "LIBFILES", lib_files);
274 /* write the SPARELIBS element (not used) */
275 borland_project_write_xml_element(project, "SPARELIBS", "");
277 /* write the PACKAGES element (no package used) */
278 borland_project_write_xml_element(project, "PACKAGES", "");
280 /* write the PATHCPP element (the path of the source files of the project) */
281 borland_project_write_xml_element(project, "PATHCPP", ".;");
283 /* write the PATHPAS element (not used) */
284 borland_project_write_xml_element(project, "PATHPAS", "");
286 /* write the PATHRC element (not used) */
287 borland_project_write_xml_element(project, "PATHRC", "");
289 /* write the PATHASM element (not used) */
290 borland_project_write_xml_element(project, "PATHASM", "");
292 /* write the DEBUGLIBPATH element (the path for debug) */
293 borland_project_write_xml_element(project, "DEBUGLIBPATH",
294 "$(BCB)\\lib\\debug");
296 /* write the RELEASELIBPATH element (the path for release) */
297 borland_project_write_xml_element(project, "RELEASELIBPATH",
298 "$(BCB)\\lib\\release");
300 /* specify the linker to use */
301 borland_project_write_xml_element(project, "LINKER", "ilink32");
303 /* write the USERDEFINES element (user definitions (#define _DEBUG)) */
304 borland_project_write_xml_element(project, "USERDEFINES", "_DEBUG");
306 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL) */
307 borland_project_write_xml_element(project, "SYSDEFINES",
308 "NO_STRICT;_NO_VCL");
310 /* construct and write the MAINSOURCE element */
311 main_source = xbt_new0(char, strlen(project->name) + 5);
312 sprintf(main_source, "%s.bpf", project->name);
313 /* write the main source file to use in the borland project file */
314 borland_project_write_xml_element(project, "MAINSOURCE", main_source);
316 /* create the bpf file used by the borland project */
317 borland_project_create_main_file(main_source);
319 /* FIXME resolve the include path */
320 /* write the INCLUDEPATH element */
323 buffer = xbt_new0(char, MAX_PATH);
324 GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
326 __gras_path = xbt_new0(char, MAX_PATH);
327 sprintf(__gras_path, "%s\\simgrid\\include", buffer);
330 /*find_file_path("C:\\","gras.h",__gras_path); */
334 xbt_new0(char, strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
335 sprintf(include_path, "$(BCB)\\include;%s", __gras_path);
337 borland_project_write_xml_element(project, "INCLUDEPATH", include_path);
339 xbt_free(include_path);
341 /* write the LIBPATH element (no librarie paths specified) */
342 borland_project_write_xml_element(project, "LIBPATH",
343 "$(BCB)\\lib;$(BCB)\\lib\\obj");
346 * write the WARNINGS element :
347 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
348 * -w-rvl (-w-8070) disabled the function must return warning
349 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
350 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
351 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
352 * -w-par (-w-8057) disabled the warning that detect an unused variable
353 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
354 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
355 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
357 borland_project_write_xml_element(project, "WARNINGS",
358 "-w-sus -w-rvl -w-rch -w-pia -w-pch -w-par -w-csu -w-ccc -w-aus");
360 /* write the OTHERFILES element (no other files used used) */
361 borland_project_write_xml_element(project, "OTHERFILES", "");
363 /* write the end of the node MACROS */
364 borland_project_end_xml_node(project, "MACROS");
366 /* write the begin of the node OPTIONS */
367 borland_project_begin_xml_node(project, "OPTIONS");
369 /* FIXME check the idlcflags */
370 /* write the IDLCFLAGS element */
371 borland_project_write_xml_element(project, "IDLCFLAGS", "");
374 * write the CFLAG1 element (compiler options ) :
376 * -Od this flag disable all compiler optimisation
377 * -H this flag specify the name of the file which will contain the precompiled header
378 * -Hc this flag specify to the compiler to cach the precompiled header
379 * -Vx this flag specify to the compiler to allow the empty structures
380 * -Ve this flag specify to the compiler to allow the empty base classes
381 * -X- this flag activate the auto-depend informations of the compiler
382 * -r- this flag disabled the use of the processor register
383 * -a1 this flag specify that the data must be aligned on one byte
384 * -b- this flag specify that the enums are the smallest size of the integer
385 * -k (used during debug)
386 * -y this flag generate the line number for debug
387 * -v this flag enabled the debugging of the source files
388 * -vi check the expansion of the inline functions
389 * -tWC specify that it's a console application
390 * -tWM- specify that the application is not multithread
391 * -c generate the object file, no link
393 borland_project_write_xml_element(project, "CFLAG1",
394 "-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
396 /* write the PFLAGS element */
397 borland_project_write_xml_element(project, "PFLAGS",
398 "-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
400 /* write the RFLAGS element */
401 borland_project_write_xml_element(project, "RFLAGS", "");
403 /* write the AFLAGS element (assembler flags) :
405 * /mx (not documented)
406 * /w2 (not documented)
407 * /zd (not documented)
410 borland_project_write_xml_element(project, "AFLAGS", "/mx /w2 /zd");
412 /* write the LFLAGS element (linker flags) :
414 * -I specify the output directory for object files
415 * -D register the specified description (no description "")
416 * -ap build a win32 console application
417 * -Tpe generate a exe file
418 * -x do not create the map file
419 * -Gn do not generate the state file
420 * -v include the complete debug informations
422 borland_project_write_xml_element(project, "LFLAGS",
423 "-Iobj -D"" -ap -Tpe -x -Gn -v");
425 /* write the OTHERFILES element (not used) */
426 borland_project_write_xml_element(project, "OTHERFILES", "");
428 /* write the end of the node OPTIONS */
429 borland_project_end_xml_node(project, "OPTIONS");
431 /* write the begin of the node LINKER */
432 borland_project_begin_xml_node(project, "LINKER");
434 /* write the ALLOBJ element */
435 borland_project_write_xml_element(project, "ALLOBJ",
436 "c0x32.obj $(OBJFILES)");
438 /* write the ALLRES element (not used) */
439 borland_project_write_xml_element(project, "ALLRES", "");
441 /* write the ALLLIB element */
442 borland_project_write_xml_element(project, "ALLLIB",
443 "$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
445 /* write the OTHERFILES element (not used) */
446 borland_project_write_xml_element(project, "OTHERFILES", "");
448 /* write the end of the node LINKER */
449 borland_project_end_xml_node(project, "LINKER");
451 /* write the begin of the node FILELIST */
452 borland_project_begin_xml_node(project, "FILELIST");
454 /* construct and write the list of file elements */
456 /* add the bpf file to the list */
457 borland_project_write_file_element(project, main_source, "",
458 project->name, "BPF", "", "");
459 xbt_free(main_source);
461 /* FIXME : check the source file directory */
462 /* add the generated source file to the list */
465 xbt_new0(char, strlen(project->src_dir) + strlen(project->name) + 5);
466 sprintf(file_name, "%s\\_%s.c", project->src_dir, project->name);
467 borland_project_write_file_element(project, file_name, "", project->name,
468 "CCompiler", "", "");
471 strlen(project->src_dir) + strlen(project->name) + 4);
472 sprintf(file_name, "%s\\%s.c", project->src_dir, name);
473 borland_project_write_file_element(project, file_name, "", name,
474 "CCompiler", "", "");
478 /* FIXME : check the libraries directory */
479 /* add the simgrid library to the list */
484 strlen(project->lib_dir) + strlen("libgras.lib") + 2);
485 sprintf(file_name, "%s\\libgras.lib", project->lib_dir);
486 borland_project_write_file_element(project, file_name, "",
487 "libgras.lib", "LibTool", "", "");
491 strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
492 sprintf(file_name, "%s\\simgrid.lib", project->lib_dir);
493 borland_project_write_file_element(project, file_name, "",
494 "simgrid.lib", "LibTool", "", "");
500 /* write the end of the node FILELIST */
501 borland_project_end_xml_node(project, "FILELIST");
503 /* write the begin of the node BUILDTOOLS (not used) */
504 borland_project_begin_xml_node(project, "BUILDTOOLS");
506 /* write the end of the node BUILDTOOLS (not used) */
507 borland_project_end_xml_node(project, "BUILDTOOLS");
509 /* write the begin of the node IDEOPTIONS */
510 borland_project_begin_xml_node(project, "IDEOPTIONS");
512 /* write all of the option of the IDE of Borland C++ Builder */
513 borland_project_write_ide_options(project);
515 /* write the end of the node IDEOPTIONS */
516 borland_project_end_xml_node(project, "IDEOPTIONS");
518 /* write the end of the node PROJECT */
519 borland_project_end_xml_node(project, "PROJECT");
521 /* close the borland project file */
522 borland_project_close(project);
525 void borland_project_write_tabs(borland_project_t project,
530 for (pos = 0; pos < count; pos++)
531 fprintf(project->stream, "\t");
535 borland_project_begin_xml_node(borland_project_t project, const char *name)
538 borland_project_write_tabs(project, level);
540 fprintf(project->stream, "<%s>\n", name);
545 void borland_project_end_xml_node(borland_project_t project,
551 borland_project_write_tabs(project, level);
553 fprintf(project->stream, "</%s>\n", name);
558 borland_project_write_xml_element(borland_project_t project,
559 const char *name, const char *value)
561 borland_project_write_tabs(project, level);
562 fprintf(project->stream, "<%s value=\"%s\"/>\n", name, value);
565 void borland_project_write_xml_header(borland_project_t project)
567 fprintf(project->stream, "<?xml version='%s' encoding='%s' ?>\n",
568 project->xml_version, project->encoding);
571 void borland_project_create_main_file(const char *name)
573 FILE *stream = fopen(name, "w+");
576 "Ce fichier est uniquement utilis� par le gestionnaire de projets et doit �tre trait� comme le fichier projet\n\n\nmain\n");
581 void borland_project_create(borland_project_t project)
583 char *file_name = xbt_new0(char, strlen(project->name) + 5);
584 sprintf(file_name, "%s.bpr", project->name);
585 project->stream = fopen(file_name, "w+");
589 void borland_project_write_xml_comment(borland_project_t project)
591 fprintf(project->stream, "<!-- %s -->\n", project->comment);
595 borland_project_write_file_element(borland_project_t project,
596 const char *file_name,
597 const char *form_name,
598 const char *unit_name,
599 const char *container_id,
600 const char *design_class,
601 const char *local_command)
603 borland_project_write_tabs(project, level);
605 fprintf(project->stream,
606 "<FILE FILENAME=\"%s\" FORMNAME=\"%s\" UNITNAME=\"%s\" CONTAINERID=\"%s\" DESIGNCLASS=\"%s\" LOCALCOMMAND=\"%s\"/>\n",
607 file_name, form_name, unit_name, container_id, design_class,
611 void borland_project_write_ide_options(borland_project_t project)
614 const char *ide_options =
615 "[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"
616 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n"
617 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n"
618 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n"
619 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n"
620 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n"
621 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n"
622 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n"
623 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n"
624 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n"
625 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n"
626 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n"
627 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n"
628 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n"
629 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
631 fprintf(project->stream, ide_options);
634 void borland_project_close(borland_project_t project)
636 fclose(project->stream);
639 void generate_borland_simulation_project(const char *name)
641 char buffer[MAX_PATH] = { 0 };
644 WIN32_FIND_DATA wfd = { 0 };
646 s_borland_project_t borland_project = { 0 };
647 borland_project.xml_version = "1.0";
648 borland_project.encoding = "utf-8";
649 borland_project.comment = "C++Builder XML Project";
650 borland_project.version = "BCB.06.00";
652 borland_project.lib_dir = xbt_new0(char, MAX_PATH);
655 GetEnvironmentVariable("LIB_SIMGRID_PATH", borland_project.lib_dir,
659 GetCurrentDirectory(MAX_PATH, buffer);
661 borland_project.src_dir = xbt_strdup(buffer);
663 borland_project.name =
664 xbt_new0(char, strlen(name) + strlen("simulator") + 2);
665 sprintf(borland_project.name, "%s_simulator", name);
667 borland_project.bin_dir =
668 xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
669 sprintf(borland_project.bin_dir, "%s\\bin", buffer);
671 hDir = FindFirstFile(borland_project.bin_dir, &wfd);
674 CreateDirectory(borland_project.bin_dir, NULL);
676 borland_project.obj_dir =
677 xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
678 sprintf(borland_project.obj_dir, "%s\\obj", buffer);
680 hDir = FindFirstFile(borland_project.obj_dir, &wfd);
682 if (INVALID_HANDLE_VALUE == hDir)
683 CreateDirectory(borland_project.obj_dir, NULL);
685 generate_borland_project(&borland_project, 0, name);
687 xbt_free(borland_project.name);
688 xbt_free(borland_project.src_dir);
689 xbt_free(borland_project.bin_dir);
690 xbt_free(borland_project.obj_dir);
691 xbt_free(borland_project.lib_dir);
694 void generate_borland_real_life_project(const char *name)
697 WIN32_FIND_DATA wfd = { 0 };
698 char buffer[MAX_PATH] = { 0 };
699 xbt_dict_cursor_t cursor = NULL;
702 s_borland_project_t borland_project = { 0 };
704 borland_project.xml_version = "1.0";
705 borland_project.encoding = "utf-8";
706 borland_project.comment = "C++Builder XML Project";
707 borland_project.version = "BCB.06.00";
709 borland_project.lib_dir = xbt_new0(char, MAX_PATH);
711 GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir,
714 GetCurrentDirectory(MAX_PATH, buffer);
716 borland_project.src_dir = xbt_strdup(buffer);
718 borland_project.bin_dir =
719 xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
720 sprintf(borland_project.bin_dir, "%s\\bin", buffer);
722 hDir = FindFirstFile(borland_project.bin_dir, &wfd);
724 if (INVALID_HANDLE_VALUE == hDir)
725 CreateDirectory(borland_project.bin_dir, NULL);
727 borland_project.obj_dir =
728 xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
729 sprintf(borland_project.obj_dir, "%s\\obj", buffer);
731 hDir = FindFirstFile(borland_project.obj_dir, &wfd);
734 CreateDirectory(borland_project.obj_dir, NULL);
737 xbt_dict_foreach(process_function_set, cursor, key, data) {
738 borland_project.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
740 sprintf(borland_project.name, "%s_%s", name, key);
742 generate_borland_project(&borland_project, 1, name);
743 xbt_free(borland_project.name);
746 xbt_free(borland_project.src_dir);
747 xbt_free(borland_project.bin_dir);
748 xbt_free(borland_project.obj_dir);
749 xbt_free(borland_project.lib_dir);
752 int find_file_path(const char *root_dir, const char *file_name, char *path)
756 char *prev_dir = xbt_new(char, MAX_PATH);
757 GetCurrentDirectory(MAX_PATH, prev_dir);
758 SetCurrentDirectory(root_dir);
760 // begining of the scan
761 hFind = FindFirstFile("*.*", &wfd);
763 if (hFind != INVALID_HANDLE_VALUE) {
766 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
768 if (!strcmp(file_name, wfd.cFileName)) {
769 GetCurrentDirectory(MAX_PATH, path);
770 SetCurrentDirectory(prev_dir);
777 /* it's a directory, scan it */
780 if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
781 if (find_file_path(wfd.cFileName, file_name, path)) {
783 SetCurrentDirectory(prev_dir);
789 /* next file or directory */
790 while (FindNextFile(hFind, &wfd)) {
792 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
793 if (!strcmp(file_name, wfd.cFileName)) {
794 GetCurrentDirectory(MAX_PATH, path);
795 SetCurrentDirectory(prev_dir);
801 /* it's a file scan it */
804 if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
806 if (find_file_path(wfd.cFileName, file_name, path)) {
807 SetCurrentDirectory(prev_dir);
818 SetCurrentDirectory(prev_dir);
824 /* Implementation of the functions used to create a Visual C++ project.*/
826 int generate_simulation_dsp_file(const char *name)
828 char buffer[MAX_PATH] = { 0 };
830 dsp.lib_dir = xbt_new0(char, MAX_PATH);
832 GetEnvironmentVariable("LIB_SIMGRID_PATH", dsp.lib_dir, MAX_PATH);
833 GetCurrentDirectory(MAX_PATH, buffer);
835 dsp.src_dir = xbt_strdup(buffer);
836 dsp.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2);
837 sprintf(dsp.name, "%s_simulator", name);
839 generate_dsp_project(&dsp, 0, name);
842 xbt_free(dsp.src_dir);
843 xbt_free(dsp.lib_dir);
849 * Create the Microsoft visual C++ real life project file.
851 int generate_real_live_dsp_file(const char *name)
854 char buffer[MAX_PATH] = { 0 };
855 xbt_dict_cursor_t cursor = NULL;
861 dsp.lib_dir = xbt_new0(char, MAX_PATH);
863 GetEnvironmentVariable("LIB_GRAS_PATH", dsp.lib_dir, MAX_PATH);
865 GetCurrentDirectory(MAX_PATH, buffer);
867 dsp.src_dir = xbt_strdup(buffer);
870 xbt_dict_foreach(process_function_set, cursor, key, data) {
871 dsp.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
873 sprintf(dsp.name, "%s_%s", name, key);
875 generate_dsp_project(&dsp, 1, name);
879 xbt_free(dsp.src_dir);
880 xbt_free(dsp.lib_dir);
884 void generate_dsp_project(dsp_t project, int is_rl, const char *name)
886 /* create the visual C++ project file */
888 char *file_name = xbt_new0(char, strlen(project->name) + 5);
889 sprintf(file_name, "%s.dsp", project->name);
890 project->stream = fopen(file_name, "w+");
894 buffer = xbt_new0(char, MAX_PATH);
895 GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
897 __gras_path = xbt_new0(char, MAX_PATH);
898 sprintf(__gras_path, "%s\\simgrid\\include", buffer);
902 /* dsp file header */
903 fprintf(project->stream,
904 "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",
906 fprintf(project->stream,
907 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
908 fprintf(project->stream, "# ** DO NOT EDIT **\n\n");
910 /* target type is a win32 x86 console application */
911 fprintf(project->stream,
912 "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
914 /* the current config is win32-debug */
915 fprintf(project->stream, "CFG=%s - Win32 Debug\n", project->name);
918 fprintf(project->stream,
919 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
922 fprintf(project->stream,
923 "!MESSAGE use the Export Makefile command and run\n");
924 fprintf(project->stream, "!MESSAGE\n");
925 fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n",
927 fprintf(project->stream, "!MESSAGE\n");
928 fprintf(project->stream,
929 "!MESSAGE You can specify a configuration when running NMAKE\n");
930 fprintf(project->stream,
931 "!MESSAGE by defining the macro CFG on the command line. For example:\n");
932 fprintf(project->stream, "!MESSAGE\n");
933 fprintf(project->stream,
934 "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",
935 project->name, project->name);
936 fprintf(project->stream, "!MESSAGE\n");
937 fprintf(project->stream,
938 "!MESSAGE Possible choices for configuration are:\n");
939 fprintf(project->stream, "!MESSAGE\n");
940 fprintf(project->stream,
941 "!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",
943 fprintf(project->stream,
944 "!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",
946 fprintf(project->stream, "!MESSAGE\n\n");
948 fprintf(project->stream, "# Begin Project\n\n");
949 fprintf(project->stream, "# PROP AllowPerConfigDependencies 0\n");
950 fprintf(project->stream, "# PROP Scc_ProjName\n");
951 fprintf(project->stream, "# PROP Scc_LocalPath\n");
952 fprintf(project->stream, "CPP=cl.exe\n");
953 fprintf(project->stream, "RSC=rc.exe\n\n");
955 fprintf(project->stream, "!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",
958 fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
959 fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 0\n");
960 fprintf(project->stream, "# PROP BASE Output_Dir \"Release\"\n");
961 fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Release\"\n");
962 fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
963 fprintf(project->stream, "# PROP Use_MFC 0\n");
964 fprintf(project->stream, "# PROP Use_Debug_Libraries 0\n");
965 fprintf(project->stream, "# PROP Output_Dir \"Release\"\n");
966 fprintf(project->stream, "# PROP Intermediate_Dir \"Release\"\n");
967 fprintf(project->stream, "# PROP Target_Dir \"\"\n");
968 /* TODO : the include directory */
969 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"./%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path); */
970 fprintf(project->stream,
971 "# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",
973 fprintf(project->stream,
974 "# ADD CPP /nologo /W3 /GX /O2 /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
975 fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
976 fprintf(project->stream, "# ADD RSC /l 0x40c /d \"NDEBUG\n");
977 fprintf(project->stream, "BSC32=bscmake.exe\n");
978 fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
979 fprintf(project->stream, "# ADD BSC32 /nologo\n");
980 fprintf(project->stream, "LINK32=link.exe\n");
981 fprintf(project->stream,
982 "# 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");
985 fprintf(project->stream,
986 "# 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");
988 fprintf(project->stream,
989 "# 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");
991 fprintf(project->stream, "!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",
994 fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
995 fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 1\n");
996 fprintf(project->stream, "# PROP BASE Output_Dir \"Debug\"\n");
997 fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Debug\"\n");
998 fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
999 fprintf(project->stream, "# PROP Use_MFC 0\n");
1000 fprintf(project->stream, "# PROP Use_Debug_Libraries 1\n");
1001 fprintf(project->stream, "# PROP Output_Dir \"Debug\"\n");
1002 fprintf(project->stream, "# PROP Intermediate_Dir \"Debug\"\n");
1003 fprintf(project->stream, "# PROP Ignore_Export_Lib 0\n");
1004 fprintf(project->stream, "# PROP Target_Dir \"\"\n");
1005 /* TODO : the include directory */
1006 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"./%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",__gras_path); */
1007 fprintf(project->stream,
1008 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",
1010 fprintf(project->stream,
1011 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1012 fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1013 fprintf(project->stream, "# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1014 fprintf(project->stream, "BSC32=bscmake.exe\n");
1015 fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
1016 fprintf(project->stream, "# ADD BSC32 /nologo\n");
1017 fprintf(project->stream, "LINK32=link.exe\n");
1018 fprintf(project->stream,
1019 "# 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");
1022 fprintf(project->stream,
1023 "# 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");
1025 fprintf(project->stream,
1026 "# 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");
1028 fprintf(project->stream, "!ENDIF\n\n");
1030 fprintf(project->stream, "# Begin Target\n\n");
1031 fprintf(project->stream, "# Name \"%s - Win32 Release\"\n",
1033 fprintf(project->stream, "# Name \"%s - Win32 Debug\"\n", project->name);
1034 fprintf(project->stream, "# Begin Group \"Source Files\"\n\n");
1035 fprintf(project->stream,
1036 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1038 fprintf(project->stream, "# Begin Source File\n");
1039 fprintf(project->stream, "SOURCE=%s\\_%s.c\n", project->src_dir,
1041 fprintf(project->stream, "# End Source File\n\n");
1043 fprintf(project->stream, "# Begin Source File\n");
1044 fprintf(project->stream, "SOURCE=%s\\%s.c\n", project->src_dir, name);
1045 fprintf(project->stream, "# End Source File\n\n");
1047 fprintf(project->stream, "# End Group\n");
1048 fprintf(project->stream, "# Begin Group \"Header Files\"\n\n");
1049 fprintf(project->stream, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1050 fprintf(project->stream, "# End Group\n");
1051 fprintf(project->stream, "# Begin Group \"Resource Files\"\n\n");
1052 fprintf(project->stream,
1053 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1054 fprintf(project->stream, "# End Group\n");
1055 fprintf(project->stream, "# End Target\n");
1056 fprintf(project->stream, "# End Project\n");