2004-01-12 10:21:20 +03:00
|
|
|
//
|
2005-11-05 22:57:48 +03:00
|
|
|
// Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
// University Research and Technology
|
|
|
|
// Corporation. All rights reserved.
|
|
|
|
// Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
// of Tennessee Research Foundation. All rights
|
|
|
|
// reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
// Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
// University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
// Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
// All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
// $COPYRIGHT$
|
|
|
|
//
|
|
|
|
// Additional copyrights may follow
|
|
|
|
//
|
2004-01-12 10:21:20 +03:00
|
|
|
// $HEADER$
|
|
|
|
//
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-12 10:21:20 +03:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#ifdef HAVE_STRING_H
|
2004-01-12 10:21:20 +03:00
|
|
|
#include <string.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#endif /* HAVE_STRING_H */
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2004-01-12 10:21:20 +03:00
|
|
|
#include <sys/types.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#endif /* HAVE_SYS_TYPES_H */
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2004-08-17 19:12:42 +04:00
|
|
|
#include <sys/wait.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#endif /* HAVE_SYS_WAIT_H */
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
2004-01-12 10:21:20 +03:00
|
|
|
#include <sys/stat.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#endif /* HAVE_SYS_STAT_H */
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-01-12 10:21:20 +03:00
|
|
|
#include <unistd.h>
|
2005-12-20 02:31:42 +03:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
2004-01-12 10:21:20 +03:00
|
|
|
#include <errno.h>
|
|
|
|
|
2005-07-04 05:59:52 +04:00
|
|
|
#include "opal/util/path.h"
|
2005-07-04 04:13:44 +04:00
|
|
|
#include "opal/util/argv.h"
|
|
|
|
#include "opal/util/few.h"
|
2005-07-04 05:59:52 +04:00
|
|
|
#include "opal/util/path.h"
|
2005-07-04 06:38:44 +04:00
|
|
|
#include "opal/util/show_help.h"
|
2004-09-25 23:31:17 +04:00
|
|
|
#include "tools/wrappers/ompi_wrap.h"
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-02-11 01:01:57 +03:00
|
|
|
extern char **environ;
|
|
|
|
|
2004-01-12 10:21:20 +03:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Global variables
|
|
|
|
//
|
|
|
|
|
|
|
|
bool fl_libs(true);
|
|
|
|
bool fl_profile(false);
|
|
|
|
bool fl_cpp(false);
|
|
|
|
bool fl_want_show_error(false);
|
|
|
|
|
|
|
|
bool showme_cmd(false);
|
|
|
|
bool showme_compile(false);
|
|
|
|
bool showme_link(false);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Local variables
|
|
|
|
//
|
|
|
|
|
|
|
|
static string cmd_name("<unknown>");
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_parse_args(int argc, char *argv[], bool & want_flags)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
string str;
|
|
|
|
bool have_arg;
|
|
|
|
cmd_name = argv[0];
|
|
|
|
|
|
|
|
// Note: only add all the compiler/linker flags if there is an
|
|
|
|
// argv[] that doesn not begin with "-" or some form of "-showme" is
|
|
|
|
// specified.
|
|
|
|
|
|
|
|
want_flags = false;
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
str = argv[i];
|
|
|
|
if ("-showme" == str.substr(0, 7) || "--showme" == str.substr(0, 8)
|
|
|
|
|| "-show" == str || "--show" == str) {
|
|
|
|
want_flags = true;
|
|
|
|
fl_want_show_error = true;
|
|
|
|
if ("-showme:" == str.substr(0, 8)) {
|
|
|
|
str = str.substr(8);
|
|
|
|
have_arg = true;
|
2004-10-29 14:39:35 +04:00
|
|
|
} else if ("--showme:" == str.substr(0, 9)) {
|
2004-09-25 23:31:17 +04:00
|
|
|
str = str.substr(9);
|
|
|
|
have_arg = true;
|
|
|
|
} else {
|
|
|
|
showme_cmd = true;
|
|
|
|
have_arg = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (have_arg) {
|
|
|
|
if ("compile" == str) {
|
|
|
|
showme_compile = true;
|
|
|
|
} else if ("link" == str) {
|
|
|
|
showme_link = true;
|
|
|
|
} else {
|
|
|
|
showme_cmd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ("-c" == str) {
|
|
|
|
fl_libs = false;
|
|
|
|
} else if ("-E" == str || "-M" == str) {
|
|
|
|
fl_libs = false;
|
|
|
|
fl_cpp = true;
|
|
|
|
} else if ("-S" == str) {
|
|
|
|
fl_libs = false;
|
|
|
|
} else if ("-lpmpi" == str) {
|
|
|
|
fl_profile = true;
|
|
|
|
} else if ('-' != str[0]) {
|
|
|
|
want_flags = true;
|
|
|
|
fl_want_show_error = true;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
2004-09-25 23:31:17 +04:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
#if !OMPI_ENABLE_MPI_PROFILING
|
2004-09-25 23:31:17 +04:00
|
|
|
// Sanity check
|
|
|
|
if (fl_profile) {
|
2005-07-04 06:38:44 +04:00
|
|
|
opal_show_help("help-wrapper.txt", "no-profiling-support", true,
|
2004-09-25 23:31:17 +04:00
|
|
|
argv[0], NULL);
|
|
|
|
fl_profile = false;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_get_compiler(const ompi_sv_t & env_list,
|
|
|
|
const string & default_comp, ompi_sv_t & out)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
char *env;
|
|
|
|
string comp;
|
|
|
|
string temp1, temp2;
|
|
|
|
string::size_type i, pos;
|
|
|
|
string compiler0;
|
|
|
|
|
|
|
|
out.clear();
|
|
|
|
|
|
|
|
// Check for environment variable overrides
|
|
|
|
|
|
|
|
for (i = 0; i < env_list.size(); ++i) {
|
|
|
|
env = getenv(env_list[i].c_str());
|
|
|
|
if (NULL != env) {
|
|
|
|
comp = env;
|
|
|
|
ompi_wrap_split(comp, ' ', out);
|
|
|
|
break;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// If we didn't find any of the environment variables, use the default
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (out.empty()) {
|
|
|
|
ompi_wrap_split(default_comp, ' ', out);
|
|
|
|
}
|
|
|
|
// If we're preprocessing, we need to know the basename of argv0
|
|
|
|
// (see below).
|
|
|
|
|
|
|
|
if (fl_cpp) {
|
|
|
|
pos = out[0].find_last_of('/');
|
|
|
|
if (pos != string::npos) {
|
|
|
|
// JMS There has to be a better way to do this
|
|
|
|
compiler0 = out[0].substr(pos + 1);
|
|
|
|
} else {
|
|
|
|
compiler0 = out[0];
|
|
|
|
}
|
2004-08-17 06:34:17 +04:00
|
|
|
}
|
2004-09-25 23:31:17 +04:00
|
|
|
// Ugh. If we're acting as the preprocessor, ditch any libtool
|
|
|
|
// arguments.
|
|
|
|
|
|
|
|
if (fl_cpp) {
|
|
|
|
// If we find "libtool", then advance until we find an argument
|
|
|
|
// that does not begin with "--"; the arguments after that will be
|
|
|
|
// the compiler (preprocessor) stuff
|
|
|
|
|
|
|
|
if ("libtool" == compiler0) {
|
|
|
|
i = 1;
|
|
|
|
while (i < out.size() && "--" == out[i].substr(0, 2)) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
out.erase(out.begin(), out.begin() + i);
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_build_xppflags(const ompi_sv_t & env_list,
|
|
|
|
bool want_f77_includes, ompi_sv_t & xppflags)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
string incdir(OMPI_INCDIR);
|
|
|
|
char *env;
|
|
|
|
string temp;
|
|
|
|
|
|
|
|
xppflags.clear();
|
|
|
|
|
|
|
|
// Check for environment variable overrides. If we find some, use
|
|
|
|
// them, regardless of the f77_include setting.
|
|
|
|
|
|
|
|
for (string::size_type i = 0; i < env_list.size(); ++i) {
|
|
|
|
env = getenv(env_list[i].c_str());
|
|
|
|
if (NULL != env) {
|
|
|
|
temp = env;
|
|
|
|
ompi_wrap_split(temp, ' ', xppflags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Ensure that we don't -I/usr/include, for the reasons listed
|
|
|
|
// above. EXCEPTION: If this is fortran, then we add -I regardless
|
|
|
|
// of what the prefix is, because the fortran compiler will not
|
|
|
|
// -I/usr/include automatically.
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (want_f77_includes || "/usr/include" != incdir) {
|
|
|
|
xppflags.push_back("-I" + incdir);
|
|
|
|
}
|
2004-07-14 18:11:03 +04:00
|
|
|
|
2005-07-08 22:26:01 +04:00
|
|
|
#if OMPI_WANT_DEVEL_HEADERS
|
|
|
|
xppflags.push_back("-I" + incdir + "/openmpi");
|
|
|
|
xppflags.push_back("-I" + incdir + "/openmpi/opal");
|
|
|
|
xppflags.push_back("-I" + incdir + "/openmpi/orte");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if OMPI_WANT_CXX_BINDINGS || OMPI_WANT_DEVEL_HEADERS
|
2005-07-02 19:06:47 +04:00
|
|
|
xppflags.push_back("-I" + incdir + "/openmpi/ompi");
|
2004-07-14 18:11:03 +04:00
|
|
|
#endif
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_build_xflags(const ompi_sv_t & env_list,
|
|
|
|
const string & default_xflags, ompi_sv_t & xflags)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
char *env;
|
|
|
|
string temp;
|
|
|
|
|
|
|
|
// Check for environment variable overrides. If we find some, use
|
|
|
|
// them, regardless of the f77_include setting.
|
|
|
|
|
|
|
|
for (string::size_type i = 0; i < env_list.size(); ++i) {
|
|
|
|
env = getenv(env_list[i].c_str());
|
|
|
|
if (NULL != env) {
|
|
|
|
temp = env;
|
|
|
|
ompi_wrap_split(temp, ' ', xflags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!default_xflags.empty()) {
|
|
|
|
ompi_wrap_split_append_sv(default_xflags, xflags);
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_build_user_args(int argc, char *argv[], ompi_sv_t & user_args)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
string str;
|
|
|
|
|
|
|
|
// Don't copy -showme* or -lpmpi. -lpmpi will be
|
|
|
|
// insertted elsewhere if necessary.
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
str = argv[i];
|
|
|
|
if ("-showme" != str.substr(0, 7) &&
|
|
|
|
"--showme" != str.substr(0, 8) &&
|
|
|
|
"-show" != str && "--show" != str && "-lpmpi" != str) {
|
|
|
|
user_args.push_back(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ompi_wrap_build_ldflags(const ompi_sv_t & env_list, ompi_sv_t & ldflags)
|
|
|
|
{
|
|
|
|
char *env;
|
|
|
|
string s;
|
|
|
|
string temp;
|
|
|
|
string libdir(OMPI_LIBDIR);
|
|
|
|
ompi_sv_t sv;
|
|
|
|
ompi_sv_t::iterator svi;
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
ldflags.clear();
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// If we don't want the libs, then we don't want ldflags, either.
|
|
|
|
// Hence, return with ldflags empty.
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (!fl_libs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check for environment variable overrides
|
|
|
|
|
|
|
|
for (string::size_type i = 0; i < env_list.size(); ++i) {
|
|
|
|
env = getenv(env_list[i].c_str());
|
|
|
|
if (NULL != env) {
|
|
|
|
temp = env;
|
|
|
|
ompi_wrap_split(temp, ' ', ldflags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Add in the extra flags passed by configure. Do the same kinds of
|
|
|
|
// checks that we do below -- ensure that we don't add a "-L/usr" to
|
|
|
|
// the command line.
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
s = WRAPPER_EXTRA_LDFLAGS;
|
|
|
|
ompi_wrap_split(s, ' ', sv);
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (!sv.empty()) {
|
|
|
|
for (svi = sv.begin(); svi != sv.end(); ++svi) {
|
|
|
|
if ("-L/usr" != *svi) {
|
|
|
|
ompi_wrap_split_append_sv(*svi, ldflags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Form library directory pathname.
|
|
|
|
//
|
|
|
|
// Add "-L$prefix/lib".
|
|
|
|
//
|
|
|
|
// Apply similar logic here as we did with -I -- if the libdir is
|
|
|
|
// /usr/lib, there's no need to explicitly add it, because the
|
|
|
|
// compiler will already be looking there.
|
|
|
|
|
|
|
|
if ("/usr/lib" != libdir) {
|
|
|
|
ldflags.push_back("-L" + libdir);
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
void
|
|
|
|
ompi_wrap_build_libs(const ompi_sv_t & env_list,
|
2005-04-13 15:54:36 +04:00
|
|
|
bool want_cxx_libs, bool want_f90_libs, ompi_sv_t & libs)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
char *env;
|
|
|
|
string temp;
|
|
|
|
string libdir(OMPI_LIBDIR);
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
libs.clear();
|
2004-07-14 18:11:03 +04:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// If we don't want the libs, then return with libs empty
|
2004-03-18 01:37:52 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (!fl_libs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check for environment variable overrides
|
|
|
|
|
|
|
|
for (string::size_type i = 0; i < env_list.size(); ++i) {
|
|
|
|
env = getenv(env_list[i].c_str());
|
|
|
|
if (NULL != env) {
|
|
|
|
temp = env;
|
|
|
|
ompi_wrap_split(temp, ' ', libs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-03-18 01:37:52 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Now we start adding libraries to libs
|
2004-03-18 01:37:52 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
#if OMPI_WANT_CXX_BINDINGS
|
|
|
|
// The C++ bindings come next
|
|
|
|
if (want_cxx_libs) {
|
2005-04-13 02:24:21 +04:00
|
|
|
if (
|
|
|
|
#ifdef WIN32
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_cxx.dll") &&
|
|
|
|
#endif
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_cxx.a") &&
|
2004-09-25 23:31:17 +04:00
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_cxx.so") &&
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_cxx.dylib")) {
|
|
|
|
cerr << "WARNING: " << cmd_name
|
|
|
|
<< " expected to find libmpi_cxx.* in " << libdir << endl
|
|
|
|
<< "WARNING: MPI C++ support will be disabled" << endl;
|
|
|
|
} else {
|
|
|
|
libs.push_back("-lmpi_cxx");
|
|
|
|
}
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
#endif
|
2005-04-13 15:54:36 +04:00
|
|
|
#if OMPI_WANT_F90_BINDINGS
|
|
|
|
// The F90 bindings come next
|
|
|
|
if (want_f90_libs) {
|
|
|
|
if (
|
|
|
|
#ifdef WIN32
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_f90.dll") &&
|
|
|
|
#endif
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_f90.a") &&
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_f90.so") &&
|
|
|
|
!ompi_wrap_check_file(libdir, "libmpi_f90.dylib")) {
|
|
|
|
cerr << "WARNING: " << cmd_name
|
|
|
|
<< " expected to find libmpi_f90.* in " << libdir << endl
|
|
|
|
<< "WARNING: MPI F90 support will be disabled" << endl;
|
|
|
|
} else {
|
|
|
|
libs.push_back("-lmpi_f90");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Next comes the MPI library
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
libs.push_back("-lmpi");
|
2005-07-03 08:06:59 +04:00
|
|
|
libs.push_back("-lorte");
|
|
|
|
libs.push_back("-lopal");
|
2004-09-25 23:31:17 +04:00
|
|
|
|
|
|
|
ompi_wrap_split_append_sv(WRAPPER_EXTRA_LIBS, libs);
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_print_sv(const ompi_sv_t & sv)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
for (string::size_type i = 0; i < sv.size(); ++i) {
|
|
|
|
cout << sv[i] << " ";
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_exec_sv(const ompi_sv_t & sv)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
int status;
|
|
|
|
int ret;
|
|
|
|
int ac = 0;
|
|
|
|
char **av = 0;
|
|
|
|
char *tmp = NULL;
|
|
|
|
string::size_type i;
|
|
|
|
|
|
|
|
// Build up a C array of the args
|
|
|
|
|
|
|
|
for (i = 0; i < sv.size(); ++i) {
|
2005-07-04 04:13:44 +04:00
|
|
|
opal_argv_append(&ac, &av, (char *) sv[i].c_str());
|
2004-09-25 23:31:17 +04:00
|
|
|
}
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
// There is no way to tell whether opal_few returned non-zero because
|
2004-09-25 23:31:17 +04:00
|
|
|
// the called app returned non-zero or if there was a failure in the
|
|
|
|
// exec (like the file not being found). So we look for the
|
|
|
|
// compiler first, just to try to eliminate that case.
|
2005-07-04 05:59:52 +04:00
|
|
|
tmp = opal_path_findv(av[0], 0, environ, NULL);
|
2004-09-25 23:31:17 +04:00
|
|
|
if (NULL == tmp) {
|
2005-07-04 06:38:44 +04:00
|
|
|
opal_show_help("help-wrapper.txt", "no-compiler-found", true,
|
2004-09-25 23:31:17 +04:00
|
|
|
av[0], NULL);
|
|
|
|
errno = 0;
|
|
|
|
status = -1;
|
|
|
|
} else {
|
|
|
|
free(tmp);
|
2005-07-04 04:13:44 +04:00
|
|
|
ret = opal_few(av, &status);
|
2004-09-25 23:31:17 +04:00
|
|
|
status = WIFEXITED(status) ? WEXITSTATUS(status) :
|
|
|
|
(WIFSIGNALED(status) ? WTERMSIG(status) :
|
|
|
|
(WIFSTOPPED(status) ? WSTOPSIG(status) : 255));
|
|
|
|
|
|
|
|
if (0 != ret && 0 != errno && fl_want_show_error) {
|
|
|
|
perror(cmd_name.c_str());
|
|
|
|
}
|
2004-08-17 06:34:17 +04:00
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Free the C array
|
2005-07-04 04:13:44 +04:00
|
|
|
opal_argv_free(av);
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
return status;
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
void
|
|
|
|
ompi_wrap_strip_white(string & str)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
int start, end, size(str.size());
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
/* Remove leading whitespace */
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
for (start = 0; start < size; ++start) {
|
|
|
|
if (!isspace(str[start])) {
|
|
|
|
break;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
/* Remove trailing whitespace */
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
for (end = start; end < size; ++end) {
|
|
|
|
if (isspace(str[end])) {
|
|
|
|
break;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
str = str.substr(start, end);
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
bool
|
|
|
|
ompi_wrap_split(const string & str, char c, ompi_sv_t & out)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
int start, i(0), size(str.size());
|
|
|
|
out.clear();
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
// Strip off the first bunch of c's
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
while (i < size && str[i] == c) {
|
|
|
|
++i;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
if (i >= size) {
|
|
|
|
return false;
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
2004-09-25 23:31:17 +04:00
|
|
|
// Now start making a vector of the strings
|
|
|
|
|
|
|
|
while (i < size) {
|
|
|
|
start = i;
|
|
|
|
while (i < size && str[i] != c) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
out.push_back(str.substr(start, i - start));
|
|
|
|
while (i < size && str[i] == c) {
|
|
|
|
++i;
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
return true;
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_split_append_sv(const string & str, ompi_sv_t & out)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_sv_t temp;
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_split(str, ' ', temp);
|
|
|
|
for (string::size_type i = 0; i < temp.size(); ++i) {
|
|
|
|
out.push_back(temp[i]);
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
void
|
|
|
|
ompi_wrap_append_sv(const ompi_sv_t & in, ompi_sv_t & out)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
// JMS Is there a better way to do this?
|
|
|
|
for (string::size_type i = 0; i < in.size(); ++i) {
|
|
|
|
out.push_back(in[i]);
|
|
|
|
}
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2004-09-25 23:31:17 +04:00
|
|
|
ompi_wrap_check_file(const string & dir, const string & file)
|
2004-01-12 10:21:20 +03:00
|
|
|
{
|
2004-09-25 23:31:17 +04:00
|
|
|
int ret;
|
|
|
|
struct stat buf;
|
|
|
|
string name = dir + "/" + file;
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
ret = stat(name.c_str(), &buf);
|
2004-01-12 10:21:20 +03:00
|
|
|
|
2004-09-25 23:31:17 +04:00
|
|
|
return (bool) (0 == ret);
|
2004-01-12 10:21:20 +03:00
|
|
|
}
|