Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change SIMGRID_INSTALL_PATH to GRAS_ROOT. It's not as clear, but I had to
[simgrid.git] / tools / gras / stub_generator.c
1 /*      $Id$     */
2
3 /* gras_stub_generator - creates the main() to use a GRAS program           */
4
5 /* Copyright (c) 2003,2004,2005 Martin Quinson, Arnaud Legrand. 
6    All rights reserved.                  */
7
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. */
10
11 #include"xbt/sysdep.h"
12 #include"xbt/dict.h"
13 #include"xbt/dynar.h"
14 #include"xbt/error.h"
15 #include "surf/surf_parse.h"
16 #include "surf/surf.h"
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
19
20 #define WARN "/***********\n * DO NOT EDIT! THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM %s BY gras_stub_generator\n ***********/\n"
21 #define SIM_SOURCENAME  "_%s_simulator.c"
22 #define SIM_OBJNAME  "_%s_simulator.o"
23 #define SIM_BINARYNAME  "%s_simulator"
24 #define SIM_SOURCENAME_LDADD  "%s_simulator_LDADD"
25 #define SIM_SOURCENAME_SOURCES  "%s_simulator_SOURCES"
26 #define RL_SOURCENAME  "_%s_%s.c"
27 #define RL_OBJNAME  "_%s_%s.o"
28 #define RL_BINARYNAME  "%s_%s"
29 #define RL_SOURCENAME_LDADD  "%s_%s_LDADD"
30 #define RL_SOURCENAME_SOURCES  "%s_%s_SOURCES"
31 #define MAKEFILE_FILENAME_AM  "%s.Makefile.am"
32 #define MAKEFILE_FILENAME_LOCAL  "%s.Makefile.local"
33 #define MAKEFILE_FILENAME_REMOTE  "%s.Makefile.remote"
34 #define DEPLOYMENT  "%s.deploy.sh"
35
36 char *warning = NULL;
37
38 /**********************************************/
39 /**** Generate the file for the simulator *****/
40 /**********************************************/
41
42 const char *SIM_PREEMBULE =
43 "#include <stdlib.h>\n"
44 "#include <stdio.h>\n"
45 "#include \"msg/msg.h\"\n"
46 "#include <gras.h>\n"
47 "\n"
48 "char *gras_log=NULL;\n";
49
50
51 #define SIM_LAUNCH_FUNC  \
52 "int launch_%s(int argc, char **argv) {\n" \
53 "  char **myargv=argv;\n" \
54 "  int myargc=argc;\n" \
55 "  int i;\n" \
56 "  int retcode;\n"\
57 "    \n"\
58 "  if (gras_log) {\n"\
59 "    myargv=malloc((argc+1) * sizeof(char**));\n" \
60 "    for (i=0; i<argc; i++)\n" \
61 "      myargv[i] = argv[i];\n" \
62 "    myargv[myargc++] = gras_log;\n" \
63 "  }\n" \
64 "  retcode = %s(myargc,myargv);\n" \
65 "  if (myargv != argv)\n" \
66 "    free(myargv);\n" \
67 "  return retcode;\n" \
68 "}\n"
69
70 #define SIM_MAIN_PREEMBULE \
71 "int main (int argc,char *argv[]) {\n" \
72 "  int i,j;\n" \
73 "\n" \
74 "  /*  Simulation setup */\n" \
75 "  MSG_global_init_args(&argc,argv);\n" \
76 "  if (argc != 3) {\n" \
77 "    fprintf(stderr, \"Usage: %%s platform_file application_description.txt [--gras-log=...]\\n\",argv[0]);\n" \
78 "    exit(1);\n" \
79 "  }\n" \
80 "\n" \
81 "  MSG_paje_output(\"%s.trace\");\n" \
82 "  MSG_set_channel_number(10); /* Using at most 10 channel (ports) per host. Change it here if needed */\n" \
83 "  MSG_create_environment(argv[1]);\n" \
84 "\n" \
85 "  /*  Application deployment */\n"
86
87 const char *SIM_MAIN_POSTEMBULE = "\n"
88 "\n"
89 "  MSG_launch_application(argv[2]);\n"
90 "\n"
91 "  /*  Run the simulation */\n"
92 "  MSG_main();\n"
93 "\n"
94 "  /* cleanup the place */\n"
95 "  MSG_clean();\n"
96 "  if (gras_log)\n"
97 "    free(gras_log);\n"
98 "  return 0;\n"
99 "}\n";
100
101
102
103 /**********************************************/
104 /********* Parse XML deployment file **********/
105 /**********************************************/
106 xbt_dict_t process_function_set = NULL;
107 xbt_dynar_t process_list = NULL;
108 xbt_dict_t machine_set = NULL;
109
110 typedef struct s_process_t {
111   int argc;
112   char **argv;
113   char *host;
114 } s_process_t;
115
116 static void s_process_free(void *process)
117 {
118   int i;
119   for(i=0;i<((s_process_t*)process)->argc; i++)
120     free(((s_process_t*)process)->argv[i]);
121   free(((s_process_t*)process)->host);
122 }
123
124 static int parse_argc = -1 ;
125 static char **parse_argv = NULL;
126
127 static void parse_process_init(void)
128 {
129   parse_argc = 0 ;
130   parse_argv = NULL;
131   parse_argc++;
132   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
133   parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
134 }
135
136 static void parse_argument(void)
137 {
138   parse_argc++;
139   parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
140   parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
141 }
142
143 static void parse_process_finalize(void)
144 {
145   s_process_t process;
146   void *p = (void *) 1234;
147
148   xbt_dict_set(process_function_set, A_process_function, p, NULL);
149   xbt_dict_set(machine_set, A_process_host, p, NULL);
150   process.argc=parse_argc;
151   process.argv=parse_argv;
152   process.host=strdup(A_process_host);
153   xbt_dynar_push(process_list,&process);
154 }
155
156 static void generate_sim(char *project)
157 {
158   xbt_dict_cursor_t cursor=NULL;
159   char *key = NULL;
160   void *data = NULL;
161   char *filename = NULL;
162   FILE *OUT = NULL;
163   filename = xbt_new(char,strlen(project) + strlen(SIM_SOURCENAME));
164   sprintf(filename,SIM_SOURCENAME,project);
165   
166   OUT=fopen(filename,"w");
167   xbt_assert1(OUT, "Unable to open %s for writing",filename);
168
169   fprintf(OUT, "%s\n",warning);
170   fprintf(OUT, "%s", SIM_PREEMBULE);
171   xbt_dict_foreach(process_function_set,cursor,key,data) {
172     fprintf(OUT,"int %s(int argc,char *argv[]);\n",key);
173   }
174   fprintf(OUT,"\n");
175   xbt_dict_foreach(process_function_set,cursor,key,data) {
176     fprintf(OUT,"int launch_%s(int argc,char *argv[]);\n",key);
177   }
178   fprintf(OUT, "\n%s\n",warning);
179   xbt_dict_foreach(process_function_set,cursor,key,data) {
180     fprintf(OUT,SIM_LAUNCH_FUNC,key,key);
181   }
182   fprintf(OUT, "\n%s\n",warning);
183
184   fprintf(OUT, SIM_MAIN_PREEMBULE, project);
185   xbt_dict_foreach(process_function_set,cursor,key,data) {
186     fprintf(OUT,"  MSG_function_register(\"%s\", launch_%s);\n",key,key);
187   }
188   fprintf(OUT, "%s", SIM_MAIN_POSTEMBULE);
189   fclose(OUT);
190   free(filename);
191 }
192
193 /**********************************************/
194 /**** Generate the file for the real life *****/
195 /**********************************************/
196 static void generate_rl(char *project)
197 {
198   xbt_dict_cursor_t cursor=NULL;
199   char *key = NULL;
200   void *data = NULL;
201   char *filename = NULL;
202   FILE *OUT = NULL;
203
204   xbt_dict_foreach(process_function_set,cursor,key,data) {
205     filename = xbt_new(char,strlen(project) + strlen(RL_SOURCENAME) + strlen(key));
206     sprintf(filename,RL_SOURCENAME,project,key);
207   
208     OUT=fopen(filename,"w");
209     xbt_assert1(OUT, "Unable to open %s for writing",filename);
210
211     fprintf(OUT, "\n%s\n",warning);
212     fprintf(OUT, "#include <stdio.h>\n" \
213                  "#include <signal.h>\n" \
214                  "#include <gras.h>\n" \
215                  "\n" \
216                  "extern const char *_gras_procname;\n" \
217                  "/* user code */\n" \
218                  "int %s(int argc, char *argv[]);\n" \
219                  "\n" \
220                  "int main(int argc, char *argv[]){\n" \
221                  "  int errcode;\n" \
222                  "\n" \
223                  "  _gras_procname = \"%s\";\n" \
224                  "  errcode=%s(argc,argv);\n"\
225                  " \n" \
226                  "  return errcode;\n"\
227                  "}\n",
228             key,key,key);
229     fprintf(OUT, "\n%s\n",warning);
230     fclose(OUT);
231     free(filename);
232   }
233 }
234
235 static void generate_makefile_am(char *project, char *deployment)
236 {
237   xbt_dict_cursor_t cursor=NULL;
238   char *key = NULL;
239   void *data = NULL;
240   char *filename = NULL;
241   FILE *OUT = NULL;
242
243   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_AM));
244   sprintf(filename,MAKEFILE_FILENAME_AM, project);
245   
246   OUT=fopen(filename,"w");
247   xbt_assert1(OUT, "Unable to open %s for writing",filename);
248
249   fprintf(OUT, "# AUTOMAKE variable definition\n");
250   fprintf(OUT, "INCLUDES= @CFLAGS_SimGrid@\n\n");
251   fprintf(OUT, "PROGRAMS=");
252   fprintf(OUT, SIM_BINARYNAME,project);
253
254   xbt_dict_foreach(process_function_set,cursor,key,data) {
255     fprintf(OUT, " ");
256     fprintf(OUT, RL_BINARYNAME, project, key);
257   }
258
259   fprintf(OUT, "\n\n");
260   fprintf(OUT, SIM_SOURCENAME_SOURCES,project);
261   fprintf(OUT, "=\t");
262   fprintf(OUT, SIM_SOURCENAME,project);
263   fprintf(OUT, " %s.c\n", project);
264   fprintf(OUT, SIM_SOURCENAME_LDADD, project);
265   fprintf(OUT, "=\tpath/to/libsimgrid.a\n\n");
266
267   xbt_dict_foreach(process_function_set,cursor,key,data) {
268     fprintf(OUT, RL_SOURCENAME_SOURCES, project,key);
269     fprintf(OUT, "=\t");
270     fprintf(OUT, RL_SOURCENAME, project,key);
271     fprintf(OUT, " %s.c\n", project);
272     fprintf(OUT, RL_SOURCENAME_LDADD, project, key);
273     fprintf(OUT, "=\tpath/to/libgras.a\n\n");
274   }
275
276   fprintf(OUT, "\n# cleanup temps\n");
277   fprintf(OUT, "CLEANFILES= ");
278   fprintf(OUT, SIM_SOURCENAME, project);
279   
280   xbt_dict_foreach(process_function_set,cursor,key,data) {
281     fprintf(OUT, " ");
282     fprintf(OUT, RL_SOURCENAME, project,key);
283   }
284   fprintf(OUT, "\n");
285
286   fprintf(OUT, "\n# generate temps\n");
287   fprintf(OUT, "\n# A rule to generate the source file each time the deployment file changes\n");
288
289   xbt_dict_foreach(process_function_set,cursor,key,data) {
290     fprintf(OUT, RL_SOURCENAME, project,key);
291     fprintf(OUT, " ");
292   }
293   fprintf(OUT, SIM_SOURCENAME, project);
294   fprintf(OUT, ": %s\n", deployment);
295   fprintf(OUT, "\tstub_generator %s %s >/dev/null\n", project, deployment);
296   fclose(OUT);
297 }
298
299 static void generate_makefile_local(char *project, char *deployment)
300 {
301   xbt_dict_cursor_t cursor=NULL;
302   char *key = NULL;
303   void *data = NULL;
304   char *filename = NULL;
305   FILE *OUT = NULL;
306
307   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_LOCAL));
308   sprintf(filename,MAKEFILE_FILENAME_LOCAL, project);
309   
310   OUT=fopen(filename,"w");
311   xbt_assert1(OUT, "Unable to open %s for writing",filename);
312   free(filename);
313    
314   fprintf(OUT, "############ PROJECT COMPILING AND ARCHIVING #########\n");
315   fprintf(OUT, "PROJECT_NAME=%s\n",project);
316   fprintf(OUT, 
317           "DISTDIR=gras-$(PROJECT_NAME)\n\n"
318           "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n"
319           "CFLAGS = -O3 -w\n"
320           "INCLUDES = -I$(GRAS_ROOT)/include\n"
321           "LIBS_SIM = -lm  -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
322           "LIBS_RL = -lm  -L$(GRAS_ROOT)/lib/ -lgras\n"
323           "LIBS = \n"
324           "\n");
325
326   fprintf(OUT, "C_FILES = ");
327   fprintf(OUT, SIM_SOURCENAME" ",project);
328   xbt_dict_foreach(process_function_set,cursor,key,data) {
329     fprintf(OUT, RL_SOURCENAME " ",project, key);
330   }
331   fprintf(OUT, "%s.c\n", project);
332
333   fprintf(OUT,"OBJ_FILES = \n");
334
335   fprintf(OUT, "BIN_FILES = ");
336
337   fprintf(OUT, SIM_BINARYNAME " ",project);
338   xbt_dict_foreach(process_function_set,cursor,key,data) {
339     fprintf(OUT, RL_BINARYNAME " ", project, key);
340   }
341   fprintf(OUT, "\n");
342
343   fprintf(OUT,
344           "\n"
345           "all: $(BIN_FILES)\n"
346           "\n");
347   fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " %s.o\n",project, project, project);
348   fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
349   xbt_dict_foreach(process_function_set,cursor,key,data) {
350     fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " %s.o\n", project, key, project, key, project);
351     fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
352   }
353   fprintf(OUT, 
354           "\n"
355           "%%: %%.o\n"
356           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS) $(LDADD) -o $@ \n"
357           "\n"
358           "%%.o: %%.c\n"
359           "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
360           "\n"
361           "DIST_FILES= $(C_FILES) "MAKEFILE_FILENAME_LOCAL" "MAKEFILE_FILENAME_REMOTE"\n"
362           "distdir: $(DIST_FILES)\n"
363           "\trm -rf $(DISTDIR)\n"
364           "\tmkdir -p $(DISTDIR)\n"
365           "\tcp $^ $(DISTDIR)\n"
366           "\n"
367           "dist: clean distdir\n"
368           "\ttar c $(DISTDIR) | gzip -c > $(DISTDIR).tar.gz\n"
369           "\n"
370           "clean:\n"
371           "\trm -f $(BIN_FILES) $(OBJ_FILES) *~\n"
372           "\trm -rf $(DISTDIR)\n"
373           "\n"
374           ".SUFFIXES:\n"
375           ".PHONY : clean\n"
376           "\n", project, project);
377
378   fprintf(OUT, "############ REMOTE COMPILING #########\n");
379   fprintf(OUT, 
380           "MACHINES ?= ");
381   xbt_dict_foreach(machine_set,cursor,key,data) {
382     fprintf(OUT, "%s ",key);
383   }
384   fprintf(OUT,"\n");
385
386   fprintf(OUT, 
387           "INSTALL_PATH ?='$$HOME/tmp/src' ### Has to be an absolute path !!! \n"
388           "GRAS_ROOT ?='$(INSTALL_PATH)' ### Has to be an absolute path !!! \n"
389           "SRCDIR ?= ./\n"
390           "SIMGRID_URL ?=http://gcl.ucsd.edu/simgrid/dl/\n"
391           "SIMGRID_VERSION ?=2.92\n"
392           "GRAS_PROJECT ?= %s\n"
393           "GRAS_PROJECT_URL ?= http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
394           "\n"
395           "remote:\n"
396           "\t@echo;echo \"----[ Compile the package on remote hosts ]----\"\n"
397           "\t@test -e $(SRCDIR)/buildlogs/ || mkdir -p $(SRCDIR)/buildlogs/\n"
398           "\t for site in $(MACHINES) ; do \\\n"
399           "\t   machine=`echo $$site |sed 's/^\\([^%%]*\\)%%.*$$/\\1/'`;\\\n"
400           "\t   machine2=`echo $$site |sed 's/^\\([^%%]*\\)%%\\(.*\\)$$/\\2/'`;\\\n"
401           "\t   cmd_mkdir=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
402           "\t                        SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
403           "\t                        GRAS_PROJECT_URL=$(GRAS_PROJECT_URL)  mkdir -p $(INSTALL_PATH) 2>&1'\\\"\";\\\n"
404           "\t   cmd_make=\"\\\"sh -c 'env INSTALL_PATH=$(INSTALL_PATH) GRAS_ROOT=$(GRAS_ROOT) \\\n"
405           "\t                        SIMGRID_URL=$(SIMGRID_URL) SIMGRID_VERSION=$(SIMGRID_VERSION) GRAS_PROJECT=$(GRAS_PROJECT) \\\n"
406           "\t                        GRAS_PROJECT_URL=$(GRAS_PROJECT_URL)  make -C $(INSTALL_PATH) -f "MAKEFILE_FILENAME_REMOTE" $(ACTION) 2>&1'\\\"\";\\\n"
407           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
408           "\t     echo \"----[ Compile on $$machine2 (behind $$machine) ]----\";\\\n"
409           "\t   else \\\n"
410           "\t     machine=$$site;\\\n"
411           "\t     echo \"----[ Compile on $$machine ]----\";\\\n"
412           "\t   fi;\\\n"
413           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
414           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log;\\\n"
415           "\t     then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;\\\n"
416           "\t   else \\\n"
417           "\t     if ssh $$machine \"eval $$cmd_mkdir\" 2>&1 > $(SRCDIR)/buildlogs/$$site.log ;\\\n"
418           "\t     then true; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi; \\\n"
419           "\t   fi;\\\n"
420           "\t   echo \"-- Copy the data over\"; \\\n"
421           "\t   scp "MAKEFILE_FILENAME_REMOTE" $$site:$(INSTALL_PATH) ;\\\n"
422           "\t   echo \"-- Compiling... (the output gets into $(SRCDIR)/buildlogs/$$site.log)\"; \\\n"
423           "\t   if echo $$site | grep  '%%' >/dev/null ; then \\\n"
424           "\t     if ssh $$machine \"ssh -A $$machine2 $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log;\\\n"
425           "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
426           "\t   else \\\n"
427           "\t     if ssh $$machine \"eval $$cmd_make\" 2>&1 >> $(SRCDIR)/buildlogs/$$site.log ;\\\n"
428           "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
429           "\t   fi;\\\n"
430           "\t done;\n",project,project,project);
431
432   fclose(OUT);
433 }
434
435 static void generate_makefile_remote(char *project, char *deployment)
436 {
437   xbt_dict_cursor_t cursor=NULL;
438   char *key = NULL;
439   void *data = NULL;
440   char *filename = NULL;
441   FILE *OUT = NULL;
442
443   filename = xbt_new(char,strlen(project) + strlen(MAKEFILE_FILENAME_REMOTE));
444   sprintf(filename,MAKEFILE_FILENAME_REMOTE, project);
445   
446   OUT=fopen(filename,"w");
447   xbt_assert1(OUT, "Unable to open %s for writing",filename);
448
449   fprintf(OUT, 
450           "INSTALL_PATH ?= $(shell pwd)\n"
451           "\n"
452           "compile-simgrid:\n"
453           "\tcd $$GRAS_ROOT ; \\\n"
454           "\tretrieved=`LANG=C;wget -N $(SIMGRID_URL)/simgrid-$(SIMGRID_VERSION).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
455           "\techo $$retrieved; \\\n"
456           "\tif test \"x$$retrieved\" = x; then \\\n"
457           "\t  tar zxf simgrid-$(SIMGRID_VERSION).tar.gz ; \\\n"
458           "\t  cd simgrid-$(SIMGRID_VERSION)/; \\\n"
459           "\t  ./configure --prefix=$$GRAS_ROOT ; \\\n"
460           "\t  make all install ;\\\n"
461            "\tfi\n"
462           "\n"
463           "compile-gras: compile-simgrid\n"
464           "\tnot_retrieved=`LANG=C;wget -N $(GRAS_PROJECT_URL)/gras-$(GRAS_PROJECT).tar.gz 2>&1 | grep newer | sed 's/.*no newer.*/yes/'`; \\\n"
465           "\techo $$not_retrieved; \\\n"
466           "\tif test \"x$$not_retrieved\" != xyes; then \\\n"
467           "\t  tar zxf gras-$(GRAS_PROJECT).tar.gz ; \\\n"
468           "\t  make -C gras-$(GRAS_PROJECT)/ -f $(GRAS_PROJECT).Makefile.local all ; \\\n"
469           "\tfi\n"
470           "\n"
471           "clean-simgrid:\n"
472           "\trm -rf simgrid-$(SIMGRID_VERSION)*\n"
473           "clean-gras clean-gras-$(GRAS_PROJECT):\n"
474           "\trm -rf gras-$(GRAS_PROJECT)*\n"
475           "clean: clean-simgrid clean-gras-$(GRAS_PROJECT)\n"
476           "\n"
477           ".PHONY: clean clean-simgrid clean-gras clean-gras-$(GRAS_PROJECT) \\\n"
478           "        compile-simgrid compile-gras\n"
479           );
480   fclose(OUT);
481 }
482
483
484 static void generate_deployment(char *project, char *deployment)
485 {
486   xbt_dict_cursor_t cursor=NULL;
487   char *key = NULL;
488   void *data = NULL;
489   char *filename = NULL;
490   FILE *OUT = NULL;
491
492   int cpt,i;
493   s_process_t proc;
494
495   filename = xbt_new(char,strlen(project) + strlen(DEPLOYMENT));
496   sprintf(filename,DEPLOYMENT, project);
497   
498   OUT=fopen(filename,"w");
499   xbt_assert1(OUT, "Unable to open %s for writing",filename);
500
501   fprintf(OUT, "#!/bin/sh\n");
502   fprintf(OUT, "############ DEPLOYMENT FILE #########\n");
503   fprintf(OUT,
504           "if test \"${MACHINES+set}\" != set; then \n"
505           "    export MACHINES='");
506   xbt_dict_foreach(machine_set,cursor,key,data) {
507     fprintf(OUT, "%s ",key);
508   }
509   fprintf(OUT,  
510           "';\n"
511           "fi\n"
512           "if test \"${INSTALL_PATH+set}\" != set; then \n"
513           "    export INSTALL_PATH='`echo $HOME`/tmp/src'\n"
514           "fi\n"
515           "if test \"${GRAS_ROOT+set}\" != set; then \n"
516           "    export GRAS_ROOT='`echo $INSTALL_PATH`'\n"
517           "fi\n"
518           "if test \"${SRCDIR+set}\" != set; then \n"
519           "    export SRCDIR=./\n"
520           "fi\n"
521           "if test \"${SIMGRID_URL+set}\" != set; then \n"
522           "    export SIMGRID_URL=http://gcl.ucsd.edu/simgrid/dl/\n"
523           "fi\n"
524           "if test \"${SIMGRID_VERSION+set}\" != set; then \n"
525           "    export SIMGRID_VERSION=2.91\n"
526           "fi\n"
527           "if test \"${GRAS_PROJECT+set}\" != set; then \n"
528           "    export GRAS_PROJECT=%s\n"
529           "fi\n"
530           "if test \"${GRAS_PROJECT_URL+set}\" != set; then \n"
531           "    export GRAS_PROJECT_URL=http://www-id.imag.fr/Laboratoire/Membres/Legrand_Arnaud/gras_test/\n"
532           "fi\n"
533           "\n"
534           "test -e runlogs/ || mkdir -p runlogs/\n",
535           project);
536
537   fprintf(OUT,  
538           "cmd_prolog=\"env INSTALL_PATH=$INSTALL_PATH GRAS_ROOT=$GRAS_ROOT \\\n"
539           "                 SIMGRID_URL=$SIMGRID_URL SIMGRID_VERSION=$SIMGRID_VERSION GRAS_PROJECT=$GRAS_PROJECT \\\n"
540           "                 GRAS_PROJECT_URL=$GRAS_PROJECT_URL LD_LIBRARY_PATH=$GRAS_ROOT/lib/ sh -c \";\n");
541
542   xbt_dynar_foreach (process_list,cpt,proc) {
543     fprintf(OUT,"cmd=\"\\$INSTALL_PATH/gras-%s/"RL_BINARYNAME" ",project,project,proc.argv[0]);
544     for(i=1;i<proc.argc;i++) {
545       fprintf(OUT,"%s ",proc.argv[i]);
546     }
547     fprintf(OUT,"\";\n");
548     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);
549   }
550
551   fclose(OUT);
552 }
553
554 static void print(void *p)
555 {
556   printf("%p",p);
557 }
558
559 int main(int argc, char *argv[])
560 {
561   char *project_name = NULL;
562   char *deployment_file = NULL;
563
564   surf_init(&argc, argv);
565
566   xbt_assert1((argc ==3),"Usage: %s project_name deployment_file\n",argv[0]);
567
568   project_name = argv[1];
569   deployment_file = argv[2];
570
571   process_function_set = xbt_dict_new();
572   process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
573   machine_set = xbt_dict_new();
574
575   STag_process_fun = parse_process_init;
576   ETag_argument_fun = parse_argument;
577   ETag_process_fun = parse_process_finalize;
578   surf_parse_open(deployment_file);
579   if(surf_parse()) xbt_assert1(0,"Parse error in %s",deployment_file);
580   surf_parse_close();
581
582   warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
583   sprintf(warning,WARN,deployment_file);
584
585   if(XBT_LOG_ISENABLED(stubgen, xbt_log_priority_debug)) {
586     xbt_dict_cursor_t cursor=NULL;
587     char *key = NULL;
588     void *data = NULL;
589
590     for (cursor=NULL, xbt_dict_cursor_first((process_function_set),&(cursor)) ;
591          xbt_dict_cursor_get_or_free(&(cursor),&(key),(void**)(&data));
592          xbt_dict_cursor_step(cursor) ) {
593       DEBUG1("Function %s", key);      
594     }
595     
596     xbt_dict_dump(process_function_set,print);
597   }
598
599   generate_sim(project_name);
600   generate_rl(project_name);
601   generate_makefile_local(project_name, deployment_file);
602   generate_makefile_remote(project_name, deployment_file);
603   generate_deployment(project_name, deployment_file);
604
605   free(warning);
606   surf_finalize();
607   return 0;
608 }