Logo AND Algorithmique Numérique Distribuée

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