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