Logo AND Algorithmique Numérique Distribuée

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