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"
22 #include "portable.h" /* Needed for the time of the SIMIX convertion */
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;
37 /* the gras.h header directory */
38 static char* __gras_path = NULL;
46 * A structure which represents a borland project file.
48 typedef struct s_borland_project
50 const char* xml_version;/* the xml version used to write the borland project file */
51 const char* encoding; /* the encoding used to write the borland project file */
52 const char* comment; /* the xml comment to write at the begining of the borland project file */
53 char* name; /* the name of the borland project file */
54 FILE* stream; /* the stream to the borland project file */
55 const char* version; /* the builder version of the borland project file */
56 char* bin_dir; /* the directory used to store the generated program */
57 char* obj_dir; /* the directory used to store the generated object files */
58 char* lib_dir; /* the directory used to store the librairies used in the borland project */
59 char* src_dir; /* the directory use to store the source files of the project */
60 }s_borland_project_t,* borland_project_t;
64 * A structure which represents a visual C++ project file.
75 * Write tabs in a borland project file.
76 * @param project The project concerned by the operation.
77 * @param count The count tab to write
80 borland_project_write_tabs(borland_project_t project,unsigned int count);
83 * Write the begin of an xml node in the borland project file.
84 * @param project The borland project concerned by this operation.
85 * @param name The name of the node.
88 borland_project_begin_xml_node(borland_project_t project, const char* name);
92 * Write the end of an xml node in the borland project file.
93 * @param project The borland project concerned by this operation.
94 * @param name The name of the node.
97 borland_project_end_xml_node(borland_project_t project, const char* name);
100 * Write an xml element in a borland project file.
101 * @param project The borland project concerned by this operation.
102 * @param name The name of the element to write
103 * @param value The value of the element
106 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
109 * Write a FILE xml element in the borland project file.
110 * @param project The borland project concerned by this operation.
111 * @param file_name The value of the attribute FILENAME.
112 * @param form_name The value of the attribute FORMNAME.
113 * @param unit_name The value of the attribute UNITNAME.
114 * @param container_id The value of the attribute CONTAINERID.
115 * @param design_claas The value of the attribute DESIGNCLASS.
116 * @param local_command The value of the attribute LOCALCOMMAND.
119 borland_project_write_file_element( borland_project_t project,
120 const char* file_name,
121 const char* form_name,
122 const char* unit_name,
123 const char* container_id,
124 const char* design_class,
125 const char* local_command);
127 * Write all options of the IDE of the Borland Builder C++ compiler.
128 * @ param project The project concerned by this operation.
132 borland_project_write_ide_options(borland_project_t project);
135 * Write the xml header of the xml document.
136 * @param project The project concerned by the operation.
139 borland_project_write_xml_header(borland_project_t project);
142 * Write an xml comment in a borland project file
143 * @param project The project concerned by this operation.
146 borland_project_write_xml_comment(borland_project_t project);
149 * Create a bpf file used by a borland project file.
150 * @param name The name of the bpf file to create.
153 borland_project_create_main_file(const char* name);
156 * Create a borland project file.
157 * @param project The project concerned by this operation.
160 borland_project_create(borland_project_t project);
163 * Close a borland project file.
164 * @param project the borland project file to close.
167 borland_project_close(borland_project_t project);
171 * Generate a borland simulation poject file.
172 * @param name The name of the simulation project
175 generate_borland_simulation_project(const char* name);
178 * Generate a borland project file for real life.
179 * @param name The name of the project to create.
182 generate_borland_real_life_project(const char* name);
185 * Generate a borland project file.
186 * @param project The borland project to generate.
189 generate_borland_project(borland_project_t project,int is_rl,const char* name);
192 * Find the path of a file.
193 * @param file_name The file name to find.
194 * @path path If founded this parameter will contain the path of file.
195 * @return If successful the function returns 1. Otherwise the function
199 find_file_path(const char* root_dir,const char* file_name,char* path);
203 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
207 * Create the Microsoft visual C++ file project for the simulation.
210 generate_simulation_dsp_file(const char* project_name);
213 * Create the Microsoft visual C++ real life project file.
216 generate_real_live_dsp_file(const char* project_name);
219 * generate a Microsoft Visual project file*/
221 generate_dsp_project(dsp_t project,int is_rl,const char* name);
227 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
228 #define SIM_SOURCENAME "_%s_simulator.c"
229 #define SIM_OBJNAME "_%s_simulator.o"
230 #define SIM_BINARYNAME "%s_simulator"
231 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
232 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
233 #define RL_SOURCENAME "_%s_%s.c"
234 #define RL_OBJNAME "_%s_%s.o"
235 #define RL_BINARYNAME "%s_%s"
236 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
237 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
238 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
239 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
240 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
241 #define DEPLOYMENT "%s.deploy.sh"
243 char *warning = NULL;
245 /**********************************************/
246 /**** Generate the file for the simulator *****/
247 /**********************************************/
249 const char *SIM_PREEMBULE =
250 "/* specific to Borland Compiler */\n"
251 "#ifdef __BORLANDC__\n"
254 "#include <stdlib.h>\n"
255 "#include <stdio.h>\n"
256 "#include \"msg/msg.h\"\n"
257 "#include <gras.h>\n"
259 "char *gras_log=NULL;\n";
262 #define SIM_LAUNCH_FUNC \
263 "int launch_%s(int argc, char **argv) {\n" \
264 " char **myargv=argv;\n" \
265 " int myargc=argc;\n" \
269 " if (gras_log) {\n"\
270 " myargv=malloc((argc+1) * sizeof(char**));\n" \
271 " for (i=0; i<argc; i++)\n" \
272 " myargv[i] = argv[i];\n" \
273 " myargv[myargc++] = gras_log;\n" \
275 " retcode = %s(myargc,myargv);\n" \
276 " if (myargv != argv)\n" \
278 " return retcode;\n" \
281 const char *SIM_MAIN_POSTEMBULE = "\n"
284 " gras_launch_application(argv[2]);\n"
286 " /* Run the simulation */\n"
289 " /* cleanup the place */\n"
292 " MSG_launch_application(argv[2]);\n"
294 " /* Run the simulation */\n"
297 " /* cleanup the place */\n"
307 /**********************************************/
308 /********* Parse XML deployment file **********/
309 /**********************************************/
310 xbt_dict_t process_function_set = NULL;
311 xbt_dynar_t process_list = NULL;
312 xbt_dict_t machine_set = NULL;
314 typedef struct s_process_t {
320 static void s_process_free(void *process)
323 for(i=0;i<((s_process_t*)process)->argc; i++)
324 free(((s_process_t*)process)->argv[i]);
325 free(((s_process_t*)process)->host);
328 static s_process_t process;
331 * Création de deux dictionnaires
333 static void parse_process_init(void)
335 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
336 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
338 process.argv = xbt_new(char*,1);
339 process.argv[0] = xbt_strdup(A_surfxml_process_function);
340 process.host=strdup(A_surfxml_process_host);
341 /*VERB1("Function: %s",A_surfxml_process_function);*/
344 static void parse_argument(void)
347 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
348 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
351 static void parse_process_finalize(void)
353 xbt_dynar_push(process_list,&process);
354 /*VERB1("Function: %s",process.argv[0]);*/
357 static void generate_sim(char *project)
359 xbt_dict_cursor_t cursor=NULL;
362 char *filename = NULL;
366 * Creation d'un fichier nommé : <projet>_simulator.c
370 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
371 sprintf(filename,SIM_SOURCENAME,project);
373 OUT=fopen(filename,"w");
376 xbt_assert1(OUT, "Unable to open %s for writing",filename);
379 * Ecriture du message d'avertissement.
381 fprintf(OUT, "%s\n",warning);
384 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
386 fprintf(OUT, "%s", SIM_PREEMBULE);
389 * Déclaration des fonction int <process>(int argc,char *argv[]);
391 xbt_dict_foreach(process_function_set,cursor,key,data) {
392 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
398 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
400 xbt_dict_foreach(process_function_set,cursor,key,data) {
401 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
405 * Ecriture du message d'avertissement.
407 fprintf(OUT, "\n%s\n",warning);
409 xbt_dict_foreach(process_function_set,cursor,key,data) {
410 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
412 fprintf(OUT, "\n%s\n",warning);
414 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
415 "#ifdef __BORLANDDC__\n"
419 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
421 " /* Simulation setup */\n"
423 " gras_global_init(&argc,argv);\n"
425 " MSG_global_init(&argc,argv);\n"
427 " if (argc != 3) {\n"
428 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
434 " gras_create_environment(argv[1]);\n"
436 " /* Application deployment */\n"
439 " MSG_paje_output(\"%s.trace\");\n"
440 " MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
441 " MSG_create_environment(argv[1]);\n"
443 " /* Application deployment */\n",
446 xbt_dict_foreach(process_function_set,cursor,key,data) {
448 fprintf(OUT," gras_function_register(\"%s\", launch_%s);\n",key,key);
450 fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key);
453 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
458 /**********************************************/
459 /**** Generate the file for the real life *****/
460 /**********************************************/
461 static void generate_rl(char *project)
463 xbt_dict_cursor_t cursor=NULL;
466 char *filename = NULL;
469 xbt_dict_foreach(process_function_set,cursor,key,data) {
470 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
472 sprintf(filename,RL_SOURCENAME,project,key);
474 OUT=fopen(filename,"w");
475 xbt_assert1(OUT, "Unable to open %s for writing",filename);
477 fprintf(OUT, "\n%s\n",warning);
478 fprintf(OUT, "/* specific to Borland Compiler */\n" \
479 "#ifdef __BORLANDC__\n" \
480 "#pragma hdrstop\n" \
482 "#include <stdio.h>\n" \
483 "#include <signal.h>\n" \
484 "#include <gras.h>\n" \
486 "extern const char * XBT_PUBLIC_DATA _gras_procname;\n" \
487 "/* user code */\n" \
488 "int %s(int argc, char *argv[]);\n" \
490 "/* specific to Borland Compiler */\n" \
491 "#ifdef __BORLANDC__\n" \
492 "#pragma argsused\n" \
494 "int main(int argc, char *argv[]){\n" \
497 " _gras_procname = \"%s\";\n" \
498 " errcode=%s(argc,argv);\n"\
500 " return errcode;\n"\
503 fprintf(OUT, "\n%s\n",warning);
509 static void generate_makefile_am(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_AM));
518 sprintf(filename,MAKEFILE_FILENAME_AM, project);
520 OUT=fopen(filename,"w");
521 xbt_assert1(OUT, "Unable to open %s for writing",filename);
523 fprintf(OUT, "# AUTOMAKE variable definition\n");
524 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
525 fprintf(OUT, "PROGRAMS=");
526 fprintf(OUT, SIM_BINARYNAME,project);
528 xbt_dict_foreach(process_function_set,cursor,key,data) {
530 fprintf(OUT, RL_BINARYNAME, project, key);
533 fprintf(OUT, "\n\n");
534 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
536 fprintf(OUT, SIM_SOURCENAME,project);
537 fprintf(OUT, " %s.c\n", project);
538 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
539 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
541 xbt_dict_foreach(process_function_set,cursor,key,data) {
542 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
544 fprintf(OUT, RL_SOURCENAME, project,key);
545 fprintf(OUT, " %s.c\n", project);
546 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
547 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
550 fprintf(OUT, "\n# cleanup temps\n");
551 fprintf(OUT, "CLEANFILES= ");
552 fprintf(OUT, SIM_SOURCENAME, project);
554 xbt_dict_foreach(process_function_set,cursor,key,data) {
556 fprintf(OUT, RL_SOURCENAME, project,key);
560 fprintf(OUT, "\n# generate temps\n");
561 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
563 xbt_dict_foreach(process_function_set,cursor,key,data) {
564 fprintf(OUT, RL_SOURCENAME, project,key);
567 fprintf(OUT, SIM_SOURCENAME, project);
568 fprintf(OUT, ": %s\n", deployment);
569 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
573 static void generate_makefile_local(char *project, char *deployment)
575 xbt_dict_cursor_t cursor=NULL;
578 char *filename = NULL;
581 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
582 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
584 OUT=fopen(filename,"w");
585 xbt_assert1(OUT, "Unable to open %s for writing",filename);
591 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
594 fprintf(OUT,"## Variable declarations\n"
596 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
600 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
601 "# Compilation will fail if you don't do so\n"
602 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
603 "# You can fiddle the following to make it fit your taste\n"
604 "INCLUDES = -I$(GRAS_ROOT)/include\n"
605 "CFLAGS ?= -O3 -w -g\n"
606 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
607 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
611 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
613 fprintf(OUT, "GENERATED_C_FILES = ");
614 fprintf(OUT, SIM_SOURCENAME" ",project);
615 xbt_dict_foreach(process_function_set,cursor,key,data) {
616 fprintf(OUT, RL_SOURCENAME " ",project, key);
620 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
622 fprintf(OUT, "BIN_FILES = ");
624 fprintf(OUT, SIM_BINARYNAME " ",project);
625 xbt_dict_foreach(process_function_set,cursor,key,data) {
626 fprintf(OUT, RL_BINARYNAME " ", project, key);
632 "## By default, build all the binaries\n"
633 "all: $(BIN_FILES)\n"
636 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
637 xbt_dict_foreach(process_function_set,cursor,key,data) {
638 fprintf(OUT, RL_SOURCENAME, project,key);
641 fprintf(OUT, SIM_SOURCENAME, project);
642 fprintf(OUT, ": %s\n", deployment);
643 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
645 fprintf(OUT, "\n## Generate the binaries\n");
646 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
647 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
648 xbt_dict_foreach(process_function_set,cursor,key,data) {
649 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
650 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
655 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
658 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
662 "##Â Rules for tarballs and cleaning\n"
663 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
664 "distdir: $(DIST_FILES)\n"
665 "\trm -rf $(DISTDIR)\n"
666 "\tmkdir -p $(DISTDIR)\n"
667 "\tcp $^ $(DISTDIR)\n"
669 "dist: clean distdir\n"
670 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
671 "\n", project /*, project*/);
675 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
676 xbt_dict_foreach(process_function_set,cursor,key,data) {
677 fprintf(OUT, " " RL_OBJNAME, project, key);
681 "\trm -rf $(DISTDIR)\n"
687 fprintf(OUT, "############ REMOTE COMPILING #########\n");
690 xbt_dict_foreach(machine_set,cursor,key,data) {
691 fprintf(OUT, "%s ",key);
696 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
697 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
699 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
700 "SIMGRID_VERSION ?=2.92\n"
701 "GRAS_PROJECT ?= %s\n"
702 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
705 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
706 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
707 "\t for site in $(MACHINES) ; do \\\n"
708 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
709 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
710 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
711 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
712 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
713 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
714 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
715 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
716 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
717 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
719 "\t machine=$$site;\\\n"
720 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
722 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
723 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
724 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
726 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
727 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
729 "\t echo \"-- Copy the data over\"; \\\n"
730 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
731 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
732 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
733 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
734 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
736 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
737 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
739 "\t done;\n",project,project,project);
744 static void generate_makefile_remote(char *project, char *deployment)
746 char *filename = NULL;
749 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
750 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
752 OUT=fopen(filename,"w");
753 xbt_assert1(OUT, "Unable to open %s for writing",filename);
756 "INSTALL_PATH ?= $(shell pwd)\n"
759 "\tcd $$GRAS_ROOT ; \\\n"
760 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
761 "\techo $$retrieved; \\\n"
762 "\tif test \"x$$retrieved\" = x; then \\\n"
763 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
764 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
765 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
766 "\t make all install ;\\\n"
769 "compile-gras: compile-simgrid\n"
770 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
771 "\techo $$not_retrieved; \\\n"
772 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
773 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
774 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
778 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
779 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
780 "\trm -rf gras-$(GRAS_PROJECT)*\n"
781 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
783 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
784 " compile-simgrid compile-gras\n"
790 static void generate_deployment(char *project, char *deployment)
792 xbt_dict_cursor_t cursor=NULL;
795 char *filename = NULL;
801 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
802 sprintf(filename,DEPLOYMENT, project);
804 OUT=fopen(filename,"w");
805 xbt_assert1(OUT, "Unable to open %s for writing",filename);
807 fprintf(OUT, "#!/bin/sh\n");
808 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
810 "if test \"${MACHINES+set}\" != set; then \n"
811 " export MACHINES='");
812 xbt_dict_foreach(machine_set,cursor,key,data) {
813 fprintf(OUT, "%s ",key);
818 "if test \"${INSTALL_PATH+set}\" != set; then \n"
819 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
821 "if test \"${GRAS_ROOT+set}\" != set; then \n"
822 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
824 "if test \"${SRCDIR+set}\" != set; then \n"
825 " export SRCDIR=./\n"
827 "if test \"${SIMGRID_URL+set}\" != set; then \n"
828 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
830 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
831 " export SIMGRID_VERSION=2.91\n"
833 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
834 " export GRAS_PROJECT=%s\n"
836 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
837 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
840 "test -e runlogs/ || mkdir -p runlogs/\n",
844 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
845 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
846 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
848 xbt_dynar_foreach (process_list,cpt,proc) {
849 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
850 for(i=1;i<proc.argc;i++) {
851 fprintf(OUT,"%s ",proc.argv[i]);
853 fprintf(OUT,"\";\n");
854 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);
860 static void print(void *p)
870 /* specific to Borland Compiler */
875 int main(int argc, char *argv[])
877 char *project_name = NULL;
878 char *deployment_file = NULL;
881 surf_init(&argc, argv);
883 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
885 project_name = argv[1];
887 process_function_set = xbt_dict_new();
888 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
889 machine_set = xbt_dict_new();
891 STag_surfxml_process_fun = parse_process_init;
892 ETag_surfxml_argument_fun = parse_argument;
893 ETag_surfxml_process_fun = parse_process_finalize;
895 for(i=2; i<argc; i++) {
896 deployment_file = argv[i];
897 surf_parse_open(deployment_file);
899 xbt_assert1(0,"Parse error in %s",deployment_file);
905 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
906 sprintf(warning,WARN,deployment_file);
908 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
909 xbt_dict_cursor_t cursor=NULL;
913 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
914 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
915 xbt_dict_cursor_step(cursor) ) {
916 DEBUG1("Function %s", key);
919 xbt_dict_dump(process_function_set,print);
922 generate_sim(project_name);
923 generate_rl(project_name);
924 generate_makefile_local(project_name, deployment_file);
926 generate_borland_simulation_project(project_name);
927 generate_borland_real_life_project(project_name);
928 generate_simulation_dsp_file(project_name);
929 generate_real_live_dsp_file(project_name);
932 xbt_free(__gras_path);
936 // generate_makefile_remote(project_name, deployment_file);
937 // generate_deployment(project_name, deployment_file);
945 generate_borland_project(borland_project_t project,int is_rl,const char* name)
947 char* binary_path; /* the path of the generated binary file */
948 char* obj_path; /* the path of the generated object file */
949 char* lib_files; /* a list of the libraries used in the borland project */
950 char* main_source; /* the name of the bpf file used by the borland project */
951 char* file_name; /* the file name of the main source file */
952 char* include_path; /* the include path */
955 /* create the borland project file */
956 borland_project_create(project);
958 /* write the xml document header */
959 borland_project_write_xml_header(project);
961 /* write the xml comment to identify a borland project file */
962 borland_project_write_xml_comment(project);
964 /* write the begin of the node PROJECT */
965 borland_project_begin_xml_node(project,"PROJECT");
967 /* write the begin of node MACROS */
968 borland_project_begin_xml_node(project,"MACROS");
970 /* write the borland project version */
971 borland_project_write_xml_element(project,"VERSION",project->version);
973 /* construct and write the borland project binary path */
974 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
975 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
976 borland_project_write_xml_element(project,"PROJECT",binary_path);
977 xbt_free(binary_path);
979 /* construct an write the object files to generate by the compiler */
980 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
981 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
982 borland_project_write_xml_element(project,"OBJFILES",obj_path);
985 /* write the resource files used by the compiler (no resource file used) */
986 borland_project_write_xml_element(project,"RESFILES","");
988 /* write the IDL files of the project (no IDL files used) */
989 borland_project_write_xml_element(project,"IDLFILES","");
991 /* write the IDLGENFILES element (not used) */
992 borland_project_write_xml_element(project,"IDLGENFILES","");
994 /* write the DEFFILE element (not used) */
995 borland_project_write_xml_element(project,"DEFFILE","");
997 /* write the RESDEPEN element (not used, no resource file used) */
998 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
1000 /* construct and write the list of libraries used by the project */
1002 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
1003 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
1007 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
1008 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
1010 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
1011 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
1014 borland_project_write_xml_element(project,"LIBFILES",lib_files);
1015 xbt_free(lib_files);
1017 /* write the SPARELIBS element (not used) */
1018 borland_project_write_xml_element(project,"SPARELIBS","");
1020 /* write the PACKAGES element (no package used) */
1021 borland_project_write_xml_element(project,"PACKAGES","");
1023 /* write the PATHCPP element (the path of the source files of the project)*/
1024 borland_project_write_xml_element(project,"PATHCPP",".;");
1026 /* write the PATHPAS element (not used) */
1027 borland_project_write_xml_element(project,"PATHPAS","");
1029 /* write the PATHRC element (not used) */
1030 borland_project_write_xml_element(project,"PATHRC","");
1032 /* write the PATHASM element (not used) */
1033 borland_project_write_xml_element(project,"PATHASM","");
1035 /* write the DEBUGLIBPATH element (the path for debug) */
1036 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
1038 /* write the RELEASELIBPATH element (the path for release) */
1039 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
1041 /* specify the linker to use */
1042 borland_project_write_xml_element(project,"LINKER","ilink32");
1044 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
1045 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
1047 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
1048 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
1050 /* construct and write the MAINSOURCE element */
1051 main_source = xbt_new0(char,strlen(project->name) + 5);
1052 sprintf(main_source,"%s.bpf",project->name);
1053 /* write the main source file to use in the borland project file */
1054 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
1056 /* create the bpf file used by the borland project */
1057 borland_project_create_main_file(main_source);
1059 /* FIXME resolve the include path */
1060 /* write the INCLUDEPATH element */
1063 buffer =xbt_new0(char,MAX_PATH);
1064 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1066 __gras_path = xbt_new0(char,MAX_PATH);
1067 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1070 /*find_file_path("C:\\","gras.h",__gras_path);*/
1073 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1074 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1076 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1078 xbt_free(include_path);
1080 /* write the LIBPATH element (no librarie paths specified)*/
1081 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1084 * write the WARNINGS element :
1085 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1086 * -w-rvl (-w-8070) disabled the function must return warning
1087 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1088 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1089 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1090 * -w-par (-w-8057) disabled the warning that detect an unused variable
1091 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1092 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1093 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1095 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");
1097 /* write the OTHERFILES element (no other files used used) */
1098 borland_project_write_xml_element(project,"OTHERFILES","");
1100 /* write the end of the node MACROS */
1101 borland_project_end_xml_node(project,"MACROS");
1103 /* write the begin of the node OPTIONS */
1104 borland_project_begin_xml_node(project,"OPTIONS");
1106 /* FIXME check the idlcflags */
1107 /* write the IDLCFLAGS element */
1108 borland_project_write_xml_element(project,"IDLCFLAGS","");
1111 * write the CFLAG1 element (compiler options ) :
1113 * -Od this flag disable all compiler optimisation
1114 * -H this flag specify the name of the file which will contain the precompiled header
1115 * -Hc this flag specify to the compiler to cach the precompiled header
1116 * -Vx this flag specify to the compiler to allow the empty structures
1117 * -Ve this flag specify to the compiler to allow the empty base classes
1118 * -X- this flag activate the auto-depend informations of the compiler
1119 * -r- this flag disabled the use of the processor register
1120 * -a1 this flag specify that the data must be aligned on one byte
1121 * -b- this flag specify that the enums are the smallest size of the integer
1122 * -k (used during debug)
1123 * -y this flag generate the line number for debug
1124 * -v this flag enabled the debugging of the source files
1125 * -vi check the expansion of the inline functions
1126 * -tWC specify that it's a console application
1127 * -tWM- specify that the application is not multithread
1128 * -c generate the object file, no link
1130 borland_project_write_xml_element(project,"CFLAG1","-Od -H=$(BCB)\\lib\\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC -tWM- -c");
1132 /* write the PFLAGS element */
1133 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1135 /* write the RFLAGS element */
1136 borland_project_write_xml_element(project,"RFLAGS","");
1138 /* write the AFLAGS element (assembler flags) :
1140 * /mx (not documented)
1141 * /w2 (not documented)
1142 * /zd (not documented)
1145 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1147 /* write the LFLAGS element (linker flags) :
1149 * -I specify the output directory for object files
1150 * -D register the specified description (no description "")
1151 * -ap build a win32 console application
1152 * -Tpe generate a exe file
1153 * -x do not create the map file
1154 * -Gn do not generate the state file
1155 * -v include the complete debug informations
1157 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1159 /* write the OTHERFILES element (not used)*/
1160 borland_project_write_xml_element(project,"OTHERFILES","");
1162 /* write the end of the node OPTIONS */
1163 borland_project_end_xml_node(project,"OPTIONS");
1165 /* write the begin of the node LINKER */
1166 borland_project_begin_xml_node(project,"LINKER");
1168 /* write the ALLOBJ element */
1169 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1171 /* write the ALLRES element (not used) */
1172 borland_project_write_xml_element(project,"ALLRES","");
1174 /* write the ALLLIB element */
1175 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1177 /* write the OTHERFILES element (not used) */
1178 borland_project_write_xml_element(project,"OTHERFILES","");
1180 /* write the end of the node LINKER */
1181 borland_project_end_xml_node(project,"LINKER");
1183 /* write the begin of the node FILELIST */
1184 borland_project_begin_xml_node(project,"FILELIST");
1186 /* construct and write the list of file elements */
1188 /* add the bpf file to the list */
1189 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1190 xbt_free(main_source);
1192 /* FIXME : check the source file directory */
1193 /* add the generated source file to the list */
1195 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1196 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1197 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1199 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1200 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1201 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1203 xbt_free(file_name);
1205 /* FIXME : check the libraries directory */
1206 /* add the simgrid library to the list */
1209 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1210 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1211 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1214 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1215 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1216 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1220 xbt_free(file_name);
1222 /* write the end of the node FILELIST */
1223 borland_project_end_xml_node(project,"FILELIST");
1225 /* write the begin of the node BUILDTOOLS (not used)*/
1226 borland_project_begin_xml_node(project,"BUILDTOOLS");
1228 /* write the end of the node BUILDTOOLS (not used)*/
1229 borland_project_end_xml_node(project,"BUILDTOOLS");
1231 /* write the begin of the node IDEOPTIONS */
1232 borland_project_begin_xml_node(project,"IDEOPTIONS");
1234 /* write all of the option of the IDE of Borland C++ Builder */
1235 borland_project_write_ide_options(project);
1237 /* write the end of the node IDEOPTIONS */
1238 borland_project_end_xml_node(project,"IDEOPTIONS");
1240 /* write the end of the node PROJECT */
1241 borland_project_end_xml_node(project,"PROJECT");
1243 /* close the borland project file */
1244 borland_project_close(project);
1248 borland_project_write_tabs(borland_project_t project,unsigned int count)
1252 for(pos = 0; pos < count; pos++)
1253 fprintf(project->stream,"\t");
1257 borland_project_begin_xml_node(borland_project_t project, const char* name)
1260 borland_project_write_tabs(project,level);
1262 fprintf(project->stream,"<%s>\n",name);
1268 borland_project_end_xml_node(borland_project_t project, const char* name)
1273 borland_project_write_tabs(project,level);
1275 fprintf(project->stream,"</%s>\n",name);
1280 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1282 borland_project_write_tabs(project,level);
1283 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1287 borland_project_write_xml_header(borland_project_t project)
1289 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1293 borland_project_create_main_file(const char* name)
1295 FILE* stream = fopen(name,"w+");
1297 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1303 borland_project_create(borland_project_t project)
1305 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1306 sprintf(file_name,"%s.bpr",project->name);
1307 project->stream = fopen(file_name,"w+");
1308 xbt_free(file_name);
1312 borland_project_write_xml_comment(borland_project_t project)
1314 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1317 borland_project_write_file_element( borland_project_t project,
1318 const char* file_name,
1319 const char* form_name,
1320 const char* unit_name,
1321 const char* container_id,
1322 const char* design_class,
1323 const char* local_command)
1325 borland_project_write_tabs(project,level);
1327 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);
1331 borland_project_write_ide_options(borland_project_t project)
1334 const char* ide_options =
1335 "[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" \
1336 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1337 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1338 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1339 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1340 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1341 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1342 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1343 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1344 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1345 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1346 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1347 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1348 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1349 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1351 fprintf(project->stream,ide_options);
1355 borland_project_close(borland_project_t project)
1357 fclose(project->stream);
1361 generate_borland_simulation_project(const char* name)
1363 char buffer[MAX_PATH] = {0};
1366 WIN32_FIND_DATA wfd = {0};
1368 s_borland_project_t borland_project = {0};
1369 borland_project.xml_version = "1.0";
1370 borland_project.encoding ="utf-8";
1371 borland_project.comment ="C++Builder XML Project";
1372 borland_project.version = "BCB.06.00";
1374 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1377 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1380 GetCurrentDirectory(MAX_PATH,buffer);
1382 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1384 strcpy(borland_project.src_dir,buffer);
1386 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1387 sprintf(borland_project.name,"%s_simulator",name);
1389 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1390 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1392 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1395 CreateDirectory(borland_project.bin_dir,NULL);
1397 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1398 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1400 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1402 if(INVALID_HANDLE_VALUE == hDir)
1403 CreateDirectory(borland_project.obj_dir,NULL);
1405 generate_borland_project(&borland_project,0,name);
1407 xbt_free(borland_project.name);
1408 xbt_free(borland_project.src_dir);
1409 xbt_free(borland_project.bin_dir);
1410 xbt_free(borland_project.obj_dir);
1411 xbt_free(borland_project.lib_dir);
1415 generate_borland_real_life_project(const char* name)
1418 WIN32_FIND_DATA wfd = {0};
1419 char buffer[MAX_PATH] = {0};
1420 xbt_dict_cursor_t cursor = NULL;
1423 s_borland_project_t borland_project = {0};
1425 borland_project.xml_version = "1.0";
1426 borland_project.encoding ="utf-8";
1427 borland_project.comment ="C++Builder XML Project";
1428 borland_project.version = "BCB.06.00";
1429 borland_project.lib_dir = " ";
1431 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1433 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1435 GetCurrentDirectory(MAX_PATH,buffer);
1437 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1439 strcpy(borland_project.src_dir,buffer);
1441 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1442 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1444 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1446 if(INVALID_HANDLE_VALUE == hDir)
1447 CreateDirectory(borland_project.bin_dir,NULL);
1449 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1450 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1452 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1455 CreateDirectory(borland_project.obj_dir,NULL);
1458 xbt_dict_foreach(process_function_set,cursor,key,data) {
1459 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1461 sprintf(borland_project.name,"%s_%s",name,key);
1463 generate_borland_project(&borland_project,1,name);
1464 xbt_free(borland_project.name);
1467 xbt_free(borland_project.src_dir);
1468 xbt_free(borland_project.bin_dir);
1469 xbt_free(borland_project.obj_dir);
1470 xbt_free(borland_project.lib_dir);
1473 find_file_path(const char* root_dir,const char* file_name,char* path)
1476 WIN32_FIND_DATA wfd;
1477 char* prev_dir = xbt_new(char,MAX_PATH);
1478 GetCurrentDirectory(MAX_PATH,prev_dir);
1479 SetCurrentDirectory(root_dir);
1481 // begining of the scan
1482 hFind=FindFirstFile ("*.*", &wfd);
1484 if(hFind!=INVALID_HANDLE_VALUE){
1487 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1489 if(!strcmp(file_name,wfd.cFileName)){
1490 GetCurrentDirectory(MAX_PATH,path);
1491 SetCurrentDirectory(prev_dir);
1498 /* it's a directory, scan it*/
1501 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1502 if(find_file_path(wfd.cFileName,file_name,path)){
1504 SetCurrentDirectory(prev_dir);
1510 /* next file or directory */
1511 while(FindNextFile(hFind,&wfd))
1514 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1516 if(!strcmp(file_name,wfd.cFileName)){
1517 GetCurrentDirectory(MAX_PATH,path);
1518 SetCurrentDirectory(prev_dir);
1524 /* it's a file scan it */
1527 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1529 if(find_file_path(wfd.cFileName,file_name,path)){
1530 SetCurrentDirectory(prev_dir);
1541 SetCurrentDirectory(prev_dir);
1547 /* Implementation of the functions used to create a Visual C++ project.*/
1550 generate_simulation_dsp_file(const char* name)
1552 char buffer[MAX_PATH] = {0};
1554 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1556 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1557 GetCurrentDirectory(MAX_PATH,buffer);
1559 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1560 strcpy(dsp.src_dir,buffer);
1561 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1562 sprintf(dsp.name,"%s_simulator",name);
1564 generate_dsp_project(&dsp,0,name);
1567 xbt_free(dsp.src_dir);
1568 xbt_free(dsp.lib_dir);
1574 * Create the Microsoft visual C++ real life project file.
1577 generate_real_live_dsp_file(const char* name)
1580 char buffer[MAX_PATH] = {0};
1581 xbt_dict_cursor_t cursor = NULL;
1587 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1589 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1591 GetCurrentDirectory(MAX_PATH,buffer);
1593 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1595 strcpy(dsp.src_dir,buffer);
1598 xbt_dict_foreach(process_function_set,cursor,key,data) {
1599 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1601 sprintf(dsp.name,"%s_%s",name,key);
1603 generate_dsp_project(&dsp,1,name);
1607 xbt_free(dsp.src_dir);
1608 xbt_free(dsp.lib_dir);
1613 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1615 /* create the visual C++ project file */
1617 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1618 sprintf(file_name,"%s.dsp",project->name);
1619 project->stream = fopen(file_name,"w+");
1620 xbt_free(file_name);
1624 buffer =xbt_new0(char,MAX_PATH);
1625 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1627 __gras_path = xbt_new0(char,MAX_PATH);
1628 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1632 /* dsp file header */
1633 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1634 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1635 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1637 /* target type is a win32 x86 console application */
1638 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1640 /* the current config is win32-debug */
1641 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1644 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1647 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1648 fprintf(project->stream,"!MESSAGE\n");
1649 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1650 fprintf(project->stream,"!MESSAGE\n");
1651 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1652 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1653 fprintf(project->stream,"!MESSAGE\n");
1654 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1655 fprintf(project->stream,"!MESSAGE\n");
1656 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1657 fprintf(project->stream,"!MESSAGE\n");
1658 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1659 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1660 fprintf(project->stream,"!MESSAGE\n\n");
1662 fprintf(project->stream,"# Begin Project\n\n");
1663 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1664 fprintf(project->stream,"# PROP Scc_ProjName\n");
1665 fprintf(project->stream,"# PROP Scc_LocalPath\n");
1666 fprintf(project->stream,"CPP=cl.exe\n");
1667 fprintf(project->stream,"RSC=rc.exe\n\n");
1669 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1671 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1672 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1673 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1674 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1675 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1676 fprintf(project->stream,"# PROP Use_MFC 0\n");
1677 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1678 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1679 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1680 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1681 /* TODO : the include directory */
1682 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"./%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);*/
1683 fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /GX /O2 /I \"%s\" /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n",__gras_path);
1684 fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1685 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1686 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1687 fprintf(project->stream,"BSC32=bscmake.exe\n");
1688 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1689 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1690 fprintf(project->stream,"LINK32=link.exe\n");
1691 fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n");
1694 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libgras.lib /nologo /subsystem:console /machine:I386\n\n");
1696 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib /nologo /subsystem:console /machine:I386\n\n");
1698 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1700 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1701 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1702 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1703 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1704 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1705 fprintf(project->stream,"# PROP Use_MFC 0\n");
1706 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1707 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1708 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1709 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1710 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1711 /* TODO : the include directory */
1712 /*fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"./%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",__gras_path);*/
1713 fprintf(project->stream,"# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I \"%s\" /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n",__gras_path);
1714 fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1715 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1716 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1717 fprintf(project->stream,"BSC32=bscmake.exe\n");
1718 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1719 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1720 fprintf(project->stream,"LINK32=link.exe\n");
1721 fprintf(project->stream,"# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n");
1724 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib libgras.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
1726 fprintf(project->stream,"# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib simgrid.lib simgrid.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\n\n");
1728 fprintf(project->stream,"!ENDIF\n\n");
1730 fprintf(project->stream,"# Begin Target\n\n");
1731 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1732 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1733 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1734 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1736 fprintf(project->stream,"# Begin Source File\n");
1737 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1738 fprintf(project->stream,"# End Source File\n\n");
1740 fprintf(project->stream,"# Begin Source File\n");
1741 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1742 fprintf(project->stream,"# End Source File\n\n");
1744 fprintf(project->stream,"# End Group\n");
1745 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1746 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1747 fprintf(project->stream,"# End Group\n");
1748 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1749 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1750 fprintf(project->stream,"# End Group\n");
1751 fprintf(project->stream,"# End Target\n");
1752 fprintf(project->stream,"# End Project\n");