'Set up the compile and runtime environments for a package.'

def setup_environment(self, spack_env, run_env):

    run_env.prepend_path('PATH', self.prefix.bin)
    dyninst_libdir = find_libraries('libdyninstAPI_RT', root=self.spec['dyninst'].prefix, shared=True, recurse=True)
    run_env.set('DYNINSTAPI_RT_LIB', dyninst_libdir)
    oss_libdir = find_libraries('libopenss-framework', root=self.spec['openspeedshop'].prefix, shared=True, recurse=True)
    run_env.prepend_path('LD_LIBRARY_PATH', os.path.dirname(oss_libdir.joined()))
    if ('+cbtf' in self.spec):
        cbtf_mc = '/sbin/cbtf_mrnet_commnode'
        cbtf_lmb = '/sbin/cbtf_libcbtf_mrnet_backend'
        run_env.set('XPLAT_RSH', 'ssh')
        run_env.set('MRNET_COMM_PATH', join_path((self.spec['cbtf-krell'].prefix + cbtf_mc)))
        run_env.set('CBTF_MRNET_BACKEND_PATH', join_path((self.spec['cbtf-krell'].prefix + cbtf_lmb)))
        run_env.prepend_path('PATH', self.spec['mrnet'].prefix.bin)
        run_env.prepend_path('PATH', self.spec['cbtf-krell'].prefix.bin)
        run_env.prepend_path('PATH', self.spec['cbtf-krell'].prefix.sbin)
    elif ('+offline' in self.spec):
        run_env.set('OPENSS_RAWDATA_DIR', '.')
        run_env.set('OPENSS_PLUGIN_PATH', join_path((oss_libdir + '/openspeedshop')))
        run_env.prepend_path('PATH', self.spec['papi'].prefix.bin)
        run_env.prepend_path('PATH', self.spec['libdwarf'].prefix.bin)
        if ('+mpich' in self.spec):
            run_env.set('OPENSS_MPI_IMPLEMENTATION', 'mpich')
        if ('+mpich2' in self.spec):
            run_env.set('OPENSS_MPI_IMPLEMENTATION', 'mpich2')
        if ('+mvapich2' in self.spec):
            run_env.set('OPENSS_MPI_IMPLEMENTATION', 'mvapich2')
        if ('+openmpi' in self.spec):
            run_env.set('OPENSS_MPI_IMPLEMENTATION', 'openmpi')
