-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbones-autocompile
More file actions
executable file
·46 lines (36 loc) · 947 Bytes
/
bones-autocompile
File metadata and controls
executable file
·46 lines (36 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
### autocompile-script for bones
#
# usage: bones-autocompile [-h] FILENAME ARGUMENT ...
set -e
case "$1" in
-h|-help|--help)
echo "usage: bones-autocompile [-h] FILENAME ARGUMENT ..."
exit;;
esac
case "`uname`" in
Darwin) oformat="-f macho64";;
*) oformat="-f elf64";;
esac
filename=$1
shift
cachedir="$BONES_AUTOCOMPILE_CACHE"
if test -z "$cachedir"; then
cachedir=~/.autocompile-cache
fi
if test \! -d "$cachedir"; then
mkdir "$cachedir"
fi
hash=`md5sum "$filename" | sed -e 's/^\([a-f0-9]\+\).*$/\1/'`
if test -z "$hash"; then
echo "invalid filename: $filename" >2
exit 1
fi
if test -x "${cachedir}/${hash}"; then
exec "${cachedir}/${hash}" "$@"
fi
filename2=`basename "$filename"`
bones "$filename" -o "/tmp/${filename2}.s"
nasm $oformat -I/usr/share/bones/ "/tmp/${filename2}.s" -o "/tmp/${filename2}.o"
gcc "/tmp/${filename2}.o" -o "${cachedir}/${hash}"
exec "${cachedir}/${hash}" "$@"