-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.sh
More file actions
executable file
·110 lines (86 loc) · 1.76 KB
/
b.sh
File metadata and controls
executable file
·110 lines (86 loc) · 1.76 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
set -e
USAGE="usage: $0 [-qvgrb -ttarget]"
CFLAGS="$CFLAGS -D_GREEN_EXPORT_INTERNALS"
CC=gcc
build=false
run=false
add_asm=false
vn=1
mname="$(uname -m)"
mn="$mname"
oname=test-green
declare -A GCCs=( \
[native]=gcc \
[x86_64]=x86_64-pc-linux-gnu-gcc \
[x64]=x86_64-pc-linux-gnu-gcc \
[aarch64]=aarch64-linux-gnu-gcc \
[arm64]=aarch64-linux-gnu-gcc \
)
while getopts qvgrbt:h name; do
case $name in
q) vn=0
;;
v) let ++vn
;;
g) CFLAGS+=" -g -D_GREEN_ASM_DEBUG -Wall -Werror"
add_asm=true
;;
r) run=true
;;
b) build=true
;;
t) CC="${GCCs[$OPTARG]}"
if [ -z "$CC" ]; then
echo "unknown target $OPTARG"
exit 2
fi
if [ "$OPTARG" != 'native' ]; then
mn="$(cut -d- -f1 <<<$CC)"
fi
;;
h) echo "$USAGE"
exit 0
;;
?) echo "$USAGE"
exit 2
;;
esac
done
if [ "$mn" != "$mname" ]; then
mname="$mn"
oname+=".$mname"
build=true
if $run; then
echo "can't run that target under this system"
exit 2
fi
fi
if ! $build && ! $run; then
build=true
run=true
fi
if $build && ! command -v "$CC" >/dev/null; then
echo "$CC not installed"
exit 2
fi
SOURCES="test-green.c green.c"
if $add_asm; then
SOURCES+=" green.$mname.s"
fi
if $build; then
if [ $vn -eq 1 ]; then
echo "cc $SOURCES"
elif [ $vn -ge 2 ]; then
echo "$CC -o $oname $CFLAGS $SOURCES"
fi
"$CC" -o $oname $CFLAGS $SOURCES
fi
if $run; then
if [ $vn -eq 1 ]; then
echo "test-green"
elif [ $vn -ge 2 ]; then
echo "./test-green"
fi
./test-green
fi