cosmopolitan/build/sanitycheck
Justine Tunney db0d8dd806 Support Linux binfmt_misc and APE loading on Apple
The "no modify self" variant of Actually Portable Executable is now
supported on all platforms. If you use `$(APE_NO_MODIFY_SELF)` then
ld.bfd will embed a 4096 byte ELF binary and a 4096 byte Macho file
which are installed on the fly to ${TMPDIR:-/tmp}, which enables us
launch the executable, without needing to copy the whole executable

To prevent it from copying a tiny executable to your temp directory
you need to install the `ape` command (renamed from ape-loader), to
a system path. For example:

    # FreeBSD / NetBSD / OpenBSD
    make -j8 o//ape/ape
    cp o//ape/ape /usr/bin/ape

    # Mac OS
    # make -j8 o//ape/ape.macho
    curl https://justine.lol/ape.macho >/usr/bin/ape
    chmod +x /usr/bin/ape

On Linux you can get even more performance with the new binfmt_misc
support which makes launching non-modifying APE binaries as fast as
launching ELF executables. Running the following command:

    # Linux
    ape/apeinstall.sh

Will copy APE loader to /usr/bin/ape and register with binfmt_misc
Lastly, this change also fixes a really interesting race condition
with OpenBSD thread joining.
2022-05-21 09:28:25 -07:00

56 lines
1 KiB
Bash
Executable file

#!/bin/sh
#
# OVERVIEW
#
# System Sanity Check
#
# DESCRIPTION
#
# This script is launched at the start of Makefile to detect if
# binfmt_misc was tuned to launch 'MZ' shell scripts under WINE
if [ x`uname -s` != xLinux ]; then
cat <<'EOF' >&2
ERROR
Want Linux Build Environment
DETAILS
Cosmopolitan builds binaries that run on all major platforms.
You need to compile them on Linux, using any distro you like.
Consider setting up Alpine, Debian, or Ubuntu in a VMWare VM.
EOF
kill $1
exit 1
fi
build/sanitycheck2
if [ $? -ne 123 ]; then
cat <<'EOF' >&2
ERROR
Thompson Shell Backwards Compatibility Issue Detected
DETAILS
Your system has likely been configured to use binfmt_misc and wine.
You need to run the command below which will install a /usr/bin/ape
program and then register it with binfmt_misc. See ape/loader.c for
source code and technical details.
WORKAROUND
ape/apeinstall.sh
SEE ALSO
https://justine.storage.googleapis.com/ape.html
EOF
kill $1
exit 1
fi