Logo AND Algorithmique Numérique Distribuée

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