forked from Neat-Lang/neat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-gcc.sh
executable file
·210 lines (200 loc) · 4.96 KB
/
release-gcc.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
set -euxo pipefail
if [ $# -lt 1 ]
then
echo "Usage: release-gcc.sh <version>"
exit 1
fi
VERSION="$1"
LLVM=0
NTFLAGS="-O"
RELEASE=""
ARCHS=64
if [ $(basename $0) == "release-llvm.sh" ]
then
LLVM=1
NTFLAGS="${NTFLAGS} -version=LLVMBackend"
RELEASE="neat-$VERSION-llvm"
elif [ $(basename $0) == "release-gcc.sh" ]
then
ARCHS="32 64"
RELEASE="neat-$VERSION-gcc"
else
echo "Unknown release name $(basename $0)"
exit 1
fi
if [ -e "$RELEASE" ]
then
echo "Release folder already exists!" 1>&2
exit 1
fi
TARGET="$RELEASE"/"$RELEASE"
mkdir -p $TARGET
rm -rf .obj
./build.sh
cp --parents $(find src -xtype f -name '*.nt' -o -name runtime.c) $TARGET
for ARCH in $ARCHS
do
ARCHFLAGS=""
if [ ARCH == "32" ]
then
ARCHFLAGS = "-m32"
fi
build/neat -backend=c -Pcompiler:src -dump-intermediates build/intermediates.txt src/main.nt -c \
$ARCHFLAGS $NTFLAGS
mkdir $TARGET/intermediate_$ARCH
cp $(cat build/intermediates.txt) $TARGET/intermediate_$ARCH/
done
if [ $LLVM -eq 0 ]
then
cat > $TARGET/build.sh <<EOT
#!/usr/bin/env bash
set -exo pipefail
if [ "\${ARCH}" == "" ]
then
ARCH=\$(getconf LONG_BIT)
echo "ARCH not set, guessing \$ARCH"
fi
DEFAULT_ARCH=""
echo "int main(void) {}" |gcc -x c - -o _platform_test
if (file _platform_test |grep -q 32-bit)
then
DEFAULT_ARCH="32"
elif (file _platform_test |grep -q 64-bit)
then
DEFAULT_ARCH="64"
else
echo "Cannot determine architecture!"
exit 1
fi
rm _platform_test
ARCHFLAG=""
if [ "\${ARCH}" != "\${DEFAULT_ARCH}" ]
then
# force targetting the ARCH architecture
ARCHFLAG="-m\${ARCH}"
fi
CFLAGS="\${CFLAGS} -Ofast -fno-strict-aliasing -pthread"
I=0
JOBS=16
OBJECTS=()
# poor man's make -j
for file in intermediate_\${ARCH}/*.c src/runtime.c; do
obj=\${file%.c}.o
gcc \$ARCHFLAG -c -fpic -rdynamic -fno-strict-aliasing \$file -o \$obj &
OBJECTS+=(\$obj)
if [ \$I -ge \$JOBS ]; then wait -n; fi
I=\$((I+1))
done
for i in \$(seq \$JOBS); do wait -n; done
gcc \$ARCHFLAG -fpic -rdynamic -fno-strict-aliasing \${OBJECTS[@]} -o neat_bootstrap -ldl -lm \$CFLAGS
rm \${OBJECTS[@]}
cat > neat.ini <<EOI
-syspackage compiler:src
-backend=c
-macro-backend=c
-running-compiler-version=$VERSION
-extra-cflags=\$ARCHFLAG
EOI
if [ \${ARCH} == "32" ]
then
cat >> neat.ini <<EOI
-m32
-macro-m32
EOI
fi
./neat_bootstrap -j src/main.nt $NTFLAGS -o neat
rm neat_bootstrap
EOT
else
if [ -f "/usr/lib/llvm/14/bin/llvm-config" ]
then
LLVM_CONFIG="/usr/lib/llvm/14/bin/llvm-config"
elif [ -f "/usr/lib/llvm-14/bin/llvm-config" ]
then
LLVM_CONFIG="/usr/lib/llvm-14/bin/llvm-config"
else
echo "Cannot find llvm-config!" 1>&2
exit 1
fi
CFLAGS="${CFLAGS:+ }-I$($LLVM_CONFIG --includedir) -L$($LLVM_CONFIG --libdir)"
cat > $TARGET/build.sh <<EOT
#!/usr/bin/env bash
set -exo pipefail
if [ -f "/usr/lib/llvm/14/bin/llvm-config" ]
then
LLVM_CONFIG="/usr/lib/llvm/14/bin/llvm-config"
elif [ -f "/usr/lib/llvm-14/bin/llvm-config" ]
then
LLVM_CONFIG="/usr/lib/llvm-14/bin/llvm-config"
else
echo "Cannot find llvm-config!" 1>&2
exit 1
fi
LLVM_CFLAGS="-I\$(\$LLVM_CONFIG --includedir) -L\$(\$LLVM_CONFIG --libdir)"
LLVM_NTFLAGS="-I\$(\$LLVM_CONFIG --includedir) -L-L\$(\$LLVM_CONFIG --libdir)"
if [ "\${ARCH}" == "" ]
then
ARCH=\$(getconf LONG_BIT)
echo "ARCH not set, guessing \$ARCH"
fi
DEFAULT_ARCH=""
echo "int main(void) {}" |gcc -x c - -o _platform_test
if (file _platform_test |grep -q 32-bit)
then
DEFAULT_ARCH="32"
elif (file _platform_test |grep -q 64-bit)
then
DEFAULT_ARCH="64"
else
echo "Cannot determine architecture!"
exit 1
fi
rm _platform_test
ARCHFLAG=""
if [ "\${ARCH}" != "\${DEFAULT_ARCH}" ]
then
# force targetting the ARCH architecture
ARCHFLAG="-m\${ARCH}"
fi
CFLAGS="\${CFLAGS:+ } \${LLVM_CFLAGS} -O2 -fno-strict-aliasing -pthread"
I=0
JOBS=16
OBJECTS=()
# poor man's make -j
for file in intermediate_\${ARCH}/*.c src/runtime.c; do
obj=\${file%.c}.o
gcc \$ARCHFLAG -c -fpic -rdynamic -fno-strict-aliasing \$file -o \$obj &
OBJECTS+=(\$obj)
if [ \$I -ge \$JOBS ]; then wait -n; fi
I=\$((I+1))
done
for i in \$(seq \$JOBS); do wait -n; done
gcc \$ARCHFLAG -fpic -rdynamic -fno-strict-aliasing \${OBJECTS[@]} -o neat_bootstrap -ldl -lm -lLLVM \$CFLAGS
rm \${OBJECTS[@]}
./neat_bootstrap -j -macro-backend=c src/main.nt \${LLVM_NTFLAGS} $NTFLAGS -o neat
rm neat_bootstrap
EOT
cat > $TARGET/neat.ini <<EOT
-syspackage compiler:src
-backend=llvm
-macro-backend=llvm
-version=LLVMBackend
-macro-version=LLVMBackend
-running-compiler-version=$VERSION
-extra-cflags=\$ARCHFLAG
EOT
fi
chmod +x $TARGET/build.sh
for ARCH in $ARCHS
do
echo "Test $ARCH"
TEST_TARGET="test_${RELEASE}_${ARCH}"
cp -R "${TARGET}" "${TEST_TARGET}"
(cd "${TEST_TARGET}" && ./build.sh)
NEAT="${TEST_TARGET}"/neat ./runtests.sh
rm -rf "${TEST_TARGET}"
done
(cd "$RELEASE"
zip -r ../"$RELEASE".zip "$RELEASE"
tar caf ../"$RELEASE".tar.xz "$RELEASE")