fix OSX_VERSION_MIN=default

take care of MACOSX_DEPLOYMENT_TARGET
fix a minor issue where '-oc-use-gcc-libs' would be ignored
This commit is contained in:
Thomas Pöchtrager 2014-04-22 19:34:08 +02:00
parent c107d228c6
commit 9b642c3931
6 changed files with 91 additions and 59 deletions

View File

@ -16,6 +16,9 @@ changed:
* <arch>-apple-darwinXX-cc/c++ defaults now to clang * <arch>-apple-darwinXX-cc/c++ defaults now to clang
* switched to two-space indents * switched to two-space indents
fixed:
* 'MACOSX_DEPLOYMENT_TARGET' env var is now handled correctly
/******************************* v0.6 *******************************/ /******************************* v0.6 *******************************/
added: added:

View File

@ -315,8 +315,9 @@ rm -f $OSXCROSS_CONF $OSXCROSS_ENV
echo "compiling wrapper ..." echo "compiling wrapper ..."
export OSXCROSS_VERSION export OSXCROSS_VERSION
export OSX_VERSION_MIN export OSXCROSS_TARGET=$TARGET
export LINKER_VERSION export OSXCROSS_OSX_VERSION_MIN=$OSX_VERSION_MIN
export OSXCROSS_LINKER_VERSION=$LINKER_VERSION
if [ "$PLATFORM" != "Darwin" ]; then if [ "$PLATFORM" != "Darwin" ]; then
# libLTO.so # libLTO.so
@ -328,7 +329,7 @@ $BASE_DIR/wrapper/build.sh 1>/dev/null
echo "" echo ""
if [ -n $OSX_VERSION_MIN ]; then if [ "$OSX_VERSION_MIN" != "default" ]; then
if [ `echo "${SDK_VERSION/u/}<$OSX_VERSION_MIN" | bc -l` -eq 1 ]; then if [ `echo "${SDK_VERSION/u/}<$OSX_VERSION_MIN" | bc -l` -eq 1 ]; then
echo "OSX_VERSION_MIN must be <= SDK_VERSION" echo "OSX_VERSION_MIN must be <= SDK_VERSION"
trap "" EXIT trap "" EXIT

View File

@ -12,9 +12,10 @@ source tools/tools.sh
# GCC version to build # GCC version to build
# (<4.7 will not work properly with libc++) # (<4.7 will not work properly with libc++)
GCC_VERSION=4.8.2 GCC_VERSION=4.8.2
#GCC_VERSION=4.9-20140416 # snapshot
# GCC mirror # GCC mirror
GCC_MIRROR="ftp://ftp.gwdg.de/pub/misc/gcc/releases" GCC_MIRROR="ftp://ftp.gwdg.de/pub/misc/gcc"
require wget require wget
@ -30,7 +31,11 @@ source $BASE_DIR/tools/trap_exit.sh
if [ ! -f "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}" ]; then if [ ! -f "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}" ]; then
pushd $OSXCROSS_TARBALL_DIR &>/dev/null pushd $OSXCROSS_TARBALL_DIR &>/dev/null
wget -c "$GCC_MIRROR/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2" if [[ $GCC_VERSION != *-* ]]; then
wget -c "$GCC_MIRROR/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2"
else
wget -c "$GCC_MIRROR/snapshots/$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2"
fi
popd &>/dev/null popd &>/dev/null
echo "cleaning up ..." echo "cleaning up ..."
@ -102,9 +107,9 @@ echo "compiling wrapper ..."
export OSXCROSS_VERSION export OSXCROSS_VERSION
export OSXCROSS_LIBLTO_PATH export OSXCROSS_LIBLTO_PATH
export TARGET=$OSXCROSS_TARGET export OSXCROSS_TARGET
export OSX_VERSION_MIN=$OSXCROSS_OSX_VERSION_MIN export OSXCROSS_OSX_VERSION_MIN=$OSXCROSS_OSX_VERSION_MIN
export LINKER_VERSION=$OSXCROSS_LINKER_VERSION export OSXCROSS_LINKER_VERSION=$OSXCROSS_LINKER_VERSION
TARGETCOMPILER=gcc \ TARGETCOMPILER=gcc \
$BASE_DIR/wrapper/build.sh 1>/dev/null $BASE_DIR/wrapper/build.sh 1>/dev/null

View File

@ -5,6 +5,12 @@ pushd .. &>/dev/null
source ./tools/tools.sh source ./tools/tools.sh
popd &>/dev/null popd &>/dev/null
set +e
if [ -z "$OSXCROSS_VERSION" ]; then
`../target/bin/osxcross-conf 2>/dev/null`
fi
set -e
EXESUFFIX="" EXESUFFIX=""
function create_wrapper_link function create_wrapper_link
@ -12,12 +18,12 @@ function create_wrapper_link
verbose_cmd ln -sf "${TARGETTRIPLE}-wrapper${EXESUFFIX}" "${1}${EXESUFFIX}" verbose_cmd ln -sf "${TARGETTRIPLE}-wrapper${EXESUFFIX}" "${1}${EXESUFFIX}"
} }
[ -z "$TARGET" ] && TARGET=darwin12 [ -z "$OSXCROSS_TARGET" ] && OSXCROSS_TARGET=darwin12
[ -z "$OSX_VERSION_MIN" ] && OSX_VERSION_MIN=10.5 [ -z "$OSXCROSS_OSX_VERSION_MIN" ] && OSXCROSS_OSX_VERSION_MIN=10.5
[ -z "$LINKER_VERSION" ] && LINKER_VERSION=134.9 [ -z "$OSXCROSS_LINKER_VERSION" ] && OSXCROSS_LINKER_VERSION=134.9
[ -z "$TARGETCOMPILER" ] && TARGETCOMPILER=clang [ -z "$TARGETCOMPILER" ] && TARGETCOMPILER=clang
TARGETTRIPLE=x86_64-apple-$TARGET TARGETTRIPLE=x86_64-apple-${OSXCROSS_TARGET}
FLAGS="" FLAGS=""
@ -61,9 +67,9 @@ function compile_wrapper()
verbose_cmd $CXX compiler.cpp -std=c++0x -pedantic -Wall -Wextra \ verbose_cmd $CXX compiler.cpp -std=c++0x -pedantic -Wall -Wextra \
"-DOSXCROSS_VERSION=\"\\\"$OSXCROSS_VERSION\\\"\"" \ "-DOSXCROSS_VERSION=\"\\\"$OSXCROSS_VERSION\\\"\"" \
"-DOSXCROSS_TARGET=\"\\\"$TARGET\\\"\"" \ "-DOSXCROSS_TARGET=\"\\\"$OSXCROSS_TARGET\\\"\"" \
"-DOSXCROSS_OSX_VERSION_MIN=\"\\\"$OSX_VERSION_MIN\\\"\"" \ "-DOSXCROSS_OSX_VERSION_MIN=\"\\\"$OSXCROSS_OSX_VERSION_MIN\\\"\"" \
"-DOSXCROSS_LINKER_VERSION=\"\\\"$LINKER_VERSION\\\"\"" \ "-DOSXCROSS_LINKER_VERSION=\"\\\"$OSXCROSS_LINKER_VERSION\\\"\"" \
"-DOSXCROSS_LIBLTO_PATH=\"\\\"$OSXCROSS_LIBLTO_PATH\\\"\"" \ "-DOSXCROSS_LIBLTO_PATH=\"\\\"$OSXCROSS_LIBLTO_PATH\\\"\"" \
-o "../target/bin/${TARGETTRIPLE}-wrapper${EXESUFFIX}" -O2 \ -o "../target/bin/${TARGETTRIPLE}-wrapper${EXESUFFIX}" -O2 \
$FLAGS $* $FLAGS $*
@ -82,13 +88,13 @@ if [ $TARGETCOMPILER = "clang" ]; then
create_wrapper_link o64-clang++ create_wrapper_link o64-clang++
create_wrapper_link o64-clang++-libc++ create_wrapper_link o64-clang++-libc++
create_wrapper_link i386-apple-$TARGET-clang create_wrapper_link i386-apple-${OSXCROSS_TARGET}-clang
create_wrapper_link i386-apple-$TARGET-clang++ create_wrapper_link i386-apple-${OSXCROSS_TARGET}-clang++
create_wrapper_link i386-apple-$TARGET-clang++-libc++ create_wrapper_link i386-apple-${OSXCROSS_TARGET}-clang++-libc++
create_wrapper_link x86_64-apple-$TARGET-clang create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-clang
create_wrapper_link x86_64-apple-$TARGET-clang++ create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-clang++
create_wrapper_link x86_64-apple-$TARGET-clang++-libc++ create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-clang++-libc++
elif [ $TARGETCOMPILER = "gcc" ]; then elif [ $TARGETCOMPILER = "gcc" ]; then
create_wrapper_link o32-gcc create_wrapper_link o32-gcc
create_wrapper_link o32-g++ create_wrapper_link o32-g++
@ -98,42 +104,42 @@ elif [ $TARGETCOMPILER = "gcc" ]; then
create_wrapper_link o64-g++ create_wrapper_link o64-g++
create_wrapper_link o64-g++-libc++ create_wrapper_link o64-g++-libc++
create_wrapper_link i386-apple-$TARGET-gcc create_wrapper_link i386-apple-${OSXCROSS_TARGET}-gcc
create_wrapper_link i386-apple-$TARGET-g++ create_wrapper_link i386-apple-${OSXCROSS_TARGET}-g++
create_wrapper_link i386-apple-$TARGET-g++-libc++ create_wrapper_link i386-apple-${OSXCROSS_TARGET}-g++-libc++
create_wrapper_link x86_64-apple-$TARGET-gcc create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-gcc
create_wrapper_link x86_64-apple-$TARGET-g++ create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-g++
create_wrapper_link x86_64-apple-$TARGET-g++-libc++ create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-g++-libc++
fi fi
create_wrapper_link i386-apple-$TARGET-cc create_wrapper_link i386-apple-${OSXCROSS_TARGET}-cc
create_wrapper_link i386-apple-$TARGET-c++ create_wrapper_link i386-apple-${OSXCROSS_TARGET}-c++
create_wrapper_link x86_64-apple-$TARGET-cc create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-cc
create_wrapper_link x86_64-apple-$TARGET-c++ create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-c++
create_wrapper_link osxcross-conf create_wrapper_link osxcross-conf
create_wrapper_link i386-apple-$TARGET-osxcross-conf create_wrapper_link i386-apple-${OSXCROSS_TARGET}-osxcross-conf
create_wrapper_link x86_64-apple-$TARGET-osxcross-conf create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-osxcross-conf
create_wrapper_link osxcross-env create_wrapper_link osxcross-env
create_wrapper_link i386-apple-$TARGET-osxcross-env create_wrapper_link i386-apple-${OSXCROSS_TARGET}-osxcross-env
create_wrapper_link x86_64-apple-$TARGET-osxcross-env create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-osxcross-env
create_wrapper_link osxcross create_wrapper_link osxcross
create_wrapper_link i386-apple-$TARGET-osxcross create_wrapper_link i386-apple-${OSXCROSS_TARGET}-osxcross
create_wrapper_link x86_64-apple-$TARGET-osxcross create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-osxcross
if [ "$PLATFORM" != "Darwin" ]; then if [ "$PLATFORM" != "Darwin" ]; then
create_wrapper_link sw_vers create_wrapper_link sw_vers
create_wrapper_link i386-apple-$TARGET-sw_vers create_wrapper_link i386-apple-${OSXCROSS_TARGET}-sw_vers
create_wrapper_link x86_64-apple-$TARGET-sw_vers create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-sw_vers
fi fi
create_wrapper_link dsymutil create_wrapper_link dsymutil
create_wrapper_link i386-apple-$TARGET-dsymutil create_wrapper_link i386-apple-${OSXCROSS_TARGET}-dsymutil
create_wrapper_link x86_64-apple-$TARGET-dsymutil create_wrapper_link x86_64-apple-${OSXCROSS_TARGET}-dsymutil
popd &>/dev/null popd &>/dev/null
popd &>/dev/null popd &>/dev/null

View File

@ -29,9 +29,6 @@
* *
* Debug messages can be enabled by setting 'OCDEBUG' (ENV) to 1. * Debug messages can be enabled by setting 'OCDEBUG' (ENV) to 1.
* *
* TODO:
* - handle MACOSX_DEPLOYMENT_TARGET (env)
*
*/ */
#include "compat.h" #include "compat.h"
@ -429,8 +426,8 @@ private:
struct OSVersion { struct OSVersion {
constexpr OSVersion(int major, int minor, int patch = 0) constexpr OSVersion(int major, int minor, int patch = 0)
: major(major), minor(minor), patch(patch) {} : major(major), minor(minor), patch(patch), s() {}
constexpr OSVersion() : major(), minor(), patch() {} constexpr OSVersion() : major(), minor(), patch(), s() {}
constexpr int Num() const { constexpr int Num() const {
return major * 10000 + minor * 100 + patch; return major * 10000 + minor * 100 + patch;
@ -490,6 +487,7 @@ struct OSVersion {
int major; int major;
int minor; int minor;
int patch; int patch;
char s[12];
}; };
static_assert(OSVersion(10, 6) != OSVersion(10, 5), ""); static_assert(OSVersion(10, 6) != OSVersion(10, 5), "");
@ -657,6 +655,11 @@ struct Target {
bool hasLibCXX() const { return getSDKOSNum() >= OSVersion(10, 7); } bool hasLibCXX() const { return getSDKOSNum() >= OSVersion(10, 7); }
bool libCXXIsDefaultCXXLib() const { bool libCXXIsDefaultCXXLib() const {
OSVersion OSNum = this->OSNum;
if (!OSNum.Num())
OSNum = getSDKOSNum();
return stdlib != libstdcxx && hasLibCXX() && OSNum >= OSVersion(10, 9); return stdlib != libstdcxx && hasLibCXX() && OSNum >= OSVersion(10, 9);
} }
@ -988,7 +991,6 @@ struct Target {
break; break;
if (usegcclibs) { if (usegcclibs) {
#ifndef _WIN32
// Use libs from './build_gcc.sh' installation // Use libs from './build_gcc.sh' installation
CXXHeaderPath += "/../../"; CXXHeaderPath += "/../../";
@ -1017,10 +1019,6 @@ struct Target {
CXXHeaderPath += gccversion.Str(); CXXHeaderPath += gccversion.Str();
addCXXPath(otriple); addCXXPath(otriple);
#else
std::cerr << "'-oc-use-gcc-libs' not implemented" << std::endl;
return false;
#endif
} else { } else {
// Use SDK libs // Use SDK libs
std::string tmp; std::string tmp;
@ -1261,7 +1259,8 @@ struct Target {
// Program 'sw_vers' // Program 'sw_vers'
// //
__attribute__((noreturn)) void prog_sw_vers(int argc, char **argv) { __attribute__((noreturn)) void prog_sw_vers(int argc, char **argv,
const Target &target) {
auto genFakeBuildVer = [](std::string & build)->std::string & { auto genFakeBuildVer = [](std::string & build)->std::string & {
std::stringstream tmp; std::stringstream tmp;
@ -1281,16 +1280,22 @@ __attribute__((noreturn)) void prog_sw_vers(int argc, char **argv) {
return build; return build;
}; };
auto getProductVer = []()->OSVersion { auto getProductVer = [&]()->OSVersion {
char *p = getenv("OSXCROSS_SW_VERS_OSX_VERSION"); char *p = getenv("OSXCROSS_SW_VERS_OSX_VERSION");
OSVersion OSNum;
if (!p) if (!p)
p = getenv("MACOSX_DEPLOYMENT_TARGET"); p = getenv("MACOSX_DEPLOYMENT_TARGET");
if (p) if (p)
return parseOSVersion(p); OSNum = parseOSVersion(p);
else
OSNum = getDefaultMinTarget();
return getDefaultMinTarget(); if (!OSNum.Num())
OSNum = target.getSDKOSNum();
return OSNum;
}; };
if (argc == 2) { if (argc == 2) {
@ -1337,6 +1342,7 @@ __attribute__((noreturn)) void prog_osxcross(int argc, char **argv) {
__attribute__((noreturn)) void prog_osxcross_conf(const Target &target) { __attribute__((noreturn)) void prog_osxcross_conf(const Target &target) {
std::string sdkpath; std::string sdkpath;
OSVersion OSXVersionMin = getDefaultMinTarget();
const char *ltopath = getLibLTOPath(); const char *ltopath = getLibLTOPath();
if (!target.getSDKPath(sdkpath)) { if (!target.getSDKPath(sdkpath)) {
@ -1344,12 +1350,15 @@ __attribute__((noreturn)) void prog_osxcross_conf(const Target &target) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!OSXVersionMin.Num())
OSXVersionMin = target.getSDKOSNum();
if (!ltopath) if (!ltopath)
ltopath = ""; ltopath = "";
std::cout << "export OSXCROSS_VERSION=" << getOSXCrossVersion() << std::endl; std::cout << "export OSXCROSS_VERSION=" << getOSXCrossVersion() << std::endl;
std::cout << "export OSXCROSS_OSX_VERSION_MIN=" std::cout << "export OSXCROSS_OSX_VERSION_MIN=" << OSXVersionMin.shortStr()
<< getDefaultMinTarget().shortStr() << std::endl; << std::endl;
std::cout << "export OSXCROSS_TARGET=" << getDefaultTarget() << std::endl; std::cout << "export OSXCROSS_TARGET=" << getDefaultTarget() << std::endl;
std::cout << "export OSXCROSS_SDK_VERSION=" << target.getSDKOSNum().shortStr() std::cout << "export OSXCROSS_SDK_VERSION=" << target.getSDKOSNum().shortStr()
<< std::endl; << std::endl;
@ -1574,6 +1583,11 @@ bool detectTarget(int argc, char **argv, Target &target) {
return val; return val;
}; };
if (char *p = getenv("MACOSX_DEPLOYMENT_TARGET")) {
target.OSNum = parseOSVersion(p);
unsetenv("MACOSX_DEPLOYMENT_TARGET");
}
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
char *arg = argv[i]; char *arg = argv[i];
@ -1624,6 +1638,7 @@ bool detectTarget(int argc, char **argv, Target &target) {
std::cerr << "warning: '" << arg << "' has no effect" << std::endl; std::cerr << "warning: '" << arg << "' has no effect" << std::endl;
continue; continue;
} }
target.stdlib = StdLib::libstdcxx;
target.usegcclibs = true; target.usegcclibs = true;
} else if (!strncmp(arg, "-o", 2)) { } else if (!strncmp(arg, "-o", 2)) {
target.outputname = getVal(arg, "-o", i); target.outputname = getVal(arg, "-o", i);
@ -1695,7 +1710,7 @@ bool detectTarget(int argc, char **argv, Target &target) {
}; };
if (!strcmp(cmd, "sw_vers")) if (!strcmp(cmd, "sw_vers"))
prog_sw_vers(argc, argv); prog_sw_vers(argc, argv, target);
else if (!strcmp(cmd, "osxcross")) else if (!strcmp(cmd, "osxcross"))
prog_osxcross(argc, argv); prog_osxcross(argc, argv);
else if (!strcmp(cmd, "osxcross-env")) else if (!strcmp(cmd, "osxcross-env"))
@ -1737,7 +1752,7 @@ bool detectTarget(int argc, char **argv, Target &target) {
else if (target.compiler == "wrapper") else if (target.compiler == "wrapper")
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
else if (target.compiler == "sw_vers") else if (target.compiler == "sw_vers")
prog_sw_vers(argc, argv); prog_sw_vers(argc, argv, target);
else if (target.compiler == "osxcross") else if (target.compiler == "osxcross")
prog_osxcross(argc, argv); prog_osxcross(argc, argv);
else if (target.compiler == "osxcross-env") else if (target.compiler == "osxcross-env")

View File

@ -10,5 +10,7 @@ int setenv(const char *name, const char *value, int overwrite) {
return putenv(buf.c_str()); return putenv(buf.c_str());
} }
int unsetenv(const char *name) { return setenv(name, "", 1); }
#endif #endif
} }