cosmopolitan/build/do
Justine Tunney f213556366 Add binfmt_misc workaround detector to builds
This is a recently introduced Linux Kernel feature that gives people
like Debian package mantainers the power to arbitrarily redefine how
executables are interpreted by the kernel. If your system gets tuned
this way and you're not able to disable it, then you need to restore
default behavior for the APE MZqFpD prefix as follows:

    sudo sh -c "echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register"

This prefix will cover all .com executables built with this tooling.
Please don't run the above command unless you're certain you need it.
See #2 for additional context.
2020-08-31 20:09:23 -07:00

55 lines
970 B
Bash
Executable file

#!/bin/sh
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Generic Command Runner
#
# DESCRIPTION
#
# This does auto mkdir and ephemeral logging.
#
# EXAMPLE
#
# build/do PROG [ARGS...]
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
# Ensure directory creation if -o PATH flag is passed.
OUT="$TARGET"
FIRST=1
OUTARG=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
elif [ $OUTARG -eq 1 ]; then
OUTARG=0
OUT="$x"
fi
case "$x" in
-o)
OUTARG=1
;;
-o*)
OUT=${x#-o}
;;
esac
set -- "$@" "$x"
done
if [ "$OUT" ]; then
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
fi
# Log command.
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
fi
exec "$@"