AMPI: Add fsglobals (filesystem) and pipglobals (Process-in-Process) privatization...
[charm.git] / src / libs / ck-libs / ampi / ampiCC
1 #!/bin/sh
2 CHARMBIN=`dirname $0`
3 CHARMLIB="$CHARMBIN/../lib"
4 CHARMINC="$CHARMBIN/../include"
5 . "$CHARMINC/conv-mach-opt.sh"
6
7 [ -z "$AMPICC_MODE" ] && AMPICC_MODE='ampi'
8 STANDALONE=''
9 ROMIO_CONFIGURE=''
10 MPITEST=''
11 FSGLOBALS=''
12 PIPGLOBALS=''
13 EXPLICIT_COMPILATION=''
14 BUILD_SHARE=''
15
16 ARGS=''
17 OBJECT=''
18
19 processArgs() {
20 while [ ! $# -eq 0 ]
21 do
22   arg="$1"
23   case "$arg" in
24   -show)
25      echo "charmc"
26      exit 0
27      ;;
28   -standalone)
29      STANDALONE='true'
30      ;;
31
32   # These arguments manage compilation of ROMIO's configure tests.
33   # Simple environment tests will be compiled as standalone binaries,
34   # while MPI tests will be compiled with AMPI.
35   -ampi-romio-configure) # Strictly for internal use.
36      ROMIO_CONFIGURE='true'
37      ;;
38   mpitest*) # mpitest.c, mpitest1.c, mpitest.f, etc
39      ARGS="$ARGS \"$arg\""
40      MPITEST='true'
41      ;;
42
43   -fsglobals)
44      FSGLOBALS='true'
45      ;;
46   -pipglobals)
47      PIPGLOBALS='true'
48      ;;
49
50   -c)
51      EXPLICIT_COMPILATION='true'
52      ARGS="$ARGS \"$arg\""
53      ;;
54   -shared|-G)
55      BUILD_SHARE='true'
56      ARGS="$ARGS \"$arg\""
57      ;;
58   -o)
59      shift
60      OBJECT="$1"
61      ;;
62   *)
63      ARGS="$ARGS \"$arg\""
64      ;;
65   esac
66   shift
67 done
68 }
69
70 eval processArgs "$@"
71
72 if [ -n "$FSGLOBALS" ]
73 then
74   if [ "$CMK_SUPPORTS_FSGLOBALS" != '1' ]
75   then
76     echo "Error: Prerequisites for -fsglobals support were not detected."
77     exit 1
78   fi
79 fi
80
81 if [ -n "$PIPGLOBALS" ]
82 then
83   if [ "$CMK_SUPPORTS_PIPGLOBALS" != '1' ]
84   then
85     echo "Error: Prerequisites for -pipglobals support were not detected."
86     exit 1
87   fi
88 fi
89
90 AMPICC_POST_OPTS=''
91
92 [ -n "$ROMIO_CONFIGURE" -a -z "$MPITEST" ] && STANDALONE='true'
93
94 [ -n "$STANDALONE" ] && ARGS="$ARGS -standalone"
95
96 [ -f $CHARMBIN/../lib/libampiromio.a -a -z "$STANDALONE" -a -z "$ROMIO_CONFIGURE" ] && ROMIO='-lampiromio'
97
98 FUNCPTR_SHIM_SUFFIX='.user'
99
100 if [ -n "$FSGLOBALS" -o -n "$PIPGLOBALS" ]
101 then
102   if [ -z "$EXPLICIT_COMPILATION" -a -z "$BUILD_SHARE" -a -z "$STANDALONE" ] # if linking an AMPI executable
103   then
104     # link the user program against the shim
105     [ -z "$OBJECT" ] && USEROBJECT="a.out$FUNCPTR_SHIM_SUFFIX" || USEROBJECT="$OBJECT$FUNCPTR_SHIM_SUFFIX"
106     SHIM_OBJS="\"$CHARMLIB/ampi_funcptr_shim.o\""
107     [ "$AMPICC_MODE" = 'ampif' ] && SHIM_OBJS="$SHIM_OBJS \"$CHARMLIB/ampi_funcptr_fortran.o\" \"$CHARMLIB/ampifimpl.o\" \"$CHARMLIB/ampimod.o\""
108     $CHARMBIN/charmc $ARGS $AMPICC_POST_OPTS $SHIM_OBJS -standalone -ampi-funcptr-shim -o "$USEROBJECT"
109
110     # set up linking the loader against the runtime
111     AMPICC_POST_OPTS="$AMPICC_POST_OPTS -clear-input \"$CHARMLIB/ampi_funcptr_loader.o\""
112     if [ -n "$FSGLOBALS" ]
113     then
114       AMPICC_POST_OPTS="$AMPICC_POST_OPTS \"$CHARMLIB/ampi_funcptr_fsglobals.o\""
115     elif [ -n "$PIPGLOBALS" ]
116     then
117       AMPICC_POST_OPTS="$AMPICC_POST_OPTS \"$CHARMLIB/ampi_funcptr_pipglobals.o\""
118
119       # look for PiP-glibc
120       [ -z "$PIP_GLIBC_INSTALL_DIR" ] && PIP_GLIBC_INSTALL_DIR='/opt/pip'
121       pipldquery="$PIP_GLIBC_INSTALL_DIR/lib/ld-*.so"
122       set -- $pipldquery
123       pipld="$1"
124       if [ "$pipld" = "$pipldquery" ]
125       then
126         echo 'Note: PiP-glibc not found. Maximum virtualization count will be limited.'
127         echo '      Please set and export $PIP_GLIBC_INSTALL_DIR appropriately.'
128       else
129         AMPICC_POST_OPTS="$AMPICC_POST_OPTS -Wl,--dynamic-linker=$pipld"
130       fi
131     fi
132   else
133     AMPICC_POST_OPTS="$AMPICC_POST_OPTS -ampi-funcptr-shim"
134   fi
135 fi
136
137 if [ -n "$OBJECT" ]
138 then
139   AMPICC_POST_OPTS="$AMPICC_POST_OPTS -o \"$OBJECT\""
140 fi
141
142 $CHARMBIN/charmc -language $AMPICC_MODE -default-to-aout $ARGS $AMPICC_POST_OPTS $ROMIO
143 status=$?
144
145 # Copy ampirun, but do not overwrite it if it already exists.
146 [ $status -eq 0 ] && cp -n $CHARMBIN/ampirun .
147
148 exit $status