2006-07-20 22:57:46 +00:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
# Prime Mover
|
|
|
|
|
#
|
|
|
|
|
# © 2006 David Given.
|
|
|
|
|
# Prime Mover is licensed under the MIT open source license. To get the full
|
|
|
|
|
# license text, run this file with the '--license' option.
|
|
|
|
|
#
|
2006-07-25 09:23:21 +00:00
|
|
|
|
# $Id: shell 15 2006-07-25 09:21:06Z dtrg $
|
2006-07-20 22:57:46 +00:00
|
|
|
|
|
2006-07-25 09:23:21 +00:00
|
|
|
|
if [ -x "$(which arch 2>/dev/null)" ]; then
|
2006-07-22 12:29:40 +00:00
|
|
|
|
ARCH="$(arch)"
|
2006-07-25 09:23:21 +00:00
|
|
|
|
elif [ -x "$(which machine 2>/dev/null)" ]; then
|
2006-07-22 12:29:40 +00:00
|
|
|
|
ARCH="$(machine)"
|
2006-07-25 09:23:21 +00:00
|
|
|
|
elif [ -x "$(which uname 2>/dev/null)" ]; then
|
2006-07-22 12:29:40 +00:00
|
|
|
|
ARCH="$(uname -m)"
|
|
|
|
|
else
|
|
|
|
|
echo "pm: unable to determine target type, proceeding anyway"
|
|
|
|
|
ARCH=unknown
|
|
|
|
|
fi
|
|
|
|
|
|
2006-07-20 22:57:46 +00:00
|
|
|
|
THISFILE="$0"
|
2006-07-22 12:29:40 +00:00
|
|
|
|
PMEXEC="./.pm-exec-$ARCH"
|
2006-07-20 22:57:46 +00:00
|
|
|
|
set -e
|
|
|
|
|
|
2006-07-21 13:13:47 +00:00
|
|
|
|
GZFILE=/tmp/pm-$$.gz
|
|
|
|
|
CFILE=/tmp/pm-$$.c
|
|
|
|
|
trap "rm -f $GZFILE $CFILE" EXIT
|
|
|
|
|
|
2006-07-20 22:57:46 +00:00
|
|
|
|
extract_section() {
|
|
|
|
|
sed -e "1,/^XXXXSTART$1/d" "$THISFILE" | (
|
|
|
|
|
read size
|
|
|
|
|
dd bs=1 count=$size 2>/dev/null
|
2006-07-21 13:13:47 +00:00
|
|
|
|
) > $GZFILE
|
|
|
|
|
cat $GZFILE | zcat
|
2006-07-20 22:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# If the bootstrap's built, run it.
|
|
|
|
|
|
2006-07-22 12:29:40 +00:00
|
|
|
|
if [ "$PMEXEC" -nt $0 ]; then
|
|
|
|
|
extract_section script | "$PMEXEC" /dev/stdin "$@"
|
2006-07-20 22:57:46 +00:00
|
|
|
|
exit $?
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Otherwise, compile it and restart.
|
|
|
|
|
|
|
|
|
|
echo "pm: bootstrapping..."
|
|
|
|
|
|
2006-07-25 09:23:21 +00:00
|
|
|
|
if [ -x "$(which gcc 2>/dev/null)" ]; then
|
|
|
|
|
CC="gcc -O2 -s"
|
|
|
|
|
else
|
|
|
|
|
CC="cc"
|
|
|
|
|
fi
|
|
|
|
|
|
2006-07-20 22:57:46 +00:00
|
|
|
|
extract_section interpreter > /tmp/pm-$$.c
|
2006-07-22 12:29:40 +00:00
|
|
|
|
$CC $CFILE -o "$PMEXEC" && exec "$THISFILE" "$@"
|
2006-07-20 22:57:46 +00:00
|
|
|
|
|
|
|
|
|
echo "pm: bootstrap failed."
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
|
|
XXXXSTARTscript
|
2006-07-30 23:33:31 +00:00
|
|
|
|
10658
|
|
|
|
|
<1F> |