8 my $include="-I@top_srcdir@/include -I@top_srcdir@/include/smpi -I@includedir@ -I@includedir@/smpi";
10 foreach my $fortran (@ARGV) {
11 my $output = $fortran;
13 my $tmp = new File::Temp;
15 `f2c $include -w -a $fortran`;
16 die "F2C failed\n" if $?;
20 print $tmp "#ifndef INTEGER_STAR_8\n";
21 print $tmp "#define INTEGER_STAR_8\n";
22 print $tmp "#endif\n";
23 print $tmp "#include <stdlib.h>\n";
24 print $tmp "#include <smpif.h>\n";
27 if(/\/\* Common Block Declarations \*\//) {
32 $_ = "}* __attribute__((weak)) $1 = NULL;\n";
33 } elsif(/^#define\s*(\S*)\s*\(?([^.]*)(\..*?)?\)?$/) {
34 $_ = "#define $1 $2\[smpi_current_rank\]";
39 $_ .= "\nvoid __attribute__((weak,constructor)) __preinit_$1(void) {\n if(!$2) $2 = malloc(smpi_global_size() * sizeof(*$2));\n}\n";
40 $_ .= "\nvoid __attribute__((weak,destructor)) __postfini_$1(void) {\n free($2);\n $2 = NULL;\n}\n";
43 if(/\/\* Table of constant values \*\// || /MAIN__/) {
46 if(/extern \/\* Subroutine \*\//) {
55 if(/\/* Main program alias \*\/\s*int\s+.*\s*\(\s*\)\s*{(.*)}/) {
56 $_ = "int smpi_simulated_main(int argc, char** argv) { smpi_process_init(&argc, &argv); $1 }\n";
61 copy($tmp->filename,$output) or die "Copy failed: $!\n";