v / thirdparty / build_scripts / thirdparty-linux-amd64_tcc.sh
98 lines · 77 sloc · 3.4 KB · 8fdd1e67112bb5412bd476cfbbd001307111eb06
Raw
1## NOTE: this script does *not* use a shebang **deliberately**, in order to
2## access the same shell, to capture its own launching command with `fc`,
3## and to record it later in the new commit message in thirdpart/tcc.
4
5## WARNING: THE ORIGINAL OF THIS SCRIPT IS IN:
6## https://github.com/vlang/v/blob/master/thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh ,
7## I.E. IN THE MAIN V REPOSITORY. IF YOU NEED TO MAKE CHANGES, CHANGE THAT.
8##
9## THE `build.sh` FILE IN `vlang/tccbin` REPO IS A COPY, RECORDED AT THE TIME
10## OF REBUILDING, FOR EASIER/RELIABLE REPRODUCTION OF HISTORIC VERSIONS.
11## IT IS NOT INTENDED TO BE MODIFIED.
12
13if test -z "$BUILD_CMD"; then
14 BUILD_CMD="$(fc -nl -0 2>/dev/null || true)"
15fi
16## remove whitespaces before/after the actual command:
17BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
18if test -z "$BUILD_CMD"; then
19 BUILD_CMD="$0"
20fi
21
22set -e
23
24if ! test -f vlib/v/compiler_errors_test.v; then
25 echo "this script should be run in V's main repo folder!"
26 exit 1
27fi
28
29export CURRENT_SCRIPT_PATH=$(realpath "$0")
30
31export TCC_COMMIT="${TCC_COMMIT:-mob}"
32export TCC_FOLDER="${TCC_FOLDER:-thirdparty/tcc.$TCC_COMMIT}"
33export CC="${CC:-gcc}"
34
35echo " BUILD_CMD: \`$BUILD_CMD\`"
36echo " CC: $CC"
37echo "TCC_COMMIT: $TCC_COMMIT"
38echo "TCC_FOLDER: \`$TCC_FOLDER\`"
39echo ===============================================================
40
41rm -rf tinycc/
42rm -rf thirdparty/tcc.original/
43rsync -a thirdparty/tcc/ thirdparty/tcc.original/
44## rm -rf $TCC_FOLDER
45
46pushd .
47
48git clone https://repo.or.cz/tinycc.git
49
50cd tinycc
51
52git checkout $TCC_COMMIT
53export TCC_COMMIT_FULL_HASH=$(git rev-parse HEAD)
54
55## Note: crt1.o is located in:
56## /usr/lib/x86_64-linux-gnu on Debian/Ubuntu
57## /usr/lib64 on Redhat/CentOS
58## /usr/lib on ArchLinux
59
60./configure \
61 --prefix=$TCC_FOLDER \
62 --bindir=$TCC_FOLDER \
63 --crtprefix=$TCC_FOLDER/lib:/usr/lib/x86_64-linux-gnu:/usr/lib64:/usr/lib:/lib/x86_64-linux-gnu:/lib \
64 --libpaths=$TCC_FOLDER/lib/tcc:$TCC_FOLDER/lib:/usr/lib/x86_64-linux-gnu:/usr/lib64:/usr/lib:/lib/x86_64-linux-gnu:/lib:/usr/local/lib/x86_64-linux-gnu:/usr/local/lib \
65 --cc=$CC \
66 --extra-cflags=-O3 \
67 --config-bcheck=yes \
68 --config-backtrace=yes \
69 --debug
70
71make
72make install
73
74popd
75
76rsync -a --delete tinycc/$TCC_FOLDER/ $TCC_FOLDER/
77rsync -a thirdparty/tcc.original/.git/ $TCC_FOLDER/.git/
78rsync -a thirdparty/tcc.original/lib/libgc* $TCC_FOLDER/lib/
79rsync -a thirdparty/tcc.original/lib/build* $TCC_FOLDER/lib/
80rsync -a thirdparty/tcc.original/README.md $TCC_FOLDER/README.md
81rsync -a $CURRENT_SCRIPT_PATH $TCC_FOLDER/build.sh
82mv $TCC_FOLDER/tcc $TCC_FOLDER/tcc.exe
83
84date > $TCC_FOLDER/build_on_date.txt
85echo $TCC_COMMIT_FULL_HASH > $TCC_FOLDER/build_source_hash.txt
86$TCC_FOLDER/tcc.exe --version > $TCC_FOLDER/build_version.txt
87uname -a > $TCC_FOLDER/build_machine_uname.txt
88
89## show the builtin search paths for sanity checking:
90$TCC_FOLDER/tcc.exe -v -v
91
92pushd .
93cd $TCC_FOLDER
94git add .
95git commit -m "build with \`$BUILD_CMD\`"
96popd
97
98echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH . The tcc executable is ready in $TCC_FOLDER/tcc.exe "
99