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 */
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
29 /* tabulation level (used to indent the lines of the borland project file */
30 static unsigned int level = 0;
32 /* the library path for simgrid.lib and libras.lib. */
33 static char* __lib_dir = NULL;
35 /* the gras.h header directory */
36 static char* __gras_path = NULL;
44 * A structure which represents a borland project file.
46 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;
61 * Write tabs in a borland project file.
62 * @param project The project concerned by the operation.
63 * @param count The count tab to write
66 borland_project_write_tabs(borland_project_t project,unsigned int count);
69 * Write the begin of an xml node in the borland project file.
70 * @param project The borland project concerned by this operation.
71 * @param name The name of the node.
74 borland_project_begin_xml_node(borland_project_t project, const char* name);
78 * Write the end of an xml node in the borland project file.
79 * @param project The borland project concerned by this operation.
80 * @param name The name of the node.
83 borland_project_end_xml_node(borland_project_t project, const char* name);
86 * Write an xml element in a borland project file.
87 * @param project The borland project concerned by this operation.
88 * @param name The name of the element to write
89 * @param value The value of the element
92 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
95 * Write a FILE xml element in the borland project file.
96 * @param project The borland project concerned by this operation.
97 * @param file_name The value of the attribute FILENAME.
98 * @param form_name The value of the attribute FORMNAME.
99 * @param unit_name The value of the attribute UNITNAME.
100 * @param container_id The value of the attribute CONTAINERID.
101 * @param design_claas The value of the attribute DESIGNCLASS.
102 * @param local_command The value of the attribute LOCALCOMMAND.
105 borland_project_write_file_element( borland_project_t project,
106 const char* file_name,
107 const char* form_name,
108 const char* unit_name,
109 const char* container_id,
110 const char* design_class,
111 const char* local_command);
113 * Write all options of the IDE of the Borland Builder C++ compiler.
114 * @ param project The project concerned by this operation.
118 borland_project_write_ide_options(borland_project_t project);
121 * Write the xml header of the xml document.
122 * @param project The project concerned by the operation.
125 borland_project_write_xml_header(borland_project_t project);
128 * Write an xml comment in a borland project file
129 * @param project The project concerned by this operation.
132 borland_project_write_xml_comment(borland_project_t project);
135 * Create a bpf file used by a borland project file.
136 * @param name The name of the bpf file to create.
139 borland_project_create_main_file(const char* name);
142 * Create a borland project file.
143 * @param project The project concerned by this operation.
146 borland_project_create(borland_project_t project);
149 * Close a borland project file.
150 * @param project the borland project file to close.
153 borland_project_close(borland_project_t project);
157 * Generate a borland simulation poject file.
158 * @param name The name of the simulation project
161 generate_borland_simulation_project(const char* name);
164 * Generate a borland project file for real life.
165 * @param name The name of the project to create.
168 generate_borland_real_life_project(const char* name);
171 * Generate a borland project file.
172 * @param project The borland project to generate.
175 generate_borland_project(borland_project_t project);
178 * Find the path of a file.
179 * @param file_name The file name to find.
180 * @path path If founded this parameter will contain the path of file.
181 * @return If successful the function returns 1. Otherwise the function
185 find_file_path(const char* root_dir,const char* file_name,char* path);
191 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
192 #define SIM_SOURCENAME "_%s_simulator.c"
193 #define SIM_OBJNAME "_%s_simulator.o"
194 #define SIM_BINARYNAME "%s_simulator"
195 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
196 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
197 #define RL_SOURCENAME "_%s_%s.c"
198 #define RL_OBJNAME "_%s_%s.o"
199 #define RL_BINARYNAME "%s_%s"
200 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
201 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
202 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
203 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
204 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
205 #define DEPLOYMENT "%s.deploy.sh"
207 char *warning = NULL;
209 /**********************************************/
210 /**** Generate the file for the simulator *****/
211 /**********************************************/
213 const char *SIM_PREEMBULE =
214 "/* specific to Borland Compiler */\n"
215 "#ifdef __BORLANDC__\n"
218 "#include <stdlib.h>\n"
219 "#include <stdio.h>\n"
220 "#include \"msg/msg.h\"\n"
221 "#include <gras.h>\n"
223 "char *gras_log=NULL;\n";
226 #define SIM_LAUNCH_FUNC \
227 "int launch_%s(int argc, char **argv) {\n" \
228 " char **myargv=argv;\n" \
229 " int myargc=argc;\n" \
233 " if (gras_log) {\n"\
234 " myargv=malloc((argc+1) * sizeof(char**));\n" \
235 " for (i=0; i<argc; i++)\n" \
236 " myargv[i] = argv[i];\n" \
237 " myargv[myargc++] = gras_log;\n" \
239 " retcode = %s(myargc,myargv);\n" \
240 " if (myargv != argv)\n" \
242 " return retcode;\n" \
245 const char *SIM_MAIN_POSTEMBULE = "\n"
247 " MSG_launch_application(argv[2]);\n"
249 " /* Run the simulation */\n"
252 " /* cleanup the place */\n"
261 /**********************************************/
262 /********* Parse XML deployment file **********/
263 /**********************************************/
264 xbt_dict_t process_function_set = NULL;
265 xbt_dynar_t process_list = NULL;
266 xbt_dict_t machine_set = NULL;
268 typedef struct s_process_t {
274 static void s_process_free(void *process)
277 for(i=0;i<((s_process_t*)process)->argc; i++)
278 free(((s_process_t*)process)->argv[i]);
279 free(((s_process_t*)process)->host);
282 static s_process_t process;
285 * Création de deux dictionnaires
287 static void parse_process_init(void)
289 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
290 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
292 process.argv = xbt_new(char*,1);
293 process.argv[0] = xbt_strdup(A_surfxml_process_function);
294 process.host=strdup(A_surfxml_process_host);
295 /*VERB1("Function: %s",A_surfxml_process_function);*/
298 static void parse_argument(void)
301 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
302 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
305 static void parse_process_finalize(void)
307 xbt_dynar_push(process_list,&process);
308 /*VERB1("Function: %s",process.argv[0]);*/
311 static void generate_sim(char *project)
313 xbt_dict_cursor_t cursor=NULL;
316 char *filename = NULL;
320 * Creation d'un fichier nommé : <projet>_simulator.c
322 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
323 sprintf(filename,SIM_SOURCENAME,project);
325 OUT=fopen(filename,"w");
328 xbt_assert1(OUT, "Unable to open %s for writing",filename);
331 * Ecriture du message d'avertissement.
333 fprintf(OUT, "%s\n",warning);
336 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
338 fprintf(OUT, "%s", SIM_PREEMBULE);
341 * Déclaration des fonction int <process>(int argc,char *argv[]);
343 xbt_dict_foreach(process_function_set,cursor,key,data) {
344 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
350 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
352 xbt_dict_foreach(process_function_set,cursor,key,data) {
353 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
357 * Ecriture du message d'avertissement.
359 fprintf(OUT, "\n%s\n",warning);
361 xbt_dict_foreach(process_function_set,cursor,key,data) {
362 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
364 fprintf(OUT, "\n%s\n",warning);
366 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
367 "#ifdef __BORLANDDC__\n"
371 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
373 " /* Simulation setup */\n"
374 " MSG_global_init(&argc,argv);\n"
375 " if (argc != 3) {\n"
376 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
381 " MSG_paje_output(\"%s.trace\");\n"
382 " MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
383 " MSG_create_environment(argv[1]);\n"
385 " /* Application deployment */\n",
387 xbt_dict_foreach(process_function_set,cursor,key,data) {
388 fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key);
390 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
395 /**********************************************/
396 /**** Generate the file for the real life *****/
397 /**********************************************/
398 static void generate_rl(char *project)
400 xbt_dict_cursor_t cursor=NULL;
403 char *filename = NULL;
406 xbt_dict_foreach(process_function_set,cursor,key,data) {
407 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
408 sprintf(filename,RL_SOURCENAME,project,key);
410 OUT=fopen(filename,"w");
411 xbt_assert1(OUT, "Unable to open %s for writing",filename);
413 fprintf(OUT, "\n%s\n",warning);
414 fprintf(OUT, "/* specific to Borland Compiler */\n" \
415 "#ifdef __BORLANDC__\n" \
416 "#pragma hdrstop\n" \
418 "#include <stdio.h>\n" \
419 "#include <signal.h>\n" \
420 "#include <gras.h>\n" \
422 "extern const char *_gras_procname;\n" \
423 "/* user code */\n" \
424 "int %s(int argc, char *argv[]);\n" \
426 "/* specific to Borland Compiler */\n" \
427 "#ifdef __BORLANDC__\n" \
428 "#pragma argsused\n" \
430 "int main(int argc, char *argv[]){\n" \
433 " _gras_procname = \"%s\";\n" \
434 " errcode=%s(argc,argv);\n"\
436 " return errcode;\n"\
439 fprintf(OUT, "\n%s\n",warning);
445 static void generate_makefile_am(char *project, char *deployment)
447 xbt_dict_cursor_t cursor=NULL;
450 char *filename = NULL;
453 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
454 sprintf(filename,MAKEFILE_FILENAME_AM, project);
456 OUT=fopen(filename,"w");
457 xbt_assert1(OUT, "Unable to open %s for writing",filename);
459 fprintf(OUT, "# AUTOMAKE variable definition\n");
460 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
461 fprintf(OUT, "PROGRAMS=");
462 fprintf(OUT, SIM_BINARYNAME,project);
464 xbt_dict_foreach(process_function_set,cursor,key,data) {
466 fprintf(OUT, RL_BINARYNAME, project, key);
469 fprintf(OUT, "\n\n");
470 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
472 fprintf(OUT, SIM_SOURCENAME,project);
473 fprintf(OUT, " %s.c\n", project);
474 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
475 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
477 xbt_dict_foreach(process_function_set,cursor,key,data) {
478 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
480 fprintf(OUT, RL_SOURCENAME, project,key);
481 fprintf(OUT, " %s.c\n", project);
482 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
483 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
486 fprintf(OUT, "\n# cleanup temps\n");
487 fprintf(OUT, "CLEANFILES= ");
488 fprintf(OUT, SIM_SOURCENAME, project);
490 xbt_dict_foreach(process_function_set,cursor,key,data) {
492 fprintf(OUT, RL_SOURCENAME, project,key);
496 fprintf(OUT, "\n# generate temps\n");
497 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
499 xbt_dict_foreach(process_function_set,cursor,key,data) {
500 fprintf(OUT, RL_SOURCENAME, project,key);
503 fprintf(OUT, SIM_SOURCENAME, project);
504 fprintf(OUT, ": %s\n", deployment);
505 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
509 static void generate_makefile_local(char *project, char *deployment)
511 xbt_dict_cursor_t cursor=NULL;
514 char *filename = NULL;
517 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
518 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
520 OUT=fopen(filename,"w");
521 xbt_assert1(OUT, "Unable to open %s for writing",filename);
527 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
530 fprintf(OUT,"## Variable declarations\n"
532 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
536 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
537 "# Compilation will fail if you don't do so\n"
538 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
539 "# You can fiddle the following to make it fit your taste\n"
540 "INCLUDES = -I$(GRAS_ROOT)/include\n"
541 "CFLAGS ?= -O3 -w -g\n"
542 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
543 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
547 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
549 fprintf(OUT, "GENERATED_C_FILES = ");
550 fprintf(OUT, SIM_SOURCENAME" ",project);
551 xbt_dict_foreach(process_function_set,cursor,key,data) {
552 fprintf(OUT, RL_SOURCENAME " ",project, key);
556 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
558 fprintf(OUT, "BIN_FILES = ");
560 fprintf(OUT, SIM_BINARYNAME " ",project);
561 xbt_dict_foreach(process_function_set,cursor,key,data) {
562 fprintf(OUT, RL_BINARYNAME " ", project, key);
568 "## By default, build all the binaries\n"
569 "all: $(BIN_FILES)\n"
572 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
573 xbt_dict_foreach(process_function_set,cursor,key,data) {
574 fprintf(OUT, RL_SOURCENAME, project,key);
577 fprintf(OUT, SIM_SOURCENAME, project);
578 fprintf(OUT, ": %s\n", deployment);
579 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
581 fprintf(OUT, "\n## Generate the binaries\n");
582 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
583 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
584 xbt_dict_foreach(process_function_set,cursor,key,data) {
585 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
586 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
591 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
594 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
598 "##Â Rules for tarballs and cleaning\n"
599 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
600 "distdir: $(DIST_FILES)\n"
601 "\trm -rf $(DISTDIR)\n"
602 "\tmkdir -p $(DISTDIR)\n"
603 "\tcp $^ $(DISTDIR)\n"
605 "dist: clean distdir\n"
606 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
607 "\n", project /*, project*/);
611 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
612 xbt_dict_foreach(process_function_set,cursor,key,data) {
613 fprintf(OUT, " " RL_OBJNAME, project, key);
617 "\trm -rf $(DISTDIR)\n"
623 fprintf(OUT, "############ REMOTE COMPILING #########\n");
626 xbt_dict_foreach(machine_set,cursor,key,data) {
627 fprintf(OUT, "%s ",key);
632 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
633 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
635 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
636 "SIMGRID_VERSION ?=2.92\n"
637 "GRAS_PROJECT ?= %s\n"
638 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
641 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
642 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
643 "\t for site in $(MACHINES) ; do \\\n"
644 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
645 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
646 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
647 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
648 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
649 "\t cmd_make=\"\\\"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) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
652 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
653 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
655 "\t machine=$$site;\\\n"
656 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
658 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
659 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
660 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
662 "\t if ssh $$machine \"eval $$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 echo \"-- Copy the data over\"; \\\n"
666 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
667 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
668 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
669 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
670 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
672 "\t if ssh $$machine \"eval $$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 done;\n",project,project,project);
680 static void generate_makefile_remote(char *project, char *deployment)
682 char *filename = NULL;
685 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
686 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
688 OUT=fopen(filename,"w");
689 xbt_assert1(OUT, "Unable to open %s for writing",filename);
692 "INSTALL_PATH ?= $(shell pwd)\n"
695 "\tcd $$GRAS_ROOT ; \\\n"
696 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
697 "\techo $$retrieved; \\\n"
698 "\tif test \"x$$retrieved\" = x; then \\\n"
699 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
700 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
701 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
702 "\t make all install ;\\\n"
705 "compile-gras: compile-simgrid\n"
706 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
707 "\techo $$not_retrieved; \\\n"
708 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
709 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
710 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
714 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
715 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
716 "\trm -rf gras-$(GRAS_PROJECT)*\n"
717 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
719 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
720 " compile-simgrid compile-gras\n"
726 static void generate_deployment(char *project, char *deployment)
728 xbt_dict_cursor_t cursor=NULL;
731 char *filename = NULL;
737 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
738 sprintf(filename,DEPLOYMENT, project);
740 OUT=fopen(filename,"w");
741 xbt_assert1(OUT, "Unable to open %s for writing",filename);
743 fprintf(OUT, "#!/bin/sh\n");
744 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
746 "if test \"${MACHINES+set}\" != set; then \n"
747 " export MACHINES='");
748 xbt_dict_foreach(machine_set,cursor,key,data) {
749 fprintf(OUT, "%s ",key);
754 "if test \"${INSTALL_PATH+set}\" != set; then \n"
755 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
757 "if test \"${GRAS_ROOT+set}\" != set; then \n"
758 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
760 "if test \"${SRCDIR+set}\" != set; then \n"
761 " export SRCDIR=./\n"
763 "if test \"${SIMGRID_URL+set}\" != set; then \n"
764 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
766 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
767 " export SIMGRID_VERSION=2.91\n"
769 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
770 " export GRAS_PROJECT=%s\n"
772 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
773 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
776 "test -e runlogs/ || mkdir -p runlogs/\n",
780 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
781 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
782 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
784 xbt_dynar_foreach (process_list,cpt,proc) {
785 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
786 for(i=1;i<proc.argc;i++) {
787 fprintf(OUT,"%s ",proc.argv[i]);
789 fprintf(OUT,"\";\n");
790 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);
796 static void print(void *p)
806 /* specific to Borland Compiler */
811 int main(int argc, char *argv[])
813 char *project_name = NULL;
814 char *deployment_file = NULL;
817 surf_init(&argc, argv);
819 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
821 project_name = argv[1];
823 process_function_set = xbt_dict_new();
824 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
825 machine_set = xbt_dict_new();
827 STag_surfxml_process_fun = parse_process_init;
828 ETag_surfxml_argument_fun = parse_argument;
829 ETag_surfxml_process_fun = parse_process_finalize;
831 for(i=2; i<argc; i++) {
832 deployment_file = argv[i];
833 surf_parse_open(deployment_file);
835 xbt_assert1(0,"Parse error in %s",deployment_file);
841 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
842 sprintf(warning,WARN,deployment_file);
844 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
845 xbt_dict_cursor_t cursor=NULL;
849 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
850 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
851 xbt_dict_cursor_step(cursor) ) {
852 DEBUG1("Function %s", key);
855 xbt_dict_dump(process_function_set,print);
858 generate_sim(project_name);
859 generate_rl(project_name);
860 generate_makefile_local(project_name, deployment_file);
862 generate_borland_simulation_project(project_name);
863 generate_borland_real_life_project(project_name);
869 xbt_free(__gras_path);
873 // generate_makefile_remote(project_name, deployment_file);
874 // generate_deployment(project_name, deployment_file);
882 generate_borland_project(borland_project_t project)
884 char* binary_path; /* the path of the generated binary file */
885 char* obj_path; /* the path of the generated object file */
886 char* lib_files; /* a list of the libraries used in the borland project */
887 char* main_source; /* the name of the bpf file used by the borland project */
888 char* file_name; /* the file name of the main source file */
889 char* include_path; /* the include path */
892 /* create the borland project file */
893 borland_project_create(project);
895 /* write the xml document header */
896 borland_project_write_xml_header(project);
898 /* write the xml comment to identify a borland project file */
899 borland_project_write_xml_comment(project);
901 /* write the begin of the node PROJECT */
902 borland_project_begin_xml_node(project,"PROJECT");
904 /* write the begin of node MACROS */
905 borland_project_begin_xml_node(project,"MACROS");
907 /* write the borland project version */
908 borland_project_write_xml_element(project,"VERSION",project->version);
910 /* construct and write the borland project binary path */
911 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
912 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
913 borland_project_write_xml_element(project,"PROJECT",binary_path);
914 xbt_free(binary_path);
916 /* construct an write the object files to generate by the compiler */
917 obj_path = xbt_new0(char,strlen(project->name) + strlen(project->obj_dir) + 6);
918 sprintf(binary_path,"%s\\%s.obj",project->obj_dir,project->name);
919 borland_project_write_xml_element(project,"OBJFILES",obj_path);
922 /* write the resource files used by the compiler (no resource file used) */
923 borland_project_write_xml_element(project,"RESFILES","");
925 /* write the IDL files of the project (no IDL files used) */
926 borland_project_write_xml_element(project,"IDLFILES","");
928 /* write the IDLGENFILES element (not used) */
929 borland_project_write_xml_element(project,"IDLGENFILES","");
931 /* write the DEFFILE element (not used) */
932 borland_project_write_xml_element(project,"DEFFILE","");
934 /* write the RESDEPEN element (not used, no resource file used) */
935 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
937 /* construct and write the list of libraries used by the project */
939 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
940 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
943 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
944 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
946 borland_project_write_xml_element(project,"LIBFILES",lib_files);
949 /* write the SPARELIBS element (not used) */
950 borland_project_write_xml_element(project,"SPARELIBS","");
952 /* write the PACKAGES element (no package used) */
953 borland_project_write_xml_element(project,"PACKAGES","");
955 /* write the PATHCPP element (the path of the source files of the project)*/
956 borland_project_write_xml_element(project,"PATHCPP",".;");
958 /* write the PATHPAS element (not used) */
959 borland_project_write_xml_element(project,"PATHPAS","");
961 /* write the PATHRC element (not used) */
962 borland_project_write_xml_element(project,"PATHRC","");
964 /* write the PATHASM element (not used) */
965 borland_project_write_xml_element(project,"PATHASM","");
967 /* write the DEBUGLIBPATH element (the path for debug) */
968 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
970 /* write the RELEASELIBPATH element (the path for release) */
971 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
973 /* specify the linker to use */
974 borland_project_write_xml_element(project,"LINKER","ilink32");
976 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
977 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
979 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
980 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
982 /* construct and write the MAINSOURCE element */
983 main_source = xbt_new0(char,strlen(project->name) + 5);
984 sprintf(main_source,"%s.bpf",project->name);
985 /* write the main source file to use in the borland project file */
986 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
988 /* create the bpf file used by the borland project */
989 borland_project_create_main_file(main_source);
991 /* FIXME resolve the include path */
992 /* write the INCLUDEPATH element */
995 __gras_path = xbt_new0(char,MAX_PATH);
996 find_file_path("C:\\","gras.h",__gras_path);
999 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1000 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1002 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1004 xbt_free(include_path);
1006 /* write the LIBPATH element (no librarie paths specified)*/
1007 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1010 * write the WARNINGS element :
1011 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1012 * -w-rvl (-w-8070) disabled the function must return warning
1013 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1014 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1015 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1016 * -w-par (-w-8057) disabled the warning that detect an unused variable
1017 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1018 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1019 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1021 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");
1023 /* write the OTHERFILES element (no other files used used) */
1024 borland_project_write_xml_element(project,"OTHERFILES","");
1026 /* write the end of the node MACROS */
1027 borland_project_end_xml_node(project,"MACROS");
1029 /* write the begin of the node OPTIONS */
1030 borland_project_begin_xml_node(project,"OPTIONS");
1032 /* FIXME check the idlcflags */
1033 /* write the IDLCFLAGS element */
1034 borland_project_write_xml_element(project,"IDLCFLAGS","");
1037 * write the CFLAG1 element (compiler options ) :
1039 * -Od this flag disable all compiler optimisation
1040 * -H this flag specify the name of the file which will contain the precompiled header
1041 * -Hc this flag specify to the compiler to cach the precompiled header
1042 * -Vx this flag specify to the compiler to allow the empty structures
1043 * -Ve this flag specify to the compiler to allow the empty base classes
1044 * -X- this flag activate the auto-depend informations of the compiler
1045 * -r- this flag disabled the use of the processor register
1046 * -a1 this flag specify that the data must be aligned on one byte
1047 * -b- this flag specify that the enums are the smallest size of the integer
1048 * -k (used during debug)
1049 * -y this flag generate the line number for debug
1050 * -v this flag enabled the debugging of the source files
1051 * -vi check the expansion of the inline functions
1052 * -tWC specify that it's a console application
1053 * -tWM- specify that the application is not multithread
1054 * -c generate the object file, no link
1056 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");
1058 /* write the PFLAGS element */
1059 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE -M");
1061 /* write the RFLAGS element */
1062 borland_project_write_xml_element(project,"RFLAGS","");
1064 /* write the AFLAGS element (assembler flags) :
1066 * /mx (not documented)
1067 * /w2 (not documented)
1068 * /zd (not documented)
1071 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1073 /* write the LFLAGS element (linker flags) :
1075 * -I specify the output directory for object files
1076 * -D register the specified description (no description "")
1077 * -ap build a win32 console application
1078 * -Tpe generate a exe file
1079 * -x do not create the map file
1080 * -Gn do not generate the state file
1081 * -v include the complete debug informations
1083 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1085 /* write the OTHERFILES element (not used)*/
1086 borland_project_write_xml_element(project,"OTHERFILES","");
1088 /* write the end of the node OPTIONS */
1089 borland_project_end_xml_node(project,"OPTIONS");
1091 /* write the begin of the node LINKER */
1092 borland_project_begin_xml_node(project,"LINKER");
1094 /* write the ALLOBJ element */
1095 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1097 /* write the ALLRES element (not used) */
1098 borland_project_write_xml_element(project,"ALLRES","");
1100 /* write the ALLLIB element */
1101 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1103 /* write the OTHERFILES element (not used) */
1104 borland_project_write_xml_element(project,"OTHERFILES","");
1106 /* write the end of the node LINKER */
1107 borland_project_end_xml_node(project,"LINKER");
1109 /* write the begin of the node FILELIST */
1110 borland_project_begin_xml_node(project,"FILELIST");
1112 /* construct and write the list of file elements */
1114 /* add the bpf file to the list */
1115 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1116 xbt_free(main_source);
1118 /* FIXME : check the source file directory */
1119 /* add the generated source file to the list */
1120 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 4);
1121 sprintf(file_name,"%s\\%s.c",project->src_dir,project->name);
1122 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1123 xbt_free(file_name);
1125 /* FIXME : check the libraries directory */
1126 /* add the simgrid library to the list */
1127 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1128 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1129 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1130 xbt_free(file_name);
1133 add the libgras library to the list
1135 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1136 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1138 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1139 xbt_free(file_name);
1142 /* write the end of the node FILELIST */
1143 borland_project_end_xml_node(project,"FILELIST");
1145 /* write the begin of the node BUILDTOOLS (not used)*/
1146 borland_project_begin_xml_node(project,"BUILDTOOLS");
1148 /* write the end of the node BUILDTOOLS (not used)*/
1149 borland_project_end_xml_node(project,"BUILDTOOLS");
1151 /* write the begin of the node IDEOPTIONS */
1152 borland_project_begin_xml_node(project,"IDEOPTIONS");
1154 /* write all of the option of the IDE of Borland C++ Builder */
1155 borland_project_write_ide_options(project);
1157 /* write the end of the node IDEOPTIONS */
1158 borland_project_end_xml_node(project,"IDEOPTIONS");
1160 /* write the end of the node PROJECT */
1161 borland_project_end_xml_node(project,"PROJECT");
1163 /* close the borland project file */
1164 borland_project_close(project);
1168 borland_project_write_tabs(borland_project_t project,unsigned int count)
1172 for(pos = 0; pos < count; pos++)
1173 fprintf(project->stream,"\t");
1177 borland_project_begin_xml_node(borland_project_t project, const char* name)
1180 borland_project_write_tabs(project,level);
1182 fprintf(project->stream,"<%s>\n",name);
1188 borland_project_end_xml_node(borland_project_t project, const char* name)
1193 borland_project_write_tabs(project,level);
1195 fprintf(project->stream,"</%s>\n",name);
1200 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1202 borland_project_write_tabs(project,level);
1204 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1208 borland_project_write_xml_header(borland_project_t project)
1210 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1214 borland_project_create_main_file(const char* name)
1216 FILE* stream = fopen(name,"w+");
1218 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1224 borland_project_create(borland_project_t project)
1226 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1227 sprintf(file_name,"%s.bpr",project->name);
1228 project->stream = fopen(file_name,"w+");
1229 xbt_free(file_name);
1233 borland_project_write_xml_comment(borland_project_t project)
1235 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1238 borland_project_write_file_element( borland_project_t project,
1239 const char* file_name,
1240 const char* form_name,
1241 const char* unit_name,
1242 const char* container_id,
1243 const char* design_class,
1244 const char* local_command)
1246 borland_project_write_tabs(project,level);
1248 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);
1252 borland_project_write_ide_options(borland_project_t project)
1255 const char* ide_options =
1256 "[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" \
1257 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1258 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1259 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1260 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1261 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1262 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1263 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1264 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1265 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1266 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1267 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1268 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1269 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1270 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1272 fprintf(project->stream,ide_options);
1276 borland_project_close(borland_project_t project)
1278 fclose(project->stream);
1282 generate_borland_simulation_project(const char* name)
1284 char buffer[MAX_PATH] = {0};
1287 WIN32_FIND_DATA wfd = {0};
1289 s_borland_project_t borland_project = {0};
1290 borland_project.xml_version = "1.0";
1291 borland_project.encoding ="utf-8";
1292 borland_project.comment ="C++Builder XML Project";
1293 borland_project.version = "BCB.06.00";
1295 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1298 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1299 __lib_dir = strdup(borland_project.lib_dir);
1302 borland_project.lib_dir = strdup(__lib_dir);
1304 GetCurrentDirectory(MAX_PATH,buffer);
1306 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1308 strcpy(borland_project.src_dir,buffer);
1310 borland_project.name = xbt_new0(char,strlen(name) + strlen("_simulator") + 2);
1311 sprintf(borland_project.name,"_%s_simulator",name);
1313 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1314 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1316 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1319 CreateDirectory(borland_project.bin_dir,NULL);
1321 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1322 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1324 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1326 if(INVALID_HANDLE_VALUE == hDir)
1327 CreateDirectory(borland_project.obj_dir,NULL);
1329 generate_borland_project(&borland_project);
1331 xbt_free(borland_project.name);
1332 xbt_free(borland_project.src_dir);
1333 xbt_free(borland_project.bin_dir);
1334 xbt_free(borland_project.obj_dir);
1335 xbt_free(borland_project.lib_dir);
1339 generate_borland_real_life_project(const char* name)
1342 WIN32_FIND_DATA wfd = {0};
1343 char buffer[MAX_PATH] = {0};
1344 xbt_dict_cursor_t cursor = NULL;
1347 s_borland_project_t borland_project = {0};
1349 borland_project.xml_version = "1.0";
1350 borland_project.encoding ="utf-8";
1351 borland_project.comment ="C++Builder XML Project";
1352 borland_project.version = "BCB.06.00";
1353 borland_project.lib_dir = " ";
1355 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1358 find_file_path("C:\\","simgrid.lib",borland_project.lib_dir);
1359 __lib_dir = strdup(borland_project.lib_dir);
1362 borland_project.lib_dir = strdup(__lib_dir);
1364 GetCurrentDirectory(MAX_PATH,buffer);
1366 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1368 strcpy(borland_project.src_dir,buffer);
1370 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1371 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1373 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1375 if(INVALID_HANDLE_VALUE == hDir)
1376 CreateDirectory(borland_project.bin_dir,NULL);
1378 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1379 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1381 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1384 CreateDirectory(borland_project.obj_dir,NULL);
1387 xbt_dict_foreach(process_function_set,cursor,key,data) {
1388 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 3);
1390 sprintf(borland_project.name,"_%s_%s",name,key);
1392 generate_borland_project(&borland_project);
1393 xbt_free(borland_project.name);
1396 xbt_free(borland_project.src_dir);
1397 xbt_free(borland_project.bin_dir);
1398 xbt_free(borland_project.obj_dir);
1399 xbt_free(borland_project.lib_dir);
1402 find_file_path(const char* root_dir,const char* file_name,char* path)
1405 WIN32_FIND_DATA wfd;
1406 char* prev_dir = xbt_new(char,MAX_PATH);
1407 GetCurrentDirectory(MAX_PATH,prev_dir);
1408 SetCurrentDirectory(root_dir);
1410 // begining of the scan
1411 hFind=FindFirstFile ("*.*", &wfd);
1413 if(hFind!=INVALID_HANDLE_VALUE){
1416 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1418 if(!strcmp(file_name,wfd.cFileName)){
1419 GetCurrentDirectory(MAX_PATH,path);
1420 SetCurrentDirectory(prev_dir);
1427 /* it's a directory, scan it*/
1430 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1431 if(find_file_path(wfd.cFileName,file_name,path)){
1433 SetCurrentDirectory(prev_dir);
1439 /* next file or directory */
1440 while(FindNextFile(hFind,&wfd))
1443 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1445 if(!strcmp(file_name,wfd.cFileName)){
1446 GetCurrentDirectory(MAX_PATH,path);
1447 SetCurrentDirectory(prev_dir);
1453 /* it's a file scan it */
1456 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1458 if(find_file_path(wfd.cFileName,file_name,path)){
1459 SetCurrentDirectory(prev_dir);
1470 SetCurrentDirectory(prev_dir);