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 /* specific to Borland Compiler */
16 #include "xbt/sysdep.h"
17 #include "xbt/function_types.h"
19 #include "surf/surfxml_parse.h"
20 #include "surf/surf.h"
24 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
28 /* tabulation level (used to indent the lines of the borland project file */
29 static unsigned int level = 0;
31 /* the library path for simgrid.lib and libras.lib. */
32 static char* __lib_dir = NULL;
34 /* the gras.h header directory */
35 static char* __gras_path = NULL;
43 * A structure which represents a borland project file.
45 typedef struct s_borland_project
47 const char* xml_version;/* the xml version used to write the borland project file */
48 const char* encoding; /* the encoding used to write the borland project file */
49 const char* comment; /* the xml comment to write at the begining of the borland project file */
50 char* name; /* the name of the borland project file */
51 FILE* stream; /* the stream to the borland project file */
52 const char* version; /* the builder version of the borland project file */
53 char* bin_dir; /* the directory used to store the generated program */
54 char* obj_dir; /* the directory used to store the generated object files */
55 char* lib_dir; /* the directory used to store the librairies used in the borland project */
56 char* src_dir; /* the directory use to store the source files of the project */
57 }s_borland_project_t,* borland_project_t;
60 * Write tabs in a borland project file.
61 * @param project The project concerned by the operation.
62 * @param count The count tab to write
65 borland_project_write_tabs(borland_project_t project,unsigned int count);
68 * Write the begin of an xml node in the borland project file.
69 * @param project The borland project concerned by this operation.
70 * @param name The name of the node.
73 borland_project_begin_xml_node(borland_project_t project, const char* name);
77 * Write the end of an xml node in the borland project file.
78 * @param project The borland project concerned by this operation.
79 * @param name The name of the node.
82 borland_project_end_xml_node(borland_project_t project, const char* name);
85 * Write an xml element in a borland project file.
86 * @param project The borland project concerned by this operation.
87 * @param name The name of the element to write
88 * @param value The value of the element
91 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
94 * Write a FILE xml element in the borland project file.
95 * @param project The borland project concerned by this operation.
96 * @param file_name The value of the attribute FILENAME.
97 * @param form_name The value of the attribute FORMNAME.
98 * @param unit_name The value of the attribute UNITNAME.
99 * @param container_id The value of the attribute CONTAINERID.
100 * @param design_claas The value of the attribute DESIGNCLASS.
101 * @param local_command The value of the attribute LOCALCOMMAND.
104 borland_project_write_file_element( borland_project_t project,
105 const char* file_name,
106 const char* form_name,
107 const char* unit_name,
108 const char* container_id,
109 const char* design_class,
110 const char* local_command);
112 * Write all options of the IDE of the Borland Builder C++ compiler.
113 * @ param project The project concerned by this operation.
117 borland_project_write_ide_options(borland_project_t project);
120 * Write the xml header of the xml document.
121 * @param project The project concerned by the operation.
124 borland_project_write_xml_header(borland_project_t project);
127 * Write an xml comment in a borland project file
128 * @param project The project concerned by this operation.
131 borland_project_write_xml_comment(borland_project_t project);
134 * Create a bpf file used by a borland project file.
135 * @param name The name of the bpf file to create.
138 borland_project_create_main_file(const char* name);
141 * Create a borland project file.
142 * @param project The project concerned by this operation.
145 borland_project_create(borland_project_t project);
148 * Close a borland project file.
149 * @param project the borland project file to close.
152 borland_project_close(borland_project_t project);
156 * Generate a borland simulation poject file.
157 * @param name The name of the simulation project
160 generate_borland_simulation_project(const char* name);
163 * Generate a borland project file for real life.
164 * @param name The name of the project to create.
167 generate_borland_real_life_project(const char* name);
170 * Generate a borland project file.
171 * @param project The borland project to generate.
174 generate_borland_project(borland_project_t project);
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);
190 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
191 #define SIM_SOURCENAME "_%s_simulator.c"
192 #define SIM_OBJNAME "_%s_simulator.o"
193 #define SIM_BINARYNAME "%s_simulator"
194 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
195 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
196 #define RL_SOURCENAME "_%s_%s.c"
197 #define RL_OBJNAME "_%s_%s.o"
198 #define RL_BINARYNAME "%s_%s"
199 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
200 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
201 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
202 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
203 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
204 #define DEPLOYMENT "%s.deploy.sh"
206 char *warning = NULL;
208 /**********************************************/
209 /**** Generate the file for the simulator *****/
210 /**********************************************/
212 const char *SIM_PREEMBULE =
213 "/* specific to Borland Compiler */\n"
214 "#ifdef __BORLANDC__\n"
217 "#include <stdlib.h>\n"
218 "#include <stdio.h>\n"
219 "#include \"msg/msg.h\"\n"
220 "#include <gras.h>\n"
222 "char *gras_log=NULL;\n";
225 #define SIM_LAUNCH_FUNC \
226 "int launch_%s(int argc, char **argv) {\n" \
227 " char **myargv=argv;\n" \
228 " int myargc=argc;\n" \
232 " if (gras_log) {\n"\
233 " myargv=malloc((argc+1) * sizeof(char**));\n" \
234 " for (i=0; i<argc; i++)\n" \
235 " myargv[i] = argv[i];\n" \
236 " myargv[myargc++] = gras_log;\n" \
238 " retcode = %s(myargc,myargv);\n" \
239 " if (myargv != argv)\n" \
241 " return retcode;\n" \
244 const char *SIM_MAIN_POSTEMBULE = "\n"
246 " MSG_launch_application(argv[2]);\n"
248 " /* Run the simulation */\n"
251 " /* cleanup the place */\n"
260 /**********************************************/
261 /********* Parse XML deployment file **********/
262 /**********************************************/
263 xbt_dict_t process_function_set = NULL;
264 xbt_dynar_t process_list = NULL;
265 xbt_dict_t machine_set = NULL;
267 typedef struct s_process_t {
273 static void s_process_free(void *process)
276 for(i=0;i<((s_process_t*)process)->argc; i++)
277 free(((s_process_t*)process)->argv[i]);
278 free(((s_process_t*)process)->host);
281 static s_process_t process;
284 * Création de deux dictionnaires
286 static void parse_process_init(void)
288 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
289 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
291 process.argv = xbt_new(char*,1);
292 process.argv[0] = xbt_strdup(A_surfxml_process_function);
293 process.host=strdup(A_surfxml_process_host);
294 /*VERB1("Function: %s",A_surfxml_process_function);*/
297 static void parse_argument(void)
300 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
301 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
304 static void parse_process_finalize(void)
306 xbt_dynar_push(process_list,&process);
307 /*VERB1("Function: %s",process.argv[0]);*/
310 static void generate_sim(char *project)
312 xbt_dict_cursor_t cursor=NULL;
315 char *filename = NULL;
319 * Creation d'un fichier nommé : <projet>_simulator.c
321 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
322 sprintf(filename,SIM_SOURCENAME,project);
324 OUT=fopen(filename,"w");
327 xbt_assert1(OUT, "Unable to open %s for writing",filename);
330 * Ecriture du message d'avertissement.
332 fprintf(OUT, "%s\n",warning);
335 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
337 fprintf(OUT, "%s", SIM_PREEMBULE);
340 * Déclaration des fonction int <process>(int argc,char *argv[]);
342 xbt_dict_foreach(process_function_set,cursor,key,data) {
343 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
349 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
351 xbt_dict_foreach(process_function_set,cursor,key,data) {
352 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
356 * Ecriture du message d'avertissement.
358 fprintf(OUT, "\n%s\n",warning);
360 xbt_dict_foreach(process_function_set,cursor,key,data) {
361 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
363 fprintf(OUT, "\n%s\n",warning);
365 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
366 "#ifdef __BORLANDDC__\n"
370 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
372 " /* Simulation setup */\n"
373 " MSG_global_init(&argc,argv);\n"
374 " if (argc != 3) {\n"
375 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
380 " MSG_paje_output(\"%s.trace\");\n"
381 " MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
382 " MSG_create_environment(argv[1]);\n"
384 " /* Application deployment */\n",
386 xbt_dict_foreach(process_function_set,cursor,key,data) {
387 fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key);
389 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
394 /**********************************************/
395 /**** Generate the file for the real life *****/
396 /**********************************************/
397 static void generate_rl(char *project)
399 xbt_dict_cursor_t cursor=NULL;
402 char *filename = NULL;
405 xbt_dict_foreach(process_function_set,cursor,key,data) {
406 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
407 sprintf(filename,RL_SOURCENAME,project,key);
409 OUT=fopen(filename,"w");
410 xbt_assert1(OUT, "Unable to open %s for writing",filename);
412 fprintf(OUT, "\n%s\n",warning);
413 fprintf(OUT, "/* specific to Borland Compiler */\n" \
414 "#ifdef __BORLANDC__\n" \
415 "#pragma hdrstop\n" \
417 "#include <stdio.h>\n" \
418 "#include <signal.h>\n" \
419 "#include <gras.h>\n" \
421 "extern const char *_gras_procname;\n" \
422 "/* user code */\n" \
423 "int %s(int argc, char *argv[]);\n" \
425 "/* specific to Borland Compiler */\n" \
426 "#ifdef __BORLANDC__\n" \
427 "#pragma argsused\n" \
429 "int main(int argc, char *argv[]){\n" \
432 " _gras_procname = \"%s\";\n" \
433 " errcode=%s(argc,argv);\n"\
435 " return errcode;\n"\
438 fprintf(OUT, "\n%s\n",warning);
444 static void generate_makefile_am(char *project, char *deployment)
446 xbt_dict_cursor_t cursor=NULL;
449 char *filename = NULL;
452 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
453 sprintf(filename,MAKEFILE_FILENAME_AM, project);
455 OUT=fopen(filename,"w");
456 xbt_assert1(OUT, "Unable to open %s for writing",filename);
458 fprintf(OUT, "# AUTOMAKE variable definition\n");
459 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
460 fprintf(OUT, "PROGRAMS=");
461 fprintf(OUT, SIM_BINARYNAME,project);
463 xbt_dict_foreach(process_function_set,cursor,key,data) {
465 fprintf(OUT, RL_BINARYNAME, project, key);
468 fprintf(OUT, "\n\n");
469 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
471 fprintf(OUT, SIM_SOURCENAME,project);
472 fprintf(OUT, " %s.c\n", project);
473 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
474 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
476 xbt_dict_foreach(process_function_set,cursor,key,data) {
477 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
479 fprintf(OUT, RL_SOURCENAME, project,key);
480 fprintf(OUT, " %s.c\n", project);
481 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
482 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
485 fprintf(OUT, "\n# cleanup temps\n");
486 fprintf(OUT, "CLEANFILES= ");
487 fprintf(OUT, SIM_SOURCENAME, project);
489 xbt_dict_foreach(process_function_set,cursor,key,data) {
491 fprintf(OUT, RL_SOURCENAME, project,key);
495 fprintf(OUT, "\n# generate temps\n");
496 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
498 xbt_dict_foreach(process_function_set,cursor,key,data) {
499 fprintf(OUT, RL_SOURCENAME, project,key);
502 fprintf(OUT, SIM_SOURCENAME, project);
503 fprintf(OUT, ": %s\n", deployment);
504 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
508 static void generate_makefile_local(char *project, char *deployment)
510 xbt_dict_cursor_t cursor=NULL;
513 char *filename = NULL;
516 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
517 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
519 OUT=fopen(filename,"w");
520 xbt_assert1(OUT, "Unable to open %s for writing",filename);
526 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
529 fprintf(OUT,"## Variable declarations\n"
531 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
535 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
536 "# Compilation will fail if you don't do so\n"
537 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
538 "# You can fiddle the following to make it fit your taste\n"
539 "INCLUDES = -I$(GRAS_ROOT)/include\n"
540 "CFLAGS ?= -O3 -w -g\n"
541 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
542 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
546 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
548 fprintf(OUT, "GENERATED_C_FILES = ");
549 fprintf(OUT, SIM_SOURCENAME" ",project);
550 xbt_dict_foreach(process_function_set,cursor,key,data) {
551 fprintf(OUT, RL_SOURCENAME " ",project, key);
555 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
557 fprintf(OUT, "BIN_FILES = ");
559 fprintf(OUT, SIM_BINARYNAME " ",project);
560 xbt_dict_foreach(process_function_set,cursor,key,data) {
561 fprintf(OUT, RL_BINARYNAME " ", project, key);
567 "## By default, build all the binaries\n"
568 "all: $(BIN_FILES)\n"
571 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
572 xbt_dict_foreach(process_function_set,cursor,key,data) {
573 fprintf(OUT, RL_SOURCENAME, project,key);
576 fprintf(OUT, SIM_SOURCENAME, project);
577 fprintf(OUT, ": %s\n", deployment);
578 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
580 fprintf(OUT, "\n## Generate the binaries\n");
581 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
582 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
583 xbt_dict_foreach(process_function_set,cursor,key,data) {
584 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
585 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
590 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
593 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
597 "##Â Rules for tarballs and cleaning\n"
598 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
599 "distdir: $(DIST_FILES)\n"
600 "\trm -rf $(DISTDIR)\n"
601 "\tmkdir -p $(DISTDIR)\n"
602 "\tcp $^ $(DISTDIR)\n"
604 "dist: clean distdir\n"
605 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
606 "\n", project /*, project*/);
610 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
611 xbt_dict_foreach(process_function_set,cursor,key,data) {
612 fprintf(OUT, " " RL_OBJNAME, project, key);
616 "\trm -rf $(DISTDIR)\n"
622 fprintf(OUT, "############ REMOTE COMPILING #########\n");
625 xbt_dict_foreach(machine_set,cursor,key,data) {
626 fprintf(OUT, "%s ",key);
631 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
632 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
634 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
635 "SIMGRID_VERSION ?=2.92\n"
636 "GRAS_PROJECT ?= %s\n"
637 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
640 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
641 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
642 "\t for site in $(MACHINES) ; do \\\n"
643 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
644 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
645 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
646 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
647 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
648 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
649 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
650 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
651 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
652 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
654 "\t machine=$$site;\\\n"
655 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
657 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
658 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
659 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
661 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
662 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
664 "\t echo \"-- Copy the data over\"; \\\n"
665 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
666 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
667 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
668 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
669 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
671 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
672 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
674 "\t done;\n",project,project,project);
679 static void generate_makefile_remote(char *project, char *deployment)
681 char *filename = NULL;
684 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
685 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
687 OUT=fopen(filename,"w");
688 xbt_assert1(OUT, "Unable to open %s for writing",filename);
691 "INSTALL_PATH ?= $(shell pwd)\n"
694 "\tcd $$GRAS_ROOT ; \\\n"
695 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
696 "\techo $$retrieved; \\\n"
697 "\tif test \"x$$retrieved\" = x; then \\\n"
698 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
699 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
700 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
701 "\t make all install ;\\\n"
704 "compile-gras: compile-simgrid\n"
705 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
706 "\techo $$not_retrieved; \\\n"
707 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
708 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
709 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
713 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
714 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
715 "\trm -rf gras-$(GRAS_PROJECT)*\n"
716 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
718 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
719 " compile-simgrid compile-gras\n"
725 static void generate_deployment(char *project, char *deployment)
727 xbt_dict_cursor_t cursor=NULL;
730 char *filename = NULL;
736 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
737 sprintf(filename,DEPLOYMENT, project);
739 OUT=fopen(filename,"w");
740 xbt_assert1(OUT, "Unable to open %s for writing",filename);
742 fprintf(OUT, "#!/bin/sh\n");
743 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
745 "if test \"${MACHINES+set}\" != set; then \n"
746 " export MACHINES='");
747 xbt_dict_foreach(machine_set,cursor,key,data) {
748 fprintf(OUT, "%s ",key);
753 "if test \"${INSTALL_PATH+set}\" != set; then \n"
754 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
756 "if test \"${GRAS_ROOT+set}\" != set; then \n"
757 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
759 "if test \"${SRCDIR+set}\" != set; then \n"
760 " export SRCDIR=./\n"
762 "if test \"${SIMGRID_URL+set}\" != set; then \n"
763 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
765 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
766 " export SIMGRID_VERSION=2.91\n"
768 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
769 " export GRAS_PROJECT=%s\n"
771 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
772 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
775 "test -e runlogs/ || mkdir -p runlogs/\n",
779 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
780 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
781 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
783 xbt_dynar_foreach (process_list,cpt,proc) {
784 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
785 for(i=1;i<proc.argc;i++) {
786 fprintf(OUT,"%s ",proc.argv[i]);
788 fprintf(OUT,"\";\n");
789 fprintf(OUT,"ssh %s \"$cmd_prolog 'export LD_LIBRARY_PATH=\\$INSTALL_PATH/lib:\\$LD_LIBRARY_PATH; echo \\\"$cmd\\\" ; $cmd 2>&1'\" > runlogs/%s_%d.log &\n",proc.host,proc.host,cpt);
795 static void print(void *p)
805 /* specific to Borland Compiler */
810 int main(int argc, char *argv[])
812 char *project_name = NULL;
813 char *deployment_file = NULL;
816 surf_init(&argc, argv);
818 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
820 project_name = argv[1];
822 process_function_set = xbt_dict_new();
823 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
824 machine_set = xbt_dict_new();
826 STag_surfxml_process_fun = parse_process_init;
827 ETag_surfxml_argument_fun = parse_argument;
828 ETag_surfxml_process_fun = parse_process_finalize;
830 for(i=2; i<argc; i++) {
831 deployment_file = argv[i];
832 surf_parse_open(deployment_file);
834 xbt_assert1(0,"Parse error in %s",deployment_file);
840 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
841 sprintf(warning,WARN,deployment_file);
843 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
844 xbt_dict_cursor_t cursor=NULL;
848 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
849 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
850 xbt_dict_cursor_step(cursor) ) {
851 DEBUG1("Function %s", key);
854 xbt_dict_dump(process_function_set,print);
857 generate_sim(project_name);
858 generate_rl(project_name);
859 generate_makefile_local(project_name, deployment_file);
861 generate_borland_simulation_project(project_name);
862 generate_borland_real_life_project(project_name);
868 xbt_free(__gras_path);
872 // generate_makefile_remote(project_name, deployment_file);
873 // generate_deployment(project_name, deployment_file);
881 generate_borland_project(borland_project_t project)
883 char* binary_path; /* the path of the generated binary file */
884 char* obj_path; /* the path of the generated object file */
885 char* lib_files; /* a list of the libraries used in the borland project */
886 char* main_source; /* the name of the bpf file used by the borland project */
887 char* file_name; /* the file name of the main source file */
888 char* include_path; /* the include path */
891 /* create the borland project file */
892 borland_project_create(project);
894 /* write the xml document header */
895 borland_project_write_xml_header(project);
897 /* write the xml comment to identify a borland project file */
898 borland_project_write_xml_comment(project);
900 /* write the begin of the node PROJECT */
901 borland_project_begin_xml_node(project,"PROJECT");
903 /* write the begin of node MACROS */
904 borland_project_begin_xml_node(project,"MACROS");
906 /* write the borland project version */
907 borland_project_write_xml_element(project,"VERSION",project->version);
909 /* construct and write the borland project binary path */
910 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
911 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
912 borland_project_write_xml_element(project,"PROJECT",binary_path);
913 xbt_free(binary_path);
915 /* construct an write the object files to generate by the compiler */
916 obj_path = xbt_new0(char,strlen(project->name) + strlen(project->obj_dir) + 6);
917 sprintf(binary_path,"%s\\%s.obj",project->obj_dir,project->name);
918 borland_project_write_xml_element(project,"OBJFILES",obj_path);
921 /* write the resource files used by the compiler (no resource file used) */
922 borland_project_write_xml_element(project,"RESFILES","");
924 /* write the IDL files of the project (no IDL files used) */
925 borland_project_write_xml_element(project,"IDLFILES","");
927 /* write the IDLGENFILES element (not used) */
928 borland_project_write_xml_element(project,"IDLGENFILES","");
930 /* write the DEFFILE element (not used) */
931 borland_project_write_xml_element(project,"DEFFILE","");
933 /* write the RESDEPEN element (not used, no resource file used) */
934 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
936 /* construct and write the list of libraries used by the project */
938 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
939 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
942 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
943 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
945 borland_project_write_xml_element(project,"LIBFILES",lib_files);
948 /* write the SPARELIBS element (not used) */
949 borland_project_write_xml_element(project,"SPARELIBS","");
951 /* write the PACKAGES element (no package used) */
952 borland_project_write_xml_element(project,"PACKAGES","");
954 /* write the PATHCPP element (the path of the source files of the project)*/
955 borland_project_write_xml_element(project,"PATHCPP",".;");
957 /* write the PATHPAS element (not used) */
958 borland_project_write_xml_element(project,"PATHPAS","");
960 /* write the PATHRC element (not used) */
961 borland_project_write_xml_element(project,"PATHRC","");
963 /* write the PATHASM element (not used) */
964 borland_project_write_xml_element(project,"PATHASM","");
966 /* write the DEBUGLIBPATH element (the path for debug) */
967 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
969 /* write the RELEASELIBPATH element (the path for release) */
970 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
972 /* specify the linker to use */
973 borland_project_write_xml_element(project,"LINKER","ilink32");
975 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
976 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
978 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
979 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
981 /* construct and write the MAINSOURCE element */
982 main_source = xbt_new0(char,strlen(project->name) + 5);
983 sprintf(main_source,"%s.bpf",project->name);
984 /* write the main source file to use in the borland project file */
985 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
987 /* create the bpf file used by the borland project */
988 borland_project_create_main_file(main_source);
990 /* FIXME resolve the include path */
991 /* write the INCLUDEPATH element */
994 __gras_path = xbt_new0(char,MAX_PATH);
995 find_file_path("C:\\","gras.h",__gras_path);
998 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
999 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1001 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1003 xbt_free(include_path);
1005 /* write the LIBPATH element (no librarie paths specified)*/
1006 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1009 * write the WARNINGS element :
1010 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1011 * -w-rvl (-w-8070) disabled the function must return warning
1012 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1013 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1014 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1015 * -w-par (-w-8057) disabled the warning that detect an unused variable
1016 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1017 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1018 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1020 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");
1022 /* write the OTHERFILES element (no other files used used) */
1023 borland_project_write_xml_element(project,"OTHERFILES","");
1025 /* write the end of the node MACROS */
1026 borland_project_end_xml_node(project,"MACROS");
1028 /* write the begin of the node OPTIONS */
1029 borland_project_begin_xml_node(project,"OPTIONS");
1031 /* FIXME check the idlcflags */
1032 /* write the IDLCFLAGS element */
1033 borland_project_write_xml_element(project,"IDLCFLAGS","");
1036 * write the CFLAG1 element (compiler options ) :
1038 * -Od this flag disable all compiler optimisation
1039 * -H this flag specify the name of the file which will contain the precompiled header
1040 * -Hc this flag specify to the compiler to cach the precompiled header
1041 * -Vx this flag specify to the compiler to allow the empty structures
1042 * -Ve this flag specify to the compiler to allow the empty base classes
1043 * -X- this flag activate the auto-depend informations of the compiler
1044 * -r- this flag disabled the use of the processor register
1045 * -a1 this flag specify that the data must be aligned on one byte
1046 * -b- this flag specify that the enums are the smallest size of the integer
1047 * -k (used during debug)
1048 * -y this flag generate the line number for debug
1049 * -v this flag enabled the debugging of the source files
1050 * -vi check the expansion of the inline functions
1051 * -tWC specify that it's a console application
1052 * -tWM- specify that the application is not multithread
1053 * -c generate the object file, no link
1055 borland_project_write_xml_element(project,"CFLAG1","-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a1 -b- -k -y -v -vi- -tWC -tWM- -c");
1057 /* write the PFLAGS element */
1058 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE -M");
1060 /* write the RFLAGS element */
1061 borland_project_write_xml_element(project,"RFLAGS","");
1063 /* write the AFLAGS element (assembler flags) :
1065 * /mx (not documented)
1066 * /w2 (not documented)
1067 * /zd (not documented)
1070 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1072 /* write the LFLAGS element (linker flags) :
1074 * -I specify the output directory for object files
1075 * -D register the specified description (no description "")
1076 * -ap build a win32 console application
1077 * -Tpe generate a exe file
1078 * -x do not create the map file
1079 * -Gn do not generate the state file
1080 * -v include the complete debug informations
1082 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1084 /* write the OTHERFILES element (not used)*/
1085 borland_project_write_xml_element(project,"OTHERFILES","");
1087 /* write the end of the node OPTIONS */
1088 borland_project_end_xml_node(project,"OPTIONS");
1090 /* write the begin of the node LINKER */
1091 borland_project_begin_xml_node(project,"LINKER");
1093 /* write the ALLOBJ element */
1094 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1096 /* write the ALLRES element (not used) */
1097 borland_project_write_xml_element(project,"ALLRES","");
1099 /* write the ALLLIB element */
1100 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1102 /* write the OTHERFILES element (not used) */
1103 borland_project_write_xml_element(project,"OTHERFILES","");
1105 /* write the end of the node LINKER */
1106 borland_project_end_xml_node(project,"LINKER");
1108 /* write the begin of the node FILELIST */
1109 borland_project_begin_xml_node(project,"FILELIST");
1111 /* construct and write the list of file elements */
1113 /* add the bpf file to the list */
1114 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1115 xbt_free(main_source);
1117 /* FIXME : check the source file directory */
1118 /* add the generated source file to the list */
1119 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 4);
1120 sprintf(file_name,"%s\\%s.c",project->src_dir,project->name);
1121 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1122 xbt_free(file_name);
1124 /* FIXME : check the libraries directory */
1125 /* add the simgrid library to the list */
1126 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1127 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1128 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1129 xbt_free(file_name);
1132 add the libgras library to the list
1134 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1135 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1137 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1138 xbt_free(file_name);
1141 /* write the end of the node FILELIST */
1142 borland_project_end_xml_node(project,"FILELIST");
1144 /* write the begin of the node BUILDTOOLS (not used)*/
1145 borland_project_begin_xml_node(project,"BUILDTOOLS");
1147 /* write the end of the node BUILDTOOLS (not used)*/
1148 borland_project_end_xml_node(project,"BUILDTOOLS");
1150 /* write the begin of the node IDEOPTIONS */
1151 borland_project_begin_xml_node(project,"IDEOPTIONS");
1153 /* write all of the option of the IDE of Borland C++ Builder */
1154 borland_project_write_ide_options(project);
1156 /* write the end of the node IDEOPTIONS */
1157 borland_project_end_xml_node(project,"IDEOPTIONS");
1159 /* write the end of the node PROJECT */
1160 borland_project_end_xml_node(project,"PROJECT");
1162 /* close the borland project file */
1163 borland_project_close(project);
1167 borland_project_write_tabs(borland_project_t project,unsigned int count)
1171 for(pos = 0; pos < count; pos++)
1172 fprintf(project->stream,"\t");
1176 borland_project_begin_xml_node(borland_project_t project, const char* name)
1179 borland_project_write_tabs(project,level);
1181 fprintf(project->stream,"<%s>\n",name);
1187 borland_project_end_xml_node(borland_project_t project, const char* name)
1192 borland_project_write_tabs(project,level);
1194 fprintf(project->stream,"</%s>\n",name);
1199 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1201 borland_project_write_tabs(project,level);
1203 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1207 borland_project_write_xml_header(borland_project_t project)
1209 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1213 borland_project_create_main_file(const char* name)
1215 FILE* stream = fopen(name,"w+");
1217 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1223 borland_project_create(borland_project_t project)
1225 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1226 sprintf(file_name,"%s.bpr",project->name);
1227 project->stream = fopen(file_name,"w+");
1228 xbt_free(file_name);
1232 borland_project_write_xml_comment(borland_project_t project)
1234 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1237 borland_project_write_file_element( borland_project_t project,
1238 const char* file_name,
1239 const char* form_name,
1240 const char* unit_name,
1241 const char* container_id,
1242 const char* design_class,
1243 const char* local_command)
1245 borland_project_write_tabs(project,level);
1247 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);
1251 borland_project_write_ide_options(borland_project_t project)
1254 const char* ide_options =
1255 "[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" \
1256 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1257 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1258 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1259 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1260 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1261 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1262 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1263 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1264 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1265 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1266 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1267 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1268 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1269 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1271 fprintf(project->stream,ide_options);
1275 borland_project_close(borland_project_t project)
1277 fclose(project->stream);
1281 generate_borland_simulation_project(const char* name)
1283 char buffer[MAX_PATH] = {0};
1286 WIN32_FIND_DATA wfd = {0};
1288 s_borland_project_t borland_project = {0};
1289 borland_project.xml_version = "1.0";
1290 borland_project.encoding ="utf-8";
1291 borland_project.comment ="C++Builder XML Project";
1292 borland_project.version = "BCB.06.00";
1294 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1297 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1298 __lib_dir = strdup(borland_project.lib_dir);
1301 borland_project.lib_dir = strdup(__lib_dir);
1303 GetCurrentDirectory(MAX_PATH,buffer);
1305 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1307 strcpy(borland_project.src_dir,buffer);
1309 borland_project.name = xbt_new0(char,strlen(name) + strlen("_simulator") + 2);
1310 sprintf(borland_project.name,"_%s_simulator",name);
1312 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1313 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1315 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1318 CreateDirectory(borland_project.bin_dir,NULL);
1320 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1321 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1323 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1325 if(INVALID_HANDLE_VALUE == hDir)
1326 CreateDirectory(borland_project.obj_dir,NULL);
1328 generate_borland_project(&borland_project);
1330 xbt_free(borland_project.name);
1331 xbt_free(borland_project.src_dir);
1332 xbt_free(borland_project.bin_dir);
1333 xbt_free(borland_project.obj_dir);
1334 xbt_free(borland_project.lib_dir);
1338 generate_borland_real_life_project(const char* name)
1341 WIN32_FIND_DATA wfd = {0};
1342 char buffer[MAX_PATH] = {0};
1343 xbt_dict_cursor_t cursor = NULL;
1346 s_borland_project_t borland_project = {0};
1348 borland_project.xml_version = "1.0";
1349 borland_project.encoding ="utf-8";
1350 borland_project.comment ="C++Builder XML Project";
1351 borland_project.version = "BCB.06.00";
1352 borland_project.lib_dir = " ";
1354 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1357 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1358 __lib_dir = strdup(borland_project.lib_dir);
1361 borland_project.lib_dir = strdup(__lib_dir);
1363 GetCurrentDirectory(MAX_PATH,buffer);
1365 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1367 strcpy(borland_project.src_dir,buffer);
1369 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1370 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1372 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1374 if(INVALID_HANDLE_VALUE == hDir)
1375 CreateDirectory(borland_project.bin_dir,NULL);
1377 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1378 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1380 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1383 CreateDirectory(borland_project.obj_dir,NULL);
1386 xbt_dict_foreach(process_function_set,cursor,key,data) {
1387 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 3);
1389 sprintf(borland_project.name,"_%s_%s",name,key);
1391 generate_borland_project(&borland_project);
1392 xbt_free(borland_project.name);
1395 xbt_free(borland_project.src_dir);
1396 xbt_free(borland_project.bin_dir);
1397 xbt_free(borland_project.obj_dir);
1398 xbt_free(borland_project.lib_dir);
1401 find_file_path(const char* root_dir,const char* file_name,char* path)
1404 WIN32_FIND_DATA wfd;
1405 char* prev_dir = xbt_new(char,MAX_PATH);
1406 GetCurrentDirectory(MAX_PATH,prev_dir);
1407 SetCurrentDirectory(root_dir);
1409 // begining of the scan
1410 hFind=FindFirstFile ("*.*", &wfd);
1412 if(hFind!=INVALID_HANDLE_VALUE){
1415 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1417 if(!strcmp(file_name,wfd.cFileName)){
1418 GetCurrentDirectory(MAX_PATH,path);
1419 SetCurrentDirectory(prev_dir);
1426 /* it's a directory, scan it*/
1429 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1430 if(find_file_path(wfd.cFileName,file_name,path)){
1432 SetCurrentDirectory(prev_dir);
1438 /* next file or directory */
1439 while(FindNextFile(hFind,&wfd))
1442 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1444 if(!strcmp(file_name,wfd.cFileName)){
1445 GetCurrentDirectory(MAX_PATH,path);
1446 SetCurrentDirectory(prev_dir);
1452 /* it's a file scan it */
1455 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1457 if(find_file_path(wfd.cFileName,file_name,path)){
1458 SetCurrentDirectory(prev_dir);
1469 SetCurrentDirectory(prev_dir);