-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheoscpp
executable file
·81 lines (69 loc) · 1.85 KB
/
eoscpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash -e
SDKDIR="$( dirname "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" )"
function copy_skeleton {
cp -r $SDKDIR/share/eosiocontract/skeleton .
echo "TODO: renaming step"
}
function build_contract {
output=$1
shift
workdir=`mktemp -d`
mkdir $workdir/built
for file in $@; do
name=`basename $file`
filePath=`dirname $file`
$SDKDIR/bin/clang++ -emit-llvm -O3 --std=c++14 --target=wasm32 -ffreestanding -nostdlib -fno-threadsafe-statics -fno-rtti -fno-exceptions -I $SDKDIR/include -I $filePath -c $file -o $workdir/built/$name
done
$SDKDIR/bin/llvm-link -o $workdir/linked.bc $workdir/built/*
$SDKDIR/bin/llc --asm-verbose=false -o $workdir/assembly.s $workdir/linked.bc
$SDKDIR/bin/s2wasm -o $output -s 1024 $workdir/assembly.s
rm -rf $workdir
}
function print_help {
echo "Usage: $0 output.wast contract.cpp [other.cpp ...]"
echo " OR"
echo " $0 -n mycontract"
echo
echo "Options:"
echo " -n | --newcontract [name]"
echo " Create a new contract in the [name] folder, based on the example contract"
}
OPTIONS=$(getopt --options=hn: --longoptions=help,newcontract: --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
# getopt failed
exit 2
fi
eval set -- "$OPTIONS"
while true; do
case "$1" in
-n|--newcontract)
newname=$2
shift 2
;;
-h|--help)
print_help
exit 1
;;
--)
shift
break
;;
*)
echo "Unrecognized option: $1"
exit 1
;;
esac
done
if [[ "x" == "x$newname" ]]; then
if [[ $# -le 1 ]]; then
print_help
exit 1
fi
build_contract $@
else
if [[ $# -ne 0 ]]; then
print_help
exit 1
fi
copy_skeleton $newname
fi