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"
283 " gras_launch_application(argv[2]);\n"
285 " /* Run the simulation */\n"
288 " /* cleanup the place */\n"
297 /**********************************************/
298 /********* Parse XML deployment file **********/
299 /**********************************************/
300 xbt_dict_t process_function_set = NULL;
301 xbt_dynar_t process_list = NULL;
302 xbt_dict_t machine_set = NULL;
304 typedef struct s_process_t {
310 static void s_process_free(void *process)
313 for(i=0;i<((s_process_t*)process)->argc; i++)
314 free(((s_process_t*)process)->argv[i]);
315 free(((s_process_t*)process)->host);
318 static s_process_t process;
321 * Création de deux dictionnaires
323 static void parse_process_init(void)
325 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
326 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
328 process.argv = xbt_new(char*,1);
329 process.argv[0] = xbt_strdup(A_surfxml_process_function);
330 process.host=strdup(A_surfxml_process_host);
331 /*VERB1("Function: %s",A_surfxml_process_function);*/
334 static void parse_argument(void)
337 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
338 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
341 static void parse_process_finalize(void)
343 xbt_dynar_push(process_list,&process);
344 /*VERB1("Function: %s",process.argv[0]);*/
347 static void generate_sim(char *project)
349 xbt_dict_cursor_t cursor=NULL;
352 char *filename = NULL;
356 * Creation d'un fichier nommé : <projet>_simulator.c
360 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
361 sprintf(filename,SIM_SOURCENAME,project);
363 OUT=fopen(filename,"w");
366 xbt_assert1(OUT, "Unable to open %s for writing",filename);
369 * Ecriture du message d'avertissement.
371 fprintf(OUT, "%s\n",warning);
374 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
376 fprintf(OUT, "%s", SIM_PREEMBULE);
379 * Déclaration des fonction int <process>(int argc,char *argv[]);
381 xbt_dict_foreach(process_function_set,cursor,key,data) {
382 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
388 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
390 xbt_dict_foreach(process_function_set,cursor,key,data) {
391 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
395 * Ecriture du message d'avertissement.
397 fprintf(OUT, "\n%s\n",warning);
399 xbt_dict_foreach(process_function_set,cursor,key,data) {
400 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
402 fprintf(OUT, "\n%s\n",warning);
404 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
405 "#ifdef __BORLANDDC__\n"
409 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
411 " /* Simulation setup */\n"
412 " gras_global_init(&argc,argv);\n"
413 " if (argc != 3) {\n"
414 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
419 " gras_create_environment(argv[1]);\n"
421 " /* Application deployment */\n"
423 xbt_dict_foreach(process_function_set,cursor,key,data) {
424 fprintf(OUT," gras_function_register(\"%s\", launch_%s);\n",key,key);
426 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
431 /**********************************************/
432 /**** Generate the file for the real life *****/
433 /**********************************************/
434 static void generate_rl(char *project)
436 xbt_dict_cursor_t cursor=NULL;
439 char *filename = NULL;
442 xbt_dict_foreach(process_function_set,cursor,key,data) {
443 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
445 sprintf(filename,RL_SOURCENAME,project,key);
447 OUT=fopen(filename,"w");
448 xbt_assert1(OUT, "Unable to open %s for writing",filename);
450 fprintf(OUT, "\n%s\n",warning);
451 fprintf(OUT, "/* specific to Borland Compiler */\n" \
452 "#ifdef __BORLANDC__\n" \
453 "#pragma hdrstop\n" \
455 "#include <stdio.h>\n" \
456 "#include <signal.h>\n" \
457 "#include <gras.h>\n" \
459 "XBT_PUBLIC_DATA(const char *) _gras_procname;\n" \
460 "/* user code */\n" \
461 "int %s(int argc, char *argv[]);\n" \
463 "/* specific to Borland Compiler */\n" \
464 "#ifdef __BORLANDC__\n" \
465 "#pragma argsused\n" \
467 "int main(int argc, char *argv[]){\n" \
470 " _gras_procname = \"%s\";\n" \
471 " errcode=%s(argc,argv);\n"\
473 " return errcode;\n"\
476 fprintf(OUT, "\n%s\n",warning);
482 static void generate_makefile_am(char *project, char *deployment)
484 xbt_dict_cursor_t cursor=NULL;
487 char *filename = NULL;
490 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
491 sprintf(filename,MAKEFILE_FILENAME_AM, project);
493 OUT=fopen(filename,"w");
494 xbt_assert1(OUT, "Unable to open %s for writing",filename);
496 fprintf(OUT, "# AUTOMAKE variable definition\n");
497 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
498 fprintf(OUT, "PROGRAMS=");
499 fprintf(OUT, SIM_BINARYNAME,project);
501 xbt_dict_foreach(process_function_set,cursor,key,data) {
503 fprintf(OUT, RL_BINARYNAME, project, key);
506 fprintf(OUT, "\n\n");
507 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
509 fprintf(OUT, SIM_SOURCENAME,project);
510 fprintf(OUT, " %s.c\n", project);
511 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
512 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
514 xbt_dict_foreach(process_function_set,cursor,key,data) {
515 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
517 fprintf(OUT, RL_SOURCENAME, project,key);
518 fprintf(OUT, " %s.c\n", project);
519 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
520 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
523 fprintf(OUT, "\n# cleanup temps\n");
524 fprintf(OUT, "CLEANFILES= ");
525 fprintf(OUT, SIM_SOURCENAME, project);
527 xbt_dict_foreach(process_function_set,cursor,key,data) {
529 fprintf(OUT, RL_SOURCENAME, project,key);
533 fprintf(OUT, "\n# generate temps\n");
534 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
536 xbt_dict_foreach(process_function_set,cursor,key,data) {
537 fprintf(OUT, RL_SOURCENAME, project,key);
540 fprintf(OUT, SIM_SOURCENAME, project);
541 fprintf(OUT, ": %s\n", deployment);
542 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
546 static void generate_makefile_local(char *project, char *deployment)
548 xbt_dict_cursor_t cursor=NULL;
551 char *filename = NULL;
554 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
555 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
557 OUT=fopen(filename,"w");
558 xbt_assert1(OUT, "Unable to open %s for writing",filename);
564 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
567 fprintf(OUT,"## Variable declarations\n"
569 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
573 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
574 "# Compilation will fail if you don't do so\n"
575 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
576 "# You can fiddle the following to make it fit your taste\n"
577 "INCLUDES = -I$(GRAS_ROOT)/include\n"
578 "CFLAGS ?= -O3 -w -g\n"
579 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
580 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
584 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
586 fprintf(OUT, "GENERATED_C_FILES = ");
587 fprintf(OUT, SIM_SOURCENAME" ",project);
588 xbt_dict_foreach(process_function_set,cursor,key,data) {
589 fprintf(OUT, RL_SOURCENAME " ",project, key);
593 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
595 fprintf(OUT, "BIN_FILES = ");
597 fprintf(OUT, SIM_BINARYNAME " ",project);
598 xbt_dict_foreach(process_function_set,cursor,key,data) {
599 fprintf(OUT, RL_BINARYNAME " ", project, key);
605 "## By default, build all the binaries\n"
606 "all: $(BIN_FILES)\n"
609 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
610 xbt_dict_foreach(process_function_set,cursor,key,data) {
611 fprintf(OUT, RL_SOURCENAME, project,key);
614 fprintf(OUT, SIM_SOURCENAME, project);
615 fprintf(OUT, ": %s\n", deployment);
616 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
618 fprintf(OUT, "\n## Generate the binaries\n");
619 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
620 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
621 xbt_dict_foreach(process_function_set,cursor,key,data) {
622 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
623 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
628 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
631 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
635 "##Â Rules for tarballs and cleaning\n"
636 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
637 "distdir: $(DIST_FILES)\n"
638 "\trm -rf $(DISTDIR)\n"
639 "\tmkdir -p $(DISTDIR)\n"
640 "\tcp $^ $(DISTDIR)\n"
642 "dist: clean distdir\n"
643 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
644 "\n", project /*, project*/);
648 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
649 xbt_dict_foreach(process_function_set,cursor,key,data) {
650 fprintf(OUT, " " RL_OBJNAME, project, key);
654 "\trm -rf $(DISTDIR)\n"
660 fprintf(OUT, "############ REMOTE COMPILING #########\n");
663 xbt_dict_foreach(machine_set,cursor,key,data) {
664 fprintf(OUT, "%s ",key);
669 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
670 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
672 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
673 "SIMGRID_VERSION ?=2.92\n"
674 "GRAS_PROJECT ?= %s\n"
675 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
678 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
679 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
680 "\t for site in $(MACHINES) ; do \\\n"
681 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
682 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
683 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
684 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
685 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
686 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
687 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
688 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
689 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
690 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
692 "\t machine=$$site;\\\n"
693 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
695 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
696 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
697 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
699 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
700 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
702 "\t echo \"-- Copy the data over\"; \\\n"
703 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
704 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
705 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
706 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
707 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
709 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
710 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
712 "\t done;\n",project,project,project);
717 static void generate_makefile_remote(char *project, char *deployment)
719 char *filename = NULL;
722 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
723 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
725 OUT=fopen(filename,"w");
726 xbt_assert1(OUT, "Unable to open %s for writing",filename);
729 "INSTALL_PATH ?= $(shell pwd)\n"
732 "\tcd $$GRAS_ROOT ; \\\n"
733 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
734 "\techo $$retrieved; \\\n"
735 "\tif test \"x$$retrieved\" = x; then \\\n"
736 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
737 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
738 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
739 "\t make all install ;\\\n"
742 "compile-gras: compile-simgrid\n"
743 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
744 "\techo $$not_retrieved; \\\n"
745 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
746 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
747 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
751 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
752 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
753 "\trm -rf gras-$(GRAS_PROJECT)*\n"
754 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
756 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
757 " compile-simgrid compile-gras\n"
763 static void generate_deployment(char *project, char *deployment)
765 xbt_dict_cursor_t cursor=NULL;
768 char *filename = NULL;
774 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
775 sprintf(filename,DEPLOYMENT, project);
777 OUT=fopen(filename,"w");
778 xbt_assert1(OUT, "Unable to open %s for writing",filename);
780 fprintf(OUT, "#!/bin/sh\n");
781 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
783 "if test \"${MACHINES+set}\" != set; then \n"
784 " export MACHINES='");
785 xbt_dict_foreach(machine_set,cursor,key,data) {
786 fprintf(OUT, "%s ",key);
791 "if test \"${INSTALL_PATH+set}\" != set; then \n"
792 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
794 "if test \"${GRAS_ROOT+set}\" != set; then \n"
795 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
797 "if test \"${SRCDIR+set}\" != set; then \n"
798 " export SRCDIR=./\n"
800 "if test \"${SIMGRID_URL+set}\" != set; then \n"
801 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
803 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
804 " export SIMGRID_VERSION=2.91\n"
806 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
807 " export GRAS_PROJECT=%s\n"
809 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
810 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
813 "test -e runlogs/ || mkdir -p runlogs/\n",
817 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
818 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
819 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
821 xbt_dynar_foreach (process_list,cpt,proc) {
822 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
823 for(i=1;i<proc.argc;i++) {
824 fprintf(OUT,"%s ",proc.argv[i]);
826 fprintf(OUT,"\";\n");
827 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);
833 static void print(void *p)
843 /* specific to Borland Compiler */
848 int main(int argc, char *argv[])
850 char *project_name = NULL;
851 char *deployment_file = NULL;
854 surf_init(&argc, argv);
856 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
858 project_name = argv[1];
860 process_function_set = xbt_dict_new();
861 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
862 machine_set = xbt_dict_new();
864 STag_surfxml_process_fun = parse_process_init;
865 ETag_surfxml_argument_fun = parse_argument;
866 ETag_surfxml_process_fun = parse_process_finalize;
868 for(i=2; i<argc; i++) {
869 deployment_file = argv[i];
870 surf_parse_open(deployment_file);
872 xbt_assert1(0,"Parse error in %s",deployment_file);
878 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
879 sprintf(warning,WARN,deployment_file);
881 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
882 xbt_dict_cursor_t cursor=NULL;
886 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
887 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
888 xbt_dict_cursor_step(cursor) ) {
889 DEBUG1("Function %s", key);
892 xbt_dict_dump(process_function_set,print);
895 generate_sim(project_name);
896 generate_rl(project_name);
897 generate_makefile_local(project_name, deployment_file);
899 generate_borland_simulation_project(project_name);
900 generate_borland_real_life_project(project_name);
901 generate_simulation_dsp_file(project_name);
902 generate_real_live_dsp_file(project_name);
905 xbt_free(__gras_path);
909 // generate_makefile_remote(project_name, deployment_file);
910 // generate_deployment(project_name, deployment_file);
918 generate_borland_project(borland_project_t project,int is_rl,const char* name)
920 char* binary_path; /* the path of the generated binary file */
921 char* obj_path; /* the path of the generated object file */
922 char* lib_files; /* a list of the libraries used in the borland project */
923 char* main_source; /* the name of the bpf file used by the borland project */
924 char* file_name; /* the file name of the main source file */
925 char* include_path; /* the include path */
928 /* create the borland project file */
929 borland_project_create(project);
931 /* write the xml document header */
932 borland_project_write_xml_header(project);
934 /* write the xml comment to identify a borland project file */
935 borland_project_write_xml_comment(project);
937 /* write the begin of the node PROJECT */
938 borland_project_begin_xml_node(project,"PROJECT");
940 /* write the begin of node MACROS */
941 borland_project_begin_xml_node(project,"MACROS");
943 /* write the borland project version */
944 borland_project_write_xml_element(project,"VERSION",project->version);
946 /* construct and write the borland project binary path */
947 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
948 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
949 borland_project_write_xml_element(project,"PROJECT",binary_path);
950 xbt_free(binary_path);
952 /* construct an write the object files to generate by the compiler */
953 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
954 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
955 borland_project_write_xml_element(project,"OBJFILES",obj_path);
958 /* write the resource files used by the compiler (no resource file used) */
959 borland_project_write_xml_element(project,"RESFILES","");
961 /* write the IDL files of the project (no IDL files used) */
962 borland_project_write_xml_element(project,"IDLFILES","");
964 /* write the IDLGENFILES element (not used) */
965 borland_project_write_xml_element(project,"IDLGENFILES","");
967 /* write the DEFFILE element (not used) */
968 borland_project_write_xml_element(project,"DEFFILE","");
970 /* write the RESDEPEN element (not used, no resource file used) */
971 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
973 /* construct and write the list of libraries used by the project */
975 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
976 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
980 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
981 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
983 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
984 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
987 borland_project_write_xml_element(project,"LIBFILES",lib_files);
990 /* write the SPARELIBS element (not used) */
991 borland_project_write_xml_element(project,"SPARELIBS","");
993 /* write the PACKAGES element (no package used) */
994 borland_project_write_xml_element(project,"PACKAGES","");
996 /* write the PATHCPP element (the path of the source files of the project)*/
997 borland_project_write_xml_element(project,"PATHCPP",".;");
999 /* write the PATHPAS element (not used) */
1000 borland_project_write_xml_element(project,"PATHPAS","");
1002 /* write the PATHRC element (not used) */
1003 borland_project_write_xml_element(project,"PATHRC","");
1005 /* write the PATHASM element (not used) */
1006 borland_project_write_xml_element(project,"PATHASM","");
1008 /* write the DEBUGLIBPATH element (the path for debug) */
1009 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
1011 /* write the RELEASELIBPATH element (the path for release) */
1012 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
1014 /* specify the linker to use */
1015 borland_project_write_xml_element(project,"LINKER","ilink32");
1017 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
1018 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
1020 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
1021 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
1023 /* construct and write the MAINSOURCE element */
1024 main_source = xbt_new0(char,strlen(project->name) + 5);
1025 sprintf(main_source,"%s.bpf",project->name);
1026 /* write the main source file to use in the borland project file */
1027 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
1029 /* create the bpf file used by the borland project */
1030 borland_project_create_main_file(main_source);
1032 /* FIXME resolve the include path */
1033 /* write the INCLUDEPATH element */
1036 buffer =xbt_new0(char,MAX_PATH);
1037 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1039 __gras_path = xbt_new0(char,MAX_PATH);
1040 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1043 /*find_file_path("C:\\","gras.h",__gras_path);*/
1046 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1047 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1049 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1051 xbt_free(include_path);
1053 /* write the LIBPATH element (no librarie paths specified)*/
1054 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1057 * write the WARNINGS element :
1058 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1059 * -w-rvl (-w-8070) disabled the function must return warning
1060 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1061 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1062 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1063 * -w-par (-w-8057) disabled the warning that detect an unused variable
1064 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1065 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1066 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1068 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");
1070 /* write the OTHERFILES element (no other files used used) */
1071 borland_project_write_xml_element(project,"OTHERFILES","");
1073 /* write the end of the node MACROS */
1074 borland_project_end_xml_node(project,"MACROS");
1076 /* write the begin of the node OPTIONS */
1077 borland_project_begin_xml_node(project,"OPTIONS");
1079 /* FIXME check the idlcflags */
1080 /* write the IDLCFLAGS element */
1081 borland_project_write_xml_element(project,"IDLCFLAGS","");
1084 * write the CFLAG1 element (compiler options ) :
1086 * -Od this flag disable all compiler optimisation
1087 * -H this flag specify the name of the file which will contain the precompiled header
1088 * -Hc this flag specify to the compiler to cach the precompiled header
1089 * -Vx this flag specify to the compiler to allow the empty structures
1090 * -Ve this flag specify to the compiler to allow the empty base classes
1091 * -X- this flag activate the auto-depend informations of the compiler
1092 * -r- this flag disabled the use of the processor register
1093 * -a1 this flag specify that the data must be aligned on one byte
1094 * -b- this flag specify that the enums are the smallest size of the integer
1095 * -k (used during debug)
1096 * -y this flag generate the line number for debug
1097 * -v this flag enabled the debugging of the source files
1098 * -vi check the expansion of the inline functions
1099 * -tWC specify that it's a console application
1100 * -tWM- specify that the application is not multithread
1101 * -c generate the object file, no link
1103 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");
1105 /* write the PFLAGS element */
1106 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1108 /* write the RFLAGS element */
1109 borland_project_write_xml_element(project,"RFLAGS","");
1111 /* write the AFLAGS element (assembler flags) :
1113 * /mx (not documented)
1114 * /w2 (not documented)
1115 * /zd (not documented)
1118 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1120 /* write the LFLAGS element (linker flags) :
1122 * -I specify the output directory for object files
1123 * -D register the specified description (no description "")
1124 * -ap build a win32 console application
1125 * -Tpe generate a exe file
1126 * -x do not create the map file
1127 * -Gn do not generate the state file
1128 * -v include the complete debug informations
1130 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1132 /* write the OTHERFILES element (not used)*/
1133 borland_project_write_xml_element(project,"OTHERFILES","");
1135 /* write the end of the node OPTIONS */
1136 borland_project_end_xml_node(project,"OPTIONS");
1138 /* write the begin of the node LINKER */
1139 borland_project_begin_xml_node(project,"LINKER");
1141 /* write the ALLOBJ element */
1142 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1144 /* write the ALLRES element (not used) */
1145 borland_project_write_xml_element(project,"ALLRES","");
1147 /* write the ALLLIB element */
1148 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1150 /* write the OTHERFILES element (not used) */
1151 borland_project_write_xml_element(project,"OTHERFILES","");
1153 /* write the end of the node LINKER */
1154 borland_project_end_xml_node(project,"LINKER");
1156 /* write the begin of the node FILELIST */
1157 borland_project_begin_xml_node(project,"FILELIST");
1159 /* construct and write the list of file elements */
1161 /* add the bpf file to the list */
1162 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1163 xbt_free(main_source);
1165 /* FIXME : check the source file directory */
1166 /* add the generated source file to the list */
1168 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1169 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1170 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1172 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1173 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1174 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1176 xbt_free(file_name);
1178 /* FIXME : check the libraries directory */
1179 /* add the simgrid library to the list */
1182 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1183 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1184 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1187 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1188 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1189 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1193 xbt_free(file_name);
1195 /* write the end of the node FILELIST */
1196 borland_project_end_xml_node(project,"FILELIST");
1198 /* write the begin of the node BUILDTOOLS (not used)*/
1199 borland_project_begin_xml_node(project,"BUILDTOOLS");
1201 /* write the end of the node BUILDTOOLS (not used)*/
1202 borland_project_end_xml_node(project,"BUILDTOOLS");
1204 /* write the begin of the node IDEOPTIONS */
1205 borland_project_begin_xml_node(project,"IDEOPTIONS");
1207 /* write all of the option of the IDE of Borland C++ Builder */
1208 borland_project_write_ide_options(project);
1210 /* write the end of the node IDEOPTIONS */
1211 borland_project_end_xml_node(project,"IDEOPTIONS");
1213 /* write the end of the node PROJECT */
1214 borland_project_end_xml_node(project,"PROJECT");
1216 /* close the borland project file */
1217 borland_project_close(project);
1221 borland_project_write_tabs(borland_project_t project,unsigned int count)
1225 for(pos = 0; pos < count; pos++)
1226 fprintf(project->stream,"\t");
1230 borland_project_begin_xml_node(borland_project_t project, const char* name)
1233 borland_project_write_tabs(project,level);
1235 fprintf(project->stream,"<%s>\n",name);
1241 borland_project_end_xml_node(borland_project_t project, const char* name)
1246 borland_project_write_tabs(project,level);
1248 fprintf(project->stream,"</%s>\n",name);
1253 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1255 borland_project_write_tabs(project,level);
1256 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1260 borland_project_write_xml_header(borland_project_t project)
1262 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1266 borland_project_create_main_file(const char* name)
1268 FILE* stream = fopen(name,"w+");
1270 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1276 borland_project_create(borland_project_t project)
1278 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1279 sprintf(file_name,"%s.bpr",project->name);
1280 project->stream = fopen(file_name,"w+");
1281 xbt_free(file_name);
1285 borland_project_write_xml_comment(borland_project_t project)
1287 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1290 borland_project_write_file_element( borland_project_t project,
1291 const char* file_name,
1292 const char* form_name,
1293 const char* unit_name,
1294 const char* container_id,
1295 const char* design_class,
1296 const char* local_command)
1298 borland_project_write_tabs(project,level);
1300 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);
1304 borland_project_write_ide_options(borland_project_t project)
1307 const char* ide_options =
1308 "[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" \
1309 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1310 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1311 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1312 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1313 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1314 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1315 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1316 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1317 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1318 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1319 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1320 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1321 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1322 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1324 fprintf(project->stream,ide_options);
1328 borland_project_close(borland_project_t project)
1330 fclose(project->stream);
1334 generate_borland_simulation_project(const char* name)
1336 char buffer[MAX_PATH] = {0};
1339 WIN32_FIND_DATA wfd = {0};
1341 s_borland_project_t borland_project = {0};
1342 borland_project.xml_version = "1.0";
1343 borland_project.encoding ="utf-8";
1344 borland_project.comment ="C++Builder XML Project";
1345 borland_project.version = "BCB.06.00";
1347 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1350 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1353 GetCurrentDirectory(MAX_PATH,buffer);
1355 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1357 strcpy(borland_project.src_dir,buffer);
1359 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1360 sprintf(borland_project.name,"%s_simulator",name);
1362 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1363 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1365 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1368 CreateDirectory(borland_project.bin_dir,NULL);
1370 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1371 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1373 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1375 if(INVALID_HANDLE_VALUE == hDir)
1376 CreateDirectory(borland_project.obj_dir,NULL);
1378 generate_borland_project(&borland_project,0,name);
1380 xbt_free(borland_project.name);
1381 xbt_free(borland_project.src_dir);
1382 xbt_free(borland_project.bin_dir);
1383 xbt_free(borland_project.obj_dir);
1384 xbt_free(borland_project.lib_dir);
1388 generate_borland_real_life_project(const char* name)
1391 WIN32_FIND_DATA wfd = {0};
1392 char buffer[MAX_PATH] = {0};
1393 xbt_dict_cursor_t cursor = NULL;
1396 s_borland_project_t borland_project = {0};
1398 borland_project.xml_version = "1.0";
1399 borland_project.encoding ="utf-8";
1400 borland_project.comment ="C++Builder XML Project";
1401 borland_project.version = "BCB.06.00";
1402 borland_project.lib_dir = " ";
1404 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1406 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1408 GetCurrentDirectory(MAX_PATH,buffer);
1410 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1412 strcpy(borland_project.src_dir,buffer);
1414 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1415 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1417 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1419 if(INVALID_HANDLE_VALUE == hDir)
1420 CreateDirectory(borland_project.bin_dir,NULL);
1422 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1423 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1425 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1428 CreateDirectory(borland_project.obj_dir,NULL);
1431 xbt_dict_foreach(process_function_set,cursor,key,data) {
1432 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1434 sprintf(borland_project.name,"%s_%s",name,key);
1436 generate_borland_project(&borland_project,1,name);
1437 xbt_free(borland_project.name);
1440 xbt_free(borland_project.src_dir);
1441 xbt_free(borland_project.bin_dir);
1442 xbt_free(borland_project.obj_dir);
1443 xbt_free(borland_project.lib_dir);
1446 find_file_path(const char* root_dir,const char* file_name,char* path)
1449 WIN32_FIND_DATA wfd;
1450 char* prev_dir = xbt_new(char,MAX_PATH);
1451 GetCurrentDirectory(MAX_PATH,prev_dir);
1452 SetCurrentDirectory(root_dir);
1454 // begining of the scan
1455 hFind=FindFirstFile ("*.*", &wfd);
1457 if(hFind!=INVALID_HANDLE_VALUE){
1460 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1462 if(!strcmp(file_name,wfd.cFileName)){
1463 GetCurrentDirectory(MAX_PATH,path);
1464 SetCurrentDirectory(prev_dir);
1471 /* it's a directory, scan it*/
1474 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1475 if(find_file_path(wfd.cFileName,file_name,path)){
1477 SetCurrentDirectory(prev_dir);
1483 /* next file or directory */
1484 while(FindNextFile(hFind,&wfd))
1487 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1489 if(!strcmp(file_name,wfd.cFileName)){
1490 GetCurrentDirectory(MAX_PATH,path);
1491 SetCurrentDirectory(prev_dir);
1497 /* it's a file scan it */
1500 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1502 if(find_file_path(wfd.cFileName,file_name,path)){
1503 SetCurrentDirectory(prev_dir);
1514 SetCurrentDirectory(prev_dir);
1520 /* Implementation of the functions used to create a Visual C++ project.*/
1523 generate_simulation_dsp_file(const char* name)
1525 char buffer[MAX_PATH] = {0};
1527 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1529 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1530 GetCurrentDirectory(MAX_PATH,buffer);
1532 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1533 strcpy(dsp.src_dir,buffer);
1534 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1535 sprintf(dsp.name,"%s_simulator",name);
1537 generate_dsp_project(&dsp,0,name);
1540 xbt_free(dsp.src_dir);
1541 xbt_free(dsp.lib_dir);
1547 * Create the Microsoft visual C++ real life project file.
1550 generate_real_live_dsp_file(const char* name)
1553 char buffer[MAX_PATH] = {0};
1554 xbt_dict_cursor_t cursor = NULL;
1560 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1562 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1564 GetCurrentDirectory(MAX_PATH,buffer);
1566 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1568 strcpy(dsp.src_dir,buffer);
1571 xbt_dict_foreach(process_function_set,cursor,key,data) {
1572 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1574 sprintf(dsp.name,"%s_%s",name,key);
1576 generate_dsp_project(&dsp,1,name);
1580 xbt_free(dsp.src_dir);
1581 xbt_free(dsp.lib_dir);
1586 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1588 /* create the visual C++ project file */
1590 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1591 sprintf(file_name,"%s.dsp",project->name);
1592 project->stream = fopen(file_name,"w+");
1593 xbt_free(file_name);
1597 buffer =xbt_new0(char,MAX_PATH);
1598 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1600 __gras_path = xbt_new0(char,MAX_PATH);
1601 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1605 /* dsp file header */
1606 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1607 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1608 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1610 /* target type is a win32 x86 console application */
1611 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1613 /* the current config is win32-debug */
1614 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1617 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1620 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1621 fprintf(project->stream,"!MESSAGE\n");
1622 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1623 fprintf(project->stream,"!MESSAGE\n");
1624 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1625 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1626 fprintf(project->stream,"!MESSAGE\n");
1627 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1628 fprintf(project->stream,"!MESSAGE\n");
1629 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1630 fprintf(project->stream,"!MESSAGE\n");
1631 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1632 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1633 fprintf(project->stream,"!MESSAGE\n\n");
1635 fprintf(project->stream,"# Begin Project\n\n");
1636 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1637 fprintf(project->stream,"# PROP Scc_ProjName\n");
1638 fprintf(project->stream,"# PROP Scc_LocalPath\n");
1639 fprintf(project->stream,"CPP=cl.exe\n");
1640 fprintf(project->stream,"RSC=rc.exe\n\n");
1642 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1644 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1645 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1646 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1647 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1648 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1649 fprintf(project->stream,"# PROP Use_MFC 0\n");
1650 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1651 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1652 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1653 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1654 /* TODO : the include directory */
1655 /*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);*/
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 CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1658 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1659 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1660 fprintf(project->stream,"BSC32=bscmake.exe\n");
1661 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1662 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1663 fprintf(project->stream,"LINK32=link.exe\n");
1664 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");
1667 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");
1669 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");
1671 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1673 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1674 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1675 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1676 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1677 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1678 fprintf(project->stream,"# PROP Use_MFC 0\n");
1679 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1680 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1681 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1682 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1683 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1684 /* TODO : the include directory */
1685 /*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);*/
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 CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1688 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1689 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1690 fprintf(project->stream,"BSC32=bscmake.exe\n");
1691 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1692 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1693 fprintf(project->stream,"LINK32=link.exe\n");
1694 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");
1697 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");
1699 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");
1701 fprintf(project->stream,"!ENDIF\n\n");
1703 fprintf(project->stream,"# Begin Target\n\n");
1704 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1705 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1706 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1707 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1709 fprintf(project->stream,"# Begin Source File\n");
1710 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1711 fprintf(project->stream,"# End Source File\n\n");
1713 fprintf(project->stream,"# Begin Source File\n");
1714 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1715 fprintf(project->stream,"# End Source File\n\n");
1717 fprintf(project->stream,"# End Group\n");
1718 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1719 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1720 fprintf(project->stream,"# End Group\n");
1721 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1722 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1723 fprintf(project->stream,"# End Group\n");
1724 fprintf(project->stream,"# End Target\n");
1725 fprintf(project->stream,"# End Project\n");