diff --git a/build.sh b/build.sh index cc2e5cf..ba54df5 100755 --- a/build.sh +++ b/build.sh @@ -132,37 +132,35 @@ if [ $f_res -eq 1 ]; then $MAKE -j$JOBS $MAKE install -j$JOBS popd &>/dev/null - - pushd $TARGET_DIR/bin &>/dev/null - CCTOOLS=$(find . -name "x86_64-apple-darwin*") - CCTOOLS=($CCTOOLS) - if [ $X86_64H_SUPPORTED -eq 1 ]; then - for CCTOOL in ${CCTOOLS[@]}; do - CCTOOL_X86_64H=$(echo "$CCTOOL" | $SED 's/x86_64/x86_64h/g') - create_symlink $CCTOOL $CCTOOL_X86_64H - done - fi - if [ $I386_SUPPORTED -eq 1 ]; then - for CCTOOL in ${CCTOOLS[@]}; do - CCTOOL_I386=$(echo "$CCTOOL" | $SED 's/x86_64/i386/g') - create_symlink $CCTOOL $CCTOOL_I386 - done - fi - if [ $ARM_SUPPORTED -eq 1 ]; then - for CCTOOL in ${CCTOOLS[@]}; do - CCTOOL_ARM64=$(echo "$CCTOOL" | $SED 's/x86_64/arm64/g') - create_symlink $CCTOOL $CCTOOL_ARM64 - done - for CCTOOL in ${CCTOOLS[@]}; do - CCTOOL_ARM64E=$(echo "$CCTOOL" | $SED 's/x86_64/arm64e/g') - create_symlink $CCTOOL $CCTOOL_ARM64E - done - fi - # For unpatched dsymutil. There is currently no way around it. - create_symlink x86_64-apple-$TARGET-lipo lipo - popd &>/dev/null fi +## Create Arch Symlinks ## + +pushd $TARGET_DIR/bin &>/dev/null +CCTOOLS=($(find . -name "x86_64-apple-${TARGET}*")) +function create_arch_symlinks() +{ + local arch=$1 + for CCTOOL in ${CCTOOLS[@]}; do + verbose_cmd create_symlink $CCTOOL $(echo "$CCTOOL" | $SED "s/x86_64/$arch/g") + done +} +if [ $X86_64H_SUPPORTED -eq 1 ]; then + create_arch_symlinks "x86_64h" +fi +if [ $I386_SUPPORTED -eq 1 ]; then + create_arch_symlinks "i386" +fi + +if [ $ARM_SUPPORTED -eq 1 ]; then + create_arch_symlinks "aarch64" + create_arch_symlinks "arm64" + create_arch_symlinks "arm64e" +fi +# For unpatched dsymutil. There is currently no way around it. +create_symlink x86_64-apple-$TARGET-lipo lipo +popd &>/dev/null + ## MacPorts ## @@ -271,6 +269,7 @@ if [ $X86_64H_SUPPORTED -eq 1 ]; then fi if [ $ARM_SUPPORTED -eq 1 ]; then + create_symlink osxcross-cmake "$TARGET_DIR/bin/aarch64-apple-$TARGET-cmake" create_symlink osxcross-cmake "$TARGET_DIR/bin/arm64-apple-$TARGET-cmake" create_symlink osxcross-cmake "$TARGET_DIR/bin/arm64e-apple-$TARGET-cmake" fi @@ -360,6 +359,14 @@ echo "Example 3: o64-clang -Wall test.c -o test" echo "Example 4: x86_64-apple-$TARGET-strip -x test" echo "" +if [ $ARM_SUPPORTED -eq 1 ]; then + echo "!!! Use aarch64-apple-$TARGET-* instead of arm64-* when dealing with Automake !!!" + echo "!!! CC=aarch64-apple-$TARGET-clang ./configure --host=aarch64-apple-$TARGET !!!" + echo "!!! CC=\"aarch64-apple-$TARGET-clang -arch arm64e\" ./configure --host=aarch64-apple-$TARGET !!!" + echo "" +fi + + if [ $I386_SUPPORTED -eq 0 ]; then echo "Your SDK does not support i386 anymore." echo "Use <= 10.13 SDK if you rely on i386 support." diff --git a/wrapper/build_wrapper.sh b/wrapper/build_wrapper.sh index e8941c5..e10c30f 100755 --- a/wrapper/build_wrapper.sh +++ b/wrapper/build_wrapper.sh @@ -82,6 +82,8 @@ function create_wrapper_link fi if [ $ARM_SUPPORTED -eq 1 ]; then + verbose_cmd create_symlink "${TARGETTRIPLE}-wrapper" \ + "aarch64-apple-${TARGET}-${1}" verbose_cmd create_symlink "${TARGETTRIPLE}-wrapper" \ "arm64-apple-${TARGET}-${1}" verbose_cmd create_symlink "${TARGETTRIPLE}-wrapper" \ diff --git a/wrapper/main.cpp b/wrapper/main.cpp index cc25d2d..cc94f69 100644 --- a/wrapper/main.cpp +++ b/wrapper/main.cpp @@ -373,8 +373,8 @@ void detectCXXLib(Target &target) { bool detectTarget(int argc, char **argv, Target &target) { const char *cmd = argv[0]; const char *p = strrchr(cmd, '/'); + char archName[16]; size_t len; - size_t i = 0; if (p) cmd = &p[1]; @@ -386,51 +386,54 @@ bool detectTarget(int argc, char **argv, Target &target) { p = strchr(cmd, '-'); len = (p ? p : cmd) - cmd; - for (auto arch : ArchNames) { - ++i; + if (len >= sizeof(archName)) + return false; - if (!strncmp(cmd, arch, len)) { - target.arch = static_cast(i - 1); - cmd += len; + memcpy(archName, cmd, len); + archName[len] = '\0'; - if (*cmd++ != '-') - return false; + target.arch = parseArch(archName); - if (strncmp(cmd, "apple-", 6)) - return false; + if (target.arch != Arch::unknown) { + cmd += len; - cmd += 6; + if (*cmd++ != '-') + return false; - if (strncmp(cmd, "darwin", 6)) - return false; + if (strncmp(cmd, "apple-", 6)) + return false; - if (!(p = strchr(cmd, '-'))) - return false; + cmd += 6; - target.target = std::string(cmd, p - cmd); - target.compiler = getCompilerIdentifier(&p[1]); - target.compilername = &p[1]; + if (strncmp(cmd, "darwin", 6)) + return false; - if (target.compilername == "cc") { - target.compiler = getDefaultCompilerIdentifier(); - target.compilername = getDefaultCompilerName(); - } else if (target.compilername == "c++") { - target.compiler = getDefaultCXXCompilerIdentifier(); - target.compilername = getDefaultCXXCompilerName(); - } else if (auto *prog = program::getprog(target.compilername)) { - (*prog)(argc, argv, target); - } + if (!(p = strchr(cmd, '-'))) + return false; - if (target.target != getDefaultTarget()) - warn << "this wrapper was built for target " - << "'" << getDefaultTarget() << "'" << warn.endl(); + target.target = std::string(cmd, p - cmd); + target.compiler = getCompilerIdentifier(&p[1]); + target.compilername = &p[1]; - if (!commandopts::parse(argc, argv, target)) - return false; - - detectCXXLib(target); - return target.setup(); + if (target.compilername == "cc") { + target.compiler = getDefaultCompilerIdentifier(); + target.compilername = getDefaultCompilerName(); + } else if (target.compilername == "c++") { + target.compiler = getDefaultCXXCompilerIdentifier(); + target.compilername = getDefaultCXXCompilerName(); + } else if (auto *prog = program::getprog(target.compilername)) { + (*prog)(argc, argv, target); } + + if (target.target != getDefaultTarget()) + warn << "this wrapper was built for target " + << "'" << getDefaultTarget() << "'" << warn.endl(); + + if (!commandopts::parse(argc, argv, target)) + return false; + + detectCXXLib(target); + return target.setup(); } if (!strncmp(cmd, "o32", 3)) diff --git a/wrapper/tools.h b/wrapper/tools.h index 5136a5f..86ad4ae 100644 --- a/wrapper/tools.h +++ b/wrapper/tools.h @@ -379,19 +379,7 @@ inline Compiler getCompilerIdentifier(const char *compilername) { // enum Arch { - armv4t, - armv5, - armv6, - armv7, - armv7f, - armv7k, - armv7s, - armv6m, - armv7m, - armv7em, - armv8, arm64, - arm64v8, arm64e, i386, i486, @@ -399,21 +387,29 @@ enum Arch { i686, x86_64, x86_64h, // Haswell - ppc, - ppc64, unknown }; constexpr const char *ArchNames[] = { - "armv4t", "armv5", "armv6", "armv7", "armv7f", "armv7k", "armv7s", - "amrv6m", "armv7m", "armv7em", "armv8", "arm64", "arm64v8", "arm64e", - "i386", "i486", "i586", "i686", "x86_64", "x86_64h", "ppc", - "ppc64", "unknown" + "arm64", + "arm64e", + "i386", + "i486", + "i586", + "i686", + "x86_64", + "x86_64h", + "unknown" }; -constexpr const char *getArchName(Arch arch) { return ArchNames[arch]; } +constexpr const char *getArchName(Arch arch) { + return ArchNames[arch]; +} inline Arch parseArch(const char *arch) { + if (!strcmp(arch, "aarch64")) // treat aarch64 as arm64 + return Arch::arm64; + size_t i = 0; for (auto archname : ArchNames) { if (!strcmp(arch, archname)) { @@ -421,6 +417,7 @@ inline Arch parseArch(const char *arch) { } ++i; } + return Arch::unknown; } @@ -434,7 +431,11 @@ enum StdLib { libstdcxx }; -constexpr const char *StdLibNames[] = { "default", "libc++", "libstdc++" }; +constexpr const char *StdLibNames[] = { + "default", + "libc++", + "libstdc++" +}; constexpr const char *getStdLibString(StdLib stdlib) { return StdLibNames[stdlib];