Use /usr/local/bin/ape on Apple Silicon

This commit is contained in:
Justine Tunney 2023-11-05 14:48:00 -08:00
parent b893479417
commit f63c4d4f52
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
6 changed files with 24 additions and 3 deletions

View file

@ -2,6 +2,7 @@
PROG=${0##*/} PROG=${0##*/}
MODE=${MODE:-$m} MODE=${MODE:-$m}
TMPDIR=${TMPDIR:-/tmp}
COSMO=${COSMO:-/opt/cosmo} COSMO=${COSMO:-/opt/cosmo}
COSMOS=${COSMOS:-/opt/cosmos} COSMOS=${COSMOS:-/opt/cosmos}
@ -18,6 +19,19 @@ fi
echo "Actually Portable Executable (APE) Installer" >&2 echo "Actually Portable Executable (APE) Installer" >&2
echo "Author: Justine Tunney <jtunney@gmail.com>" >&2 echo "Author: Justine Tunney <jtunney@gmail.com>" >&2
# special installation process for apple silicon
if [ "$(uname -s)" = "Darwin" ] && [ "$(uname -m)" = "arm64" ]; then
echo "cc -O -o $TMPDIR/ape.$$ ape/ape-m1.c" >&2
cc -O -o "$TMPDIR/ape.$$" ape/ape-m1.c || exit
if [ ! -d /usr/local/bin ]; then
echo "$SUDO mkdir -p /usr/local/bin" >&2
$SUDO mkdir -p /usr/local/bin || exit
fi
echo "$SUDO mv -f $TMPDIR/ape.$$ /usr/local/bin/ape" >&2
$SUDO mv -f "$TMPDIR/ape.$$" /usr/local/bin/ape || exit
exit
fi
################################################################################ ################################################################################
# INSTALL APE LOADER SYSTEMWIDE # INSTALL APE LOADER SYSTEMWIDE
@ -50,8 +64,8 @@ fi
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
if ! [ /usr/bin/ape -nt o//ape/ape.macho ]; then if ! [ /usr/bin/ape -nt o//ape/ape.macho ]; then
echo >&2 echo >&2
echo "installing o//ape/ape.elf to /usr/bin/ape" >&2 echo "installing o//ape/ape.macho to /usr/bin/ape" >&2
echo "$SUDO mv -f o//ape/ape.elf /usr/bin/ape" >&2 echo "$SUDO cp -f o//ape/ape.macho /usr/bin/ape" >&2
$SUDO cp -f o//ape/ape.macho /usr/bin/ape || exit $SUDO cp -f o//ape/ape.macho /usr/bin/ape || exit
echo "done" >&2 echo "done" >&2
fi fi

View file

@ -37,6 +37,9 @@ done
if [ -f /usr/bin/ape ]; then if [ -f /usr/bin/ape ]; then
$SUDO rm -f /usr/bin/ape $SUDO rm -f /usr/bin/ape
fi fi
if [ -f /usr/local/bin/ape ]; then
$SUDO rm -f /usr/local/bin/ape
fi
# legacy installations # legacy installations
rm -f o/tmp/ape /tmp/ape "${TMPDIR:-/tmp}/ape" rm -f o/tmp/ape /tmp/ape "${TMPDIR:-/tmp}/ape"

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -127,7 +127,11 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
shargs[1] = (char *)"-"; shargs[1] = (char *)"-";
shargs[2] = (char *)prog; shargs[2] = (char *)prog;
memcpy(shargs + 3, argv, (argc + 1) * sizeof(char *)); memcpy(shargs + 3, argv, (argc + 1) * sizeof(char *));
if (IsXnuSilicon()) {
RetryExecve("/usr/local/bin/ape", shargs, envp);
} else {
RetryExecve("/usr/bin/ape", shargs, envp); RetryExecve("/usr/bin/ape", shargs, envp);
}
char *buf = alloca(PATH_MAX); char *buf = alloca(PATH_MAX);
const char *name = "/.ape-" APE_VERSION_STR; const char *name = "/.ape-" APE_VERSION_STR;
InitExecve(); InitExecve();