| 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 | |
| 13 | if test -z "$BUILD_CMD"; then |
| 14 | BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" |
| 15 | fi |
| 16 | ## remove whitespaces before/after the actual command: |
| 17 | BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" |
| 18 | if test -z "$BUILD_CMD"; then |
| 19 | BUILD_CMD="$0" |
| 20 | fi |
| 21 | |
| 22 | set -e |
| 23 | |
| 24 | if ! 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 |
| 27 | fi |
| 28 | |
| 29 | export CURRENT_SCRIPT_PATH=$(realpath "$0") |
| 30 | |
| 31 | export TCC_COMMIT="${TCC_COMMIT:-mob}" |
| 32 | export TCC_FOLDER="${TCC_FOLDER:-thirdparty/tcc.$TCC_COMMIT}" |
| 33 | export CC="${CC:-gcc}" |
| 34 | |
| 35 | echo " BUILD_CMD: \`$BUILD_CMD\`" |
| 36 | echo " CC: $CC" |
| 37 | echo "TCC_COMMIT: $TCC_COMMIT" |
| 38 | echo "TCC_FOLDER: \`$TCC_FOLDER\`" |
| 39 | echo =============================================================== |
| 40 | |
| 41 | rm -rf tinycc/ |
| 42 | rm -rf thirdparty/tcc.original/ |
| 43 | rsync -a thirdparty/tcc/ thirdparty/tcc.original/ |
| 44 | ## rm -rf $TCC_FOLDER |
| 45 | |
| 46 | pushd . |
| 47 | |
| 48 | git clone https://repo.or.cz/tinycc.git |
| 49 | |
| 50 | cd tinycc |
| 51 | |
| 52 | git checkout $TCC_COMMIT |
| 53 | export 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 | |
| 71 | make |
| 72 | make install |
| 73 | |
| 74 | popd |
| 75 | |
| 76 | rsync -a --delete tinycc/$TCC_FOLDER/ $TCC_FOLDER/ |
| 77 | rsync -a thirdparty/tcc.original/.git/ $TCC_FOLDER/.git/ |
| 78 | rsync -a thirdparty/tcc.original/lib/libgc* $TCC_FOLDER/lib/ |
| 79 | rsync -a thirdparty/tcc.original/lib/build* $TCC_FOLDER/lib/ |
| 80 | rsync -a thirdparty/tcc.original/README.md $TCC_FOLDER/README.md |
| 81 | rsync -a $CURRENT_SCRIPT_PATH $TCC_FOLDER/build.sh |
| 82 | mv $TCC_FOLDER/tcc $TCC_FOLDER/tcc.exe |
| 83 | |
| 84 | date > $TCC_FOLDER/build_on_date.txt |
| 85 | echo $TCC_COMMIT_FULL_HASH > $TCC_FOLDER/build_source_hash.txt |
| 86 | $TCC_FOLDER/tcc.exe --version > $TCC_FOLDER/build_version.txt |
| 87 | uname -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 | |
| 92 | pushd . |
| 93 | cd $TCC_FOLDER |
| 94 | git add . |
| 95 | git commit -m "build with \`$BUILD_CMD\`" |
| 96 | popd |
| 97 | |
| 98 | echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH . The tcc executable is ready in $TCC_FOLDER/tcc.exe " |
| 99 | |