X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8eabc22e75fbfc2367ae381be37d12cfe6986b57..776a9237e010b97793aa31a03303e241e83e6095:/examples/gras/gras_stub_generator diff --git a/examples/gras/gras_stub_generator b/examples/gras/gras_stub_generator new file mode 100755 index 0000000000..2791ff51ed --- /dev/null +++ b/examples/gras/gras_stub_generator @@ -0,0 +1,215 @@ +#! /usr/bin/perl + +# gras_stub_generator - creates the main() to use a GRAS program + +# Authors: Martin Quinson +# Copyright (C) 2003 the OURAGAN project. + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the license (GNU LGPL) which comes with this package. + +use strict; +eval qq{ + use warnings; +}; # warnings not defined in 5.00503/sun4-solaris + +sub usage { + my ($msg)=@_; + die ($msg? "gras_stub_generator: $msg\n":""). + "gras_stub_generator: USAGE\n". + " gras_stub_generator project_name deployment_file\n" +} + +my ($project,$deploy_file)=@ARGV; + +$project && $deploy_file || usage(); + +my (%process); + +open (DEPLOY, $deploy_file) || usage("Cannot open $deploy_file: $!"); +my $linenum=0; +while () { + $linenum++; + /^\W*\w*\W*(\w*)/ || usage("$deploy_file:$linenum: Parse error"); + $process{$1}=1; +} + +my $warn="/***********\n * DO NOT EDIT! THIS FILE WERE AUTOMATICALLY GENERATED FROM $deploy_file BY gras_stub_generator\n ***********/\n"; + +##### +# Generate the file for the simulator +##### + +open (OUT,">_${project}_simulator.c") || die "Cannot open _${project}_simulator,c: $!"; +print OUT < +#include +#include "msg/msg.h" +#include + +char *gras_log=NULL; + +EOF + ; +foreach (keys %process) { print OUT "int $_(int argc,char *argv[]);\n"; } +print OUT "\n"; +foreach (keys %process) { print OUT "int launch_$_(int argc,char *argv[]);\n"; } +print OUT "\n$warn\n"; + +foreach (keys %process) { + print OUT<_${project}_$pname.c") || die "Cannot open _${project}_$pname,c: $!"; + print OUT < +#include +#include + +/* user code */ +int $pname(int argc, char *argv[]); + +$warn + +int main(int argc, char *argv[]){ + int errcode; + + errcode=$pname(argc,argv); + + return errcode; +} + +$warn +EOF +; + close OUT || die "Cannot write _${project}_$pname,c: $!"; +} + +##### +# Outputs the Makefile.am snippet +##### + +print ">>> Files for project '$project' successfully generated.\n"; +print ">>> Add (and edit) the following to you Makefile.am:\n\n"; + +print "# AUTOMAKE variable definition\n"; +print "INCLUDES= \@CFLAGS_GRAS\@ \@CFLAGS_XML\@ \@CFLAGS_SimGrid\@\n\n"; +print "PROGRAMS=${project}_simulator "; + +foreach (keys %process) { + print "${project}_$_ "; +} +print "\n\n${project}_simulator_SOURCES=\t_${project}_simulator.c $project.c\n"; +foreach (keys %process) { + print "${project}_${_}_SOURCES=\t_${project}_${_}.c $project.c\n"; +} + +print "\n\n${project}_simulator_LDADD=\tpath/to/libgrassg.a \@LIBS_SimGrid\@ \@LIBS_XML\@\n"; +foreach (keys %process) { + print "${project}_${_}_LDADD=\tpath/to/libgrasrl.a\n"; +} + +print "\n# cleanup temps\n"; +print "CLEANFILES= _${project}_simulator.c "; +foreach (keys %process) { + print "_${project}_$_.c "; +} +print "\n"; + +print "\n# generate temps\n"; +# A rule to generate the source file each time the deployment file changes +foreach (keys %process) { + print "_${project}_$_.c "; +} +print "_${project}_simulator.c: $deploy_file\n"; +print "\tgras_stub_generator $project $deploy_file >/dev/null\n"; + + +print "\n>>> Bye.\n"