3 # gras_stub_generator - creates the main() to use a GRAS program
5 # Authors: Martin Quinson
6 # Copyright (C) 2003 the OURAGAN project.
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.
17 fail ($msg? "gras_stub_generator: $msg\n":"").
18 "gras_stub_generator: USAGE\n".
19 " gras_stub_generator project_name deployment_file\n"
22 my ($project,$deploy_file)=@ARGV;
24 $project && $deploy_file || usage();
28 open (DEPLOY, $deploy_file) || usage("Cannot open $deploy_file: $!");
32 /^\W*\w*\W*(\w*)/ || usage("$deploy_file:$linenum: Parse error");
36 my $warn="/***********\n * DO NOT EDIT! THIS FILE WERE AUTOMATICALLY GENERATED FROM $deploy_file BY gras_stub_generator\n ***********/\n";
39 # Generate the file for the simulator
42 open (OUT,">_${project}_simulator.c") || die "Cannot open _${project}_simulator,c: $!";
55 foreach (keys %process) { print OUT "int $_(int argc,char *argv[]);\n"; }
57 foreach (keys %process) { print OUT "int launch_$_(int argc,char *argv[]);\n"; }
58 print OUT "\n$warn\n";
60 foreach (keys %process) {
62 int launch_$_(int argc, char **argv) {
65 argv=realloc(argv,++argc * sizeof(char**));
66 argv[argc-1] = gras_log;
75 print OUT "\n$warn\n";
78 int main (int argc,char *argv[]) {
81 /** Save the gras-log argument */
82 for (i=1; i<argc; i++) {
83 if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
85 for (j=i+1; j<argc; j++) {
90 i--; /* compensate effect of next loop incrementation */
95 fprintf(stderr, "Usage: %s platform_file application_description.txt [--gras-log=...]\\n",argv[0]);
99 /* Simulation setup */
101 MSG_set_verbosity(MSG_SILENT);
102 MSG_set_channel_number(GRAS_MAX_CHANNEL);
103 MSG_create_environment(argv[1]);
105 /* Application deployment */
108 foreach (keys %process) {
109 print OUT " MSG_function_register(\"$_\", launch_$_);\n";
113 MSG_launch_application(argv[2]);
115 /* Run the simulation */
123 close OUT || die "Cannot write _${project}_simulator,c: $!";
126 # Generate the files for the real life
128 foreach my $pname (keys %process) {
129 open (OUT,">_${project}_$pname.c") || die "Cannot open _${project}_$pname,c: $!";
137 int $pname(int argc, char *argv[]);
141 int main(int argc, char *argv[]){
144 errcode=$pname(argc,argv);
152 close OUT || die "Cannot write _${project}_$pname,c: $!";
156 # Outputs the Makefile.am snippet
159 print ">>> Files for project '$project' successfully generated.\n";
160 print ">>> Add (and edit) the following to you Makefile.am:\n\n";
162 print "# AUTOMAKE variable definition\n";
163 print "INCLUDES= \@CFLAGS_GRAS\@ \@CFLAGS_XML\@ \@CFLAGS_SimGrid\@\n\n";
164 print "PROGRAMS=${project}_simulator ";
166 foreach (keys %process) {
167 print "${project}_$_ ";
169 print "\n\n${project}_simulator_SOURCES=\t_${project}_simulator.c $project.c\n";
170 foreach (keys %process) {
171 print "${project}_${_}_SOURCES=\t_${project}_${_}.c $project.c\n";
174 print "\n\n${project}_simulator_LDADD=\tpath/to/libgrassg.a \@LIBS_SimGrid\@ \@LIBS_XML\@\n";
175 foreach (keys %process) {
176 print "${project}_${_}_LDADD=\tpath/to/libgrasrl.a\n";
179 print "\n# cleanup temps\n";
180 print "CLEANFILES= _${project}_simulator.c ";
181 foreach (keys %process) {
182 print "_${project}_$_.c ";
186 print "\n# generate temps\n";
187 # A rule to generate the source file each time the deployment file changes
188 foreach (keys %process) {
189 print "_${project}_$_.c ";
191 print "_${project}_simulator.c: $deploy_file\n";
192 print "\tgras_stub_generator $project $deploy_file >/dev/null\n";