configs  cross.fish at [564302e990]

File fish/functions/cross.fish artifact 2f0918b138 part of check-in 564302e990


function cross --description 'Set up cross-compilation environment'
    if test (count $argv) = 0
        echo 'Usage: cross platform [architecture1] [architecture2]'
        return 1
    end

    switch $argv[1]
        case 3ds nds
            if test -z "$DEVKITPRO"
                echo 'Please set DEVKITPRO!'
                return 1
            end
            if test -z "$DEVKITARM"
                echo 'Please set DEVKITARM!'
                return 1
            end

            set PATH $DEVKITARM/bin $PATH
            set -g cross_host arm-none-eabi
            set -g objfw_configure_flags --with-$argv[1]
        case amiga
            switch $argv[2]
                case m68k
                    if test -z "$amiga_gcc_path"
                        echo 'Please set amiga_gcc_path!'
                        return 1
                    end

                    set PATH $amiga_gcc_path/bin $PATH
                    set -g cross_host m68k-amigaos
                case ppc
                    if test -z "$adtools_path"
                        echo 'Please set adtools_path!'
                        return 1
                    end

                    set PATH $adtools_path/bin $PATH
                    set -g cross_host ppc-amigaos
            end

            if test (count $argv) != 2 -o -z "$cross_host"
                echo 'Usage: cross amiga m68k|ppc'
                return 1
            end
        case ios iossim
            if ! type -q xcrun
                echo 'Can only cross-compile for iOS on a Mac with Xcode!'
                return 1
            end

            set -l sdk_type
            set -l default_archs
            switch $argv[1]
                case ios
                    set sdk_type iphoneos
                    set default_archs arm64
                case iossim
                    set sdk_type iphonesimulator
                    set default_archs x86_64
            end

            set -l sdk (xcrun --show-sdk-path --sdk $sdk_type)
            set -l archs $argv[2..-1]

            if test (count $archs) = 0
                set archs $default_archs
            end

            set -gx CC clang --sysroot $sdk
            set -gx CPP clang -E --sysroot $sdk
            set -gx CXX clang++ --sysroot $sdk
            set -gx CXXPP clang++ -E --sysroot $sdk

            for arch in $archs
                set -a CC -arch $arch
                set -a CXX -arch $arch
            end
            set -a CPP -arch $archs[1]
            set -a CXXPP -arch $archs[1]

            set -gx OBJC $CC
            set -gx OBJCPP $CPP
            set -gx OBJCXX $CXX
            set -gx OBJCPPXX $CXXPP
            set -gx IPHONEOS_DEPLOYMENT_TARGET 10.0
            set -g cross_host $archs[1]-apple-darwin
        case mingw
            set -l pkg
            switch $argv[2]
                case i686 x86_64
                    set pkg mingw-w64-$argv[2]-gcc
                    set -g cross_host $argv[2]-w64-mingw32
            end

            if test (count $argv) != 2 -o -z "$cross_host"
                echo 'Usage: cross mingw i686|x86_64'
                return 1
            end

            set -l prefix (pkg_info -qp $pkg | awk '/^@cwd/ { print $2; exit }')

            if test -z "$prefix"
                echo 'Please install $pkg from pkgsrc!'
                return 1
            end

            set PATH $prefix/cross/$cross_host/bin $PATH
        case morphos
            set -l prefix (pkg_info -qp ppc-morphos-gcc-9 |
                           awk '/^@cwd/ { print $2; exit }')

            if test -z "$prefix"
                echo 'Please install ppc-morphos-gcc-9 from pkgsrc!'
                return 1
            end

            set PATH $prefix/gg/bin $PATH
            set -gx CC ppc-morphos-gcc-9
            set -gx CXX ppc-morphos-g++-9
            set -gx OBJC ppc-morphos-gcc-9
            set -gx OBJCXX ppc-morphos-g++-9
            set -g cross_host ppc-morphos
        case switch
            if test -z "$DEVKITPRO"
                echo 'Please set DEVKITPRO!'
                return 1
            end
            if test -z "$DEVKITA64"
                echo 'Please set DEVKITA64!'
                return 1
            end

            set PATH $DEVKITA64/bin $PATH
            set -g cross_host aarch64-none-elf
            set -g objfw_configure_flags --with-switch
        case wii wii-u
            if test -z "$DEVKITPRO"
                echo 'Please set DEVKITPRO!'
                return 1
            end
            if test -z "$DEVKITPPC"
                echo 'Please set DEVKITPPC!'
                return 1
            end

            set PATH $DEVKITPPC/bin $PATH
            set -g cross_host powerpc-eabi
            set -g objfw_configure_flags --with-$argv[1]
        case '*'
            echo "Unknown target: $argv[1]"
            return 1
    end

    set -g objfw_configure_flags --host=$cross_host $objfw_configure_flags
end