Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cleanup a bit the parser code; Do not use attribute content in E[nding]Tag functions...
[simgrid.git] / tools / gras / stub_generator.c
index e4affce..d7cc972 100644 (file)
@@ -9,8 +9,9 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "xbt/sysdep.h"
+#include "xbt/function_types.h"
 #include "xbt/log.h"
-#include "surf/surf_parse_private.h"
+#include "surf/surfxml_parse.h"
 #include "surf/surf.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
@@ -27,7 +28,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(stubgen,gras,"Stub generator");
 #define RL_SOURCENAME_LDADD  "%s_%s_LDADD"
 #define RL_SOURCENAME_SOURCES  "%s_%s_SOURCES"
 #define MAKEFILE_FILENAME_AM  "%s.Makefile.am"
-#define MAKEFILE_FILENAME_LOCAL  "%s.Makefile.local"
+#define MAKEFILE_FILENAME_LOCAL  "%s.mk"
 #define MAKEFILE_FILENAME_REMOTE  "%s.Makefile.remote"
 #define DEPLOYMENT  "%s.deploy.sh"
 
@@ -102,36 +103,30 @@ static void s_process_free(void *process)
   free(((s_process_t*)process)->host);
 }
 
-static int parse_argc = -1 ;
-static char **parse_argv = NULL;
+static s_process_t process;
 
 static void parse_process_init(void)
 {
-  parse_argc = 0 ;
-  parse_argv = NULL;
-  parse_argc++;
-  parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
-  parse_argv[(parse_argc) - 1] = xbt_strdup(A_process_function);
+  xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
+  xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
+  process.argc = 1 ;
+  process.argv = xbt_new(char*,1);
+  process.argv[0] = xbt_strdup(A_surfxml_process_function);
+  process.host=strdup(A_surfxml_process_host);
+  VERB1("Function: %s",A_surfxml_process_function);
 }
 
 static void parse_argument(void)
 {
-  parse_argc++;
-  parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *));
-  parse_argv[(parse_argc) - 1] = xbt_strdup(A_argument_value);
+  process.argc++;
+  process.argv = xbt_realloc(process.argv, (process.argc) * sizeof(char *));
+  process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
 }
 
 static void parse_process_finalize(void)
 {
-  s_process_t process;
-  void *p = (void *) 1234;
-
-  xbt_dict_set(process_function_set, A_process_function, p, NULL);
-  xbt_dict_set(machine_set, A_process_host, p, NULL);
-  process.argc=parse_argc;
-  process.argv=parse_argv;
-  process.host=strdup(A_process_host);
   xbt_dynar_push(process_list,&process);
+  VERB1("Function: %s",process.argv[0]);
 }
 
 static void generate_sim(char *project)
@@ -167,13 +162,13 @@ static void generate_sim(char *project)
                     "  /*  Simulation setup */\n" 
                      "  MSG_global_init(&argc,argv);\n" 
                      "  if (argc != 3) {\n" 
-                     "    fprintf(stderr, \"Usage: %s platform_file application_description.txt [--gras-log=...]\\n\",argv[0]);\n" 
+                     "    fprintf(stderr, \"Usage: %s platform.xml deployment.xml [--gras-log=...]\\n\",argv[0]);\n" 
                      "    exit(1);\n" 
                      "  }\n"
                      "\n");
    fprintf(OUT, 
           "  MSG_paje_output(\"%s.trace\");\n" 
-          "  MSG_set_channel_number(10); /* Using at most 10 channel (ports) per host. Change it here if needed */\n" 
+          "  MSG_set_channel_number(XBT_MAX_CHANNEL); /* Using at most 10 channel (ports) per host. Change it here if needed */\n" 
           "  MSG_create_environment(argv[1]);\n" 
           "\n" 
           "  /*  Application deployment */\n",
@@ -288,7 +283,7 @@ static void generate_makefile_am(char *project, char *deployment)
   }
   fprintf(OUT, SIM_SOURCENAME, project);
   fprintf(OUT, ": %s\n", deployment);
-  fprintf(OUT, "\tstub_generator %s %s >/dev/null\n", project, deployment);
+  fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
   fclose(OUT);
 }
 
@@ -307,13 +302,24 @@ static void generate_makefile_local(char *project, char *deployment)
   xbt_assert1(OUT, "Unable to open %s for writing",filename);
   free(filename);
    
-  fprintf(OUT, "############ PROJECT COMPILING AND ARCHIVING #########\n");
-  fprintf(OUT, "PROJECT_NAME=%s\n",project);
-  fprintf(OUT, 
-         "DISTDIR=gras-$(PROJECT_NAME)\n\n"
-         "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n"
-         "CFLAGS = -O3 -w -g\n"
+  fprintf(OUT,
+         "\n"
+         "####\n"
+         "#### THIS FILE WAS GENERATED, DO NOT EDIT BEFORE RENAMING IT\n"
+         "####\n\n\n");
+
+  fprintf(OUT,"## Variable declarations\n"
+              "PROJECT_NAME=%s\n"
+             "DISTDIR=gras-$(PROJECT_NAME)\n\n"
+         ,project);
+   
+  fprintf(OUT,
+         "# Set the GRAS_ROOT environment variable to the path under which you installed SimGrid\n"
+         "# Compilation will fail if you don't do so\n" 
+         "GRAS_ROOT?= $(shell echo \"\\\"<<<< GRAS_ROOT undefined !!! >>>>\\\"\")\n\n"
+         "# You can fiddle the following to make it fit your taste\n"
          "INCLUDES = -I$(GRAS_ROOT)/include\n"
+         "CFLAGS = -O3 -w -g $(INCLUDES)\n"
          "LIBS_SIM = -lm  -L$(GRAS_ROOT)/lib/ -lsimgrid\n"
          "LIBS_RL = -lm  -L$(GRAS_ROOT)/lib/ -lgras\n"
          "LIBS = \n"
@@ -338,14 +344,26 @@ static void generate_makefile_local(char *project, char *deployment)
 
   fprintf(OUT,
          "\n"
+         "## By default, build all the binaries\n"
          "all: $(BIN_FILES)\n"
          "\n");
+   
+  fprintf(OUT, "\n## generate temps: regenerate the source file each time the deployment file changes\n");
+  xbt_dict_foreach(process_function_set,cursor,key,data) {
+    fprintf(OUT, RL_SOURCENAME, project,key);
+    fprintf(OUT, " ");
+  }
+  fprintf(OUT, SIM_SOURCENAME, project);
+  fprintf(OUT, ": %s\n", deployment);
+  fprintf(OUT, "\tgras_stub_generator %s %s >/dev/null\n", project, deployment);
+
+  fprintf(OUT, "\n## Generate the binaries\n");
   fprintf(OUT, SIM_BINARYNAME ": " SIM_OBJNAME " %s.o\n",project, project, project);
   fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_SIM) $(LIBS) $(LDADD) -o $@ \n");
   xbt_dict_foreach(process_function_set,cursor,key,data) {
     fprintf(OUT, RL_BINARYNAME " : " RL_OBJNAME " %s.o\n", project, key, project, key, project);
     fprintf(OUT, "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) $^ $(LIBS_RL) $(LIBS) $(LDADD) -o $@ \n");
-  }
+  }  
   fprintf(OUT, 
          "\n"
          "%%: %%.o\n"
@@ -353,16 +371,19 @@ static void generate_makefile_local(char *project, char *deployment)
          "\n"
          "%%.o: %%.c\n"
          "\t$(CC) $(INCLUDES) $(DEFS) $(CFLAGS) -c -o $@ $<\n"
-         "\n"
-         "DIST_FILES= $(C_FILES) "MAKEFILE_FILENAME_LOCAL" "MAKEFILE_FILENAME_REMOTE"\n"
+         "\n");
+   
+  fprintf(OUT,
+         "## Rules for tarballs and cleaning\n"
+         "DIST_FILES= $(C_FILES) "MAKEFILE_FILENAME_LOCAL" " /*MAKEFILE_FILENAME_REMOTE*/"\n"
          "distdir: $(DIST_FILES)\n"
          "\trm -rf $(DISTDIR)\n"
          "\tmkdir -p $(DISTDIR)\n"
          "\tcp $^ $(DISTDIR)\n"
          "\n"
          "dist: clean distdir\n"
-         "\ttar c $(DISTDIR) | gzip -c > $(DISTDIR).tar.gz\n"
-         "\n", project, project);
+         "\ttar c $(DISTDIR) | gzip -c9 > $(DISTDIR).tar.gz\n"
+         "\n", project /*, project*/);
 
   fprintf(OUT,
          "clean:\n"
@@ -377,7 +398,7 @@ static void generate_makefile_local(char *project, char *deployment)
          ".SUFFIXES:\n"
          ".PHONY : clean\n"
          "\n");
-   
+  /* 
   fprintf(OUT, "############ REMOTE COMPILING #########\n");
   fprintf(OUT, 
          "MACHINES ?= ");
@@ -431,7 +452,7 @@ static void generate_makefile_local(char *project, char *deployment)
          "\t     then echo \"Sucessful\"; else failed=1;echo \"Failed (check $(SRCDIR)/buildlogs/$$site.log)\"; fi;echo; \\\n"
          "\t   fi;\\\n"
          "\t done;\n",project,project,project);
-
+*/
   fclose(OUT);
 }
 
@@ -560,24 +581,28 @@ int main(int argc, char *argv[])
 {
   char *project_name = NULL;
   char *deployment_file = NULL;
-
+  int i;
+   
   surf_init(&argc, argv);
 
-  xbt_assert1((argc ==3),"Usage: %s project_name deployment_file\n",argv[0]);
+  xbt_assert1((argc >= 3),"Usage: %s project_name deployment_file [deployment_file...]\n",argv[0]);
 
   project_name = argv[1];
-  deployment_file = argv[2];
 
   process_function_set = xbt_dict_new();
   process_list = xbt_dynar_new(sizeof(s_process_t),s_process_free);
   machine_set = xbt_dict_new();
 
-  STag_process_fun = parse_process_init;
-  ETag_argument_fun = parse_argument;
-  ETag_process_fun = parse_process_finalize;
-  surf_parse_open(deployment_file);
-  if(surf_parse()) xbt_assert1(0,"Parse error in %s",deployment_file);
-  surf_parse_close();
+  STag_surfxml_process_fun = parse_process_init;
+  ETag_surfxml_argument_fun = parse_argument;
+  ETag_surfxml_process_fun = parse_process_finalize;
+  for(i=2; i<argc; i++) {
+     deployment_file = argv[i];
+     surf_parse_open(deployment_file);
+     if(surf_parse()) xbt_assert1(0,"Parse error in %s",deployment_file);
+     surf_parse_close();
+  }
+
 
   warning = xbt_new(char,strlen(WARN)+strlen(deployment_file)+10);
   sprintf(warning,WARN,deployment_file);
@@ -599,8 +624,8 @@ int main(int argc, char *argv[])
   generate_sim(project_name);
   generate_rl(project_name);
   generate_makefile_local(project_name, deployment_file);
-  generate_makefile_remote(project_name, deployment_file);
-  generate_deployment(project_name, deployment_file);
+//  generate_makefile_remote(project_name, deployment_file);
+//  generate_deployment(project_name, deployment_file);
 
   free(warning);
   surf_exit();