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)
312 s_process_t*p = (s_process_t*)process;
314 for (i=0; i<p->argc ; i++)
320 static s_process_t process;
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) {
347 xbt_dict_cursor_t cursor=NULL;
350 char *filename = NULL;
353 /* Output file: <projet>_simulator.c */
354 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
355 sprintf(filename,SIM_SOURCENAME,project);
357 OUT=fopen(filename,"w");
359 xbt_assert1(OUT, "Unable to open %s for writing",filename);
361 fprintf(OUT, "%s\n",warning);
362 fprintf(OUT, "%s", SIM_PREEMBULE);
364 xbt_dict_foreach(process_function_set,cursor,key,data) {
365 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
370 xbt_dict_foreach(process_function_set,cursor,key,data) {
371 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
374 fprintf(OUT, "\n%s\n",warning);
376 xbt_dict_foreach(process_function_set,cursor,key,data) {
377 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
379 fprintf(OUT, "\n%s\n",warning);
381 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
382 "#ifdef __BORLANDDC__\n"
386 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
388 " /* Simulation setup */\n"
389 " gras_global_init(&argc,argv);\n"
390 " if (argc != 3) {\n"
391 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
396 " gras_create_environment(argv[1]);\n"
398 " /* Application deployment */\n"
400 xbt_dict_foreach(process_function_set,cursor,key,data) {
401 fprintf(OUT," gras_function_register(\"%s\", launch_%s);\n",key,key);
403 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
408 /**********************************************/
409 /**** Generate the file for the real life *****/
410 /**********************************************/
411 static void generate_rl(char *project)
413 xbt_dict_cursor_t cursor=NULL;
416 char *filename = NULL;
419 xbt_dict_foreach(process_function_set,cursor,key,data) {
420 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
422 sprintf(filename,RL_SOURCENAME,project,key);
424 OUT=fopen(filename,"w");
425 xbt_assert1(OUT, "Unable to open %s for writing",filename);
427 fprintf(OUT, "\n%s\n",warning);
428 fprintf(OUT, "/* specific to Borland Compiler */\n" \
429 "#ifdef __BORLANDC__\n" \
430 "#pragma hdrstop\n" \
432 "#include <stdio.h>\n" \
433 "#include <signal.h>\n" \
434 "#include <gras.h>\n" \
436 "XBT_PUBLIC_DATA(const char *) _gras_procname;\n" \
437 "/* user code */\n" \
438 "int %s(int argc, char *argv[]);\n" \
440 "/* specific to Borland Compiler */\n" \
441 "#ifdef __BORLANDC__\n" \
442 "#pragma argsused\n" \
444 "int main(int argc, char *argv[]){\n" \
447 " _gras_procname = \"%s\";\n" \
448 " errcode=%s(argc,argv);\n"\
450 " return errcode;\n"\
453 fprintf(OUT, "\n%s\n",warning);
459 static void generate_makefile_am(char *project, char *deployment)
461 xbt_dict_cursor_t cursor=NULL;
464 char *filename = NULL;
467 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
468 sprintf(filename,MAKEFILE_FILENAME_AM, project);
470 OUT=fopen(filename,"w");
471 xbt_assert1(OUT, "Unable to open %s for writing",filename);
473 fprintf(OUT, "# AUTOMAKE variable definition\n");
474 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
475 fprintf(OUT, "PROGRAMS=");
476 fprintf(OUT, SIM_BINARYNAME,project);
478 xbt_dict_foreach(process_function_set,cursor,key,data) {
480 fprintf(OUT, RL_BINARYNAME, project, key);
483 fprintf(OUT, "\n\n");
484 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
486 fprintf(OUT, SIM_SOURCENAME,project);
487 fprintf(OUT, " %s.c\n", project);
488 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
489 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
491 xbt_dict_foreach(process_function_set,cursor,key,data) {
492 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
494 fprintf(OUT, RL_SOURCENAME, project,key);
495 fprintf(OUT, " %s.c\n", project);
496 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
497 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
500 fprintf(OUT, "\n# cleanup temps\n");
501 fprintf(OUT, "CLEANFILES= ");
502 fprintf(OUT, SIM_SOURCENAME, project);
504 xbt_dict_foreach(process_function_set,cursor,key,data) {
506 fprintf(OUT, RL_SOURCENAME, project,key);
510 fprintf(OUT, "\n# generate temps\n");
511 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
513 xbt_dict_foreach(process_function_set,cursor,key,data) {
514 fprintf(OUT, RL_SOURCENAME, project,key);
517 fprintf(OUT, SIM_SOURCENAME, project);
518 fprintf(OUT, ": %s\n", deployment);
519 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
523 static void generate_makefile_local(char *project, char *deployment)
525 xbt_dict_cursor_t cursor=NULL;
528 char *filename = NULL;
531 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
532 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
534 OUT=fopen(filename,"w");
535 xbt_assert1(OUT, "Unable to open %s for writing",filename);
541 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
544 fprintf(OUT,"## Variable declarations\n"
546 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
550 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
551 "# Compilation will fail if you don't do so\n"
552 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
553 "# You can fiddle the following to make it fit your taste\n"
554 "INCLUDES = -I$(GRAS_ROOT)/include\n"
555 "CFLAGS ?= -O3 -w -g\n"
556 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
557 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
561 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
563 fprintf(OUT, "GENERATED_C_FILES = ");
564 fprintf(OUT, SIM_SOURCENAME" ",project);
565 xbt_dict_foreach(process_function_set,cursor,key,data) {
566 fprintf(OUT, RL_SOURCENAME " ",project, key);
570 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
572 fprintf(OUT, "BIN_FILES = ");
574 fprintf(OUT, SIM_BINARYNAME " ",project);
575 xbt_dict_foreach(process_function_set,cursor,key,data) {
576 fprintf(OUT, RL_BINARYNAME " ", project, key);
582 "## By default, build all the binaries\n"
583 "all: $(BIN_FILES)\n"
586 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
587 xbt_dict_foreach(process_function_set,cursor,key,data) {
588 fprintf(OUT, RL_SOURCENAME, project,key);
591 fprintf(OUT, SIM_SOURCENAME, project);
592 fprintf(OUT, ": %s\n", deployment);
593 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
595 fprintf(OUT, "\n## Generate the binaries\n");
596 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
597 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
598 xbt_dict_foreach(process_function_set,cursor,key,data) {
599 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
600 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
605 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
608 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
612 "##Â Rules for tarballs and cleaning\n"
613 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
614 "distdir: $(DIST_FILES)\n"
615 "\trm -rf $(DISTDIR)\n"
616 "\tmkdir -p $(DISTDIR)\n"
617 "\tcp $^ $(DISTDIR)\n"
619 "dist: clean distdir\n"
620 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
621 "\n", project /*, project*/);
625 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
626 xbt_dict_foreach(process_function_set,cursor,key,data) {
627 fprintf(OUT, " " RL_OBJNAME, project, key);
631 "\trm -rf $(DISTDIR)\n"
637 fprintf(OUT, "############ REMOTE COMPILING #########\n");
640 xbt_dict_foreach(machine_set,cursor,key,data) {
641 fprintf(OUT, "%s ",key);
646 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
647 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
649 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
650 "SIMGRID_VERSION ?=2.92\n"
651 "GRAS_PROJECT ?= %s\n"
652 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
655 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
656 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
657 "\t for site in $(MACHINES) ; do \\\n"
658 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
659 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
660 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
661 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
662 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
663 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
664 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
665 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
666 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
667 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
669 "\t machine=$$site;\\\n"
670 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
672 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
673 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
674 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
676 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
677 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
679 "\t echo \"-- Copy the data over\"; \\\n"
680 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
681 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
682 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
683 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
684 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
686 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
687 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
689 "\t done;\n",project,project,project);
694 static void generate_makefile_remote(char *project, char *deployment)
696 char *filename = NULL;
699 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
700 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
702 OUT=fopen(filename,"w");
703 xbt_assert1(OUT, "Unable to open %s for writing",filename);
706 "INSTALL_PATH ?= $(shell pwd)\n"
709 "\tcd $$GRAS_ROOT ; \\\n"
710 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
711 "\techo $$retrieved; \\\n"
712 "\tif test \"x$$retrieved\" = x; then \\\n"
713 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
714 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
715 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
716 "\t make all install ;\\\n"
719 "compile-gras: compile-simgrid\n"
720 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
721 "\techo $$not_retrieved; \\\n"
722 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
723 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
724 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
728 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
729 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
730 "\trm -rf gras-$(GRAS_PROJECT)*\n"
731 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
733 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
734 " compile-simgrid compile-gras\n"
739 static void print(void *p)
749 /* specific to Borland Compiler */
754 int main(int argc, char *argv[])
756 char *project_name = NULL;
757 char *deployment_file = NULL;
760 surf_init(&argc, argv);
761 process_function_set = xbt_dict_new();
762 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
763 machine_set = xbt_dict_new();
765 for (i=1; i<argc; i++) {
766 int need_removal = 0;
767 if (!strncmp("--extra-process=",argv[i], strlen("--extra-process="))) {
768 xbt_dict_set(process_function_set, argv[i]+strlen("--extra-process="), NULL, NULL);
773 if (need_removal) { /* remove the handled argument from argv */
775 for (j=i+1; j<argc; j++) {
780 i--; /* compensate effect of next loop incrementation */
784 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
786 project_name = argv[1];
788 STag_surfxml_process_fun = parse_process_init;
789 ETag_surfxml_argument_fun = parse_argument;
790 ETag_surfxml_process_fun = parse_process_finalize;
792 for(i=2; i<argc; i++) {
793 deployment_file = argv[i];
794 surf_parse_open(deployment_file);
796 xbt_assert1(0,"Parse error in %s",deployment_file);
802 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
803 sprintf(warning,WARN,deployment_file);
805 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
806 xbt_dict_cursor_t cursor=NULL;
810 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
811 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
812 xbt_dict_cursor_step(cursor) ) {
813 DEBUG1("Function %s", key);
816 xbt_dict_dump(process_function_set,print);
819 generate_sim(project_name);
820 generate_rl(project_name);
821 generate_makefile_local(project_name, deployment_file);
823 generate_borland_simulation_project(project_name);
824 generate_borland_real_life_project(project_name);
825 generate_simulation_dsp_file(project_name);
826 generate_real_live_dsp_file(project_name);
829 xbt_free(__gras_path);
833 // generate_makefile_remote(project_name, deployment_file);
834 // generate_deployment(project_name, deployment_file);
842 generate_borland_project(borland_project_t project,int is_rl,const char* name)
844 char* binary_path; /* the path of the generated binary file */
845 char* obj_path; /* the path of the generated object file */
846 char* lib_files; /* a list of the libraries used in the borland project */
847 char* main_source; /* the name of the bpf file used by the borland project */
848 char* file_name; /* the file name of the main source file */
849 char* include_path; /* the include path */
852 /* create the borland project file */
853 borland_project_create(project);
855 /* write the xml document header */
856 borland_project_write_xml_header(project);
858 /* write the xml comment to identify a borland project file */
859 borland_project_write_xml_comment(project);
861 /* write the begin of the node PROJECT */
862 borland_project_begin_xml_node(project,"PROJECT");
864 /* write the begin of node MACROS */
865 borland_project_begin_xml_node(project,"MACROS");
867 /* write the borland project version */
868 borland_project_write_xml_element(project,"VERSION",project->version);
870 /* construct and write the borland project binary path */
871 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
872 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
873 borland_project_write_xml_element(project,"PROJECT",binary_path);
874 xbt_free(binary_path);
876 /* construct an write the object files to generate by the compiler */
877 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
878 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
879 borland_project_write_xml_element(project,"OBJFILES",obj_path);
882 /* write the resource files used by the compiler (no resource file used) */
883 borland_project_write_xml_element(project,"RESFILES","");
885 /* write the IDL files of the project (no IDL files used) */
886 borland_project_write_xml_element(project,"IDLFILES","");
888 /* write the IDLGENFILES element (not used) */
889 borland_project_write_xml_element(project,"IDLGENFILES","");
891 /* write the DEFFILE element (not used) */
892 borland_project_write_xml_element(project,"DEFFILE","");
894 /* write the RESDEPEN element (not used, no resource file used) */
895 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
897 /* construct and write the list of libraries used by the project */
899 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
900 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
904 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
905 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
907 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
908 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
911 borland_project_write_xml_element(project,"LIBFILES",lib_files);
914 /* write the SPARELIBS element (not used) */
915 borland_project_write_xml_element(project,"SPARELIBS","");
917 /* write the PACKAGES element (no package used) */
918 borland_project_write_xml_element(project,"PACKAGES","");
920 /* write the PATHCPP element (the path of the source files of the project)*/
921 borland_project_write_xml_element(project,"PATHCPP",".;");
923 /* write the PATHPAS element (not used) */
924 borland_project_write_xml_element(project,"PATHPAS","");
926 /* write the PATHRC element (not used) */
927 borland_project_write_xml_element(project,"PATHRC","");
929 /* write the PATHASM element (not used) */
930 borland_project_write_xml_element(project,"PATHASM","");
932 /* write the DEBUGLIBPATH element (the path for debug) */
933 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
935 /* write the RELEASELIBPATH element (the path for release) */
936 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
938 /* specify the linker to use */
939 borland_project_write_xml_element(project,"LINKER","ilink32");
941 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
942 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
944 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
945 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
947 /* construct and write the MAINSOURCE element */
948 main_source = xbt_new0(char,strlen(project->name) + 5);
949 sprintf(main_source,"%s.bpf",project->name);
950 /* write the main source file to use in the borland project file */
951 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
953 /* create the bpf file used by the borland project */
954 borland_project_create_main_file(main_source);
956 /* FIXME resolve the include path */
957 /* write the INCLUDEPATH element */
960 buffer =xbt_new0(char,MAX_PATH);
961 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
963 __gras_path = xbt_new0(char,MAX_PATH);
964 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
967 /*find_file_path("C:\\","gras.h",__gras_path);*/
970 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
971 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
973 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
975 xbt_free(include_path);
977 /* write the LIBPATH element (no librarie paths specified)*/
978 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
981 * write the WARNINGS element :
982 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
983 * -w-rvl (-w-8070) disabled the function must return warning
984 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
985 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
986 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
987 * -w-par (-w-8057) disabled the warning that detect an unused variable
988 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
989 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
990 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
992 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");
994 /* write the OTHERFILES element (no other files used used) */
995 borland_project_write_xml_element(project,"OTHERFILES","");
997 /* write the end of the node MACROS */
998 borland_project_end_xml_node(project,"MACROS");
1000 /* write the begin of the node OPTIONS */
1001 borland_project_begin_xml_node(project,"OPTIONS");
1003 /* FIXME check the idlcflags */
1004 /* write the IDLCFLAGS element */
1005 borland_project_write_xml_element(project,"IDLCFLAGS","");
1008 * write the CFLAG1 element (compiler options ) :
1010 * -Od this flag disable all compiler optimisation
1011 * -H this flag specify the name of the file which will contain the precompiled header
1012 * -Hc this flag specify to the compiler to cach the precompiled header
1013 * -Vx this flag specify to the compiler to allow the empty structures
1014 * -Ve this flag specify to the compiler to allow the empty base classes
1015 * -X- this flag activate the auto-depend informations of the compiler
1016 * -r- this flag disabled the use of the processor register
1017 * -a1 this flag specify that the data must be aligned on one byte
1018 * -b- this flag specify that the enums are the smallest size of the integer
1019 * -k (used during debug)
1020 * -y this flag generate the line number for debug
1021 * -v this flag enabled the debugging of the source files
1022 * -vi check the expansion of the inline functions
1023 * -tWC specify that it's a console application
1024 * -tWM- specify that the application is not multithread
1025 * -c generate the object file, no link
1027 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");
1029 /* write the PFLAGS element */
1030 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1032 /* write the RFLAGS element */
1033 borland_project_write_xml_element(project,"RFLAGS","");
1035 /* write the AFLAGS element (assembler flags) :
1037 * /mx (not documented)
1038 * /w2 (not documented)
1039 * /zd (not documented)
1042 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1044 /* write the LFLAGS element (linker flags) :
1046 * -I specify the output directory for object files
1047 * -D register the specified description (no description "")
1048 * -ap build a win32 console application
1049 * -Tpe generate a exe file
1050 * -x do not create the map file
1051 * -Gn do not generate the state file
1052 * -v include the complete debug informations
1054 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1056 /* write the OTHERFILES element (not used)*/
1057 borland_project_write_xml_element(project,"OTHERFILES","");
1059 /* write the end of the node OPTIONS */
1060 borland_project_end_xml_node(project,"OPTIONS");
1062 /* write the begin of the node LINKER */
1063 borland_project_begin_xml_node(project,"LINKER");
1065 /* write the ALLOBJ element */
1066 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1068 /* write the ALLRES element (not used) */
1069 borland_project_write_xml_element(project,"ALLRES","");
1071 /* write the ALLLIB element */
1072 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1074 /* write the OTHERFILES element (not used) */
1075 borland_project_write_xml_element(project,"OTHERFILES","");
1077 /* write the end of the node LINKER */
1078 borland_project_end_xml_node(project,"LINKER");
1080 /* write the begin of the node FILELIST */
1081 borland_project_begin_xml_node(project,"FILELIST");
1083 /* construct and write the list of file elements */
1085 /* add the bpf file to the list */
1086 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1087 xbt_free(main_source);
1089 /* FIXME : check the source file directory */
1090 /* add the generated source file to the list */
1092 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1093 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1094 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1096 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1097 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1098 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1100 xbt_free(file_name);
1102 /* FIXME : check the libraries directory */
1103 /* add the simgrid library to the list */
1106 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1107 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1108 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1111 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1112 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1113 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1117 xbt_free(file_name);
1119 /* write the end of the node FILELIST */
1120 borland_project_end_xml_node(project,"FILELIST");
1122 /* write the begin of the node BUILDTOOLS (not used)*/
1123 borland_project_begin_xml_node(project,"BUILDTOOLS");
1125 /* write the end of the node BUILDTOOLS (not used)*/
1126 borland_project_end_xml_node(project,"BUILDTOOLS");
1128 /* write the begin of the node IDEOPTIONS */
1129 borland_project_begin_xml_node(project,"IDEOPTIONS");
1131 /* write all of the option of the IDE of Borland C++ Builder */
1132 borland_project_write_ide_options(project);
1134 /* write the end of the node IDEOPTIONS */
1135 borland_project_end_xml_node(project,"IDEOPTIONS");
1137 /* write the end of the node PROJECT */
1138 borland_project_end_xml_node(project,"PROJECT");
1140 /* close the borland project file */
1141 borland_project_close(project);
1145 borland_project_write_tabs(borland_project_t project,unsigned int count)
1149 for(pos = 0; pos < count; pos++)
1150 fprintf(project->stream,"\t");
1154 borland_project_begin_xml_node(borland_project_t project, const char* name)
1157 borland_project_write_tabs(project,level);
1159 fprintf(project->stream,"<%s>\n",name);
1165 borland_project_end_xml_node(borland_project_t project, const char* name)
1170 borland_project_write_tabs(project,level);
1172 fprintf(project->stream,"</%s>\n",name);
1177 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1179 borland_project_write_tabs(project,level);
1180 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1184 borland_project_write_xml_header(borland_project_t project)
1186 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1190 borland_project_create_main_file(const char* name)
1192 FILE* stream = fopen(name,"w+");
1194 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1200 borland_project_create(borland_project_t project)
1202 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1203 sprintf(file_name,"%s.bpr",project->name);
1204 project->stream = fopen(file_name,"w+");
1205 xbt_free(file_name);
1209 borland_project_write_xml_comment(borland_project_t project)
1211 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1214 borland_project_write_file_element( borland_project_t project,
1215 const char* file_name,
1216 const char* form_name,
1217 const char* unit_name,
1218 const char* container_id,
1219 const char* design_class,
1220 const char* local_command)
1222 borland_project_write_tabs(project,level);
1224 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);
1228 borland_project_write_ide_options(borland_project_t project)
1231 const char* ide_options =
1232 "[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" \
1233 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1234 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1235 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1236 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1237 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1238 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1239 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1240 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1241 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1242 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1243 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1244 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1245 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1246 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1248 fprintf(project->stream,ide_options);
1252 borland_project_close(borland_project_t project)
1254 fclose(project->stream);
1258 generate_borland_simulation_project(const char* name)
1260 char buffer[MAX_PATH] = {0};
1263 WIN32_FIND_DATA wfd = {0};
1265 s_borland_project_t borland_project = {0};
1266 borland_project.xml_version = "1.0";
1267 borland_project.encoding ="utf-8";
1268 borland_project.comment ="C++Builder XML Project";
1269 borland_project.version = "BCB.06.00";
1271 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1274 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1277 GetCurrentDirectory(MAX_PATH,buffer);
1279 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1281 strcpy(borland_project.src_dir,buffer);
1283 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1284 sprintf(borland_project.name,"%s_simulator",name);
1286 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1287 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1289 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1292 CreateDirectory(borland_project.bin_dir,NULL);
1294 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1295 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1297 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1299 if(INVALID_HANDLE_VALUE == hDir)
1300 CreateDirectory(borland_project.obj_dir,NULL);
1302 generate_borland_project(&borland_project,0,name);
1304 xbt_free(borland_project.name);
1305 xbt_free(borland_project.src_dir);
1306 xbt_free(borland_project.bin_dir);
1307 xbt_free(borland_project.obj_dir);
1308 xbt_free(borland_project.lib_dir);
1312 generate_borland_real_life_project(const char* name)
1315 WIN32_FIND_DATA wfd = {0};
1316 char buffer[MAX_PATH] = {0};
1317 xbt_dict_cursor_t cursor = NULL;
1320 s_borland_project_t borland_project = {0};
1322 borland_project.xml_version = "1.0";
1323 borland_project.encoding ="utf-8";
1324 borland_project.comment ="C++Builder XML Project";
1325 borland_project.version = "BCB.06.00";
1326 borland_project.lib_dir = " ";
1328 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1330 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1332 GetCurrentDirectory(MAX_PATH,buffer);
1334 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1336 strcpy(borland_project.src_dir,buffer);
1338 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1339 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1341 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1343 if(INVALID_HANDLE_VALUE == hDir)
1344 CreateDirectory(borland_project.bin_dir,NULL);
1346 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1347 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1349 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1352 CreateDirectory(borland_project.obj_dir,NULL);
1355 xbt_dict_foreach(process_function_set,cursor,key,data) {
1356 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1358 sprintf(borland_project.name,"%s_%s",name,key);
1360 generate_borland_project(&borland_project,1,name);
1361 xbt_free(borland_project.name);
1364 xbt_free(borland_project.src_dir);
1365 xbt_free(borland_project.bin_dir);
1366 xbt_free(borland_project.obj_dir);
1367 xbt_free(borland_project.lib_dir);
1370 find_file_path(const char* root_dir,const char* file_name,char* path)
1373 WIN32_FIND_DATA wfd;
1374 char* prev_dir = xbt_new(char,MAX_PATH);
1375 GetCurrentDirectory(MAX_PATH,prev_dir);
1376 SetCurrentDirectory(root_dir);
1378 // begining of the scan
1379 hFind=FindFirstFile ("*.*", &wfd);
1381 if(hFind!=INVALID_HANDLE_VALUE){
1384 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1386 if(!strcmp(file_name,wfd.cFileName)){
1387 GetCurrentDirectory(MAX_PATH,path);
1388 SetCurrentDirectory(prev_dir);
1395 /* it's a directory, scan it*/
1398 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1399 if(find_file_path(wfd.cFileName,file_name,path)){
1401 SetCurrentDirectory(prev_dir);
1407 /* next file or directory */
1408 while(FindNextFile(hFind,&wfd))
1411 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1413 if(!strcmp(file_name,wfd.cFileName)){
1414 GetCurrentDirectory(MAX_PATH,path);
1415 SetCurrentDirectory(prev_dir);
1421 /* it's a file scan it */
1424 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1426 if(find_file_path(wfd.cFileName,file_name,path)){
1427 SetCurrentDirectory(prev_dir);
1438 SetCurrentDirectory(prev_dir);
1444 /* Implementation of the functions used to create a Visual C++ project.*/
1447 generate_simulation_dsp_file(const char* name)
1449 char buffer[MAX_PATH] = {0};
1451 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1453 GetEnvironmentVariable("LIB_SIMGRID_PATH",dsp.lib_dir,MAX_PATH);
1454 GetCurrentDirectory(MAX_PATH,buffer);
1456 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1457 strcpy(dsp.src_dir,buffer);
1458 dsp.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1459 sprintf(dsp.name,"%s_simulator",name);
1461 generate_dsp_project(&dsp,0,name);
1464 xbt_free(dsp.src_dir);
1465 xbt_free(dsp.lib_dir);
1471 * Create the Microsoft visual C++ real life project file.
1474 generate_real_live_dsp_file(const char* name)
1477 char buffer[MAX_PATH] = {0};
1478 xbt_dict_cursor_t cursor = NULL;
1484 dsp.lib_dir = xbt_new0(char,MAX_PATH);
1486 GetEnvironmentVariable("LIB_GRAS_PATH",dsp.lib_dir,MAX_PATH);
1488 GetCurrentDirectory(MAX_PATH,buffer);
1490 dsp.src_dir = xbt_new0(char,strlen(buffer) + 1);
1492 strcpy(dsp.src_dir,buffer);
1495 xbt_dict_foreach(process_function_set,cursor,key,data) {
1496 dsp.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1498 sprintf(dsp.name,"%s_%s",name,key);
1500 generate_dsp_project(&dsp,1,name);
1504 xbt_free(dsp.src_dir);
1505 xbt_free(dsp.lib_dir);
1510 generate_dsp_project(dsp_t project,int is_rl,const char* name)
1512 /* create the visual C++ project file */
1514 char* file_name = xbt_new0(char,strlen(project->name) + 5);
1515 sprintf(file_name,"%s.dsp",project->name);
1516 project->stream = fopen(file_name,"w+");
1517 xbt_free(file_name);
1521 buffer =xbt_new0(char,MAX_PATH);
1522 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1524 __gras_path = xbt_new0(char,MAX_PATH);
1525 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1529 /* dsp file header */
1530 fprintf(project->stream,"# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\n",project->name);
1531 fprintf(project->stream,"# Microsoft Developer Studio Generated Build File, Format Version 6.00\n");
1532 fprintf(project->stream,"# ** DO NOT EDIT **\n\n");
1534 /* target type is a win32 x86 console application */
1535 fprintf(project->stream,"# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\n");
1537 /* the current config is win32-debug */
1538 fprintf(project->stream,"CFG=%s - Win32 Debug\n",project->name);
1541 fprintf(project->stream,"!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n");
1544 fprintf(project->stream,"!MESSAGE use the Export Makefile command and run\n");
1545 fprintf(project->stream,"!MESSAGE\n");
1546 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\".\n",project->name);
1547 fprintf(project->stream,"!MESSAGE\n");
1548 fprintf(project->stream,"!MESSAGE You can specify a configuration when running NMAKE\n");
1549 fprintf(project->stream,"!MESSAGE by defining the macro CFG on the command line. For example:\n");
1550 fprintf(project->stream,"!MESSAGE\n");
1551 fprintf(project->stream,"!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s - Win32 Debug\"\n",project->name,project->name);
1552 fprintf(project->stream,"!MESSAGE\n");
1553 fprintf(project->stream,"!MESSAGE Possible choices for configuration are:\n");
1554 fprintf(project->stream,"!MESSAGE\n");
1555 fprintf(project->stream,"!MESSAGE \"%s - Win32 Release\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1556 fprintf(project->stream,"!MESSAGE \"%s - Win32 Debug\" (based on \"Win32 (x86) Console Application\")\n",project->name);
1557 fprintf(project->stream,"!MESSAGE\n\n");
1559 fprintf(project->stream,"# Begin Project\n\n");
1560 fprintf(project->stream,"# PROP AllowPerConfigDependencies 0\n");
1561 fprintf(project->stream,"# PROP Scc_ProjName\n");
1562 fprintf(project->stream,"# PROP Scc_LocalPath\n");
1563 fprintf(project->stream,"CPP=cl.exe\n");
1564 fprintf(project->stream,"RSC=rc.exe\n\n");
1566 fprintf(project->stream,"!IF \"$(CFG)\" == \"%s - Win32 Release\"\n\n",project->name);
1568 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1569 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 0\n");
1570 fprintf(project->stream,"# PROP BASE Output_Dir \"Release\"\n");
1571 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Release\"\n");
1572 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1573 fprintf(project->stream,"# PROP Use_MFC 0\n");
1574 fprintf(project->stream,"# PROP Use_Debug_Libraries 0\n");
1575 fprintf(project->stream,"# PROP Output_Dir \"Release\"\n");
1576 fprintf(project->stream,"# PROP Intermediate_Dir \"Release\"\n");
1577 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1578 /* TODO : the include directory */
1579 /*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);*/
1580 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);
1581 fprintf(project->stream,"# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /c\n");
1582 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"NDEBUG\"\n");
1583 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"NDEBUG\n");
1584 fprintf(project->stream,"BSC32=bscmake.exe\n");
1585 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1586 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1587 fprintf(project->stream,"LINK32=link.exe\n");
1588 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");
1591 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");
1593 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");
1595 fprintf(project->stream,"!ELSEIF \"$(CFG)\" == \"%s - Win32 Debug\"\n",project->name);
1597 fprintf(project->stream,"# PROP BASE Use_MFC 0\n");
1598 fprintf(project->stream,"# PROP BASE Use_Debug_Libraries 1\n");
1599 fprintf(project->stream,"# PROP BASE Output_Dir \"Debug\"\n");
1600 fprintf(project->stream,"# PROP BASE Intermediate_Dir \"Debug\"\n");
1601 fprintf(project->stream,"# PROP BASE Target_Dir \"\"\n");
1602 fprintf(project->stream,"# PROP Use_MFC 0\n");
1603 fprintf(project->stream,"# PROP Use_Debug_Libraries 1\n");
1604 fprintf(project->stream,"# PROP Output_Dir \"Debug\"\n");
1605 fprintf(project->stream,"# PROP Intermediate_Dir \"Debug\"\n");
1606 fprintf(project->stream,"# PROP Ignore_Export_Lib 0\n");
1607 fprintf(project->stream,"# PROP Target_Dir \"\"\n");
1608 /* TODO : the include directory */
1609 /*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);*/
1610 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);
1611 fprintf(project->stream,"# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_CONSOLE\" /D \"_MBCS\" /YX /FD /GZ /c\n");
1612 fprintf(project->stream,"# ADD BASE RSC /l 0x40c /d \"_DEBUG\"\n");
1613 fprintf(project->stream,"# ADD RSC /l 0x40c /d \"_DEBUG\"\n");
1614 fprintf(project->stream,"BSC32=bscmake.exe\n");
1615 fprintf(project->stream,"# ADD BASE BSC32 /nologo\n");
1616 fprintf(project->stream,"# ADD BSC32 /nologo\n");
1617 fprintf(project->stream,"LINK32=link.exe\n");
1618 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");
1621 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");
1623 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");
1625 fprintf(project->stream,"!ENDIF\n\n");
1627 fprintf(project->stream,"# Begin Target\n\n");
1628 fprintf(project->stream,"# Name \"%s - Win32 Release\"\n",project->name);
1629 fprintf(project->stream,"# Name \"%s - Win32 Debug\"\n",project->name);
1630 fprintf(project->stream,"# Begin Group \"Source Files\"\n\n");
1631 fprintf(project->stream,"# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n\n");
1633 fprintf(project->stream,"# Begin Source File\n");
1634 fprintf(project->stream,"SOURCE=%s\\_%s.c\n",project->src_dir,project->name);
1635 fprintf(project->stream,"# End Source File\n\n");
1637 fprintf(project->stream,"# Begin Source File\n");
1638 fprintf(project->stream,"SOURCE=%s\\%s.c\n",project->src_dir,name);
1639 fprintf(project->stream,"# End Source File\n\n");
1641 fprintf(project->stream,"# End Group\n");
1642 fprintf(project->stream,"# Begin Group \"Header Files\"\n\n");
1643 fprintf(project->stream,"# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n");
1644 fprintf(project->stream,"# End Group\n");
1645 fprintf(project->stream,"# Begin Group \"Resource Files\"\n\n");
1646 fprintf(project->stream,"# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n");
1647 fprintf(project->stream,"# End Group\n");
1648 fprintf(project->stream,"# End Target\n");
1649 fprintf(project->stream,"# End Project\n");