Skip to content

Commit

Permalink
Use /usr/local/bin/ape on Apple Silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Nov 5, 2023
1 parent b893479 commit f63c4d4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions bin/ape-install
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

PROG=${0##*/}
MODE=${MODE:-$m}
TMPDIR=${TMPDIR:-/tmp}
COSMO=${COSMO:-/opt/cosmo}
COSMOS=${COSMOS:-/opt/cosmos}

Expand All @@ -18,6 +19,19 @@ fi
echo "Actually Portable Executable (APE) Installer" >&2
echo "Author: Justine Tunney <[email protected]>" >&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

Expand Down Expand Up @@ -50,8 +64,8 @@ fi
if [ "$(uname -s)" = "Darwin" ]; then
if ! [ /usr/bin/ape -nt o//ape/ape.macho ]; then
echo >&2
echo "installing o//ape/ape.elf to /usr/bin/ape" >&2
echo "$SUDO mv -f o//ape/ape.elf /usr/bin/ape" >&2
echo "installing o//ape/ape.macho to /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
echo "done" >&2
fi
Expand Down
3 changes: 3 additions & 0 deletions bin/ape-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ done
if [ -f /usr/bin/ape ]; then
$SUDO rm -f /usr/bin/ape
fi
if [ -f /usr/local/bin/ape ]; then
$SUDO rm -f /usr/local/bin/ape
fi

# legacy installations
rm -f o/tmp/ape /tmp/ape "${TMPDIR:-/tmp}/ape"
Expand Down
Binary file modified build/bootstrap/cocmd.com
Binary file not shown.
Binary file modified build/bootstrap/compile.com
Binary file not shown.
Binary file modified build/bootstrap/make.com
Binary file not shown.
6 changes: 5 additions & 1 deletion libc/proc/execve-sysv.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
shargs[1] = (char *)"-";
shargs[2] = (char *)prog;
memcpy(shargs + 3, argv, (argc + 1) * sizeof(char *));
RetryExecve("/usr/bin/ape", shargs, envp);
if (IsXnuSilicon()) {
RetryExecve("/usr/local/bin/ape", shargs, envp);
} else {
RetryExecve("/usr/bin/ape", shargs, envp);
}
char *buf = alloca(PATH_MAX);
const char *name = "/.ape-" APE_VERSION_STR;
InitExecve();
Expand Down

0 comments on commit f63c4d4

Please sign in to comment.