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 {
48 const char *xml_version; /* the xml version used to write the borland project file */
49 const char *encoding; /* the encoding used to write the borland project file */
50 const char *comment; /* the xml comment to write at the begining of the borland project file */
51 char *name; /* the name of the borland project file */
52 FILE *stream; /* the stream to the borland project file */
53 const char *version; /* the builder version of the borland project file */
54 char *bin_dir; /* the directory used to store the generated program */
55 char *obj_dir; /* the directory used to store the generated object files */
56 char *lib_dir; /* the directory used to store the librairies used in the borland project */
57 char *src_dir; /* the directory use to store the source files of the project */
58 } s_borland_project_t, *borland_project_t;
62 * A structure which represents a visual C++ project file.
64 typedef struct s_dsp {
72 * Write tabs in a borland project file.
73 * @param project The project concerned by the operation.
74 * @param count The count tab to write
77 borland_project_write_tabs(borland_project_t project, unsigned int count);
80 * Write the begin of an xml node in the borland project file.
81 * @param project The borland project concerned by this operation.
82 * @param name The name of the node.
85 borland_project_begin_xml_node(borland_project_t project,
90 * Write the end of an xml node in the borland project file.
91 * @param project The borland project concerned by this operation.
92 * @param name The name of the node.
95 borland_project_end_xml_node(borland_project_t project, const char *name);
98 * Write an xml element in a borland project file.
99 * @param project The borland project concerned by this operation.
100 * @param name The name of the element to write
101 * @param value The value of the element
104 borland_project_write_xml_element(borland_project_t project,
105 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.
130 static void borland_project_write_ide_options(borland_project_t project);
133 * Write the xml header of the xml document.
134 * @param project The project concerned by the operation.
136 static void borland_project_write_xml_header(borland_project_t project);
139 * Write an xml comment in a borland project file
140 * @param project The project concerned by this operation.
142 static void borland_project_write_xml_comment(borland_project_t project);
145 * Create a bpf file used by a borland project file.
146 * @param name The name of the bpf file to create.
148 static void borland_project_create_main_file(const char *name);
151 * Create a borland project file.
152 * @param project The project concerned by this operation.
154 static void borland_project_create(borland_project_t project);
157 * Close a borland project file.
158 * @param project the borland project file to close.
160 static void borland_project_close(borland_project_t project);
164 * Generate a borland project file.
165 * @param project The borland project to generate.
168 generate_borland_project(borland_project_t project, int is_rl,
172 * Find the path of a file.
173 * @param file_name The file name to find.
174 * @path path If founded this parameter will contain the path of file.
175 * @return If successful the function returns 1. Otherwise the function
179 find_file_path(const char *root_dir, const char *file_name, char *path);
183 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
187 * generate a Microsoft Visual project file*/
188 static void generate_dsp_project(dsp_t project, int is_rl,
192 generate_borland_project(borland_project_t project, int is_rl,
195 char *binary_path; /* the path of the generated binary file */
196 char *obj_path; /* the path of the generated object file */
197 char *lib_files; /* a list of the libraries used in the borland project */
198 char *main_source; /* the name of the bpf file used by the borland project */
199 char *file_name; /* the file name of the main source file */
200 char *include_path; /* the include path */
203 /* create the borland project file */
204 borland_project_create(project);
206 /* write the xml document header */
207 borland_project_write_xml_header(project);
209 /* write the xml comment to identify a borland project file */
210 borland_project_write_xml_comment(project);
212 /* write the begin of the node PROJECT */
213 borland_project_begin_xml_node(project, "PROJECT");
215 /* write the begin of node MACROS */
216 borland_project_begin_xml_node(project, "MACROS");
218 /* write the borland project version */
219 borland_project_write_xml_element(project, "VERSION", project->version);
221 /* construct and write the borland project binary path */
223 xbt_new0(char, strlen(project->name) + strlen(project->bin_dir) + 6);
224 sprintf(binary_path, "%s\\%s.exe", project->bin_dir, project->name);
225 borland_project_write_xml_element(project, "PROJECT", binary_path);
226 xbt_free(binary_path);
228 /* construct an write the object files to generate by the compiler */
231 strlen(project->name) + strlen(name) +
232 (2 * strlen(project->obj_dir)) + 11);
233 sprintf(binary_path, "%s\\%s.obj\n%s\\%s.obj", project->obj_dir,
234 project->name, project->obj_dir, name);
235 borland_project_write_xml_element(project, "OBJFILES", obj_path);
238 /* write the resource files used by the compiler (no resource file used) */
239 borland_project_write_xml_element(project, "RESFILES", "");
241 /* write the IDL files of the project (no IDL files used) */
242 borland_project_write_xml_element(project, "IDLFILES", "");
244 /* write the IDLGENFILES element (not used) */
245 borland_project_write_xml_element(project, "IDLGENFILES", "");
247 /* write the DEFFILE element (not used) */
248 borland_project_write_xml_element(project, "DEFFILE", "");
250 /* write the RESDEPEN element (not used, no resource file used) */
251 borland_project_write_xml_element(project, "RESDEPEN", "$(RESFILES)");
253 /* construct and write the list of libraries used by the project */
255 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
256 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
262 (2 * (strlen(project->lib_dir) + 1)) +
263 strlen("libgras.lib") + 2);
264 sprintf(lib_files, "%s\\libgras.lib", project->lib_dir);
268 (2 * (strlen(project->lib_dir) + 1)) +
269 strlen("simgrid.lib") + 2);
270 sprintf(lib_files, "%s\\simgrid.lib", project->lib_dir);
273 borland_project_write_xml_element(project, "LIBFILES", lib_files);
276 /* write the SPARELIBS element (not used) */
277 borland_project_write_xml_element(project, "SPARELIBS", "");
279 /* write the PACKAGES element (no package used) */
280 borland_project_write_xml_element(project, "PACKAGES", "");
282 /* write the PATHCPP element (the path of the source files of the project) */
283 borland_project_write_xml_element(project, "PATHCPP", ".;");
285 /* write the PATHPAS element (not used) */
286 borland_project_write_xml_element(project, "PATHPAS", "");
288 /* write the PATHRC element (not used) */
289 borland_project_write_xml_element(project, "PATHRC", "");
291 /* write the PATHASM element (not used) */
292 borland_project_write_xml_element(project, "PATHASM", "");
294 /* write the DEBUGLIBPATH element (the path for debug) */
295 borland_project_write_xml_element(project, "DEBUGLIBPATH",
296 "$(BCB)\\lib\\debug");
298 /* write the RELEASELIBPATH element (the path for release) */
299 borland_project_write_xml_element(project, "RELEASELIBPATH",
300 "$(BCB)\\lib\\release");
302 /* specify the linker to use */
303 borland_project_write_xml_element(project, "LINKER", "ilink32");
305 /* write the USERDEFINES element (user definitions (#define _DEBUG)) */
306 borland_project_write_xml_element(project, "USERDEFINES", "_DEBUG");
308 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL) */
309 borland_project_write_xml_element(project, "SYSDEFINES",
310 "NO_STRICT;_NO_VCL");
312 /* construct and write the MAINSOURCE element */
313 main_source = xbt_new0(char, strlen(project->name) + 5);
314 sprintf(main_source, "%s.bpf", project->name);
315 /* write the main source file to use in the borland project file */
316 borland_project_write_xml_element(project, "MAINSOURCE", main_source);
318 /* create the bpf file used by the borland project */
319 borland_project_create_main_file(main_source);
321 /* FIXME resolve the include path */
322 /* write the INCLUDEPATH element */
325 buffer = xbt_new0(char, MAX_PATH);
326 GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
328 __gras_path = xbt_new0(char, MAX_PATH);
329 sprintf(__gras_path, "%s\\simgrid\\include", buffer);
332 /*find_file_path("C:\\","gras.h",__gras_path); */
336 xbt_new0(char, strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
337 sprintf(include_path, "$(BCB)\\include;%s", __gras_path);
339 borland_project_write_xml_element(project, "INCLUDEPATH", include_path);
341 xbt_free(include_path);
343 /* write the LIBPATH element (no librarie paths specified) */
344 borland_project_write_xml_element(project, "LIBPATH",
345 "$(BCB)\\lib;$(BCB)\\lib\\obj");
348 * write the WARNINGS element :
349 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
350 * -w-rvl (-w-8070) disabled the function must return warning
351 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
352 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
353 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
354 * -w-par (-w-8057) disabled the warning that detect an unused variable
355 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
356 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
357 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
359 borland_project_write_xml_element(project, "WARNINGS",
360 "-w-sus -w-rvl -w-rch -w-pia -w-pch -w-par -w-csu -w-ccc -w-aus");
362 /* write the OTHERFILES element (no other files used used) */
363 borland_project_write_xml_element(project, "OTHERFILES", "");
365 /* write the end of the node MACROS */
366 borland_project_end_xml_node(project, "MACROS");
368 /* write the begin of the node OPTIONS */
369 borland_project_begin_xml_node(project, "OPTIONS");
371 /* FIXME check the idlcflags */
372 /* write the IDLCFLAGS element */
373 borland_project_write_xml_element(project, "IDLCFLAGS", "");
376 * write the CFLAG1 element (compiler options ) :
378 * -Od this flag disable all compiler optimisation
379 * -H this flag specify the name of the file which will contain the precompiled header
380 * -Hc this flag specify to the compiler to cach the precompiled header
381 * -Vx this flag specify to the compiler to allow the empty structures
382 * -Ve this flag specify to the compiler to allow the empty base classes
383 * -X- this flag activate the auto-depend informations of the compiler
384 * -r- this flag disabled the use of the processor register
385 * -a1 this flag specify that the data must be aligned on one byte
386 * -b- this flag specify that the enums are the smallest size of the integer
387 * -k (used during debug)
388 * -y this flag generate the line number for debug
389 * -v this flag enabled the debugging of the source files
390 * -vi check the expansion of the inline functions
391 * -tWC specify that it's a console application
392 * -tWM- specify that the application is not multithread
393 * -c generate the object file, no link
395 borland_project_write_xml_element(project, "CFLAG1",
396 "-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
398 /* write the PFLAGS element */
399 borland_project_write_xml_element(project, "PFLAGS",
400 "-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
402 /* write the RFLAGS element */
403 borland_project_write_xml_element(project, "RFLAGS", "");
405 /* write the AFLAGS element (assembler flags) :
407 * /mx (not documented)
408 * /w2 (not documented)
409 * /zd (not documented)
412 borland_project_write_xml_element(project, "AFLAGS", "/mx /w2 /zd");
414 /* write the LFLAGS element (linker flags) :
416 * -I specify the output directory for object files
417 * -D register the specified description (no description "")
418 * -ap build a win32 console application
419 * -Tpe generate a exe file
420 * -x do not create the map file
421 * -Gn do not generate the state file
422 * -v include the complete debug informations
424 borland_project_write_xml_element(project, "LFLAGS",
425 "-Iobj -D"" -ap -Tpe -x -Gn -v");
427 /* write the OTHERFILES element (not used) */
428 borland_project_write_xml_element(project, "OTHERFILES", "");
430 /* write the end of the node OPTIONS */
431 borland_project_end_xml_node(project, "OPTIONS");
433 /* write the begin of the node LINKER */
434 borland_project_begin_xml_node(project, "LINKER");
436 /* write the ALLOBJ element */
437 borland_project_write_xml_element(project, "ALLOBJ",
438 "c0x32.obj $(OBJFILES)");
440 /* write the ALLRES element (not used) */
441 borland_project_write_xml_element(project, "ALLRES", "");
443 /* write the ALLLIB element */
444 borland_project_write_xml_element(project, "ALLLIB",
445 "$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
447 /* write the OTHERFILES element (not used) */
448 borland_project_write_xml_element(project, "OTHERFILES", "");
450 /* write the end of the node LINKER */
451 borland_project_end_xml_node(project, "LINKER");
453 /* write the begin of the node FILELIST */
454 borland_project_begin_xml_node(project, "FILELIST");
456 /* construct and write the list of file elements */
458 /* add the bpf file to the list */
459 borland_project_write_file_element(project, main_source, "",
460 project->name, "BPF", "", "");
461 xbt_free(main_source);
463 /* FIXME : check the source file directory */
464 /* add the generated source file to the list */
467 xbt_new0(char, strlen(project->src_dir) + strlen(project->name) + 5);
468 sprintf(file_name, "%s\\_%s.c", project->src_dir, project->name);
469 borland_project_write_file_element(project, file_name, "", project->name,
470 "CCompiler", "", "");
473 strlen(project->src_dir) + strlen(project->name) + 4);
474 sprintf(file_name, "%s\\%s.c", project->src_dir, name);
475 borland_project_write_file_element(project, file_name, "", name,
476 "CCompiler", "", "");
480 /* FIXME : check the libraries directory */
481 /* add the simgrid library to the list */
486 strlen(project->lib_dir) + strlen("libgras.lib") + 2);
487 sprintf(file_name, "%s\\libgras.lib", project->lib_dir);
488 borland_project_write_file_element(project, file_name, "",
489 "libgras.lib", "LibTool", "", "");
493 strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
494 sprintf(file_name, "%s\\simgrid.lib", project->lib_dir);
495 borland_project_write_file_element(project, file_name, "",
496 "simgrid.lib", "LibTool", "", "");
502 /* write the end of the node FILELIST */
503 borland_project_end_xml_node(project, "FILELIST");
505 /* write the begin of the node BUILDTOOLS (not used) */
506 borland_project_begin_xml_node(project, "BUILDTOOLS");
508 /* write the end of the node BUILDTOOLS (not used) */
509 borland_project_end_xml_node(project, "BUILDTOOLS");
511 /* write the begin of the node IDEOPTIONS */
512 borland_project_begin_xml_node(project, "IDEOPTIONS");
514 /* write all of the option of the IDE of Borland C++ Builder */
515 borland_project_write_ide_options(project);
517 /* write the end of the node IDEOPTIONS */
518 borland_project_end_xml_node(project, "IDEOPTIONS");
520 /* write the end of the node PROJECT */
521 borland_project_end_xml_node(project, "PROJECT");
523 /* close the borland project file */
524 borland_project_close(project);
527 void borland_project_write_tabs(borland_project_t project,
532 for (pos = 0; pos < count; pos++)
533 fprintf(project->stream, "\t");
537 borland_project_begin_xml_node(borland_project_t project, const char *name)
540 borland_project_write_tabs(project, level);
542 fprintf(project->stream, "<%s>\n", name);
547 void borland_project_end_xml_node(borland_project_t project,
553 borland_project_write_tabs(project, level);
555 fprintf(project->stream, "</%s>\n", name);
560 borland_project_write_xml_element(borland_project_t project,
561 const char *name, const char *value)
563 borland_project_write_tabs(project, level);
564 fprintf(project->stream, "<%s value=\"%s\"/>\n", name, value);
567 void borland_project_write_xml_header(borland_project_t project)
569 fprintf(project->stream, "<?xml version='%s' encoding='%s' ?>\n",
570 project->xml_version, project->encoding);
573 void borland_project_create_main_file(const char *name)
575 FILE *stream = fopen(name, "w+");
578 "Ce fichier est uniquement utilis� par le gestionnaire de projets et doit �tre trait� comme le fichier projet\n\n\nmain\n");
583 void borland_project_create(borland_project_t project)
585 char *file_name = xbt_new0(char, strlen(project->name) + 5);
586 sprintf(file_name, "%s.bpr", project->name);
587 project->stream = fopen(file_name, "w+");
591 void borland_project_write_xml_comment(borland_project_t project)
593 fprintf(project->stream, "<!-- %s -->\n", project->comment);
597 borland_project_write_file_element(borland_project_t project,
598 const char *file_name,
599 const char *form_name,
600 const char *unit_name,
601 const char *container_id,
602 const char *design_class,
603 const char *local_command)
605 borland_project_write_tabs(project, level);
607 fprintf(project->stream,
608 "<FILE FILENAME=\"%s\" FORMNAME=\"%s\" UNITNAME=\"%s\" CONTAINERID=\"%s\" DESIGNCLASS=\"%s\" LOCALCOMMAND=\"%s\"/>\n",
609 file_name, form_name, unit_name, container_id, design_class,
613 void borland_project_write_ide_options(borland_project_t project)
616 const char *ide_options =
617 "[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"
618 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n"
619 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n"
620 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n"
621 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n"
622 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n"
623 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n"
624 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n"
625 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n"
626 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n"
627 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n"
628 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n"
629 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n"
630 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n"
631 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
633 fprintf(project->stream, ide_options);
636 void borland_project_close(borland_project_t project)
638 fclose(project->stream);
641 void generate_borland_simulation_project(const char *name)
643 char buffer[MAX_PATH] = { 0 };
646 WIN32_FIND_DATA wfd = { 0 };
648 s_borland_project_t borland_project = { 0 };
649 borland_project.xml_version = "1.0";
650 borland_project.encoding = "utf-8";
651 borland_project.comment = "C++Builder XML Project";
652 borland_project.version = "BCB.06.00";
654 borland_project.lib_dir = xbt_new0(char, MAX_PATH);
657 GetEnvironmentVariable("LIB_SIMGRID_PATH", borland_project.lib_dir,
661 GetCurrentDirectory(MAX_PATH, buffer);
663 borland_project.src_dir = xbt_new0(char, strlen(buffer) + 1);
665 strcpy(borland_project.src_dir, buffer);
667 borland_project.name =
668 xbt_new0(char, strlen(name) + strlen("simulator") + 2);
669 sprintf(borland_project.name, "%s_simulator", name);
671 borland_project.bin_dir =
672 xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
673 sprintf(borland_project.bin_dir, "%s\\bin", buffer);
675 hDir = FindFirstFile(borland_project.bin_dir, &wfd);
678 CreateDirectory(borland_project.bin_dir, NULL);
680 borland_project.obj_dir =
681 xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
682 sprintf(borland_project.obj_dir, "%s\\obj", buffer);
684 hDir = FindFirstFile(borland_project.obj_dir, &wfd);
686 if (INVALID_HANDLE_VALUE == hDir)
687 CreateDirectory(borland_project.obj_dir, NULL);
689 generate_borland_project(&borland_project, 0, name);
691 xbt_free(borland_project.name);
692 xbt_free(borland_project.src_dir);
693 xbt_free(borland_project.bin_dir);
694 xbt_free(borland_project.obj_dir);
695 xbt_free(borland_project.lib_dir);
698 void generate_borland_real_life_project(const char *name)
701 WIN32_FIND_DATA wfd = { 0 };
702 char buffer[MAX_PATH] = { 0 };
703 xbt_dict_cursor_t cursor = NULL;
706 s_borland_project_t borland_project = { 0 };
708 borland_project.xml_version = "1.0";
709 borland_project.encoding = "utf-8";
710 borland_project.comment = "C++Builder XML Project";
711 borland_project.version = "BCB.06.00";
713 borland_project.lib_dir = xbt_new0(char, MAX_PATH);
715 GetEnvironmentVariable("LIB_GRAS_PATH", borland_project.lib_dir,
718 GetCurrentDirectory(MAX_PATH, buffer);
720 borland_project.src_dir = xbt_new0(char, strlen(buffer) + 1);
722 strcpy(borland_project.src_dir, buffer);
724 borland_project.bin_dir =
725 xbt_new0(char, strlen(buffer) + strlen("\\bin") + 1);
726 sprintf(borland_project.bin_dir, "%s\\bin", buffer);
728 hDir = FindFirstFile(borland_project.bin_dir, &wfd);
730 if (INVALID_HANDLE_VALUE == hDir)
731 CreateDirectory(borland_project.bin_dir, NULL);
733 borland_project.obj_dir =
734 xbt_new0(char, strlen(buffer) + strlen("\\obj") + 1);
735 sprintf(borland_project.obj_dir, "%s\\obj", buffer);
737 hDir = FindFirstFile(borland_project.obj_dir, &wfd);
740 CreateDirectory(borland_project.obj_dir, NULL);
743 xbt_dict_foreach(process_function_set, cursor, key, data) {
744 borland_project.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
746 sprintf(borland_project.name, "%s_%s", name, key);
748 generate_borland_project(&borland_project, 1, name);
749 xbt_free(borland_project.name);
752 xbt_free(borland_project.src_dir);
753 xbt_free(borland_project.bin_dir);
754 xbt_free(borland_project.obj_dir);
755 xbt_free(borland_project.lib_dir);
758 int find_file_path(const char *root_dir, const char *file_name, char *path)
762 char *prev_dir = xbt_new(char, MAX_PATH);
763 GetCurrentDirectory(MAX_PATH, prev_dir);
764 SetCurrentDirectory(root_dir);
766 // begining of the scan
767 hFind = FindFirstFile("*.*", &wfd);
769 if (hFind != INVALID_HANDLE_VALUE) {
772 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
774 if (!strcmp(file_name, wfd.cFileName)) {
775 GetCurrentDirectory(MAX_PATH, path);
776 SetCurrentDirectory(prev_dir);
783 /* it's a directory, scan it */
786 if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
787 if (find_file_path(wfd.cFileName, file_name, path)) {
789 SetCurrentDirectory(prev_dir);
795 /* next file or directory */
796 while (FindNextFile(hFind, &wfd)) {
798 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
799 if (!strcmp(file_name, wfd.cFileName)) {
800 GetCurrentDirectory(MAX_PATH, path);
801 SetCurrentDirectory(prev_dir);
807 /* it's a file scan it */
810 if (strcmp(wfd.cFileName, ".") && strcmp(wfd.cFileName, "..")) {
812 if (find_file_path(wfd.cFileName, file_name, path)) {
813 SetCurrentDirectory(prev_dir);
824 SetCurrentDirectory(prev_dir);
830 /* Implementation of the functions used to create a Visual C++ project.*/
832 int generate_simulation_dsp_file(const char *name)
834 char buffer[MAX_PATH] = { 0 };
836 dsp.lib_dir = xbt_new0(char, MAX_PATH);
838 GetEnvironmentVariable("LIB_SIMGRID_PATH", dsp.lib_dir, MAX_PATH);
839 GetCurrentDirectory(MAX_PATH, buffer);
841 dsp.src_dir = xbt_new0(char, strlen(buffer) + 1);
842 strcpy(dsp.src_dir, buffer);
843 dsp.name = xbt_new0(char, strlen(name) + strlen("simulator") + 2);
844 sprintf(dsp.name, "%s_simulator", name);
846 generate_dsp_project(&dsp, 0, name);
849 xbt_free(dsp.src_dir);
850 xbt_free(dsp.lib_dir);
856 * Create the Microsoft visual C++ real life project file.
858 int generate_real_live_dsp_file(const char *name)
861 char buffer[MAX_PATH] = { 0 };
862 xbt_dict_cursor_t cursor = NULL;
868 dsp.lib_dir = xbt_new0(char, MAX_PATH);
870 GetEnvironmentVariable("LIB_GRAS_PATH", dsp.lib_dir, MAX_PATH);
872 GetCurrentDirectory(MAX_PATH, buffer);
874 dsp.src_dir = xbt_new0(char, strlen(buffer) + 1);
876 strcpy(dsp.src_dir, buffer);
879 xbt_dict_foreach(process_function_set, cursor, key, data) {
880 dsp.name = xbt_new0(char, strlen(name) + strlen(key) + 2);
882 sprintf(dsp.name, "%s_%s", name, key);
884 generate_dsp_project(&dsp, 1, name);
888 xbt_free(dsp.src_dir);
889 xbt_free(dsp.lib_dir);
893 void generate_dsp_project(dsp_t project, int is_rl, const char *name)
895 /* create the visual C++ project file */
897 char *file_name = xbt_new0(char, strlen(project->name) + 5);
898 sprintf(file_name, "%s.dsp", project->name);
899 project->stream = fopen(file_name, "w+");
903 buffer = xbt_new0(char, MAX_PATH);
904 GetEnvironmentVariable("SG_INSTALL_DIR", buffer, MAX_PATH);
906 __gras_path = xbt_new0(char, MAX_PATH);
907 sprintf(__gras_path, "%s\\simgrid\\include", buffer);
911 /* dsp file header */
912 fprintf(project->stream,
913 "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",
915 fprintf(project->stream,
916 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
917 fprintf(project->stream, "# ** DO NOT EDIT **\n\n");
919 /* target type is a win32 x86 console application */
920 fprintf(project->stream,
921 "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
923 /* the current config is win32-debug */
924 fprintf(project->stream, "CFG=%s - Win32 Debug\n", project->name);
927 fprintf(project->stream,
928 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
931 fprintf(project->stream,
932 "!MESSAGE use the Export Makefile command and run\n");
933 fprintf(project->stream, "!MESSAGE\n");
934 fprintf(project->stream, "!MESSAGE NMAKE /f \"%s.mak\".\n",
936 fprintf(project->stream, "!MESSAGE\n");
937 fprintf(project->stream,
938 "!MESSAGE You can specify a configuration when running NMAKE\n");
939 fprintf(project->stream,
940 "!MESSAGE by defining the macro CFG on the command line. For example:\n");
941 fprintf(project->stream, "!MESSAGE\n");
942 fprintf(project->stream,
943 "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",
944 project->name, project->name);
945 fprintf(project->stream, "!MESSAGE\n");
946 fprintf(project->stream,
947 "!MESSAGE Possible choices for configuration are:\n");
948 fprintf(project->stream, "!MESSAGE\n");
949 fprintf(project->stream,
950 "!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",
952 fprintf(project->stream,
953 "!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",
955 fprintf(project->stream, "!MESSAGE\n\n");
957 fprintf(project->stream, "# Begin Project\n\n");
958 fprintf(project->stream, "# PROP AllowPerConfigDependencies 0\n");
959 fprintf(project->stream, "# PROP Scc_ProjName\n");
960 fprintf(project->stream, "# PROP Scc_LocalPath\n");
961 fprintf(project->stream, "CPP=cl.exe\n");
962 fprintf(project->stream, "RSC=rc.exe\n\n");
964 fprintf(project->stream, "!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",
967 fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
968 fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 0\n");
969 fprintf(project->stream, "# PROP BASE Output_Dir \"Release\"\n");
970 fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Release\"\n");
971 fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
972 fprintf(project->stream, "# PROP Use_MFC 0\n");
973 fprintf(project->stream, "# PROP Use_Debug_Libraries 0\n");
974 fprintf(project->stream, "# PROP Output_Dir \"Release\"\n");
975 fprintf(project->stream, "# PROP Intermediate_Dir \"Release\"\n");
976 fprintf(project->stream, "# PROP Target_Dir \"\"\n");
977 /* TODO : the include directory */
978 /*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); */
979 fprintf(project->stream,
980 "# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",
982 fprintf(project->stream,
983 "# ADD CPP /nologo /W3 /GX /O2 /D \"_XBT_WIN32\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
984 fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
985 fprintf(project->stream, "# ADD RSC /l 0x40c /d \"NDEBUG\n");
986 fprintf(project->stream, "BSC32=bscmake.exe\n");
987 fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
988 fprintf(project->stream, "# ADD BSC32 /nologo\n");
989 fprintf(project->stream, "LINK32=link.exe\n");
990 fprintf(project->stream,
991 "# 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");
994 fprintf(project->stream,
995 "# 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");
997 fprintf(project->stream,
998 "# 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");
1000 fprintf(project->stream, "!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",
1003 fprintf(project->stream, "# PROP BASE Use_MFC 0\n");
1004 fprintf(project->stream, "# PROP BASE Use_Debug_Libraries 1\n");
1005 fprintf(project->stream, "# PROP BASE Output_Dir \"Debug\"\n");
1006 fprintf(project->stream, "# PROP BASE Intermediate_Dir \"Debug\"\n");
1007 fprintf(project->stream, "# PROP BASE Target_Dir \"\"\n");
1008 fprintf(project->stream, "# PROP Use_MFC 0\n");
1009 fprintf(project->stream, "# PROP Use_Debug_Libraries 1\n");
1010 fprintf(project->stream, "# PROP Output_Dir \"Debug\"\n");
1011 fprintf(project->stream, "# PROP Intermediate_Dir \"Debug\"\n");
1012 fprintf(project->stream, "# PROP Ignore_Export_Lib 0\n");
1013 fprintf(project->stream, "# PROP Target_Dir \"\"\n");
1014 /* TODO : the include directory */
1015 /*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); */
1016 fprintf(project->stream,
1017 "# 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",
1019 fprintf(project->stream,
1020 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"_XBT_WIN32\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1021 fprintf(project->stream, "# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1022 fprintf(project->stream, "# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1023 fprintf(project->stream, "BSC32=bscmake.exe\n");
1024 fprintf(project->stream, "# ADD BASE BSC32 /nologo\n");
1025 fprintf(project->stream, "# ADD BSC32 /nologo\n");
1026 fprintf(project->stream, "LINK32=link.exe\n");
1027 fprintf(project->stream,
1028 "# 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");
1031 fprintf(project->stream,
1032 "# 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");
1034 fprintf(project->stream,
1035 "# 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");
1037 fprintf(project->stream, "!ENDIF\n\n");
1039 fprintf(project->stream, "# Begin Target\n\n");
1040 fprintf(project->stream, "# Name \"%s - Win32 Release\"\n",
1042 fprintf(project->stream, "# Name \"%s - Win32 Debug\"\n", project->name);
1043 fprintf(project->stream, "# Begin Group \"Source Files\"\n\n");
1044 fprintf(project->stream,
1045 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1047 fprintf(project->stream, "# Begin Source File\n");
1048 fprintf(project->stream, "SOURCE=%s\\_%s.c\n", project->src_dir,
1050 fprintf(project->stream, "# End Source File\n\n");
1052 fprintf(project->stream, "# Begin Source File\n");
1053 fprintf(project->stream, "SOURCE=%s\\%s.c\n", project->src_dir, name);
1054 fprintf(project->stream, "# End Source File\n\n");
1056 fprintf(project->stream, "# End Group\n");
1057 fprintf(project->stream, "# Begin Group \"Header Files\"\n\n");
1058 fprintf(project->stream, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1059 fprintf(project->stream, "# End Group\n");
1060 fprintf(project->stream, "# Begin Group \"Resource Files\"\n\n");
1061 fprintf(project->stream,
1062 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1063 fprintf(project->stream, "# End Group\n");
1064 fprintf(project->stream, "# End Target\n");
1065 fprintf(project->stream, "# End Project\n");