From afa5e4f04e0a44b38ff45f846264d43da33fc40f Mon Sep 17 00:00:00 2001 From: pini Date: Fri, 26 Nov 2010 19:55:02 +0000 Subject: [PATCH] smpif2c: Compile common structs and building function as weak symbol (so that they can be defined in multiple object files). smpiff: Fix linking of object files. Also remove generated C file upon compilation success. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8684 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/smpi/smpif2c.in | 9 ++++++--- src/smpi/smpiff.in | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/smpi/smpif2c.in b/src/smpi/smpif2c.in index 02330f352c..296ca198b0 100755 --- a/src/smpi/smpif2c.in +++ b/src/smpi/smpif2c.in @@ -16,6 +16,9 @@ foreach my $fortran (@ARGV) { die "F2C failed\n" if $?; open F2C,"<$output"; my $started = 0; + print $tmp "#ifndef INTEGER_STAR_8\n"; + print $tmp "#define INTEGER_STAR_8\n"; + print $tmp "#endif\n"; print $tmp "#include \n"; print $tmp "#include \n"; while() { @@ -25,15 +28,15 @@ foreach my $fortran (@ARGV) { } if($started) { if(/^} (.*?);/) { - $_ = "}* $1 = NULL;\n"; + $_ = "}* __attribute__((weak)) $1 = NULL;\n"; } elsif(/^#define\s*(\S*)\s*\(?([^.]*)(\..*?)?\)?$/) { $_ = "#define $1 $2\[smpi_global_rank()\]"; if(defined $3) { $_ .= $3; } $_ .= "\n"; - $_ .= "\nvoid __attribute__((constructor)) __preinit_$1(void) {\n if(!$2) $2 = malloc(smpi_global_size() * sizeof(*$2));\n}\n"; - $_ .= "\nvoid __attribute__((destructor)) __postfini_$1(void) {\n free($2);\n $2 = NULL;\n}\n"; + $_ .= "\nvoid __attribute__((weak,constructor)) __preinit_$1(void) {\n if(!$2) $2 = malloc(smpi_global_size() * sizeof(*$2));\n}\n"; + $_ .= "\nvoid __attribute__((weak,destructor)) __postfini_$1(void) {\n free($2);\n $2 = NULL;\n}\n"; } } if(/\/\* Table of constant values \*\// || /MAIN__/) { diff --git a/src/smpi/smpiff.in b/src/smpi/smpiff.in index 3d9000327a..315349dbf7 100644 --- a/src/smpi/smpiff.in +++ b/src/smpi/smpiff.in @@ -21,8 +21,15 @@ while [ -n "$1" ]; do esac done -for SRCFILE in "${SRCFILES}" -do - CFILE="${SRCFILE%.f}.c" - $prefix/bin/smpif2c ${SRCFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} -done +if [ -n "${SRCFILES}" ] +then + for SRCFILE in "${SRCFILES}" + do + CFILE="${SRCFILE%.f}.c" + #echo "$prefix/bin/smpif2c ${SRCFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE}" + $prefix/bin/smpif2c ${SRCFILE} && $prefix/bin/smpicc ${ARGS} ${CFILE} && rm ${CFILE} + done +else + #echo "$prefix/bin/smpicc ${ARGS}" + $prefix/bin/smpicc ${ARGS} +fi -- 2.20.1