3 /* gras_stub_generator - creates the main() to use a GRAS program */
5 /* Copyright (c) 2003-2007 Martin Quinson, Arnaud Legrand, Malek Cherier. */
6 /* All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 /* specific to Borland Compiler */
17 #include "xbt/sysdep.h"
18 #include "xbt/function_types.h"
20 #include "surf/surfxml_parse.h"
21 #include "surf/surf.h"
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
31 /* tabulation level (used to indent the lines of the borland project file */
32 static unsigned int level = 0;
36 /* the gras.h header directory */
37 static char* __gras_path = NULL;
45 * A structure which represents a borland project file.
47 typedef struct s_borland_project
49 const char* xml_version;/* the xml version used to write the borland project file */
50 const char* encoding; /* the encoding used to write the borland project file */
51 const char* comment; /* the xml comment to write at the begining of the borland project file */
52 char* name; /* the name of the borland project file */
53 FILE* stream; /* the stream to the borland project file */
54 const char* version; /* the builder version of the borland project file */
55 char* bin_dir; /* the directory used to store the generated program */
56 char* obj_dir; /* the directory used to store the generated object files */
57 char* lib_dir; /* the directory used to store the librairies used in the borland project */
58 char* src_dir; /* the directory use to store the source files of the project */
59 }s_borland_project_t,* borland_project_t;
62 * Write tabs in a borland project file.
63 * @param project The project concerned by the operation.
64 * @param count The count tab to write
67 borland_project_write_tabs(borland_project_t project,unsigned int count);
70 * Write the begin of an xml node in the borland project file.
71 * @param project The borland project concerned by this operation.
72 * @param name The name of the node.
75 borland_project_begin_xml_node(borland_project_t project, const char* name);
79 * Write the end of an xml node in the borland project file.
80 * @param project The borland project concerned by this operation.
81 * @param name The name of the node.
84 borland_project_end_xml_node(borland_project_t project, const char* name);
87 * Write an xml element in a borland project file.
88 * @param project The borland project concerned by this operation.
89 * @param name The name of the element to write
90 * @param value The value of the element
93 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value);
96 * Write a FILE xml element in the borland project file.
97 * @param project The borland project concerned by this operation.
98 * @param file_name The value of the attribute FILENAME.
99 * @param form_name The value of the attribute FORMNAME.
100 * @param unit_name The value of the attribute UNITNAME.
101 * @param container_id The value of the attribute CONTAINERID.
102 * @param design_claas The value of the attribute DESIGNCLASS.
103 * @param local_command The value of the attribute LOCALCOMMAND.
106 borland_project_write_file_element( borland_project_t project,
107 const char* file_name,
108 const char* form_name,
109 const char* unit_name,
110 const char* container_id,
111 const char* design_class,
112 const char* local_command);
114 * Write all options of the IDE of the Borland Builder C++ compiler.
115 * @ param project The project concerned by this operation.
119 borland_project_write_ide_options(borland_project_t project);
122 * Write the xml header of the xml document.
123 * @param project The project concerned by the operation.
126 borland_project_write_xml_header(borland_project_t project);
129 * Write an xml comment in a borland project file
130 * @param project The project concerned by this operation.
133 borland_project_write_xml_comment(borland_project_t project);
136 * Create a bpf file used by a borland project file.
137 * @param name The name of the bpf file to create.
140 borland_project_create_main_file(const char* name);
143 * Create a borland project file.
144 * @param project The project concerned by this operation.
147 borland_project_create(borland_project_t project);
150 * Close a borland project file.
151 * @param project the borland project file to close.
154 borland_project_close(borland_project_t project);
158 * Generate a borland simulation poject file.
159 * @param name The name of the simulation project
162 generate_borland_simulation_project(const char* name);
165 * Generate a borland project file for real life.
166 * @param name The name of the project to create.
169 generate_borland_real_life_project(const char* name);
172 * Generate a borland project file.
173 * @param project The borland project to generate.
176 generate_borland_project(borland_project_t project,int is_rl,const char* name);
179 * Find the path of a file.
180 * @param file_name The file name to find.
181 * @path path If founded this parameter will contain the path of file.
182 * @return If successful the function returns 1. Otherwise the function
186 find_file_path(const char* root_dir,const char* file_name,char* path);
192 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
193 #define SIM_SOURCENAME "_%s_simulator.c"
194 #define SIM_OBJNAME "_%s_simulator.o"
195 #define SIM_BINARYNAME "%s_simulator"
196 #define SIM_SOURCENAME_LDADD "%s_simulator_LDADD"
197 #define SIM_SOURCENAME_SOURCES "%s_simulator_SOURCES"
198 #define RL_SOURCENAME "_%s_%s.c"
199 #define RL_OBJNAME "_%s_%s.o"
200 #define RL_BINARYNAME "%s_%s"
201 #define RL_SOURCENAME_LDADD "%s_%s_LDADD"
202 #define RL_SOURCENAME_SOURCES "%s_%s_SOURCES"
203 #define MAKEFILE_FILENAME_AM "%s.Makefile.am"
204 #define MAKEFILE_FILENAME_LOCAL "%s.mk"
205 #define MAKEFILE_FILENAME_REMOTE "%s.Makefile.remote"
206 #define DEPLOYMENT "%s.deploy.sh"
208 char *warning = NULL;
210 /**********************************************/
211 /**** Generate the file for the simulator *****/
212 /**********************************************/
214 const char *SIM_PREEMBULE =
215 "/* specific to Borland Compiler */\n"
216 "#ifdef __BORLANDC__\n"
219 "#include <stdlib.h>\n"
220 "#include <stdio.h>\n"
221 "#include \"msg/msg.h\"\n"
222 "#include <gras.h>\n"
224 "char *gras_log=NULL;\n";
227 #define SIM_LAUNCH_FUNC \
228 "int launch_%s(int argc, char **argv) {\n" \
229 " char **myargv=argv;\n" \
230 " int myargc=argc;\n" \
234 " if (gras_log) {\n"\
235 " myargv=malloc((argc+1) * sizeof(char**));\n" \
236 " for (i=0; i<argc; i++)\n" \
237 " myargv[i] = argv[i];\n" \
238 " myargv[myargc++] = gras_log;\n" \
240 " retcode = %s(myargc,myargv);\n" \
241 " if (myargv != argv)\n" \
243 " return retcode;\n" \
246 const char *SIM_MAIN_POSTEMBULE = "\n"
248 " MSG_launch_application(argv[2]);\n"
250 " /* Run the simulation */\n"
253 " /* cleanup the place */\n"
262 /**********************************************/
263 /********* Parse XML deployment file **********/
264 /**********************************************/
265 xbt_dict_t process_function_set = NULL;
266 xbt_dynar_t process_list = NULL;
267 xbt_dict_t machine_set = NULL;
269 typedef struct s_process_t {
275 static void s_process_free(void *process)
278 for(i=0;i<((s_process_t*)process)->argc; i++)
279 free(((s_process_t*)process)->argv[i]);
280 free(((s_process_t*)process)->host);
283 static s_process_t process;
286 * Création de deux dictionnaires
288 static void parse_process_init(void)
290 xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
291 xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
293 process.argv = xbt_new(char*,1);
294 process.argv[0] = xbt_strdup(A_surfxml_process_function);
295 process.host=strdup(A_surfxml_process_host);
296 /*VERB1("Function: %s",A_surfxml_process_function);*/
299 static void parse_argument(void)
302 process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
303 process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
306 static void parse_process_finalize(void)
308 xbt_dynar_push(process_list,&process);
309 /*VERB1("Function: %s",process.argv[0]);*/
312 static void generate_sim(char *project)
314 xbt_dict_cursor_t cursor=NULL;
317 char *filename = NULL;
321 * Creation d'un fichier nommé : <projet>_simulator.c
325 filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
326 sprintf(filename,SIM_SOURCENAME,project);
328 OUT=fopen(filename,"w");
331 xbt_assert1(OUT, "Unable to open %s for writing",filename);
334 * Ecriture du message d'avertissement.
336 fprintf(OUT, "%s\n",warning);
339 * Ecriture du préambule (inclusion de certains fichiers d'en-tête
341 fprintf(OUT, "%s", SIM_PREEMBULE);
344 * Déclaration des fonction int <process>(int argc,char *argv[]);
346 xbt_dict_foreach(process_function_set,cursor,key,data) {
347 fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
353 * Déclaration des fonction int launch_<process>(int argc,char *argv[]);
355 xbt_dict_foreach(process_function_set,cursor,key,data) {
356 fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
360 * Ecriture du message d'avertissement.
362 fprintf(OUT, "\n%s\n",warning);
364 xbt_dict_foreach(process_function_set,cursor,key,data) {
365 fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
367 fprintf(OUT, "\n%s\n",warning);
369 fprintf(OUT,"%s", "/* specific to Borland Compiler */\n"
370 "#ifdef __BORLANDDC__\n"
374 fprintf(OUT, "%s", "int main (int argc,char *argv[]) {\n"
376 " /* Simulation setup */\n"
377 " MSG_global_init(&argc,argv);\n"
378 " if (argc != 3) {\n"
379 " fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n"
384 " MSG_paje_output(\"%s.trace\");\n"
385 " MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n"
386 " MSG_create_environment(argv[1]);\n"
388 " /* Application deployment */\n",
390 xbt_dict_foreach(process_function_set,cursor,key,data) {
391 fprintf(OUT," MSG_function_register(\"%s\", launch_%s);\n",key,key);
393 fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
398 /**********************************************/
399 /**** Generate the file for the real life *****/
400 /**********************************************/
401 static void generate_rl(char *project)
403 xbt_dict_cursor_t cursor=NULL;
406 char *filename = NULL;
409 xbt_dict_foreach(process_function_set,cursor,key,data) {
410 filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
412 sprintf(filename,RL_SOURCENAME,project,key);
414 OUT=fopen(filename,"w");
415 xbt_assert1(OUT, "Unable to open %s for writing",filename);
417 fprintf(OUT, "\n%s\n",warning);
418 fprintf(OUT, "/* specific to Borland Compiler */\n" \
419 "#ifdef __BORLANDC__\n" \
420 "#pragma hdrstop\n" \
422 "#include <stdio.h>\n" \
423 "#include <signal.h>\n" \
424 "#include <gras.h>\n" \
426 "extern const char * XBT_PUBLIC_DATA _gras_procname;\n" \
427 "/* user code */\n" \
428 "int %s(int argc, char *argv[]);\n" \
430 "/* specific to Borland Compiler */\n" \
431 "#ifdef __BORLANDC__\n" \
432 "#pragma argsused\n" \
434 "int main(int argc, char *argv[]){\n" \
437 " _gras_procname = \"%s\";\n" \
438 " errcode=%s(argc,argv);\n"\
440 " return errcode;\n"\
443 fprintf(OUT, "\n%s\n",warning);
449 static void generate_makefile_am(char *project, char *deployment)
451 xbt_dict_cursor_t cursor=NULL;
454 char *filename = NULL;
457 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
458 sprintf(filename,MAKEFILE_FILENAME_AM, project);
460 OUT=fopen(filename,"w");
461 xbt_assert1(OUT, "Unable to open %s for writing",filename);
463 fprintf(OUT, "# AUTOMAKE variable definition\n");
464 fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
465 fprintf(OUT, "PROGRAMS=");
466 fprintf(OUT, SIM_BINARYNAME,project);
468 xbt_dict_foreach(process_function_set,cursor,key,data) {
470 fprintf(OUT, RL_BINARYNAME, project, key);
473 fprintf(OUT, "\n\n");
474 fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
476 fprintf(OUT, SIM_SOURCENAME,project);
477 fprintf(OUT, " %s.c\n", project);
478 fprintf(OUT, SIM_SOURCENAME_LDADD, project);
479 fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
481 xbt_dict_foreach(process_function_set,cursor,key,data) {
482 fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
484 fprintf(OUT, RL_SOURCENAME, project,key);
485 fprintf(OUT, " %s.c\n", project);
486 fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
487 fprintf(OUT, "=\tpath/to/libgras.a\n\n");
490 fprintf(OUT, "\n# cleanup temps\n");
491 fprintf(OUT, "CLEANFILES= ");
492 fprintf(OUT, SIM_SOURCENAME, project);
494 xbt_dict_foreach(process_function_set,cursor,key,data) {
496 fprintf(OUT, RL_SOURCENAME, project,key);
500 fprintf(OUT, "\n# generate temps\n");
501 fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
503 xbt_dict_foreach(process_function_set,cursor,key,data) {
504 fprintf(OUT, RL_SOURCENAME, project,key);
507 fprintf(OUT, SIM_SOURCENAME, project);
508 fprintf(OUT, ": %s\n", deployment);
509 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
513 static void generate_makefile_local(char *project, char *deployment)
515 xbt_dict_cursor_t cursor=NULL;
518 char *filename = NULL;
521 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
522 sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
524 OUT=fopen(filename,"w");
525 xbt_assert1(OUT, "Unable to open %s for writing",filename);
531 "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
534 fprintf(OUT,"## Variable declarations\n"
536 "DISTDIR=gras-$(PROJECT_NAME)\n\n"
540 "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
541 "# Compilation will fail if you don't do so\n"
542 "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
543 "# You can fiddle the following to make it fit your taste\n"
544 "INCLUDES = -I$(GRAS_ROOT)/include\n"
545 "CFLAGS ?= -O3 -w -g\n"
546 "LIBS_SIM = -lm -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
547 "LIBS_RL = -lm -L$(GRAS_ROOT)/lib/ -lgras\n"
551 fprintf(OUT, "PRECIOUS_C_FILES ?= %s.c\n", project);
553 fprintf(OUT, "GENERATED_C_FILES = ");
554 fprintf(OUT, SIM_SOURCENAME" ",project);
555 xbt_dict_foreach(process_function_set,cursor,key,data) {
556 fprintf(OUT, RL_SOURCENAME " ",project, key);
560 fprintf(OUT,"OBJ_FILES = $(patsubst %%.c,%%.o,$(PRECIOUS_C_FILES))\n");
562 fprintf(OUT, "BIN_FILES = ");
564 fprintf(OUT, SIM_BINARYNAME " ",project);
565 xbt_dict_foreach(process_function_set,cursor,key,data) {
566 fprintf(OUT, RL_BINARYNAME " ", project, key);
572 "## By default, build all the binaries\n"
573 "all: $(BIN_FILES)\n"
576 fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
577 xbt_dict_foreach(process_function_set,cursor,key,data) {
578 fprintf(OUT, RL_SOURCENAME, project,key);
581 fprintf(OUT, SIM_SOURCENAME, project);
582 fprintf(OUT, ": %s\n", deployment);
583 fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
585 fprintf(OUT, "\n## Generate the binaries\n");
586 fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " $(OBJ_FILES)\n",project, project);
587 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
588 xbt_dict_foreach(process_function_set,cursor,key,data) {
589 fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " $(OBJ_FILES)\n", project, key, project, key);
590 fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
595 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
598 "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
602 "##Â Rules for tarballs and cleaning\n"
603 "DIST_FILES= $(EXTRA_DIST) $(GENERATED_C_FILES) $(PRECIOUS_C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
604 "distdir: $(DIST_FILES)\n"
605 "\trm -rf $(DISTDIR)\n"
606 "\tmkdir -p $(DISTDIR)\n"
607 "\tcp $^ $(DISTDIR)\n"
609 "dist: clean distdir\n"
610 "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
611 "\n", project /*, project*/);
615 "\trm -f $(BIN_FILES) $(OBJ_FILES) *~ %s.o " SIM_OBJNAME, project, project);
616 xbt_dict_foreach(process_function_set,cursor,key,data) {
617 fprintf(OUT, " " RL_OBJNAME, project, key);
621 "\trm -rf $(DISTDIR)\n"
627 fprintf(OUT, "############ REMOTE COMPILING #########\n");
630 xbt_dict_foreach(machine_set,cursor,key,data) {
631 fprintf(OUT, "%s ",key);
636 "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
637 "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
639 "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
640 "SIMGRID_VERSION ?=2.92\n"
641 "GRAS_PROJECT ?= %s\n"
642 "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
645 "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
646 "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
647 "\t for site in $(MACHINES) ; do \\\n"
648 "\t machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
649 "\t machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
650 "\t cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
651 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
652 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
653 "\t cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
654 "\t SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
655 "\t GRAS_PROJECT_URL=$(GRAS_PROJECT_URL) make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
656 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
657 "\t echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
659 "\t machine=$$site;\\\n"
660 "\t echo \"----[ Compile on $$machine ]----\";\\\n"
662 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
663 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
664 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
666 "\t if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
667 "\t then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
669 "\t echo \"-- Copy the data over\"; \\\n"
670 "\t scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
671 "\t echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
672 "\t if echo $$site | grep '%%' >/dev/null ; then \\\n"
673 "\t if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
674 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
676 "\t if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
677 "\t then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
679 "\t done;\n",project,project,project);
684 static void generate_makefile_remote(char *project, char *deployment)
686 char *filename = NULL;
689 filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
690 sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
692 OUT=fopen(filename,"w");
693 xbt_assert1(OUT, "Unable to open %s for writing",filename);
696 "INSTALL_PATH ?= $(shell pwd)\n"
699 "\tcd $$GRAS_ROOT ; \\\n"
700 "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
701 "\techo $$retrieved; \\\n"
702 "\tif test \"x$$retrieved\" = x; then \\\n"
703 "\t tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
704 "\t cd simgrid-$(SIMGRID_VERSION)/; \\\n"
705 "\t ./configure --prefix=$$GRAS_ROOT ; \\\n"
706 "\t make all install ;\\\n"
709 "compile-gras: compile-simgrid\n"
710 "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
711 "\techo $$not_retrieved; \\\n"
712 "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
713 "\t tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
714 "\t make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
718 "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
719 "clean-gras clean-gras-$(GRAS_PROJECT):\n"
720 "\trm -rf gras-$(GRAS_PROJECT)*\n"
721 "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
723 ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
724 " compile-simgrid compile-gras\n"
730 static void generate_deployment(char *project, char *deployment)
732 xbt_dict_cursor_t cursor=NULL;
735 char *filename = NULL;
741 filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
742 sprintf(filename,DEPLOYMENT, project);
744 OUT=fopen(filename,"w");
745 xbt_assert1(OUT, "Unable to open %s for writing",filename);
747 fprintf(OUT, "#!/bin/sh\n");
748 fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
750 "if test \"${MACHINES+set}\" != set; then \n"
751 " export MACHINES='");
752 xbt_dict_foreach(machine_set,cursor,key,data) {
753 fprintf(OUT, "%s ",key);
758 "if test \"${INSTALL_PATH+set}\" != set; then \n"
759 " export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
761 "if test \"${GRAS_ROOT+set}\" != set; then \n"
762 " export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
764 "if test \"${SRCDIR+set}\" != set; then \n"
765 " export SRCDIR=./\n"
767 "if test \"${SIMGRID_URL+set}\" != set; then \n"
768 " export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
770 "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
771 " export SIMGRID_VERSION=2.91\n"
773 "if test \"${GRAS_PROJECT+set}\" != set; then \n"
774 " export GRAS_PROJECT=%s\n"
776 "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
777 " export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
780 "test -e runlogs/ || mkdir -p runlogs/\n",
784 "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
785 " SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
786 " GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
788 xbt_dynar_foreach (process_list,cpt,proc) {
789 fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
790 for(i=1;i<proc.argc;i++) {
791 fprintf(OUT,"%s ",proc.argv[i]);
793 fprintf(OUT,"\";\n");
794 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);
800 static void print(void *p)
810 /* specific to Borland Compiler */
815 int main(int argc, char *argv[])
817 char *project_name = NULL;
818 char *deployment_file = NULL;
821 surf_init(&argc, argv);
823 xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
825 project_name = argv[1];
827 process_function_set = xbt_dict_new();
828 process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
829 machine_set = xbt_dict_new();
831 STag_surfxml_process_fun = parse_process_init;
832 ETag_surfxml_argument_fun = parse_argument;
833 ETag_surfxml_process_fun = parse_process_finalize;
835 for(i=2; i<argc; i++) {
836 deployment_file = argv[i];
837 surf_parse_open(deployment_file);
839 xbt_assert1(0,"Parse error in %s",deployment_file);
845 warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
846 sprintf(warning,WARN,deployment_file);
848 /*if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
849 xbt_dict_cursor_t cursor=NULL;
853 for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
854 xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
855 xbt_dict_cursor_step(cursor) ) {
856 DEBUG1("Function %s", key);
859 xbt_dict_dump(process_function_set,print);
862 generate_sim(project_name);
863 generate_rl(project_name);
864 generate_makefile_local(project_name, deployment_file);
866 generate_borland_simulation_project(project_name);
867 generate_borland_real_life_project(project_name);
870 xbt_free(__gras_path);
874 // generate_makefile_remote(project_name, deployment_file);
875 // generate_deployment(project_name, deployment_file);
883 generate_borland_project(borland_project_t project,int is_rl,const char* name)
885 char* binary_path; /* the path of the generated binary file */
886 char* obj_path; /* the path of the generated object file */
887 char* lib_files; /* a list of the libraries used in the borland project */
888 char* main_source; /* the name of the bpf file used by the borland project */
889 char* file_name; /* the file name of the main source file */
890 char* include_path; /* the include path */
893 /* create the borland project file */
894 borland_project_create(project);
896 /* write the xml document header */
897 borland_project_write_xml_header(project);
899 /* write the xml comment to identify a borland project file */
900 borland_project_write_xml_comment(project);
902 /* write the begin of the node PROJECT */
903 borland_project_begin_xml_node(project,"PROJECT");
905 /* write the begin of node MACROS */
906 borland_project_begin_xml_node(project,"MACROS");
908 /* write the borland project version */
909 borland_project_write_xml_element(project,"VERSION",project->version);
911 /* construct and write the borland project binary path */
912 binary_path = xbt_new0(char,strlen(project->name) + strlen(project->bin_dir) + 6);
913 sprintf(binary_path,"%s\\%s.exe",project->bin_dir,project->name);
914 borland_project_write_xml_element(project,"PROJECT",binary_path);
915 xbt_free(binary_path);
917 /* construct an write the object files to generate by the compiler */
918 obj_path = xbt_new0(char,strlen(project->name) + strlen(name) + (2*strlen(project->obj_dir)) + 11);
919 sprintf(binary_path,"%s\\%s.obj\n%s\\%s.obj",project->obj_dir,project->name,project->obj_dir,name);
920 borland_project_write_xml_element(project,"OBJFILES",obj_path);
923 /* write the resource files used by the compiler (no resource file used) */
924 borland_project_write_xml_element(project,"RESFILES","");
926 /* write the IDL files of the project (no IDL files used) */
927 borland_project_write_xml_element(project,"IDLFILES","");
929 /* write the IDLGENFILES element (not used) */
930 borland_project_write_xml_element(project,"IDLGENFILES","");
932 /* write the DEFFILE element (not used) */
933 borland_project_write_xml_element(project,"DEFFILE","");
935 /* write the RESDEPEN element (not used, no resource file used) */
936 borland_project_write_xml_element(project,"RESDEPEN","$(RESFILES)");
938 /* construct and write the list of libraries used by the project */
940 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + strlen("libgras.lib") + 3);
941 sprintf(lib_files,"%s\\simgrid.lib %s\\libgras.lib",project->lib_dir,project->lib_dir);
945 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("libgras.lib") + 2);
946 sprintf(lib_files,"%s\\libgras.lib",project->lib_dir);
948 lib_files = xbt_new0(char,(2 * (strlen(project->lib_dir) + 1)) + strlen("simgrid.lib") + 2);
949 sprintf(lib_files,"%s\\simgrid.lib",project->lib_dir);
952 borland_project_write_xml_element(project,"LIBFILES",lib_files);
955 /* write the SPARELIBS element (not used) */
956 borland_project_write_xml_element(project,"SPARELIBS","");
958 /* write the PACKAGES element (no package used) */
959 borland_project_write_xml_element(project,"PACKAGES","");
961 /* write the PATHCPP element (the path of the source files of the project)*/
962 borland_project_write_xml_element(project,"PATHCPP",".;");
964 /* write the PATHPAS element (not used) */
965 borland_project_write_xml_element(project,"PATHPAS","");
967 /* write the PATHRC element (not used) */
968 borland_project_write_xml_element(project,"PATHRC","");
970 /* write the PATHASM element (not used) */
971 borland_project_write_xml_element(project,"PATHASM","");
973 /* write the DEBUGLIBPATH element (the path for debug) */
974 borland_project_write_xml_element(project,"DEBUGLIBPATH","$(BCB)\\lib\\debug");
976 /* write the RELEASELIBPATH element (the path for release) */
977 borland_project_write_xml_element(project,"RELEASELIBPATH","$(BCB)\\lib\\release");
979 /* specify the linker to use */
980 borland_project_write_xml_element(project,"LINKER","ilink32");
982 /* write the USERDEFINES element (user definitions (#define _DEBUG))*/
983 borland_project_write_xml_element(project,"USERDEFINES","_DEBUG");
985 /* write the SYSDEFINES element (use the system definitions, not used strict ANSI and no use the VCL)*/
986 borland_project_write_xml_element(project,"SYSDEFINES","NO_STRICT;_NO_VCL");
988 /* construct and write the MAINSOURCE element */
989 main_source = xbt_new0(char,strlen(project->name) + 5);
990 sprintf(main_source,"%s.bpf",project->name);
991 /* write the main source file to use in the borland project file */
992 borland_project_write_xml_element(project,"MAINSOURCE",main_source);
994 /* create the bpf file used by the borland project */
995 borland_project_create_main_file(main_source);
997 /* FIXME resolve the include path */
998 /* write the INCLUDEPATH element */
1001 buffer =xbt_new0(char,MAX_PATH);
1002 GetEnvironmentVariable("SG_INSTALL_DIR",buffer,MAX_PATH);
1004 __gras_path = xbt_new0(char,MAX_PATH);
1005 sprintf(__gras_path,"%s\\simgrid\\include",buffer);
1008 /*find_file_path("C:\\","gras.h",__gras_path);*/
1011 include_path = xbt_new0(char,strlen("$(BCB)\\include") + strlen(__gras_path) + 2);
1012 sprintf(include_path,"$(BCB)\\include;%s",__gras_path);
1014 borland_project_write_xml_element(project,"INCLUDEPATH",include_path);
1016 xbt_free(include_path);
1018 /* write the LIBPATH element (no librarie paths specified)*/
1019 borland_project_write_xml_element(project,"LIBPATH","$(BCB)\\lib;$(BCB)\\lib\\obj");
1022 * write the WARNINGS element :
1023 * -w-sus (-w-8075) disabled the suspect conversion pointer warning
1024 * -w-rvl (-w-8070) disabled the function must return warning
1025 * -w-rch (-w-8066) disabled the warning which specify that we can't attain the code
1026 * -w-pia (-w-8060) disabled the warning that detect a possible bad assignement
1027 * -w-pch (-w-8058) disabled the warning throw when the compiler can't precompile a header file
1028 * -w-par (-w-8057) disabled the warning that detect an unused variable
1029 * -w-csu (-w-8012) disabled the warning that detect a comparison between a signed number and an unsigned number
1030 * -w-ccc (-w-8008) disabled the warning that detect une conditon which is always true
1031 * -w-aus (-w-8008) disabled the warning that detect an affected value which is never used
1033 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");
1035 /* write the OTHERFILES element (no other files used used) */
1036 borland_project_write_xml_element(project,"OTHERFILES","");
1038 /* write the end of the node MACROS */
1039 borland_project_end_xml_node(project,"MACROS");
1041 /* write the begin of the node OPTIONS */
1042 borland_project_begin_xml_node(project,"OPTIONS");
1044 /* FIXME check the idlcflags */
1045 /* write the IDLCFLAGS element */
1046 borland_project_write_xml_element(project,"IDLCFLAGS","");
1049 * write the CFLAG1 element (compiler options ) :
1051 * -Od this flag disable all compiler optimisation
1052 * -H this flag specify the name of the file which will contain the precompiled header
1053 * -Hc this flag specify to the compiler to cach the precompiled header
1054 * -Vx this flag specify to the compiler to allow the empty structures
1055 * -Ve this flag specify to the compiler to allow the empty base classes
1056 * -X- this flag activate the auto-depend informations of the compiler
1057 * -r- this flag disabled the use of the processor register
1058 * -a1 this flag specify that the data must be aligned on one byte
1059 * -b- this flag specify that the enums are the smallest size of the integer
1060 * -k (used during debug)
1061 * -y this flag generate the line number for debug
1062 * -v this flag enabled the debugging of the source files
1063 * -vi check the expansion of the inline functions
1064 * -tWC specify that it's a console application
1065 * -tWM- specify that the application is not multithread
1066 * -c generate the object file, no link
1068 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");
1070 /* write the PFLAGS element */
1071 borland_project_write_xml_element(project,"PFLAGS","-N2obj -N0obj -$YD -$W -$O- -$A8 -v -JPHNE ");
1073 /* write the RFLAGS element */
1074 borland_project_write_xml_element(project,"RFLAGS","");
1076 /* write the AFLAGS element (assembler flags) :
1078 * /mx (not documented)
1079 * /w2 (not documented)
1080 * /zd (not documented)
1083 borland_project_write_xml_element(project,"AFLAGS","/mx /w2 /zd");
1085 /* write the LFLAGS element (linker flags) :
1087 * -I specify the output directory for object files
1088 * -D register the specified description (no description "")
1089 * -ap build a win32 console application
1090 * -Tpe generate a exe file
1091 * -x do not create the map file
1092 * -Gn do not generate the state file
1093 * -v include the complete debug informations
1095 borland_project_write_xml_element(project,"LFLAGS","-Iobj -D"" -ap -Tpe -x -Gn -v");
1097 /* write the OTHERFILES element (not used)*/
1098 borland_project_write_xml_element(project,"OTHERFILES","");
1100 /* write the end of the node OPTIONS */
1101 borland_project_end_xml_node(project,"OPTIONS");
1103 /* write the begin of the node LINKER */
1104 borland_project_begin_xml_node(project,"LINKER");
1106 /* write the ALLOBJ element */
1107 borland_project_write_xml_element(project,"ALLOBJ","c0x32.obj $(OBJFILES)");
1109 /* write the ALLRES element (not used) */
1110 borland_project_write_xml_element(project,"ALLRES","");
1112 /* write the ALLLIB element */
1113 borland_project_write_xml_element(project,"ALLLIB","$(LIBFILES) $(LIBRARIES) import32.lib cw32.lib");
1115 /* write the OTHERFILES element (not used) */
1116 borland_project_write_xml_element(project,"OTHERFILES","");
1118 /* write the end of the node LINKER */
1119 borland_project_end_xml_node(project,"LINKER");
1121 /* write the begin of the node FILELIST */
1122 borland_project_begin_xml_node(project,"FILELIST");
1124 /* construct and write the list of file elements */
1126 /* add the bpf file to the list */
1127 borland_project_write_file_element(project,main_source,"",project->name,"BPF","","");
1128 xbt_free(main_source);
1130 /* FIXME : check the source file directory */
1131 /* add the generated source file to the list */
1133 file_name = xbt_new0(char,strlen(project->src_dir) + strlen(project->name) + 5);
1134 sprintf(file_name,"%s\\_%s.c",project->src_dir,project->name);
1135 borland_project_write_file_element(project,file_name,"",project->name,"CCompiler","","");
1137 memset(file_name,0,strlen(project->src_dir) + strlen(project->name) + 4);
1138 sprintf(file_name,"%s\\%s.c",project->src_dir,name);
1139 borland_project_write_file_element(project,file_name,"",name,"CCompiler","","");
1141 xbt_free(file_name);
1143 /* FIXME : check the libraries directory */
1144 /* add the simgrid library to the list */
1147 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("libgras.lib") + 2);
1148 sprintf(file_name,"%s\\libgras.lib",project->lib_dir);
1149 borland_project_write_file_element(project,file_name,"","libgras.lib","LibTool","","");
1152 file_name = xbt_new0(char,strlen(project->lib_dir) + strlen("simgrid.lib") + 2);
1153 sprintf(file_name,"%s\\simgrid.lib",project->lib_dir);
1154 borland_project_write_file_element(project,file_name,"","simgrid.lib","LibTool","","");
1158 xbt_free(file_name);
1160 /* write the end of the node FILELIST */
1161 borland_project_end_xml_node(project,"FILELIST");
1163 /* write the begin of the node BUILDTOOLS (not used)*/
1164 borland_project_begin_xml_node(project,"BUILDTOOLS");
1166 /* write the end of the node BUILDTOOLS (not used)*/
1167 borland_project_end_xml_node(project,"BUILDTOOLS");
1169 /* write the begin of the node IDEOPTIONS */
1170 borland_project_begin_xml_node(project,"IDEOPTIONS");
1172 /* write all of the option of the IDE of Borland C++ Builder */
1173 borland_project_write_ide_options(project);
1175 /* write the end of the node IDEOPTIONS */
1176 borland_project_end_xml_node(project,"IDEOPTIONS");
1178 /* write the end of the node PROJECT */
1179 borland_project_end_xml_node(project,"PROJECT");
1181 /* close the borland project file */
1182 borland_project_close(project);
1186 borland_project_write_tabs(borland_project_t project,unsigned int count)
1190 for(pos = 0; pos < count; pos++)
1191 fprintf(project->stream,"\t");
1195 borland_project_begin_xml_node(borland_project_t project, const char* name)
1198 borland_project_write_tabs(project,level);
1200 fprintf(project->stream,"<%s>\n",name);
1206 borland_project_end_xml_node(borland_project_t project, const char* name)
1211 borland_project_write_tabs(project,level);
1213 fprintf(project->stream,"</%s>\n",name);
1218 borland_project_write_xml_element(borland_project_t project,const char* name,const char* value)
1220 borland_project_write_tabs(project,level);
1221 fprintf(project->stream,"<%s value=\"%s\"/>\n",name,value);
1225 borland_project_write_xml_header(borland_project_t project)
1227 fprintf(project->stream,"<?xml version='%s' encoding='%s' ?>\n",project->xml_version, project->encoding);
1231 borland_project_create_main_file(const char* name)
1233 FILE* stream = fopen(name,"w+");
1235 fprintf(stream,"Ce fichier est uniquement utilisé par le gestionnaire de projets et doit être traité comme le fichier projet\n\n\nmain\n");
1241 borland_project_create(borland_project_t project)
1243 char* file_name = xbt_new0(char,strlen(project->name ) + 5);
1244 sprintf(file_name,"%s.bpr",project->name);
1245 project->stream = fopen(file_name,"w+");
1246 xbt_free(file_name);
1250 borland_project_write_xml_comment(borland_project_t project)
1252 fprintf(project->stream,"<!-- %s -->\n",project->comment);
1255 borland_project_write_file_element( borland_project_t project,
1256 const char* file_name,
1257 const char* form_name,
1258 const char* unit_name,
1259 const char* container_id,
1260 const char* design_class,
1261 const char* local_command)
1263 borland_project_write_tabs(project,level);
1265 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);
1269 borland_project_write_ide_options(borland_project_t project)
1272 const char* ide_options =
1273 "[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" \
1274 "[Version Info Keys]\nCompanyName=\nFileDescription=\nFileVersion=1.0.0.0\nInternalName=\nLegalCopyright=\nLegalTrademarks=\nOriginalFilename=\nProductName=\nProductVersion=1.0.0.0\nComments=\n\n" \
1275 "[Excluded Packages]\n$(BCB)\\dclclxdb60.bpl=Composants BD CLX Borland\n$(BCB)\\Bin\\dclclxstd60.bpl=Composants Standard CLX Borland\n\n" \
1276 "[HistoryLists\\hlIncludePath]\nCount=1\nItem0=$(BCB)\\include;$(BCB)\\include\\vcl;\n\n" \
1277 "[HistoryLists\\hlLibraryPath]\nCount=1\nItem0=$(BCB)\\lib\\obj;$(BCB)\\lib\n\n" \
1278 "[HistoryLists\\hlDebugSourcePath]\nCount=1\nItem0=$(BCB)\\source\\vcl\\\n\n" \
1279 "[HistoryLists\\hlConditionals]\nCount=1\nItem0=_DEBUG\n\n" \
1280 "[HistoryLists\\hlIntOutputDir]\nCount=0\n\n" \
1281 "[HistoryLists\\hlFinalOutputDir]\nCount=0\n\n" \
1282 "[HistoryLists\\hIBPIOutputDir]\nCount=0\n\n" \
1283 "[Debugging]\nDebugSourceDirs=$(BCB)\\source\\vcl\n\n" \
1284 "[Parameters]\nRunParams=\nLauncher=\nUseLauncher=0\nDebugCWD=\nHostApplication=\nRemoteHost=\nRemotePath=\nRemoteLauncher=\nRemoteCWD=\nRemoteDebug=0\n\n" \
1285 "[Compiler]\nShowInfoMsgs=0\nLinkDebugVcl=0\nLinkCGLIB=0\n\n" \
1286 "[CORBA]\nAddServerUnit=1\nAddClientUnit=1\nPrecompiledHeaders=1\n\n" \
1287 "[Language]\nActiveLang=\nProjectLang=\nRootDir=\n";
1289 fprintf(project->stream,ide_options);
1293 borland_project_close(borland_project_t project)
1295 fclose(project->stream);
1299 generate_borland_simulation_project(const char* name)
1301 char buffer[MAX_PATH] = {0};
1304 WIN32_FIND_DATA wfd = {0};
1306 s_borland_project_t borland_project = {0};
1307 borland_project.xml_version = "1.0";
1308 borland_project.encoding ="utf-8";
1309 borland_project.comment ="C++Builder XML Project";
1310 borland_project.version = "BCB.06.00";
1312 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1315 GetEnvironmentVariable("LIB_SIMGRID_PATH",borland_project.lib_dir,MAX_PATH);
1318 GetCurrentDirectory(MAX_PATH,buffer);
1320 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1322 strcpy(borland_project.src_dir,buffer);
1324 borland_project.name = xbt_new0(char,strlen(name) + strlen("simulator") + 2);
1325 sprintf(borland_project.name,"%s_simulator",name);
1327 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1328 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1330 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1333 CreateDirectory(borland_project.bin_dir,NULL);
1335 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1336 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1338 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1340 if(INVALID_HANDLE_VALUE == hDir)
1341 CreateDirectory(borland_project.obj_dir,NULL);
1343 generate_borland_project(&borland_project,0,name);
1345 xbt_free(borland_project.name);
1346 xbt_free(borland_project.src_dir);
1347 xbt_free(borland_project.bin_dir);
1348 xbt_free(borland_project.obj_dir);
1349 xbt_free(borland_project.lib_dir);
1353 generate_borland_real_life_project(const char* name)
1356 WIN32_FIND_DATA wfd = {0};
1357 char buffer[MAX_PATH] = {0};
1358 xbt_dict_cursor_t cursor = NULL;
1361 s_borland_project_t borland_project = {0};
1363 borland_project.xml_version = "1.0";
1364 borland_project.encoding ="utf-8";
1365 borland_project.comment ="C++Builder XML Project";
1366 borland_project.version = "BCB.06.00";
1367 borland_project.lib_dir = " ";
1369 borland_project.lib_dir = xbt_new0(char,MAX_PATH);
1371 GetEnvironmentVariable("LIB_GRAS_PATH",borland_project.lib_dir,MAX_PATH);
1373 GetCurrentDirectory(MAX_PATH,buffer);
1375 borland_project.src_dir = xbt_new0(char,strlen(buffer) + 1);
1377 strcpy(borland_project.src_dir,buffer);
1379 borland_project.bin_dir = xbt_new0(char,strlen(buffer) + strlen("\\bin") + 1);
1380 sprintf(borland_project.bin_dir,"%s\\bin",buffer);
1382 hDir = FindFirstFile(borland_project.bin_dir,&wfd);
1384 if(INVALID_HANDLE_VALUE == hDir)
1385 CreateDirectory(borland_project.bin_dir,NULL);
1387 borland_project.obj_dir = xbt_new0(char,strlen(buffer) + strlen("\\obj") + 1);
1388 sprintf(borland_project.obj_dir,"%s\\obj",buffer);
1390 hDir = FindFirstFile(borland_project.obj_dir,&wfd);
1393 CreateDirectory(borland_project.obj_dir,NULL);
1396 xbt_dict_foreach(process_function_set,cursor,key,data) {
1397 borland_project.name = xbt_new0(char,strlen(name) + strlen(key) + 2);
1399 sprintf(borland_project.name,"%s_%s",name,key);
1401 generate_borland_project(&borland_project,1,name);
1402 xbt_free(borland_project.name);
1405 xbt_free(borland_project.src_dir);
1406 xbt_free(borland_project.bin_dir);
1407 xbt_free(borland_project.obj_dir);
1408 xbt_free(borland_project.lib_dir);
1411 find_file_path(const char* root_dir,const char* file_name,char* path)
1414 WIN32_FIND_DATA wfd;
1415 char* prev_dir = xbt_new(char,MAX_PATH);
1416 GetCurrentDirectory(MAX_PATH,prev_dir);
1417 SetCurrentDirectory(root_dir);
1419 // begining of the scan
1420 hFind=FindFirstFile ("*.*", &wfd);
1422 if(hFind!=INVALID_HANDLE_VALUE){
1425 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
1427 if(!strcmp(file_name,wfd.cFileName)){
1428 GetCurrentDirectory(MAX_PATH,path);
1429 SetCurrentDirectory(prev_dir);
1436 /* it's a directory, scan it*/
1439 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1440 if(find_file_path(wfd.cFileName,file_name,path)){
1442 SetCurrentDirectory(prev_dir);
1448 /* next file or directory */
1449 while(FindNextFile(hFind,&wfd))
1452 if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
1454 if(!strcmp(file_name,wfd.cFileName)){
1455 GetCurrentDirectory(MAX_PATH,path);
1456 SetCurrentDirectory(prev_dir);
1462 /* it's a file scan it */
1465 if(strcmp(wfd.cFileName,".") && strcmp(wfd.cFileName,"..")){
1467 if(find_file_path(wfd.cFileName,file_name,path)){
1468 SetCurrentDirectory(prev_dir);
1479 SetCurrentDirectory(prev_dir);