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"
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
31 /* tabulation level (used to indent the lines of the borland project file */
32 static unsigned int level = 0;
36 /* the gras.h header directory */
37 static char* __gras_path = NULL;
45 * A structure which represents a borland project file.
47 typedef struct s_borland_project
49 const char* xml_version;/* the xml version used to write the borland project file */
50 const char* encoding; /* the encoding used to write the borland project file */
51 const char* comment; /* the xml comment to write at the begining of the borland project file */
52 char* name; /* the name of the borland project file */
53 FILE* stream; /* the stream to the borland project file */
54 const char* version; /* the builder version of the borland project file */
55 char* bin_dir; /* the directory used to store the generated program */
56 char* obj_dir; /* the directory used to store the generated object files */
57 char* lib_dir; /* the directory used to store the librairies used in the borland project */
58 char* src_dir; /* the directory use to store the source files of the project */
59 }s_borland_project_t,* borland_project_t;
63 * A structure which represents a visual C++ project file.
74 * Write tabs in a borland project file.
75 * @param project The project concerned by the operation.
76 * @param count The count tab to write
79 borland_project_write_tabs(borland_project_t project,unsigned int count);
82 * Write the begin of an xml node in the borland project file.
83 * @param project The borland project concerned by this operation.
84 * @param name The name of the node.
87 borland_project_begin_xml_node(borland_project_t project, const char* name);
91 * Write the end of an xml node in the borland project file.
92 * @param project The borland project concerned by this operation.
93 * @param name The name of the node.
96 borland_project_end_xml_node(borland_project_t project, const char* name);
99 * Write an xml element in a borland project file.
100 * @param project The borland project concerned by this operation.
101 * @param name The name of the element to write
102 * @param value The value of the element
105 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
108 * Write a FILE xml element in the borland project file.
109 * @param project The borland project concerned by this operation.
110 * @param file_name The value of the attribute FILENAME.
111 * @param form_name The value of the attribute FORMNAME.
112 * @param unit_name The value of the attribute UNITNAME.
113 * @param container_id The value of the attribute CONTAINERID.
114 * @param design_claas The value of the attribute DESIGNCLASS.
115 * @param local_command The value of the attribute LOCALCOMMAND.
118 borland_project_write_file_element( borland_project_t project,
119 const char* file_name,
120 const char* form_name,
121 const char* unit_name,
122 const char* container_id,
123 const char* design_class,
124 const char* local_command);
126 * Write all options of the IDE of the Borland Builder C++ compiler.
127 * @ param project The project concerned by this operation.
131 borland_project_write_ide_options(borland_project_t project);
134 * Write the xml header of the xml document.
135 * @param project The project concerned by the operation.
138 borland_project_write_xml_header(borland_project_t project);
141 * Write an xml comment in a borland project file
142 * @param project The project concerned by this operation.
145 borland_project_write_xml_comment(borland_project_t project);
148 * Create a bpf file used by a borland project file.
149 * @param name The name of the bpf file to create.
152 borland_project_create_main_file(const char* name);
155 * Create a borland project file.
156 * @param project The project concerned by this operation.
159 borland_project_create(borland_project_t project);
162 * Close a borland project file.
163 * @param project the borland project file to close.
166 borland_project_close(borland_project_t project);
170 * Generate a borland simulation poject file.
171 * @param name The name of the simulation project
174 generate_borland_simulation_project(const char* name);
177 * Generate a borland project file for real life.
178 * @param name The name of the project to create.
181 generate_borland_real_life_project(const char* name);
184 * Generate a borland project file.
185 * @param project The borland project to generate.
188 generate_borland_project(borland_project_t project,int is_rl,const char* name);
191 * Find the path of a file.
192 * @param file_name The file name to find.
193 * @path path If founded this parameter will contain the path of file.
194 * @return If successful the function returns 1. Otherwise the function
198 find_file_path(const char* root_dir,const char* file_name,char* path);
202 * Functions used to create a Microsoft Visual C++ project file (*.dsp).
206 * Create the Microsoft visual C++ file project for the simulation.
209 generate_simulation_dsp_file(const char* project_name);
212 * Create the Microsoft visual C++ real life project file.
215 generate_real_live_dsp_file(const char* project_name);
218 * generate a Microsoft Visual project file*/
220 generate_dsp_project(dsp_t project,int is_rl,const char* name);
226 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
227 #define SIM_SOURCENAME "_%s_simulator.c"
228 #define SIM_OBJNAME "_%s_simulator.o"
229 #define SIM_BINARYNAME "%s_simulator"
230 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
231 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
232 #define RL_SOURCENAME "_%s_%s.c"
233 #define RL_OBJNAME "_%s_%s.o"
234 #define RL_BINARYNAME "%s_%s"
235 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
236 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
237 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
238 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
239 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
240 #define DEPLOYMENT "%s.deploy.sh"
242 char *warning = NULL;
244 /**********************************************/
245 /**** Generate the file for the simulator *****/
246 /**********************************************/
248 const char *SIM_PREEMBULE =
249 "/* specific to Borland Compiler */\n"
250 "#ifdef __BORLANDC__\n"
253 "#include <stdlib.h>\n"
254 "#include <stdio.h>\n"
255 "#include \"msg/msg.h\"\n"
256 "#include <gras.h>\n"
258 "char *gras_log=NULL;\n";
261 #define SIM_LAUNCH_FUNC \
262 "int launch_%s(int argc, char **argv) {\n" \
263 " char **myargv=argv;\n" \
264 " int myargc=argc;\n" \
268 " if (gras_log) {\n"\
269 " myargv=malloc((argc+1) * sizeof(char**));\n" \
270 " for (i=0; i<argc; i++)\n" \
271 " myargv[i] = argv[i];\n" \
272 " myargv[myargc++] = gras_log;\n" \
274 " retcode = %s(myargc,myargv);\n" \
275 " if (myargv != argv)\n" \
277 " return retcode;\n" \
280 const char *SIM_MAIN_POSTEMBULE = "\n"
282 " gras_launch_application(argv[2]);\n"
284 " /* Run the simulation */\n"
287 " /* cleanup the place */\n"
296 /**********************************************/
297 /********* Parse XML deployment file **********/
298 /**********************************************/
299 xbt_dict_t process_function_set = NULL;
300 xbt_dynar_t process_list = NULL;
301 xbt_dict_t machine_set = NULL;
303 typedef struct s_process_t {
309 static void s_process_free(void *process)
312 for(i=0;i<((s_process_t*)process)->argc; i++)
313 free(((s_process_t*)process)->argv[i]);
314 free(((s_process_t*)process)->host);
317 static s_process_t process;
320 * Création de deux dictionnaires
322 static void parse_process_init(void)
324 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
325 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
327 process.argv = xbt_new(char*,1);
328 process.argv[0] = xbt_strdup(A_surfxml_process_function);
329 process.host=strdup(A_surfxml_process_host);
330 /*VERB1("Function: %s",A_surfxml_process_function);*/
333 static void parse_argument(void)
336 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
337 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
340 static void parse_process_finalize(void)
342 xbt_dynar_push(process_list,&process);
343 /*VERB1("Function: %s",process.argv[0]);*/
346 static void generate_sim(char *project)
348 xbt_dict_cursor_t cursor=NULL;
351 char *filename = NULL;
355 * Creation d'un fichier nommé : <projet>_simulator.c
359 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
360 sprintf(filename,SIM_SOURCENAME,project);
362 OUT=fopen(filename,"w");
365 xbt_assert1(OUT, "Unable to open %s for writing",filename);
368 * Ecriture du message d'avertissement.
370 fprintf(OUT, "%s\n",warning);
373 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
375 fprintf(OUT, "%s", SIM_PREEMBULE);
378 * Déclaration des fonction int <process>(int argc,char *argv[]);
380 xbt_dict_foreach(process_function_set,cursor,key,data) {
381 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
387 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
389 xbt_dict_foreach(process_function_set,cursor,key,data) {
390 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
394 * Ecriture du message d'avertissement.
396 fprintf(OUT, "\n%s\n",warning);
398 xbt_dict_foreach(process_function_set,cursor,key,data) {
399 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
401 fprintf(OUT, "\n%s\n",warning);
403 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
404 "#ifdef __BORLANDDC__\n"
408 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
410 " /* Simulation setup */\n"
411 " gras_global_init(&argc,argv);\n"
412 " if (argc != 3) {\n"
413 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
418 " //MSG_paje_output(\"%s.trace\");\n"
419 " //MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
420 " gras_create_environment(argv[1]);\n"
422 " /* Application deployment */\n",
424 xbt_dict_foreach(process_function_set,cursor,key,data) {
425 fprintf(OUT," gras_function_register(\"%s\", launch_%s);\n",key,key);
427 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
432 /**********************************************/
433 /**** Generate the file for the real life *****/
434 /**********************************************/
435 static void generate_rl(char *project)
437 xbt_dict_cursor_t cursor=NULL;
440 char *filename = NULL;
443 xbt_dict_foreach(process_function_set,cursor,key,data) {
444 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
446 sprintf(filename,RL_SOURCENAME,project,key);
448 OUT=fopen(filename,"w");
449 xbt_assert1(OUT, "Unable to open %s for writing",filename);
451 fprintf(OUT, "\n%s\n",warning);
452 fprintf(OUT, "/* specific to Borland Compiler */\n" \
453 "#ifdef __BORLANDC__\n" \
454 "#pragma hdrstop\n" \
456 "#include <stdio.h>\n" \
457 "#include <signal.h>\n" \
458 "#include <gras.h>\n" \
460 "extern const char * XBT_PUBLIC_DATA _gras_procname;\n" \
461 "/* user code */\n" \
462 "int %s(int argc, char *argv[]);\n" \
464 "/* specific to Borland Compiler */\n" \
465 "#ifdef __BORLANDC__\n" \
466 "#pragma argsused\n" \
468 "int main(int argc, char *argv[]){\n" \
471 " _gras_procname = \"%s\";\n" \
472 " errcode=%s(argc,argv);\n"\
474 " return errcode;\n"\
477 fprintf(OUT, "\n%s\n",warning);
483 static void generate_makefile_am(char *project, char *deployment)
485 xbt_dict_cursor_t cursor=NULL;
488 char *filename = NULL;
491 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
492 sprintf(filename,MAKEFILE_FILENAME_AM, project);
494 OUT=fopen(filename,"w");
495 xbt_assert1(OUT, "Unable to open %s for writing",filename);
497 fprintf(OUT, "# AUTOMAKE variable definition\n");
498 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
499 fprintf(OUT, "PROGRAMS=");
500 fprintf(OUT, SIM_BINARYNAME,project);
502 xbt_dict_foreach(process_function_set,cursor,key,data) {
504 fprintf(OUT, RL_BINARYNAME, project, key);
507 fprintf(OUT, "\n\n");
508 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
510 fprintf(OUT, SIM_SOURCENAME,project);
511 fprintf(OUT, " %s.c\n", project);
512 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
513 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
515 xbt_dict_foreach(process_function_set,cursor,key,data) {
516 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
518 fprintf(OUT, RL_SOURCENAME, project,key);
519 fprintf(OUT, " %s.c\n", project);
520 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
521 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
524 fprintf(OUT, "\n# cleanup temps\n");
525 fprintf(OUT, "CLEANFILES= ");
526 fprintf(OUT, SIM_SOURCENAME, project);
528 xbt_dict_foreach(process_function_set,cursor,key,data) {
530 fprintf(OUT, RL_SOURCENAME, project,key);
534 fprintf(OUT, "\n# generate temps\n");
535 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
537 xbt_dict_foreach(process_function_set,cursor,key,data) {
538 fprintf(OUT, RL_SOURCENAME, project,key);
541 fprintf(OUT, SIM_SOURCENAME, project);
542 fprintf(OUT, ": %s\n", deployment);
543 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
547 static void generate_makefile_local(char *project, char *deployment)
549 xbt_dict_cursor_t cursor=NULL;
552 char *filename = NULL;
555 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
556 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
558 OUT=fopen(filename,"w");
559 xbt_assert1(OUT, "Unable to open %s for writing",filename);
565 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
568 fprintf(OUT,"## Variable declarations\n"
570 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
574 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
575 "# Compilation will fail if you don't do so\n"
576 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
577 "# You can fiddle the following to make it fit your taste\n"
578 "INCLUDES = -I$(GRAS_ROOT)/include\n"
579 "CFLAGS ?= -O3 -w -g\n"
580 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
581 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
585 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
587 fprintf(OUT, "GENERATED_C_FILES = ");
588 fprintf(OUT, SIM_SOURCENAME" ",project);
589 xbt_dict_foreach(process_function_set,cursor,key,data) {
590 fprintf(OUT, RL_SOURCENAME " ",project, key);
594 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
596 fprintf(OUT, "BIN_FILES = ");
598 fprintf(OUT, SIM_BINARYNAME " ",project);
599 xbt_dict_foreach(process_function_set,cursor,key,data) {
600 fprintf(OUT, RL_BINARYNAME " ", project, key);
606 "## By default, build all the binaries\n"
607 "all: $(BIN_FILES)\n"
610 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
611 xbt_dict_foreach(process_function_set,cursor,key,data) {
612 fprintf(OUT, RL_SOURCENAME, project,key);
615 fprintf(OUT, SIM_SOURCENAME, project);
616 fprintf(OUT, ": %s\n", deployment);
617 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
619 fprintf(OUT, "\n## Generate the binaries\n");
620 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
621 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
622 xbt_dict_foreach(process_function_set,cursor,key,data) {
623 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
624 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
629 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
632 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
636 "##Â Rules for tarballs and cleaning\n"
637 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
638 "distdir: $(DIST_FILES)\n"
639 "\trm -rf $(DISTDIR)\n"
640 "\tmkdir -p $(DISTDIR)\n"
641 "\tcp $^ $(DISTDIR)\n"
643 "dist: clean distdir\n"
644 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
645 "\n", project /*, project*/);
649 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
650 xbt_dict_foreach(process_function_set,cursor,key,data) {
651 fprintf(OUT, " " RL_OBJNAME, project, key);
655 "\trm -rf $(DISTDIR)\n"
661 fprintf(OUT, "############ REMOTE COMPILING #########\n");
664 xbt_dict_foreach(machine_set,cursor,key,data) {
665 fprintf(OUT, "%s ",key);
670 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
671 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
673 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
674 "SIMGRID_VERSION ?=2.92\n"
675 "GRAS_PROJECT ?= %s\n"
676 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
679 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
680 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
681 "\t for site in $(MACHINES) ; do \\\n"
682 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
683 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
684 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
685 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
686 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
687 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
688 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
689 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
690 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
691 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
693 "\t machine=$$site;\\\n"
694 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
696 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
697 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
698 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
700 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
701 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
703 "\t echo \"-- Copy the data over\"; \\\n"
704 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
705 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
706 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
707 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
708 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
710 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
711 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
713 "\t done;\n",project,project,project);
718 static void generate_makefile_remote(char *project, char *deployment)
720 char *filename = NULL;
723 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
724 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
726 OUT=fopen(filename,"w");
727 xbt_assert1(OUT, "Unable to open %s for writing",filename);
730 "INSTALL_PATH ?= $(shell pwd)\n"
733 "\tcd $$GRAS_ROOT ; \\\n"
734 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
735 "\techo $$retrieved; \\\n"
736 "\tif test \"x$$retrieved\" = x; then \\\n"
737 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
738 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
739 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
740 "\t make all install ;\\\n"
743 "compile-gras: compile-simgrid\n"
744 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
745 "\techo $$not_retrieved; \\\n"
746 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
747 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
748 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
752 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
753 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
754 "\trm -rf gras-$(GRAS_PROJECT)*\n"
755 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
757 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
758 " compile-simgrid compile-gras\n"
764 static void generate_deployment(char *project, char *deployment)
766 xbt_dict_cursor_t cursor=NULL;
769 char *filename = NULL;
775 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
776 sprintf(filename,DEPLOYMENT, project);
778 OUT=fopen(filename,"w");
779 xbt_assert1(OUT, "Unable to open %s for writing",filename);
781 fprintf(OUT, "#!/bin/sh\n");
782 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
784 "if test \"${MACHINES+set}\" != set; then \n"
785 " export MACHINES='");
786 xbt_dict_foreach(machine_set,cursor,key,data) {
787 fprintf(OUT, "%s ",key);
792 "if test \"${INSTALL_PATH+set}\" != set; then \n"
793 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
795 "if test \"${GRAS_ROOT+set}\" != set; then \n"
796 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
798 "if test \"${SRCDIR+set}\" != set; then \n"
799 " export SRCDIR=./\n"
801 "if test \"${SIMGRID_URL+set}\" != set; then \n"
802 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
804 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
805 " export SIMGRID_VERSION=2.91\n"
807 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
808 " export GRAS_PROJECT=%s\n"
810 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
811 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
814 "test -e runlogs/ || mkdir -p runlogs/\n",
818 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
819 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
820 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
822 xbt_dynar_foreach (process_list,cpt,proc) {
823 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
824 for(i=1;i<proc.argc;i++) {
825 fprintf(OUT,"%s ",proc.argv[i]);
827 fprintf(OUT,"\";\n");
828 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);
834 static void print(void *p)
844 /* specific to Borland Compiler */
849 int main(int argc, char *argv[])
851 char *project_name = NULL;
852 char *deployment_file = NULL;
855 surf_init(&argc, argv);
857 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
859 project_name = argv[1];
861 process_function_set = xbt_dict_new();
862 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
863 machine_set = xbt_dict_new();
865 STag_surfxml_process_fun = parse_process_init;
866 ETag_surfxml_argument_fun = parse_argument;
867 ETag_surfxml_process_fun = parse_process_finalize;
869 for(i=2; i<argc; i++) {
870 deployment_file = argv[i];
871 surf_parse_open(deployment_file);
873 xbt_assert1(0,"Parse error in %s",deployment_file);
879 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
880 sprintf(warning,WARN,deployment_file);
882 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
883 xbt_dict_cursor_t cursor=NULL;
887 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
888 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
889 xbt_dict_cursor_step(cursor) ) {
890 DEBUG1("Function %s", key);
893 xbt_dict_dump(process_function_set,print);
896 generate_sim(project_name);
897 generate_rl(project_name);
898 generate_makefile_local(project_name, deployment_file);
900 generate_borland_simulation_project(project_name);
901 generate_borland_real_life_project(project_name);
902 generate_simulation_dsp_file(project_name);
903 generate_real_live_dsp_file(project_name);
906 xbt_free(__gras_path);
910 // generate_makefile_remote(project_name, deployment_file);
911 // generate_deployment(project_name, deployment_file);
919 generate_borland_project(borland_project_t project,int is_rl,const char* name)
921 char* binary_path; /* the path of the generated binary file */
922 char* obj_path; /* the path of the generated object file */
923 char* lib_files; /* a list of the libraries used in the borland project */
924 char* main_source; /* the name of the bpf file used by the borland project */
925 char* file_name; /* the file name of the main source file */
926 char* include_path; /* the include path */
929 /* create the borland project file */
930 borland_project_create(project);
932 /* write the xml document header */
933 borland_project_write_xml_header(project);
935 /* write the xml comment to identify a borland project file */
936 borland_project_write_xml_comment(project);
938 /* write the begin of the node PROJECT */
939 borland_project_begin_xml_node(project,"PROJECT");
941 /* write the begin of node MACROS */
942 borland_project_begin_xml_node(project,"MACROS");
944 /* write the borland project version */
945 borland_project_write_xml_element(project,"VERSION",project->version);
947 /* construct and write the borland project binary path */
948 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
949 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
950 borland_project_write_xml_element(project,"PROJECT",binary_path);
951 xbt_free(binary_path);
953 /* construct an write the object files to generate by the compiler */
954 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
955 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
956 borland_project_write_xml_element(project,"OBJFILES",obj_path);
959 /* write the resource files used by the compiler (no resource file used) */
960 borland_project_write_xml_element(project,"RESFILES","");
962 /* write the IDL files of the project (no IDL files used) */
963 borland_project_write_xml_element(project,"IDLFILES","");
965 /* write the IDLGENFILES element (not used) */
966 borland_project_write_xml_element(project,"IDLGENFILES","");
968 /* write the DEFFILE element (not used) */
969 borland_project_write_xml_element(project,"DEFFILE","");
971 /* write the RESDEPEN element (not used, no resource file used) */
972 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
974 /* construct and write the list of libraries used by the project */
976 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
977 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
981 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
982 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
984 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
985 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
988 borland_project_write_xml_element(project,"LIBFILES",lib_files);
991 /* write the SPARELIBS element (not used) */
992 borland_project_write_xml_element(project,"SPARELIBS","");
994 /* write the PACKAGES element (no package used) */
995 borland_project_write_xml_element(project,"PACKAGES","");
997 /* write the PATHCPP element (the path of the source files of the project)*/
998 borland_project_write_xml_element(project,"PATHCPP",".;");
1000 /* write the PATHPAS element (not used) */
1001 borland_project_write_xml_element(project,"PATHPAS","");
1003 /* write the PATHRC element (not used) */
1004 borland_project_write_xml_element(project,"PATHRC","");
1006 /* write the PATHASM element (not used) */
1007 borland_project_write_xml_element(project,"PATHASM","");
1009 /* write the DEBUGLIBPATH element (the path for debug) */
1010 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
1012 /* write the RELEASELIBPATH element (the path for release) */
1013 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
1015 /* specify the linker to use */
1016 borland_project_write_xml_element(project,"LINKER","ilink32");
1018 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
1019 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
1021 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
1022 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
1024 /* construct and write the MAINSOURCE element */
1025 main_source = xbt_new0(char,strlen(project->name) + 5);
1026 sprintf(main_source,"%s.bpf",project->name);
1027 /* write the main source file to use in the borland project file */
1028 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
1030 /* create the bpf file used by the borland project */
1031 borland_project_create_main_file(main_source);
1033 /* FIXME resolve the include path */
1034 /* write the INCLUDEPATH element */
1037 buffer =xbt_new0(char,MAX_PATH);
1038 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1040 __gras_path = xbt_new0(char,MAX_PATH);
1041 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1044 /*find_file_path("C:\\","gras.h",__gras_path);*/
1047 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1048 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1050 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1052 xbt_free(include_path);
1054 /* write the LIBPATH element (no librarie paths specified)*/
1055 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1058 * write the WARNINGS element :
1059 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1060 * -w-rvl (-w-8070) disabled the function must return warning
1061 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1062 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1063 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1064 * -w-par (-w-8057) disabled the warning that detect an unused variable
1065 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1066 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1067 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1069 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");
1071 /* write the OTHERFILES element (no other files used used) */
1072 borland_project_write_xml_element(project,"OTHERFILES","");
1074 /* write the end of the node MACROS */
1075 borland_project_end_xml_node(project,"MACROS");
1077 /* write the begin of the node OPTIONS */
1078 borland_project_begin_xml_node(project,"OPTIONS");
1080 /* FIXME check the idlcflags */
1081 /* write the IDLCFLAGS element */
1082 borland_project_write_xml_element(project,"IDLCFLAGS","");
1085 * write the CFLAG1 element (compiler options ) :
1087 * -Od this flag disable all compiler optimisation
1088 * -H this flag specify the name of the file which will contain the precompiled header
1089 * -Hc this flag specify to the compiler to cach the precompiled header
1090 * -Vx this flag specify to the compiler to allow the empty structures
1091 * -Ve this flag specify to the compiler to allow the empty base classes
1092 * -X- this flag activate the auto-depend informations of the compiler
1093 * -r- this flag disabled the use of the processor register
1094 * -a1 this flag specify that the data must be aligned on one byte
1095 * -b- this flag specify that the enums are the smallest size of the integer
1096 * -k (used during debug)
1097 * -y this flag generate the line number for debug
1098 * -v this flag enabled the debugging of the source files
1099 * -vi check the expansion of the inline functions
1100 * -tWC specify that it's a console application
1101 * -tWM- specify that the application is not multithread
1102 * -c generate the object file, no link
1104 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");
1106 /* write the PFLAGS element */
1107 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1109 /* write the RFLAGS element */
1110 borland_project_write_xml_element(project,"RFLAGS","");
1112 /* write the AFLAGS element (assembler flags) :
1114 * /mx (not documented)
1115 * /w2 (not documented)
1116 * /zd (not documented)
1119 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1121 /* write the LFLAGS element (linker flags) :
1123 * -I specify the output directory for object files
1124 * -D register the specified description (no description "")
1125 * -ap build a win32 console application
1126 * -Tpe generate a exe file
1127 * -x do not create the map file
1128 * -Gn do not generate the state file
1129 * -v include the complete debug informations
1131 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1133 /* write the OTHERFILES element (not used)*/
1134 borland_project_write_xml_element(project,"OTHERFILES","");
1136 /* write the end of the node OPTIONS */
1137 borland_project_end_xml_node(project,"OPTIONS");
1139 /* write the begin of the node LINKER */
1140 borland_project_begin_xml_node(project,"LINKER");
1142 /* write the ALLOBJ element */
1143 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1145 /* write the ALLRES element (not used) */
1146 borland_project_write_xml_element(project,"ALLRES","");
1148 /* write the ALLLIB element */
1149 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1151 /* write the OTHERFILES element (not used) */
1152 borland_project_write_xml_element(project,"OTHERFILES","");
1154 /* write the end of the node LINKER */
1155 borland_project_end_xml_node(project,"LINKER");
1157 /* write the begin of the node FILELIST */
1158 borland_project_begin_xml_node(project,"FILELIST");
1160 /* construct and write the list of file elements */
1162 /* add the bpf file to the list */
1163 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1164 xbt_free(main_source);
1166 /* FIXME : check the source file directory */
1167 /* add the generated source file to the list */
1169 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1170 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1171 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1173 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1174 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1175 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1177 xbt_free(file_name);
1179 /* FIXME : check the libraries directory */
1180 /* add the simgrid library to the list */
1183 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1184 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1185 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1188 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1189 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1190 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1194 xbt_free(file_name);
1196 /* write the end of the node FILELIST */
1197 borland_project_end_xml_node(project,"FILELIST");
1199 /* write the begin of the node BUILDTOOLS (not used)*/
1200 borland_project_begin_xml_node(project,"BUILDTOOLS");
1202 /* write the end of the node BUILDTOOLS (not used)*/
1203 borland_project_end_xml_node(project,"BUILDTOOLS");
1205 /* write the begin of the node IDEOPTIONS */
1206 borland_project_begin_xml_node(project,"IDEOPTIONS");
1208 /* write all of the option of the IDE of Borland C++ Builder */
1209 borland_project_write_ide_options(project);
1211 /* write the end of the node IDEOPTIONS */
1212 borland_project_end_xml_node(project,"IDEOPTIONS");
1214 /* write the end of the node PROJECT */
1215 borland_project_end_xml_node(project,"PROJECT");
1217 /* close the borland project file */
1218 borland_project_close(project);
1222 borland_project_write_tabs(borland_project_t project,unsigned int count)
1226 for(pos = 0; pos < count; pos++)
1227 fprintf(project->stream,"\t");
1231 borland_project_begin_xml_node(borland_project_t project, const char* name)
1234 borland_project_write_tabs(project,level);
1236 fprintf(project->stream,"<%s>\n",name);
1242 borland_project_end_xml_node(borland_project_t project, const char* name)
1247 borland_project_write_tabs(project,level);
1249 fprintf(project->stream,"</%s>\n",name);
1254 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1256 borland_project_write_tabs(project,level);
1257 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1261 borland_project_write_xml_header(borland_project_t project)
1263 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1267 borland_project_create_main_file(const char* name)
1269 FILE* stream = fopen(name,"w+");
1271 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1277 borland_project_create(borland_project_t project)
1279 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1280 sprintf(file_name,"%s.bpr",project->name);
1281 project->stream = fopen(file_name,"w+");
1282 xbt_free(file_name);
1286 borland_project_write_xml_comment(borland_project_t project)
1288 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1291 borland_project_write_file_element( borland_project_t project,
1292 const char* file_name,
1293 const char* form_name,
1294 const char* unit_name,
1295 const char* container_id,
1296 const char* design_class,
1297 const char* local_command)
1299 borland_project_write_tabs(project,level);
1301 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);
1305 borland_project_write_ide_options(borland_project_t project)
1308 const char* ide_options =
1309 "[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" \
1310 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1311 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1312 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1313 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1314 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1315 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1316 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1317 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1318 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1319 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1320 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1321 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1322 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1323 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1325 fprintf(project->stream,ide_options);
1329 borland_project_close(borland_project_t project)
1331 fclose(project->stream);
1335 generate_borland_simulation_project(const char* name)
1337 char buffer[MAX_PATH] = {0};
1340 WIN32_FIND_DATA wfd = {0};
1342 s_borland_project_t borland_project = {0};
1343 borland_project.xml_version = "1.0";
1344 borland_project.encoding ="utf-8";
1345 borland_project.comment ="C++Builder XML Project";
1346 borland_project.version = "BCB.06.00";
1348 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1351 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1354 GetCurrentDirectory(MAX_PATH,buffer);
1356 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1358 strcpy(borland_project.src_dir,buffer);
1360 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1361 sprintf(borland_project.name,"%s_simulator",name);
1363 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1364 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1366 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1369 CreateDirectory(borland_project.bin_dir,NULL);
1371 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1372 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1374 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1376 if(INVALID_HANDLE_VALUE == hDir)
1377 CreateDirectory(borland_project.obj_dir,NULL);
1379 generate_borland_project(&borland_project,0,name);
1381 xbt_free(borland_project.name);
1382 xbt_free(borland_project.src_dir);
1383 xbt_free(borland_project.bin_dir);
1384 xbt_free(borland_project.obj_dir);
1385 xbt_free(borland_project.lib_dir);
1389 generate_borland_real_life_project(const char* name)
1392 WIN32_FIND_DATA wfd = {0};
1393 char buffer[MAX_PATH] = {0};
1394 xbt_dict_cursor_t cursor = NULL;
1397 s_borland_project_t borland_project = {0};
1399 borland_project.xml_version = "1.0";
1400 borland_project.encoding ="utf-8";
1401 borland_project.comment ="C++Builder XML Project";
1402 borland_project.version = "BCB.06.00";
1403 borland_project.lib_dir = " ";
1405 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1407 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1409 GetCurrentDirectory(MAX_PATH,buffer);
1411 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1413 strcpy(borland_project.src_dir,buffer);
1415 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1416 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1418 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1420 if(INVALID_HANDLE_VALUE == hDir)
1421 CreateDirectory(borland_project.bin_dir,NULL);
1423 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1424 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1426 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1429 CreateDirectory(borland_project.obj_dir,NULL);
1432 xbt_dict_foreach(process_function_set,cursor,key,data) {
1433 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1435 sprintf(borland_project.name,"%s_%s",name,key);
1437 generate_borland_project(&borland_project,1,name);
1438 xbt_free(borland_project.name);
1441 xbt_free(borland_project.src_dir);
1442 xbt_free(borland_project.bin_dir);
1443 xbt_free(borland_project.obj_dir);
1444 xbt_free(borland_project.lib_dir);
1447 find_file_path(const char* root_dir,const char* file_name,char* path)
1450 WIN32_FIND_DATA wfd;
1451 char* prev_dir = xbt_new(char,MAX_PATH);
1452 GetCurrentDirectory(MAX_PATH,prev_dir);
1453 SetCurrentDirectory(root_dir);
1455 // begining of the scan
1456 hFind=FindFirstFile ("*.*", &wfd);
1458 if(hFind!=INVALID_HANDLE_VALUE){
1461 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1463 if(!strcmp(file_name,wfd.cFileName)){
1464 GetCurrentDirectory(MAX_PATH,path);
1465 SetCurrentDirectory(prev_dir);
1472 /* it's a directory, scan it*/
1475 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1476 if(find_file_path(wfd.cFileName,file_name,path)){
1478 SetCurrentDirectory(prev_dir);
1484 /* next file or directory */
1485 while(FindNextFile(hFind,&wfd))
1488 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1490 if(!strcmp(file_name,wfd.cFileName)){
1491 GetCurrentDirectory(MAX_PATH,path);
1492 SetCurrentDirectory(prev_dir);
1498 /* it's a file scan it */
1501 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1503 if(find_file_path(wfd.cFileName,file_name,path)){
1504 SetCurrentDirectory(prev_dir);
1515 SetCurrentDirectory(prev_dir);
1521 /* Implementation of the functions used to create a Visual C++ project.*/
1524 generate_simulation_dsp_file(const char* name)
1526 char buffer[MAX_PATH] = {0};
1528 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1530 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1531 GetCurrentDirectory(MAX_PATH,buffer);
1533 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1534 strcpy(dsp.src_dir,buffer);
1535 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1536 sprintf(dsp.name,"%s_simulator",name);
1538 generate_dsp_project(&dsp,0,name);
1541 xbt_free(dsp.src_dir);
1542 xbt_free(dsp.lib_dir);
1548 * Create the Microsoft visual C++ real life project file.
1551 generate_real_live_dsp_file(const char* name)
1554 char buffer[MAX_PATH] = {0};
1555 xbt_dict_cursor_t cursor = NULL;
1561 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1563 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1565 GetCurrentDirectory(MAX_PATH,buffer);
1567 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1569 strcpy(dsp.src_dir,buffer);
1572 xbt_dict_foreach(process_function_set,cursor,key,data) {
1573 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1575 sprintf(dsp.name,"%s_%s",name,key);
1577 generate_dsp_project(&dsp,1,name);
1581 xbt_free(dsp.src_dir);
1582 xbt_free(dsp.lib_dir);
1587 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1589 /* create the visual C++ project file */
1591 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1592 sprintf(file_name,"%s.dsp",project->name);
1593 project->stream = fopen(file_name,"w+");
1594 xbt_free(file_name);
1598 buffer =xbt_new0(char,MAX_PATH);
1599 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1601 __gras_path = xbt_new0(char,MAX_PATH);
1602 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1606 /* dsp file header */
1607 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1608 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1609 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1611 /* target type is a win32 x86 console application */
1612 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1614 /* the current config is win32-debug */
1615 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1618 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1621 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1622 fprintf(project->stream,"!MESSAGE\n");
1623 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1624 fprintf(project->stream,"!MESSAGE\n");
1625 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1626 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1627 fprintf(project->stream,"!MESSAGE\n");
1628 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1629 fprintf(project->stream,"!MESSAGE\n");
1630 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1631 fprintf(project->stream,"!MESSAGE\n");
1632 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1633 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1634 fprintf(project->stream,"!MESSAGE\n\n");
1636 fprintf(project->stream,"# Begin Project\n\n");
1637 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1638 fprintf(project->stream,"# PROP Scc_ProjName\n");
1639 fprintf(project->stream,"# PROP Scc_LocalPath\n");
1640 fprintf(project->stream,"CPP=cl.exe\n");
1641 fprintf(project->stream,"RSC=rc.exe\n\n");
1643 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1645 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1646 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1647 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1648 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1649 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1650 fprintf(project->stream,"# PROP Use_MFC 0\n");
1651 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1652 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1653 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1654 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1655 /* TODO : the include directory */
1656 /*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);*/
1657 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);
1658 fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1659 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1660 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1661 fprintf(project->stream,"BSC32=bscmake.exe\n");
1662 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1663 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1664 fprintf(project->stream,"LINK32=link.exe\n");
1665 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");
1668 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");
1670 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");
1672 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1674 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1675 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1676 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1677 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1678 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1679 fprintf(project->stream,"# PROP Use_MFC 0\n");
1680 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1681 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1682 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1683 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1684 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1685 /* TODO : the include directory */
1686 /*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);*/
1687 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);
1688 fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1689 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1690 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1691 fprintf(project->stream,"BSC32=bscmake.exe\n");
1692 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1693 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1694 fprintf(project->stream,"LINK32=link.exe\n");
1695 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");
1698 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");
1700 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");
1702 fprintf(project->stream,"!ENDIF\n\n");
1704 fprintf(project->stream,"# Begin Target\n\n");
1705 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1706 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1707 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1708 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1710 fprintf(project->stream,"# Begin Source File\n");
1711 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1712 fprintf(project->stream,"# End Source File\n\n");
1714 fprintf(project->stream,"# Begin Source File\n");
1715 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1716 fprintf(project->stream,"# End Source File\n\n");
1718 fprintf(project->stream,"# End Group\n");
1719 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1720 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1721 fprintf(project->stream,"# End Group\n");
1722 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1723 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1724 fprintf(project->stream,"# End Group\n");
1725 fprintf(project->stream,"# End Target\n");
1726 fprintf(project->stream,"# End Project\n");