mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 15:38:22 +00:00
I wanted a tiny scriptable meltdown proof way to run userspace programs and visualize how program execution impacts memory. It helps to explain how things like Actually Portable Executable works. It can show you how the GCC generated code is going about manipulating matrices and more. I didn't feel fully comfortable with Qemu and Bochs because I'm not smart enough to understand them. I wanted something like gVisor but with much stronger levels of assurances. I wanted a single binary that'll run, on all major operating systems with an embedded GPL barrier ZIP filesystem that is tiny enough to transpile to JavaScript and run in browsers too. https://justine.storage.googleapis.com/emulator625.mp4
81 lines
1.8 KiB
Text
Executable file
81 lines
1.8 KiB
Text
Executable file
#-*-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
|
|
#
|
|
# GNU Archiver Veneer
|
|
#
|
|
# DESCRIPTION
|
|
#
|
|
# This script wraps normal archive commands that're transparently
|
|
# passed-through. It adds value too, by addressing difficulties
|
|
# that would normally cause a developer to need `make clean`.
|
|
#
|
|
# EXAMPLE
|
|
#
|
|
# build/archive ar rcsD library.a foo.o ...
|
|
|
|
if [ ! -d o/third_party/gcc ]; then
|
|
third_party/gcc/unbundle.sh
|
|
fi
|
|
|
|
export LC_ALL=C
|
|
RM=${RM:-$(command -v rm) -f} || exit
|
|
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
|
|
|
|
AR=$1
|
|
ARFLAGS=$2
|
|
OUT=$3
|
|
shift 3
|
|
|
|
# remove directory arguments (having .a targets depend on dirs is what
|
|
# lets them be invalidated by deleted files)
|
|
FIRST=1
|
|
for x; do
|
|
if [ $FIRST -eq 1 ]; then
|
|
set --
|
|
FIRST=0
|
|
fi
|
|
if [ -d "$x" ]; then
|
|
if [ -f "$OUT" ] && [ "$x" -nt "$OUT" ]; then
|
|
$RM "$OUT"
|
|
fi
|
|
continue
|
|
fi
|
|
if [ "$x" != "${x%.o}" ]; then
|
|
set -- "$@" "$x"
|
|
fi
|
|
done
|
|
|
|
set -- "$AR" "$ARFLAGS" "$OUT" "$@"
|
|
printf %s\\n "$*" >"$OUT.cmd"
|
|
|
|
OUTDIR="${OUT%/*}"
|
|
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
|
|
$MKDIR "$OUTDIR" || exit 2
|
|
fi
|
|
|
|
printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
|
# if [ "$SILENT" = "0" ]; then
|
|
# # some of these windows nt archives are quite huge
|
|
# COLUMNS=${COLUMNS:-80}
|
|
# COLUMNS=$((COLUMNS - 4))
|
|
# printf "%s\n" "$*" |
|
|
# /usr/bin/fold -s -w $COLUMNS |
|
|
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
|
|
# else
|
|
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
|
|
# fi
|
|
|
|
REASON=failed
|
|
trap REASON=interrupted INT
|
|
|
|
"$@" >/dev/null && exit
|
|
|
|
if [ "$TERM" = "dumb" ]; then
|
|
f='%s %s\r\n\r\n'
|
|
else
|
|
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
|
|
fi
|
|
printf "$f" "archive $REASON:" "$*" >&2
|
|
exit 1
|