v2 / thirdparty / build_scripts / thirdparty-macos-arm64_tcc.sh
110 lines · 84 sloc · 3.83 KB · 432b0afb777e4897dabd5e7941f7dcfadd5ae6e4
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-macos-arm64_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
13
14BUILD_CMD=`fc -nl -0`
15## remove whitespaces before/after the actual command:
16BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
17
18set -e
19
20## make sure that commands use English in their output, instead of the local system's local:
21export LANG=C
22
23if ! test -f vlib/v/compiler_errors_test.v; then
24 echo "this script should be run in V's main repo folder!"
25 exit 1
26fi
27
28export CFLAGS='-O3'
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:-clang}"
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 git://repo.or.cz/tinycc.git
49
50cd tinycc
51
52git checkout $TCC_COMMIT
53export TCC_COMMIT_FULL_HASH=$(git rev-parse HEAD)
54
55### NB: the symlinks below are needed, to ensure proper support for bootstrapping tcc, otherwise backtraces will be disabled .
56for i in include/*.h; do echo $i; ln -s $i $(basename $i); done
57
58# --libdir=$TCC_FOLDER/lib \
59
60./configure \
61 --prefix=$TCC_FOLDER \
62 --bindir=$TCC_FOLDER \
63 --tccdir=$TCC_FOLDER/lib \
64 --includedir=$TCC_FOLDER/include \
65 --crtprefix=$TCC_FOLDER/lib:/usr/lib \
66 --sysincludepaths=$TCC_FOLDER/include:$TCC_FOLDER/lib/include:/usr/local/include:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include \
67 --libpaths=$TCC_FOLDER/lib:/usr/local/lib:/usr/lib:/lib \
68 --config-new_macho=yes \
69 --config-codesign \
70 --cc="$CC" \
71 --extra-cflags="$CFLAGS" \
72 --config-bcheck=yes \
73 --config-backtrace=yes \
74 --enable-static \
75 --dwarf=5 \
76 --debug
77
78gmake
79gmake install
80
81popd
82
83rsync -a --delete tinycc/$TCC_FOLDER/* $TCC_FOLDER/
84rsync -a thirdparty/tcc.original/.git/ $TCC_FOLDER/.git/
85rsync -a thirdparty/tcc.original/lib/libgc* $TCC_FOLDER/lib/
86rsync -a thirdparty/tcc.original/lib/build* $TCC_FOLDER/lib/
87rsync -a thirdparty/tcc.original/README.md $TCC_FOLDER/README.md
88rsync -a $CURRENT_SCRIPT_PATH $TCC_FOLDER/build.sh
89mv $TCC_FOLDER/tcc $TCC_FOLDER/tcc.exe
90
91date > $TCC_FOLDER/build_on_date.txt
92echo $TCC_COMMIT_FULL_HASH > $TCC_FOLDER/build_source_hash.txt
93$TCC_FOLDER/tcc.exe --version > $TCC_FOLDER/build_version.txt
94uname -a > $TCC_FOLDER/build_machine_uname.txt
95
96## needed for Big Sur
97ln -s /System/DriverKit/usr/lib/libSystem.dylib $TCC_FOLDER/lib/libc.dylib
98
99## show the builtin search paths for sanity checking:
100$TCC_FOLDER/tcc.exe -v -v
101
102pushd .
103cd $TCC_FOLDER
104git add .
105git commit -m "build with \`$BUILD_CMD\`"
106popd
107
108echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH ."
109echo "The tcc executable is ready in $TCC_FOLDER/tcc.exe"
110
111