1
1
Fork 0

zshrc: Add cross() command like in fish

This commit is contained in:
Jonathan Schleifer 2020-06-04 22:01:41 +00:00
parent 8e226420eb
commit d08c149859
2 changed files with 184 additions and 5 deletions

View file

@ -8,9 +8,11 @@ function cross --description 'Set up cross-compilation environment'
case 3ds nds case 3ds nds
if test -z "$DEVKITPRO" if test -z "$DEVKITPRO"
echo 'Please set DEVKITPRO!' echo 'Please set DEVKITPRO!'
return 1
end end
if test -z "$DEVKITARM" if test -z "$DEVKITARM"
echo 'Please set DEVKITARM!' echo 'Please set DEVKITARM!'
return 1
end end
set PATH $DEVKITARM/bin $PATH set PATH $DEVKITARM/bin $PATH
@ -64,10 +66,10 @@ function cross --description 'Set up cross-compilation environment'
set archs $default_archs set archs $default_archs
end end
set -gx CC clang -isysroot $sdk set -gx CC clang --sysroot $sdk
set -gx CPP clang -E -isysroot $sdk set -gx CPP clang -E --sysroot $sdk
set -gx CXX clang++ -isysroot $sdk set -gx CXX clang++ --sysroot $sdk
set -gx CXXPP clang++ -E -isysroot $sdk set -gx CXXPP clang++ -E --sysroot $sdk
for arch in $archs for arch in $archs
set -a CC -arch $arch set -a CC -arch $arch
@ -82,7 +84,7 @@ function cross --description 'Set up cross-compilation environment'
set -gx OBJCPPXX $CXXPP set -gx OBJCPPXX $CXXPP
set -gx IPHONEOS_DEPLOYMENT_TARGET 10.0 set -gx IPHONEOS_DEPLOYMENT_TARGET 10.0
set -g cross_host $archs[1]-apple-darwin set -g cross_host $archs[1]-apple-darwin
case mingw32 case mingw
set -l pkg set -l pkg
switch $argv[2] switch $argv[2]
case i686 x86_64 case i686 x86_64
@ -121,9 +123,11 @@ function cross --description 'Set up cross-compilation environment'
case switch case switch
if test -z "$DEVKITPRO" if test -z "$DEVKITPRO"
echo 'Please set DEVKITPRO!' echo 'Please set DEVKITPRO!'
return 1
end end
if test -z "$DEVKITA64" if test -z "$DEVKITA64"
echo 'Please set DEVKITA64!' echo 'Please set DEVKITA64!'
return 1
end end
set PATH $DEVKITA64/bin $PATH set PATH $DEVKITA64/bin $PATH
@ -132,9 +136,11 @@ function cross --description 'Set up cross-compilation environment'
case wii wii-u case wii wii-u
if test -z "$DEVKITPRO" if test -z "$DEVKITPRO"
echo 'Please set DEVKITPRO!' echo 'Please set DEVKITPRO!'
return 1
end end
if test -z "$DEVKITPPC" if test -z "$DEVKITPPC"
echo 'Please set DEVKITPPC!' echo 'Please set DEVKITPPC!'
return 1
end end
set PATH $DEVKITPPC/bin $PATH set PATH $DEVKITPPC/bin $PATH

173
zshrc
View file

@ -308,5 +308,178 @@ alias pws="pwnk -k ~/.cryptopassphrase-server.key"
ixio() { curl -F 'f:1=<-' ix.io } ixio() { curl -F 'f:1=<-' ix.io }
0x0st() { curl -F'file=@-' https://0x0.st } 0x0st() { curl -F'file=@-' https://0x0.st }
cross() {
if [ $# = 0 ]; then
echo 'Usage: cross platform [architecture1] [architecture2]' \
1>&2
return 1
fi
case "$1" in
3ds | nds)
if [ -z "$DEVKITPRO" ]; then
echo "Please set DEVKITPRO!" 1>&2
return 1
fi
if [ -z "$DEVKITARM" ]; then
echo "Please set DEVKITARM!" 1>&2
return 1
fi
export PATH="$DEVKITARM/bin:$PATH"
export cross_host="arm-none-eabi"
export objfw_configure_flags="--with-$1"
;;
amiga)
case "$2" in
m68k)
if [ -z "$amiga_gcc_path" ]; then
echo -n "Please set " 1>&2
echo "amiga_gcc_path!" 1>&2
return 1
fi
export PATH="$amiga_gcc_path/bin:$PATH"
export cross_host="m68k-amigaos"
;;
ppc)
if [ -z "$adtools_path" ]; then
echo -n "Please set " 1>&2
echo "adtools_path!" 1>&2
return 1
fi
export PATH="$adtools_path/bin:$PATH"
export cross_host="ppc-amigaos"
;;
esac
if [ $# != 2 -o -z "$cross_host" ]; then
echo "Usage: cross amiga m68k|ppc" 1>&2
return 1
fi
;;
ios | iossim)
if ! which xcrun &>/dev/null; then
echo -n "Can only cross-compile for iOS " 1>&2
echo "on a Mac with Xcode!" 1>&2
return 1
fi
case "$1" in
ios)
local sdk_type=iphoneos
local default_archs="arm64"
;;
iossim)
local sdk_type=iphonesimulator
local default_archs="x86_64"
;;
esac
local sdk="$(xcrun --show-sdk-path --sdk $sdk_type)"
local archs="${@:2}"
if [ ${(w)#archs} = 0 ]; then
archs="$default_archs"
fi
export CC="clang --sysroot $sdk"
export CPP="clang -E --sysroot $sdk"
export CXX="clang++ --sysroot $sdk"
export CXXPP="clang++ -E -=sysroot $sdk"
for arch in $=archs; do
export CC="$CC -arch $arch"
export CXX="$CXX -arch $arch"
done
export CPP="$CPP -arch $archs[(w)1]"
export CXXPP="$CXXPP -arch $archs[(w)1]"
export OBJC="$CC"
export OBJCPP="$CPP"
export OBJCXX="$CXX"
export OBJCPPXX="$CXXPP"
export IPHONEOS_DEPLOYMENT_TARGET="10.0"
export cross_host="$archs[(w)1]-apple-darwin"
;;
mingw)
case "$2" in
i686 | x86_64)
local pkg="mingw-w64-$2-gcc"
export cross_host="$2-w64-mingw32"
;;
esac
if [ $# != 2 -o -z "$cross_host" ]; then
echo "Usage: cross mingw i686|x86_64" 1>&2
return 1
fi
local prefix="$(pkg_info -qp $pkg 2>/dev/null |
awk '/^@cwd/ { print $2; exit }')"
if [ -z "$prefix" ]; then
echo "Please install $pkg from pkgsrc!" 1>&2
return 1
fi
export PATH="$prefix/cross/$cross_host/bin:$PATH"
;;
morphos)
local pkg="ppc-morphos-gcc-9"
local prefix="$(pkg_info -qp $pkg 2>/dev/null |
awk '/^@cwd/ { print $2; exit }')"
if [ -z "$prefix" ]; then
echo "Please install $pkg from pkgsrc!" 1>&2
return 1
fi
export PATH="$prefix/gg/bin:$PATH"
export CC="ppc-morphos-gcc-9"
export CXX="ppc-morphos-g++-9"
export OBJC="$CC"
export OBJCXX="$CXX"
export cross_host="ppc-morphos"
;;
switch)
if [ -z "$DEVKITPRO" ]; then
echo "Please set DEVKITPRO!"
return 1
fi
if [ -z $"DEVKITA64" ]; then
echo "Please set DEVKITA64!"
return 1
fi
export PATH="$DEVKITA64/bin:$PATH"
export cross_host="aarch64-none-elf"
export objfw_configure_flags="--with-$1"
;;
wii | wii-u)
if [ -z "$DEVKITPRO" ]; then
echo "Please set DEVKITPRO!"
return 1
fi
if [ -z "$DEVKITPPC" ]; then
echo "Please set DEVKITPPC!"
return 1
fi
export PATH="$DEVKITPPC/bin:$PATH"
export cross_host="powerpc-eabi"
export objfw_configure_flags="--with-$1"
;;
*)
echo "Unknown target: $1" 1>&2
return 1
;;
esac
export objfw_configure_flags=(
--host=$cross_host
$=objfw_configure_flags
)
}
unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init simple_prompt unset fgrep grep grep_color ls ls_color ls_on_cd ls_on_init simple_prompt
unset HISTFILE unset HISTFILE