2014-05-17 23:15:15 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* OSXCross Compiler Wrapper *
|
2015-02-08 10:27:26 +01:00
|
|
|
* Copyright (C) 2014, 2015 by Thomas Poechtrager *
|
2014-05-17 23:15:15 +02:00
|
|
|
* t.poechtrager@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
|
|
|
* Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debug messages can be enabled by setting 'OCDEBUG' (ENV) to >= 1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <climits>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "tools.h"
|
|
|
|
#include "target.h"
|
|
|
|
#include "progs.h"
|
|
|
|
|
|
|
|
using namespace tools;
|
|
|
|
using namespace target;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-05-03 21:59:40 +02:00
|
|
|
int unittest = 0;
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
void warnExtension(const char *extension) {
|
|
|
|
static bool noextwarnings = !!getenv("OSXCROSS_NO_EXTENSION_WARNINGS");
|
|
|
|
if (noextwarnings)
|
|
|
|
return;
|
|
|
|
warn << extension << " is an osxcross extension" << warn.endl();
|
|
|
|
warninfo << "you can silence this warning via "
|
|
|
|
<< "'OSXCROSS_NO_EXTENSION_WARNINGS=1' (env)" << warninfo.endl();
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((unused))
|
|
|
|
void warnDeprecated(const char *flag, const char *replacement = nullptr) {
|
|
|
|
if (replacement)
|
|
|
|
warn << flag << " is deprecated; "
|
|
|
|
<< "please use " << replacement << " instead"
|
|
|
|
<< warn.endl();
|
|
|
|
else
|
|
|
|
warn << flag << " is deprecated and will be "
|
|
|
|
<< "removed soon" << warn.endl();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Command Line Options
|
|
|
|
//
|
|
|
|
|
|
|
|
namespace commandopts {
|
|
|
|
|
|
|
|
typedef bool (*optFun)(Target &target, const char *opt, const char *val,
|
|
|
|
char **);
|
|
|
|
|
|
|
|
bool versionmin(Target &target, const char *, const char *val, char **) {
|
|
|
|
target.OSNum = parseOSVersion(val);
|
|
|
|
|
|
|
|
if (target.OSNum != val)
|
|
|
|
warn << "'-mmacosx-version-min=' (" << target.OSNum.Str()
|
|
|
|
<< " != " << val << ")" << warn.endl();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool arch(Target &target, const char *opt, const char *val, char **) {
|
|
|
|
Arch arch;
|
|
|
|
|
|
|
|
if (!strcmp(opt, "-arch")) {
|
|
|
|
arch = parseArch(val);
|
|
|
|
|
|
|
|
if (arch == Arch::unknown)
|
|
|
|
warn << "'-arch': unknown architecture '" << val << "'"
|
|
|
|
<< warn.endl();
|
|
|
|
|
|
|
|
const char *name = getArchName(arch);
|
|
|
|
|
|
|
|
if (strcmp(val, name))
|
|
|
|
warn << "'-arch': '" << val << "' != '" << name << "'" << warn.endl();
|
|
|
|
} else {
|
|
|
|
if (!strcmp(opt, "-m16") || !strcmp(opt, "-mx32")) {
|
|
|
|
err << "'" << opt << "' is not supported" << err.endl();
|
|
|
|
return false;
|
|
|
|
} else if (!strcmp(opt, "-m32")) {
|
|
|
|
arch = Arch::i386;
|
|
|
|
} else if (!strcmp(opt, "-m64")) {
|
|
|
|
arch = Arch::x86_64;
|
|
|
|
} else {
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target.isClang())
|
|
|
|
target.addArch(arch);
|
|
|
|
else
|
|
|
|
target.arch = arch;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool stdlib(Target &target, const char *, const char *val, char **) {
|
|
|
|
if (target.isGCC())
|
|
|
|
warnExtension("'-stdlib='");
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
for (auto stdlibname : StdLibNames) {
|
|
|
|
if (!strcmp(val, stdlibname)) {
|
|
|
|
target.stdlib = static_cast<StdLib>(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == (sizeof(StdLibNames) / sizeof(StdLibNames[0]))) {
|
|
|
|
err << "value of '-stdlib=' must be ";
|
|
|
|
|
|
|
|
for (size_t j = 0; j < i; ++j) {
|
|
|
|
err << "'" << StdLibNames[j] << "'";
|
|
|
|
|
|
|
|
if (j == i - 2)
|
|
|
|
err << " or ";
|
|
|
|
else if (j < i - 2)
|
|
|
|
err << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
err << err.endl();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-23 22:45:53 +02:00
|
|
|
bool language(Target &target, const char *, const char *val, char **) {
|
|
|
|
target.language = val;
|
2015-08-22 23:15:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool usegcclibstdcxx(Target &target, const char *, const char *, char **) {
|
|
|
|
target.stdlib = StdLib::libstdcxx;
|
|
|
|
target.usegcclibs = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runprog(Target &target, const char *, const char *progname, char **cargs) {
|
|
|
|
auto *prog = program::getprog(progname);
|
|
|
|
|
|
|
|
if (!prog)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
std::vector<char *> args;
|
|
|
|
args.push_back(const_cast<char *>(progname));
|
|
|
|
|
|
|
|
while (*cargs)
|
|
|
|
args.push_back(*cargs++);
|
|
|
|
args.push_back(nullptr);
|
|
|
|
|
|
|
|
(*prog)(args.size() - 1, args.data(), target);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkincludepath(Target &, const char *opt, const char *path, char **) {
|
2015-05-02 21:49:23 +02:00
|
|
|
#ifndef __APPLE__
|
|
|
|
constexpr const char *DangerousIncludePaths[] = { "/usr/include",
|
|
|
|
"/usr/local/include" };
|
2015-05-30 21:04:51 +02:00
|
|
|
|
2015-05-02 21:49:23 +02:00
|
|
|
static bool noinccheck = !!getenv("OSXCROSS_NO_INCLUDE_PATH_WARNINGS");
|
|
|
|
|
|
|
|
if (noinccheck)
|
2015-08-22 23:15:27 +02:00
|
|
|
return true;
|
2015-05-02 21:49:23 +02:00
|
|
|
|
2015-05-03 21:59:40 +02:00
|
|
|
#ifndef _WIN32
|
2015-05-02 21:49:23 +02:00
|
|
|
char buf[PATH_MAX + 1];
|
|
|
|
const char *rpath = realpath(path, buf);
|
|
|
|
|
|
|
|
if (!rpath)
|
|
|
|
rpath = path;
|
2015-05-03 21:59:40 +02:00
|
|
|
#else
|
|
|
|
const char *rpath = path;
|
|
|
|
#endif
|
2015-05-02 21:49:23 +02:00
|
|
|
|
|
|
|
for (const char *dpath : DangerousIncludePaths) {
|
|
|
|
if (!strncmp(rpath, dpath, strlen(dpath))) {
|
2015-05-03 21:59:40 +02:00
|
|
|
warn << "possibly dangerous include path specified: '" << opt << " "
|
2015-05-02 21:49:23 +02:00
|
|
|
<< path << "'";
|
|
|
|
|
|
|
|
if (strcmp(path, rpath))
|
|
|
|
warn << " (" << rpath << ")";
|
|
|
|
|
|
|
|
warn << warn.endl();
|
|
|
|
|
|
|
|
warninfo << "you can silence this warning via "
|
|
|
|
<< "'OSXCROSS_NO_INCLUDE_PATH_WARNINGS=1' (env)"
|
|
|
|
<< warninfo.endl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)opt;
|
|
|
|
(void)path;
|
|
|
|
#endif
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
return true;
|
2015-05-02 21:49:23 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
constexpr struct Opt {
|
|
|
|
const char *name;
|
|
|
|
const size_t namelen;
|
|
|
|
const optFun fun;
|
|
|
|
const bool valrequired;
|
|
|
|
const bool pusharg;
|
|
|
|
const char *valseparator;
|
|
|
|
const size_t valseparatorlen;
|
|
|
|
constexpr Opt(const char *name, optFun fun, const bool valrequired = false,
|
|
|
|
const bool pusharg = false, const char *valseparator = nullptr)
|
|
|
|
: name(name), namelen(slen(name)), fun(fun),
|
|
|
|
valrequired(valrequired), pusharg(pusharg),
|
|
|
|
valseparator(valseparator),
|
|
|
|
valseparatorlen(valseparator ? slen(valseparator) : 0) {}
|
|
|
|
} opts[] = {
|
|
|
|
{"-mmacosx-version-min", versionmin, true, false, "="},
|
|
|
|
{"-stdlib", stdlib, true, false, "="},
|
|
|
|
{"-arch", arch, true},
|
|
|
|
{"-m16", arch},
|
|
|
|
{"-m32", arch},
|
|
|
|
{"-mx32", arch},
|
|
|
|
{"-m64", arch},
|
2015-08-23 22:45:53 +02:00
|
|
|
{"-x", language, true, true},
|
2015-08-22 23:15:27 +02:00
|
|
|
{"-foc-use-gcc-libstdc++", usegcclibstdcxx},
|
|
|
|
{"-foc-run-prog", runprog, true, false, "="}, // for internal use only
|
|
|
|
{"-isystem", checkincludepath, true, true},
|
|
|
|
{"-icxx-isystem", checkincludepath, true, true},
|
|
|
|
{"-cxx-isystem", checkincludepath, true, true},
|
|
|
|
{"-I", checkincludepath, true, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
bool parse(int argc, char **argv, Target &target) {
|
|
|
|
target.args.reserve(argc);
|
|
|
|
|
|
|
|
if (char *p = getenv("MACOSX_DEPLOYMENT_TARGET")) {
|
|
|
|
target.OSNum = parseOSVersion(p);
|
|
|
|
unsetenv("MACOSX_DEPLOYMENT_TARGET");
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
|
|
char *arg = argv[i];
|
2015-05-02 21:49:23 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (*arg != '-') {
|
|
|
|
target.args.push_back(arg);
|
|
|
|
continue;
|
2014-05-17 23:15:15 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
bool pusharg = true;
|
|
|
|
int j = i;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
for (const Opt &opt : opts) {
|
|
|
|
if (strncmp(arg, opt.name, opt.namelen))
|
|
|
|
continue;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
pusharg = opt.pusharg;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
const char *val = nullptr;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (opt.valrequired) {
|
|
|
|
val = arg + opt.namelen;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (opt.valseparator &&
|
|
|
|
strncmp(val, opt.valseparator, opt.valseparatorlen)) {
|
|
|
|
err << "expected '" << opt.name << opt.valseparator << "<val>' "
|
|
|
|
<< "instead of '" << arg << "'" << err.endl();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
val += opt.valseparatorlen;
|
2014-05-17 23:15:15 +02:00
|
|
|
}
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (!opt.valseparator && !*val && i < argc - 1)
|
|
|
|
val = argv[++i];
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (!*val) {
|
|
|
|
err << "missing argument for '" << opt.name << "'" << err.endl();
|
|
|
|
return false;
|
2014-05-17 23:15:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (opt.fun && !opt.fun(target, opt.name, val, &argv[i + 1]))
|
|
|
|
return false;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (pusharg) {
|
|
|
|
for (; j <= i; ++j)
|
|
|
|
target.args.push_back(argv[j]);
|
|
|
|
}
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
} // namespace commandopts
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
void detectCXXLib(Target &target) {
|
|
|
|
if (target.compilername.size() <= 7)
|
|
|
|
return;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
StdLib prevstdlib = target.stdlib;
|
|
|
|
|
|
|
|
if (endsWith(target.compilername, "-stdc++")) {
|
|
|
|
target.stdlib = StdLib::libstdcxx;
|
|
|
|
target.compilername.resize(target.compilername.size() - 7);
|
|
|
|
} else if (endsWith(target.compilername, "-gstdc++")) {
|
|
|
|
target.stdlib = StdLib::libstdcxx;
|
|
|
|
target.usegcclibs = true;
|
|
|
|
target.compilername.resize(target.compilername.size() - 8);
|
|
|
|
} else if (endsWith(target.compilername, "-libc++")) {
|
|
|
|
target.stdlib = StdLib::libcxx;
|
|
|
|
target.compilername.resize(target.compilername.size() - 7);
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (prevstdlib != StdLib::unset && prevstdlib != target.stdlib)
|
|
|
|
warn << "ignoring '-stdlib=" << getStdLibString(prevstdlib) << "'"
|
|
|
|
<< warn.endl();
|
|
|
|
}
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
//
|
|
|
|
// detectTarget():
|
|
|
|
// detect target and setup invocation command
|
|
|
|
//
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
bool detectTarget(int argc, char **argv, Target &target) {
|
|
|
|
const char *cmd = argv[0];
|
|
|
|
const char *p = strrchr(cmd, '/');
|
|
|
|
size_t len;
|
|
|
|
size_t i = 0;
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (p)
|
|
|
|
cmd = &p[1];
|
2014-05-17 23:15:15 +02:00
|
|
|
|
|
|
|
if (auto *prog = program::getprog(cmd))
|
|
|
|
(*prog)(argc, argv, target);
|
|
|
|
|
|
|
|
// -> x86_64 <- -apple-darwin13
|
|
|
|
p = strchr(cmd, '-');
|
|
|
|
len = (p ? p : cmd) - cmd;
|
|
|
|
|
|
|
|
for (auto arch : ArchNames) {
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if (!strncmp(cmd, arch, len)) {
|
|
|
|
target.arch = static_cast<Arch>(i - 1);
|
|
|
|
cmd += len;
|
|
|
|
|
|
|
|
if (*cmd++ != '-')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (strncmp(cmd, "apple-", 6))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
cmd += 6;
|
|
|
|
|
|
|
|
if (strncmp(cmd, "darwin", 6))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!(p = strchr(cmd, '-')))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
target.target = std::string(cmd, p - cmd);
|
2015-05-30 21:04:51 +02:00
|
|
|
target.compilername = &p[1];
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-05-30 21:04:51 +02:00
|
|
|
if (target.compilername == "cc")
|
|
|
|
target.compilername = getDefaultCompiler();
|
|
|
|
else if (target.compilername == "c++")
|
|
|
|
target.compilername = getDefaultCXXCompiler();
|
|
|
|
else if (auto *prog = program::getprog(target.compilername))
|
2014-05-17 23:15:15 +02:00
|
|
|
(*prog)(argc, argv, target);
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (target.target != getDefaultTarget())
|
2015-06-27 19:01:56 +02:00
|
|
|
warn << "this wrapper was built for target "
|
|
|
|
<< "'" << getDefaultTarget() << "'" << warn.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (!commandopts::parse(argc, argv, target))
|
2014-05-17 23:15:15 +02:00
|
|
|
return false;
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
detectCXXLib(target);
|
2014-05-17 23:15:15 +02:00
|
|
|
return target.setup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strncmp(cmd, "o32", 3))
|
|
|
|
target.arch = Arch::i386;
|
2014-05-18 22:07:37 +02:00
|
|
|
else if (!strncmp(cmd, "o64h", 4))
|
|
|
|
target.arch = Arch::x86_64h;
|
2014-05-17 23:15:15 +02:00
|
|
|
else if (!strncmp(cmd, "o64", 3))
|
|
|
|
target.arch = Arch::x86_64;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2014-09-27 10:07:15 +02:00
|
|
|
if (const char *p = strchr(cmd, '-'))
|
2015-05-30 21:04:51 +02:00
|
|
|
target.compilername = &cmd[p - cmd + 1];
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (!commandopts::parse(argc, argv, target))
|
2014-05-17 23:15:15 +02:00
|
|
|
return false;
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
detectCXXLib(target);
|
2014-05-17 23:15:15 +02:00
|
|
|
return target.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // unnamed namespace
|
|
|
|
|
|
|
|
//
|
|
|
|
// Main routine
|
|
|
|
//
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
char bbuf[sizeof(benchmark)];
|
|
|
|
auto b = new (bbuf) benchmark;
|
|
|
|
Target target;
|
|
|
|
char **cargs = nullptr;
|
|
|
|
int debug = 0;
|
|
|
|
int rc = -1;
|
|
|
|
|
2015-05-03 21:59:40 +02:00
|
|
|
if (char *p = getenv("OCDEBUG"))
|
|
|
|
debug = atoi(p);
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if (char *p = getenv("OSXCROSS_UNIT_TEST")) {
|
2015-05-03 21:59:40 +02:00
|
|
|
unittest = atoi(p);
|
|
|
|
|
2015-08-22 23:15:27 +02:00
|
|
|
if ((p = getenv("OSXCROSS_PROG_NAME")))
|
|
|
|
argv[0] = p;
|
|
|
|
}
|
|
|
|
|
2014-05-17 23:15:15 +02:00
|
|
|
if (!detectTarget(argc, argv, target)) {
|
2015-05-02 21:49:23 +02:00
|
|
|
err << "while detecting target" << err.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
b->halt();
|
|
|
|
|
|
|
|
if (debug >= 2) {
|
2015-05-02 21:49:23 +02:00
|
|
|
dbg << "detected target triple: " << target.getTriple() << dbg.endl();
|
2015-05-30 21:04:51 +02:00
|
|
|
dbg << "detected compiler: " << target.compilername << dbg.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
|
2015-05-02 21:49:23 +02:00
|
|
|
dbg << "detected stdlib: " << getStdLibString(target.stdlib)
|
|
|
|
<< dbg.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
|
|
|
|
b->resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 22:28:10 +02:00
|
|
|
#ifdef __DragonFly__
|
|
|
|
// Escape DragonFlyBSD's weird PFS paths.
|
|
|
|
std::string escapedexecpath;
|
|
|
|
escapePath(target.execpath, escapedexecpath);
|
|
|
|
concatEnvVariable("COMPILER_PATH", escapedexecpath);
|
|
|
|
#else
|
2014-05-17 23:15:15 +02:00
|
|
|
concatEnvVariable("COMPILER_PATH", target.execpath);
|
2015-07-19 22:28:10 +02:00
|
|
|
#endif
|
2014-05-17 23:15:15 +02:00
|
|
|
|
|
|
|
auto printCommand = [&]() {
|
|
|
|
std::string in;
|
|
|
|
std::string out;
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
in += argv[i];
|
|
|
|
in += " ";
|
|
|
|
}
|
|
|
|
|
2015-05-30 21:04:51 +02:00
|
|
|
out += target.compilerpath;
|
|
|
|
|
|
|
|
if (target.compilerpath != target.fargs[0]) {
|
|
|
|
out += " (";
|
|
|
|
out += target.fargs[0];
|
|
|
|
out += ") ";
|
|
|
|
} else {
|
|
|
|
out += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 1; i < target.fargs.size(); ++i) {
|
|
|
|
out += target.fargs[i];
|
2014-05-17 23:15:15 +02:00
|
|
|
out += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &arg : target.args) {
|
|
|
|
out += arg;
|
|
|
|
out += " ";
|
|
|
|
}
|
|
|
|
|
2015-05-03 21:59:40 +02:00
|
|
|
if (!unittest)
|
|
|
|
dbg << "--> " << in << dbg.endl();
|
|
|
|
|
2015-05-02 21:49:23 +02:00
|
|
|
dbg << "<-- " << out << dbg.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (rc == -1) {
|
|
|
|
cargs = new char *[target.fargs.size() + target.args.size() + 1];
|
|
|
|
size_t i = 0;
|
|
|
|
|
2014-09-27 10:07:15 +02:00
|
|
|
for (auto &arg : target.fargs)
|
2014-05-17 23:15:15 +02:00
|
|
|
cargs[i++] = const_cast<char *>(arg.c_str());
|
|
|
|
|
2014-09-27 10:07:15 +02:00
|
|
|
for (auto &arg : target.args)
|
2014-05-17 23:15:15 +02:00
|
|
|
cargs[i++] = const_cast<char *>(arg.c_str());
|
|
|
|
|
|
|
|
cargs[i] = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
time_type diff = b->getDiff();
|
|
|
|
|
|
|
|
if (rc == -1)
|
|
|
|
printCommand();
|
|
|
|
|
2015-05-02 21:49:23 +02:00
|
|
|
dbg << "=== time spent in wrapper: " << diff / 1000000.0 << " ms"
|
|
|
|
<< dbg.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 21:59:40 +02:00
|
|
|
if (unittest == 2)
|
|
|
|
return 0;
|
|
|
|
|
2015-05-30 21:04:51 +02:00
|
|
|
if (rc == -1 && execvp(target.compilerpath.c_str(), cargs)) {
|
2015-05-02 21:49:23 +02:00
|
|
|
err << "invoking compiler failed" << err.endl();
|
2014-05-17 23:15:15 +02:00
|
|
|
|
|
|
|
if (!debug)
|
|
|
|
printCommand();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|