1 # --- T2-COPYRIGHT-BEGIN ---
2 # t2/package/*/vlang/new_buildscript.patch
3 # Copyright (C) 2025 The T2 SDE Project
4 # SPDX-License-Identifier: GPL-2.0 or patched project license
5 # --- T2-COPYRIGHT-END ---
7 diff --git a/build.sh b/build.sh
9 index 000000000..aae8070be
19 +while [[ $# -gt 0 ]]; do
22 + key=$(echo $arg | cut -sd'=' -f1)
23 + val=$(echo $arg | cut -sd'=' -f2)
36 + if ! [ -z $val ]; then
37 + echo "argument $arg expected no value"
43 + if ! [ -z $val ]; then
44 + echo "argument $arg expected no value"
50 + if ! [ -z $val ]; then
51 + echo "argument $arg expected no value"
57 + if ! [ -z $val ]; then
58 + echo "argument $arg expected no value"
64 + echo "unknown argument: $arg"
68 + shift # Move to the next argument
71 +if ((show_help)); then
72 + echo "usage: ./build.sh [build|install|clean] (force-bootstrap)"
78 + echo "$1" > ".check.c"
79 + if $CC $2 ".check.c" -o ".check.exe" 2>/dev/null; then
87 + test_prog "int main() {return 0;}" $1
91 + test_prog "#include <$1>
92 + int main() { return 0; }"
96 +# ==================================== #
97 +echo -n "checking for cc: "
99 + if command -v cc 2>&1 > /dev/null; then
104 + echo Please manually set \$CC
108 +# ==================================== #
109 +echo -n "can cc compile simple program: "
110 +if [ $(test_prog "int main() {return 0;}") = 1 ]; then
114 + echo Please set \$CC to a working C compiler
117 +# ==================================== #
119 +echo -n "checking for backtrace(): "
120 +if [ $(test_prog "int main() {void* buf[1]; (void) backtrace(buf, 1);}") = 1 ]; then
126 +# ==================================== #
127 +echo -n "checking for v: "
129 +if command -v v 2>&1 > /dev/null; then
135 +# ==================================== #
136 +echo -n "checking for downloader: "
137 +if command -v wget 2>&1 > /dev/null; then
140 +elif command -v curl 2>&1 > /dev/null; then
144 + echo no curl or wget found in path
147 +# ==================================== #
148 +echo -n "checking for libgc: "
149 +if [ "$(check_cc_arg "-lgc")" = "1" ]; then
153 + echo please install libgc / gc-boehem
156 +# ==================================== #
157 +echo -n "checking for bindir: "
158 +if ! [ -z $BINDIR ]; then
160 +elif [ -d /usr/bin ]; then
164 + echo could not find bin dir. manually set \$BINDIR
167 +# ==================================== #
171 + if [ "$downloader" = "wget" ]; then
173 + elif [ "$downloader" = "curl" ]; then
179 +VFLAGS="-d dynamic_boehm"
180 +if ((!backtrace)); then
181 + VFLAGS+=" -d no_backtrace"
184 +if ((!have_v)); then
188 +if ((!force_boostrap)); then
189 + echo "skipping stage 1 (boostrap) because V in path, and force-bootstrap argument not set"
192 + if [ -f "v.c" ]; then
193 + echo "boostrap (v.c) already downloaded, skipping"
195 + echo "download boostrap (v.c)"
196 + download "v.c" "https://raw.githubusercontent.com/vlang/vc/f553add34becae265cd107b55d0d0b9907fc1b6d/v.c"
199 + echo "compile stage 1 (boostrap)"
200 + $CC v.c -o v1.exe -std=c99 -lpthread -lm -w
202 + stage1_cmd="./v1.exe"
205 +echo "compile stage 2"
206 +"$stage1_cmd" -no-parallel -o v2.exe $VFLAGS -d tools_vflags="$VFLAGS" cmd/v
208 +echo "compile stage 3"
209 +./v2.exe -nocache -o v3.exe $VFLAGS -d tools_vflags="$VFLAGS" cmd/v
211 +if ((install)); then
212 + echo "installing to /opt/vlang"
213 + mkdir -p /opt/vlang
214 + cp v3.exe "/opt/vlang/v"
215 + cp -r vlib "/opt/vlang/"
216 + cp -r thirdparty "/opt/vlang/"
217 + cp -r doc "/opt/vlang/"
218 + cp -r cmd "/opt/vlang/"
219 + cp v.mod "/opt/vlang/"
220 + cp LICENSE "/opt/vlang/"
222 + echo "creating symlink"
223 + if [ -f "$BINDIR/v" ]; then
226 + ln -s "/opt/vlang/v" "$BINDIR/v"