1 //---------------------------------------------------------------------------
3 /* specific to Borland Compiler */
10 /* gras_stub_generator - creates the main() to use a GRAS program */
12 /* Copyright (c) 2003,2004,2005 Martin Quinson, Arnaud Legrand.
13 All rights reserved. */
15 /* This program is free software; you can redistribute it and/or modify it
16 * under the terms of the license (GNU LGPL) which comes with this package. */
20 #include "xbt/sysdep.h"
21 #include "xbt/function_types.h"
23 #include "surf/surfxml_parse.h"
24 #include "surf/surf.h"
28 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
32 /* tabulation level (used to indent the lines of the borland project file */
33 static unsigned int level = 0;
35 /* the library path for simgrid.lib and libras.lib. */
36 static char* __lib_dir = NULL;
38 /* the gras.h header directory */
39 static char* __gras_path = NULL;
47 * A structure which represents a borland project file.
49 typedef struct s_borland_project
51 const char* xml_version;/* the xml version used to write the borland project file */
52 const char* encoding; /* the encoding used to write the borland project file */
53 const char* comment; /* the xml comment to write at the begining of the borland project file */
54 char* name; /* the name of the borland project file */
55 FILE* stream; /* the stream to the borland project file */
56 const char* version; /* the builder version of the borland project file */
57 char* bin_dir; /* the directory used to store the generated program */
58 char* obj_dir; /* the directory used to store the generated object files */
59 char* lib_dir; /* the directory used to store the librairies used in the borland project */
60 char* src_dir; /* the directory use to store the source files of the project */
61 }s_borland_project_t,* borland_project_t;
64 * Write tabs in a borland project file.
65 * @param project The project concerned by the operation.
66 * @param count The count tab to write
69 borland_project_write_tabs(borland_project_t project,unsigned int count);
72 * Write the begin of an xml node in the borland project file.
73 * @param project The borland project concerned by this operation.
74 * @param name The name of the node.
77 borland_project_begin_xml_node(borland_project_t project, const char* name);
81 * Write the end of an xml node in the borland project file.
82 * @param project The borland project concerned by this operation.
83 * @param name The name of the node.
86 borland_project_end_xml_node(borland_project_t project, const char* name);
89 * Write an xml element in a borland project file.
90 * @param project The borland project concerned by this operation.
91 * @param name The name of the element to write
92 * @param value The value of the element
95 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
98 * Write a FILE xml element in the borland project file.
99 * @param project The borland project concerned by this operation.
100 * @param file_name The value of the attribute FILENAME.
101 * @param form_name The value of the attribute FORMNAME.
102 * @param unit_name The value of the attribute UNITNAME.
103 * @param container_id The value of the attribute CONTAINERID.
104 * @param design_claas The value of the attribute DESIGNCLASS.
105 * @param local_command The value of the attribute LOCALCOMMAND.
108 borland_project_write_file_element( borland_project_t project,
109 const char* file_name,
110 const char* form_name,
111 const char* unit_name,
112 const char* container_id,
113 const char* design_class,
114 const char* local_command);
116 * Write all options of the IDE of the Borland Builder C++ compiler.
117 * @ param project The project concerned by this operation.
121 borland_project_write_ide_options(borland_project_t project);
124 * Write the xml header of the xml document.
125 * @param project The project concerned by the operation.
128 borland_project_write_xml_header(borland_project_t project);
131 * Write an xml comment in a borland project file
132 * @param project The project concerned by this operation.
135 borland_project_write_xml_comment(borland_project_t project);
138 * Create a bpf file used by a borland project file.
139 * @param name The name of the bpf file to create.
142 borland_project_create_main_file(const char* name);
145 * Create a borland project file.
146 * @param project The project concerned by this operation.
149 borland_project_create(borland_project_t project);
152 * Close a borland project file.
153 * @param project the borland project file to close.
156 borland_project_close(borland_project_t project);
160 * Generate a borland simulation poject file.
161 * @param name The name of the simulation project
164 generate_borland_simulation_project(const char* name);
167 * Generate a borland project file for real life.
168 * @param name The name of the project to create.
171 generate_borland_real_life_project(const char* name);
174 * Generate a borland project file.
175 * @param project The borland project to generate.
178 generate_borland_project(borland_project_t project);
181 * Find the path of a file.
182 * @param file_name The file name to find.
183 * @path path If founded this parameter will contain the path of file.
184 * @return If successful the function returns 1. Otherwise the function
188 find_file_path(const char* root_dir,const char* file_name,char* path);
194 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
195 #define SIM_SOURCENAME "_%s_simulator.c"
196 #define SIM_OBJNAME "_%s_simulator.o"
197 #define SIM_BINARYNAME "%s_simulator"
198 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
199 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
200 #define RL_SOURCENAME "_%s_%s.c"
201 #define RL_OBJNAME "_%s_%s.o"
202 #define RL_BINARYNAME "%s_%s"
203 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
204 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
205 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
206 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
207 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
208 #define DEPLOYMENT "%s.deploy.sh"
210 char *warning = NULL;
212 /**********************************************/
213 /**** Generate the file for the simulator *****/
214 /**********************************************/
216 const char *SIM_PREEMBULE =
217 "/* specific to Borland Compiler */\n"
218 "#ifdef __BORLANDC__\n"
221 "#include <stdlib.h>\n"
222 "#include <stdio.h>\n"
223 "#include \"msg/msg.h\"\n"
224 "#include <gras.h>\n"
226 "char *gras_log=NULL;\n";
229 #define SIM_LAUNCH_FUNC \
230 "int launch_%s(int argc, char **argv) {\n" \
231 " char **myargv=argv;\n" \
232 " int myargc=argc;\n" \
236 " if (gras_log) {\n"\
237 " myargv=malloc((argc+1) * sizeof(char**));\n" \
238 " for (i=0; i<argc; i++)\n" \
239 " myargv[i] = argv[i];\n" \
240 " myargv[myargc++] = gras_log;\n" \
242 " retcode = %s(myargc,myargv);\n" \
243 " if (myargv != argv)\n" \
245 " return retcode;\n" \
248 const char *SIM_MAIN_POSTEMBULE = "\n"
250 " MSG_launch_application(argv[2]);\n"
252 " /* Run the simulation */\n"
255 " /* cleanup the place */\n"
264 /**********************************************/
265 /********* Parse XML deployment file **********/
266 /**********************************************/
267 xbt_dict_t process_function_set = NULL;
268 xbt_dynar_t process_list = NULL;
269 xbt_dict_t machine_set = NULL;
271 typedef struct s_process_t {
277 static void s_process_free(void *process)
280 for(i=0;i<((s_process_t*)process)->argc; i++)
281 free(((s_process_t*)process)->argv[i]);
282 free(((s_process_t*)process)->host);
285 static s_process_t process;
288 * Création de deux dictionnaires
290 static void parse_process_init(void)
292 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
293 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
295 process.argv = xbt_new(char*,1);
296 process.argv[0] = xbt_strdup(A_surfxml_process_function);
297 process.host=strdup(A_surfxml_process_host);
298 /*VERB1("Function: %s",A_surfxml_process_function);*/
301 static void parse_argument(void)
304 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
305 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
308 static void parse_process_finalize(void)
310 xbt_dynar_push(process_list,&process);
311 /*VERB1("Function: %s",process.argv[0]);*/
314 static void generate_sim(char *project)
316 xbt_dict_cursor_t cursor=NULL;
319 char *filename = NULL;
323 * Creation d'un fichier nommé : <projet>_simulator.c
325 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
326 sprintf(filename,SIM_SOURCENAME,project);
328 OUT=fopen(filename,"w");
331 xbt_assert1(OUT, "Unable to open %s for writing",filename);
334 * Ecriture du message d'avertissement.
336 fprintf(OUT, "%s\n",warning);
339 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
341 fprintf(OUT, "%s", SIM_PREEMBULE);
344 * Déclaration des fonction int <process>(int argc,char *argv[]);
346 xbt_dict_foreach(process_function_set,cursor,key,data) {
347 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
353 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
355 xbt_dict_foreach(process_function_set,cursor,key,data) {
356 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
360 * Ecriture du message d'avertissement.
362 fprintf(OUT, "\n%s\n",warning);
364 xbt_dict_foreach(process_function_set,cursor,key,data) {
365 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
367 fprintf(OUT, "\n%s\n",warning);
369 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
370 "#ifdef __BORLANDDC__\n"
374 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
376 " /* Simulation setup */\n"
377 " MSG_global_init(&argc,argv);\n"
378 " if (argc != 3) {\n"
379 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
384 " MSG_paje_output(\"%s.trace\");\n"
385 " MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
386 " MSG_create_environment(argv[1]);\n"
388 " /* Application deployment */\n",
390 xbt_dict_foreach(process_function_set,cursor,key,data) {
391 fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key);
393 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
398 /**********************************************/
399 /**** Generate the file for the real life *****/
400 /**********************************************/
401 static void generate_rl(char *project)
403 xbt_dict_cursor_t cursor=NULL;
406 char *filename = NULL;
409 xbt_dict_foreach(process_function_set,cursor,key,data) {
410 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
411 sprintf(filename,RL_SOURCENAME,project,key);
413 OUT=fopen(filename,"w");
414 xbt_assert1(OUT, "Unable to open %s for writing",filename);
416 fprintf(OUT, "\n%s\n",warning);
417 fprintf(OUT, "/* specific to Borland Compiler */\n" \
418 "#ifdef __BORLANDC__\n" \
419 "#pragma hdrstop\n" \
421 "#include <stdio.h>\n" \
422 "#include <signal.h>\n" \
423 "#include <gras.h>\n" \
425 "extern const char *_gras_procname;\n" \
426 "/* user code */\n" \
427 "int %s(int argc, char *argv[]);\n" \
429 "/* specific to Borland Compiler */\n" \
430 "#ifdef __BORLANDC__\n" \
431 "#pragma argsused\n" \
433 "int main(int argc, char *argv[]){\n" \
436 " _gras_procname = \"%s\";\n" \
437 " errcode=%s(argc,argv);\n"\
439 " return errcode;\n"\
442 fprintf(OUT, "\n%s\n",warning);
448 static void generate_makefile_am(char *project, char *deployment)
450 xbt_dict_cursor_t cursor=NULL;
453 char *filename = NULL;
456 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
457 sprintf(filename,MAKEFILE_FILENAME_AM, project);
459 OUT=fopen(filename,"w");
460 xbt_assert1(OUT, "Unable to open %s for writing",filename);
462 fprintf(OUT, "# AUTOMAKE variable definition\n");
463 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
464 fprintf(OUT, "PROGRAMS=");
465 fprintf(OUT, SIM_BINARYNAME,project);
467 xbt_dict_foreach(process_function_set,cursor,key,data) {
469 fprintf(OUT, RL_BINARYNAME, project, key);
472 fprintf(OUT, "\n\n");
473 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
475 fprintf(OUT, SIM_SOURCENAME,project);
476 fprintf(OUT, " %s.c\n", project);
477 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
478 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
480 xbt_dict_foreach(process_function_set,cursor,key,data) {
481 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
483 fprintf(OUT, RL_SOURCENAME, project,key);
484 fprintf(OUT, " %s.c\n", project);
485 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
486 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
489 fprintf(OUT, "\n# cleanup temps\n");
490 fprintf(OUT, "CLEANFILES= ");
491 fprintf(OUT, SIM_SOURCENAME, project);
493 xbt_dict_foreach(process_function_set,cursor,key,data) {
495 fprintf(OUT, RL_SOURCENAME, project,key);
499 fprintf(OUT, "\n# generate temps\n");
500 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
502 xbt_dict_foreach(process_function_set,cursor,key,data) {
503 fprintf(OUT, RL_SOURCENAME, project,key);
506 fprintf(OUT, SIM_SOURCENAME, project);
507 fprintf(OUT, ": %s\n", deployment);
508 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
512 static void generate_makefile_local(char *project, char *deployment)
514 xbt_dict_cursor_t cursor=NULL;
517 char *filename = NULL;
520 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
521 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
523 OUT=fopen(filename,"w");
524 xbt_assert1(OUT, "Unable to open %s for writing",filename);
530 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
533 fprintf(OUT,"## Variable declarations\n"
535 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
539 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
540 "# Compilation will fail if you don't do so\n"
541 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
542 "# You can fiddle the following to make it fit your taste\n"
543 "INCLUDES = -I$(GRAS_ROOT)/include\n"
544 "CFLAGS ?= -O3 -w -g\n"
545 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
546 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
550 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
552 fprintf(OUT, "GENERATED_C_FILES = ");
553 fprintf(OUT, SIM_SOURCENAME" ",project);
554 xbt_dict_foreach(process_function_set,cursor,key,data) {
555 fprintf(OUT, RL_SOURCENAME " ",project, key);
559 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
561 fprintf(OUT, "BIN_FILES = ");
563 fprintf(OUT, SIM_BINARYNAME " ",project);
564 xbt_dict_foreach(process_function_set,cursor,key,data) {
565 fprintf(OUT, RL_BINARYNAME " ", project, key);
571 "## By default, build all the binaries\n"
572 "all: $(BIN_FILES)\n"
575 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
576 xbt_dict_foreach(process_function_set,cursor,key,data) {
577 fprintf(OUT, RL_SOURCENAME, project,key);
580 fprintf(OUT, SIM_SOURCENAME, project);
581 fprintf(OUT, ": %s\n", deployment);
582 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
584 fprintf(OUT, "\n## Generate the binaries\n");
585 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
586 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
587 xbt_dict_foreach(process_function_set,cursor,key,data) {
588 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
589 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
594 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
597 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
601 "##Â Rules for tarballs and cleaning\n"
602 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
603 "distdir: $(DIST_FILES)\n"
604 "\trm -rf $(DISTDIR)\n"
605 "\tmkdir -p $(DISTDIR)\n"
606 "\tcp $^ $(DISTDIR)\n"
608 "dist: clean distdir\n"
609 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
610 "\n", project /*, project*/);
614 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
615 xbt_dict_foreach(process_function_set,cursor,key,data) {
616 fprintf(OUT, " " RL_OBJNAME, project, key);
620 "\trm -rf $(DISTDIR)\n"
626 fprintf(OUT, "############ REMOTE COMPILING #########\n");
629 xbt_dict_foreach(machine_set,cursor,key,data) {
630 fprintf(OUT, "%s ",key);
635 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
636 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
638 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
639 "SIMGRID_VERSION ?=2.92\n"
640 "GRAS_PROJECT ?= %s\n"
641 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
644 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
645 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
646 "\t for site in $(MACHINES) ; do \\\n"
647 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
648 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
649 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
650 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
651 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
652 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
653 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
654 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
655 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
656 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
658 "\t machine=$$site;\\\n"
659 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
661 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
662 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
663 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
665 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
666 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
668 "\t echo \"-- Copy the data over\"; \\\n"
669 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
670 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
671 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
672 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
673 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
675 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
676 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
678 "\t done;\n",project,project,project);
683 static void generate_makefile_remote(char *project, char *deployment)
685 char *filename = NULL;
688 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
689 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
691 OUT=fopen(filename,"w");
692 xbt_assert1(OUT, "Unable to open %s for writing",filename);
695 "INSTALL_PATH ?= $(shell pwd)\n"
698 "\tcd $$GRAS_ROOT ; \\\n"
699 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
700 "\techo $$retrieved; \\\n"
701 "\tif test \"x$$retrieved\" = x; then \\\n"
702 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
703 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
704 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
705 "\t make all install ;\\\n"
708 "compile-gras: compile-simgrid\n"
709 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
710 "\techo $$not_retrieved; \\\n"
711 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
712 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
713 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
717 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
718 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
719 "\trm -rf gras-$(GRAS_PROJECT)*\n"
720 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
722 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
723 " compile-simgrid compile-gras\n"
729 static void generate_deployment(char *project, char *deployment)
731 xbt_dict_cursor_t cursor=NULL;
734 char *filename = NULL;
740 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
741 sprintf(filename,DEPLOYMENT, project);
743 OUT=fopen(filename,"w");
744 xbt_assert1(OUT, "Unable to open %s for writing",filename);
746 fprintf(OUT, "#!/bin/sh\n");
747 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
749 "if test \"${MACHINES+set}\" != set; then \n"
750 " export MACHINES='");
751 xbt_dict_foreach(machine_set,cursor,key,data) {
752 fprintf(OUT, "%s ",key);
757 "if test \"${INSTALL_PATH+set}\" != set; then \n"
758 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
760 "if test \"${GRAS_ROOT+set}\" != set; then \n"
761 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
763 "if test \"${SRCDIR+set}\" != set; then \n"
764 " export SRCDIR=./\n"
766 "if test \"${SIMGRID_URL+set}\" != set; then \n"
767 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
769 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
770 " export SIMGRID_VERSION=2.91\n"
772 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
773 " export GRAS_PROJECT=%s\n"
775 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
776 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
779 "test -e runlogs/ || mkdir -p runlogs/\n",
783 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
784 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
785 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
787 xbt_dynar_foreach (process_list,cpt,proc) {
788 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
789 for(i=1;i<proc.argc;i++) {
790 fprintf(OUT,"%s ",proc.argv[i]);
792 fprintf(OUT,"\";\n");
793 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);
799 static void print(void *p)
809 /* specific to Borland Compiler */
814 int main(int argc, char *argv[])
816 char *project_name = NULL;
817 char *deployment_file = NULL;
820 surf_init(&argc, argv);
822 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
824 project_name = argv[1];
826 process_function_set = xbt_dict_new();
827 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
828 machine_set = xbt_dict_new();
830 STag_surfxml_process_fun = parse_process_init;
831 ETag_surfxml_argument_fun = parse_argument;
832 ETag_surfxml_process_fun = parse_process_finalize;
834 for(i=2; i<argc; i++) {
835 deployment_file = argv[i];
836 surf_parse_open(deployment_file);
838 xbt_assert1(0,"Parse error in %s",deployment_file);
844 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
845 sprintf(warning,WARN,deployment_file);
847 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
848 xbt_dict_cursor_t cursor=NULL;
852 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
853 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
854 xbt_dict_cursor_step(cursor) ) {
855 DEBUG1("Function %s", key);
858 xbt_dict_dump(process_function_set,print);
861 generate_sim(project_name);
862 generate_rl(project_name);
863 generate_makefile_local(project_name, deployment_file);
865 generate_borland_simulation_project(project_name);
866 generate_borland_real_life_project(project_name);
872 xbt_free(__gras_path);
876 // generate_makefile_remote(project_name, deployment_file);
877 // generate_deployment(project_name, deployment_file);
885 generate_borland_project(borland_project_t project)
887 char* binary_path; /* the path of the generated binary file */
888 char* obj_path; /* the path of the generated object file */
889 char* lib_files; /* a list of the libraries used in the borland project */
890 char* main_source; /* the name of the bpf file used by the borland project */
891 char* file_name; /* the file name of the main source file */
892 char* include_path; /* the include path */
895 /* create the borland project file */
896 borland_project_create(project);
898 /* write the xml document header */
899 borland_project_write_xml_header(project);
901 /* write the xml comment to identify a borland project file */
902 borland_project_write_xml_comment(project);
904 /* write the begin of the node PROJECT */
905 borland_project_begin_xml_node(project,"PROJECT");
907 /* write the begin of node MACROS */
908 borland_project_begin_xml_node(project,"MACROS");
910 /* write the borland project version */
911 borland_project_write_xml_element(project,"VERSION",project->version);
913 /* construct and write the borland project binary path */
914 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
915 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
916 borland_project_write_xml_element(project,"PROJECT",binary_path);
917 xbt_free(binary_path);
919 /* construct an write the object files to generate by the compiler */
920 obj_path = xbt_new0(char,strlen(project->name) + strlen(project->obj_dir) + 6);
921 sprintf(binary_path,"%s\\%s.obj",project->obj_dir,project->name);
922 borland_project_write_xml_element(project,"OBJFILES",obj_path);
925 /* write the resource files used by the compiler (no resource file used) */
926 borland_project_write_xml_element(project,"RESFILES","");
928 /* write the IDL files of the project (no IDL files used) */
929 borland_project_write_xml_element(project,"IDLFILES","");
931 /* write the IDLGENFILES element (not used) */
932 borland_project_write_xml_element(project,"IDLGENFILES","");
934 /* write the DEFFILE element (not used) */
935 borland_project_write_xml_element(project,"DEFFILE","");
937 /* write the RESDEPEN element (not used, no resource file used) */
938 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
940 /* construct and write the list of libraries used by the project */
942 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
943 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
946 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
947 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
949 borland_project_write_xml_element(project,"LIBFILES",lib_files);
952 /* write the SPARELIBS element (not used) */
953 borland_project_write_xml_element(project,"SPARELIBS","");
955 /* write the PACKAGES element (no package used) */
956 borland_project_write_xml_element(project,"PACKAGES","");
958 /* write the PATHCPP element (the path of the source files of the project)*/
959 borland_project_write_xml_element(project,"PATHCPP",".;");
961 /* write the PATHPAS element (not used) */
962 borland_project_write_xml_element(project,"PATHPAS","");
964 /* write the PATHRC element (not used) */
965 borland_project_write_xml_element(project,"PATHRC","");
967 /* write the PATHASM element (not used) */
968 borland_project_write_xml_element(project,"PATHASM","");
970 /* write the DEBUGLIBPATH element (the path for debug) */
971 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
973 /* write the RELEASELIBPATH element (the path for release) */
974 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
976 /* specify the linker to use */
977 borland_project_write_xml_element(project,"LINKER","ilink32");
979 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
980 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
982 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
983 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
985 /* construct and write the MAINSOURCE element */
986 main_source = xbt_new0(char,strlen(project->name) + 5);
987 sprintf(main_source,"%s.bpf",project->name);
988 /* write the main source file to use in the borland project file */
989 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
991 /* create the bpf file used by the borland project */
992 borland_project_create_main_file(main_source);
994 /* FIXME resolve the include path */
995 /* write the INCLUDEPATH element */
998 __gras_path = xbt_new0(char,MAX_PATH);
999 find_file_path("C:\\","gras.h",__gras_path);
1002 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1003 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1005 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1007 xbt_free(include_path);
1009 /* write the LIBPATH element (no librarie paths specified)*/
1010 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1013 * write the WARNINGS element :
1014 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1015 * -w-rvl (-w-8070) disabled the function must return warning
1016 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1017 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1018 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1019 * -w-par (-w-8057) disabled the warning that detect an unused variable
1020 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1021 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1022 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1024 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");
1026 /* write the OTHERFILES element (no other files used used) */
1027 borland_project_write_xml_element(project,"OTHERFILES","");
1029 /* write the end of the node MACROS */
1030 borland_project_end_xml_node(project,"MACROS");
1032 /* write the begin of the node OPTIONS */
1033 borland_project_begin_xml_node(project,"OPTIONS");
1035 /* FIXME check the idlcflags */
1036 /* write the IDLCFLAGS element */
1037 borland_project_write_xml_element(project,"IDLCFLAGS","");
1040 * write the CFLAG1 element (compiler options ) :
1042 * -Od this flag disable all compiler optimisation
1043 * -H this flag specify the name of the file which will contain the precompiled header
1044 * -Hc this flag specify to the compiler to cach the precompiled header
1045 * -Vx this flag specify to the compiler to allow the empty structures
1046 * -Ve this flag specify to the compiler to allow the empty base classes
1047 * -X- this flag activate the auto-depend informations of the compiler
1048 * -r- this flag disabled the use of the processor register
1049 * -a1 this flag specify that the data must be aligned on one byte
1050 * -b- this flag specify that the enums are the smallest size of the integer
1051 * -k (used during debug)
1052 * -y this flag generate the line number for debug
1053 * -v this flag enabled the debugging of the source files
1054 * -vi check the expansion of the inline functions
1055 * -tWC specify that it's a console application
1056 * -tWM- specify that the application is not multithread
1057 * -c generate the object file, no link
1059 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");
1061 /* write the PFLAGS element */
1062 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE -M");
1064 /* write the RFLAGS element */
1065 borland_project_write_xml_element(project,"RFLAGS","");
1067 /* write the AFLAGS element (assembler flags) :
1069 * /mx (not documented)
1070 * /w2 (not documented)
1071 * /zd (not documented)
1074 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1076 /* write the LFLAGS element (linker flags) :
1078 * -I specify the output directory for object files
1079 * -D register the specified description (no description "")
1080 * -ap build a win32 console application
1081 * -Tpe generate a exe file
1082 * -x do not create the map file
1083 * -Gn do not generate the state file
1084 * -v include the complete debug informations
1086 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1088 /* write the OTHERFILES element (not used)*/
1089 borland_project_write_xml_element(project,"OTHERFILES","");
1091 /* write the end of the node OPTIONS */
1092 borland_project_end_xml_node(project,"OPTIONS");
1094 /* write the begin of the node LINKER */
1095 borland_project_begin_xml_node(project,"LINKER");
1097 /* write the ALLOBJ element */
1098 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1100 /* write the ALLRES element (not used) */
1101 borland_project_write_xml_element(project,"ALLRES","");
1103 /* write the ALLLIB element */
1104 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1106 /* write the OTHERFILES element (not used) */
1107 borland_project_write_xml_element(project,"OTHERFILES","");
1109 /* write the end of the node LINKER */
1110 borland_project_end_xml_node(project,"LINKER");
1112 /* write the begin of the node FILELIST */
1113 borland_project_begin_xml_node(project,"FILELIST");
1115 /* construct and write the list of file elements */
1117 /* add the bpf file to the list */
1118 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1119 xbt_free(main_source);
1121 /* FIXME : check the source file directory */
1122 /* add the generated source file to the list */
1123 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 4);
1124 sprintf(file_name,"%s\\%s.c",project->src_dir,project->name);
1125 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1126 xbt_free(file_name);
1128 /* FIXME : check the libraries directory */
1129 /* add the simgrid library to the list */
1130 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1131 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1132 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1133 xbt_free(file_name);
1136 add the libgras library to the list
1138 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1139 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1141 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1142 xbt_free(file_name);
1145 /* write the end of the node FILELIST */
1146 borland_project_end_xml_node(project,"FILELIST");
1148 /* write the begin of the node BUILDTOOLS (not used)*/
1149 borland_project_begin_xml_node(project,"BUILDTOOLS");
1151 /* write the end of the node BUILDTOOLS (not used)*/
1152 borland_project_end_xml_node(project,"BUILDTOOLS");
1154 /* write the begin of the node IDEOPTIONS */
1155 borland_project_begin_xml_node(project,"IDEOPTIONS");
1157 /* write all of the option of the IDE of Borland C++ Builder */
1158 borland_project_write_ide_options(project);
1160 /* write the end of the node IDEOPTIONS */
1161 borland_project_end_xml_node(project,"IDEOPTIONS");
1163 /* write the end of the node PROJECT */
1164 borland_project_end_xml_node(project,"PROJECT");
1166 /* close the borland project file */
1167 borland_project_close(project);
1171 borland_project_write_tabs(borland_project_t project,unsigned int count)
1175 for(pos = 0; pos < count; pos++)
1176 fprintf(project->stream,"\t");
1180 borland_project_begin_xml_node(borland_project_t project, const char* name)
1183 borland_project_write_tabs(project,level);
1185 fprintf(project->stream,"<%s>\n",name);
1191 borland_project_end_xml_node(borland_project_t project, const char* name)
1196 borland_project_write_tabs(project,level);
1198 fprintf(project->stream,"</%s>\n",name);
1203 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1205 borland_project_write_tabs(project,level);
1207 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1211 borland_project_write_xml_header(borland_project_t project)
1213 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1217 borland_project_create_main_file(const char* name)
1219 FILE* stream = fopen(name,"w+");
1221 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1227 borland_project_create(borland_project_t project)
1229 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1230 sprintf(file_name,"%s.bpr",project->name);
1231 project->stream = fopen(file_name,"w+");
1232 xbt_free(file_name);
1236 borland_project_write_xml_comment(borland_project_t project)
1238 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1241 borland_project_write_file_element( borland_project_t project,
1242 const char* file_name,
1243 const char* form_name,
1244 const char* unit_name,
1245 const char* container_id,
1246 const char* design_class,
1247 const char* local_command)
1249 borland_project_write_tabs(project,level);
1251 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);
1255 borland_project_write_ide_options(borland_project_t project)
1258 const char* ide_options =
1259 "[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" \
1260 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1261 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1262 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1263 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1264 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1265 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1266 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1267 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1268 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1269 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1270 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1271 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1272 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1273 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1275 fprintf(project->stream,ide_options);
1279 borland_project_close(borland_project_t project)
1281 fclose(project->stream);
1285 generate_borland_simulation_project(const char* name)
1287 char buffer[MAX_PATH] = {0};
1290 WIN32_FIND_DATA wfd = {0};
1292 s_borland_project_t borland_project = {0};
1293 borland_project.xml_version = "1.0";
1294 borland_project.encoding ="utf-8";
1295 borland_project.comment ="C++Builder XML Project";
1296 borland_project.version = "BCB.06.00";
1298 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1301 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1302 __lib_dir = strdup(borland_project.lib_dir);
1305 borland_project.lib_dir = strdup(__lib_dir);
1307 GetCurrentDirectory(MAX_PATH,buffer);
1309 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1311 strcpy(borland_project.src_dir,buffer);
1313 borland_project.name = xbt_new0(char,strlen(name) + strlen("_simulator") + 2);
1314 sprintf(borland_project.name,"_%s_simulator",name);
1316 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1317 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1319 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1322 CreateDirectory(borland_project.bin_dir,NULL);
1324 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1325 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1327 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1329 if(INVALID_HANDLE_VALUE == hDir)
1330 CreateDirectory(borland_project.obj_dir,NULL);
1332 generate_borland_project(&borland_project);
1334 xbt_free(borland_project.name);
1335 xbt_free(borland_project.src_dir);
1336 xbt_free(borland_project.bin_dir);
1337 xbt_free(borland_project.obj_dir);
1338 xbt_free(borland_project.lib_dir);
1342 generate_borland_real_life_project(const char* name)
1345 WIN32_FIND_DATA wfd = {0};
1346 char buffer[MAX_PATH] = {0};
1347 xbt_dict_cursor_t cursor = NULL;
1350 s_borland_project_t borland_project = {0};
1352 borland_project.xml_version = "1.0";
1353 borland_project.encoding ="utf-8";
1354 borland_project.comment ="C++Builder XML Project";
1355 borland_project.version = "BCB.06.00";
1356 borland_project.lib_dir = " ";
1358 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1361 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1362 __lib_dir = strdup(borland_project.lib_dir);
1365 borland_project.lib_dir = strdup(__lib_dir);
1367 GetCurrentDirectory(MAX_PATH,buffer);
1369 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1371 strcpy(borland_project.src_dir,buffer);
1373 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1374 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1376 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1378 if(INVALID_HANDLE_VALUE == hDir)
1379 CreateDirectory(borland_project.bin_dir,NULL);
1381 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1382 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1384 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1387 CreateDirectory(borland_project.obj_dir,NULL);
1390 xbt_dict_foreach(process_function_set,cursor,key,data) {
1391 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 3);
1393 sprintf(borland_project.name,"_%s_%s",name,key);
1395 generate_borland_project(&borland_project);
1396 xbt_free(borland_project.name);
1399 xbt_free(borland_project.src_dir);
1400 xbt_free(borland_project.bin_dir);
1401 xbt_free(borland_project.obj_dir);
1402 xbt_free(borland_project.lib_dir);
1405 find_file_path(const char* root_dir,const char* file_name,char* path)
1408 WIN32_FIND_DATA wfd;
1409 char* prev_dir = xbt_new(char,MAX_PATH);
1410 GetCurrentDirectory(MAX_PATH,prev_dir);
1411 SetCurrentDirectory(root_dir);
1413 // begining of the scan
1414 hFind=FindFirstFile ("*.*", &wfd);
1416 if(hFind!=INVALID_HANDLE_VALUE){
1419 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1421 if(!strcmp(file_name,wfd.cFileName)){
1422 GetCurrentDirectory(MAX_PATH,path);
1423 SetCurrentDirectory(prev_dir);
1430 /* it's a directory, scan it*/
1433 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1434 if(find_file_path(wfd.cFileName,file_name,path)){
1436 SetCurrentDirectory(prev_dir);
1442 /* next file or directory */
1443 while(FindNextFile(hFind,&wfd))
1446 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1448 if(!strcmp(file_name,wfd.cFileName)){
1449 GetCurrentDirectory(MAX_PATH,path);
1450 SetCurrentDirectory(prev_dir);
1456 /* it's a file scan it */
1459 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1461 if(find_file_path(wfd.cFileName,file_name,path)){
1462 SetCurrentDirectory(prev_dir);
1473 SetCurrentDirectory(prev_dir);