| 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-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 | |
| 14 | if test -z "$BUILD_CMD"; then |
| 15 | BUILD_CMD="$(fc -nl -0 2>/dev/null || true)" |
| 16 | fi |
| 17 | ## remove whitespaces before/after the actual command: |
| 18 | BUILD_CMD="$(echo "${BUILD_CMD}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" |
| 19 | if test -z "$BUILD_CMD"; then |
| 20 | BUILD_CMD="$0" |
| 21 | fi |
| 22 | |
| 23 | set -e |
| 24 | |
| 25 | ## make sure that commands use English in their output, instead of the local system's local: |
| 26 | export LANG=C |
| 27 | |
| 28 | if ! 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 |
| 31 | fi |
| 32 | |
| 33 | export CFLAGS='-O3' |
| 34 | export CURRENT_SCRIPT_PATH=$(realpath "$0") |
| 35 | |
| 36 | export TCC_COMMIT="${TCC_COMMIT:-mob}" |
| 37 | export TCC_FOLDER="${TCC_FOLDER:-thirdparty/tcc.$TCC_COMMIT}" |
| 38 | export CC="${CC:-clang}" |
| 39 | |
| 40 | echo " BUILD_CMD: \`$BUILD_CMD\`" |
| 41 | echo " CC: $CC" |
| 42 | echo "TCC_COMMIT: $TCC_COMMIT" |
| 43 | echo "TCC_FOLDER: \`$TCC_FOLDER\`" |
| 44 | echo =============================================================== |
| 45 | |
| 46 | rm -rf tinycc/ |
| 47 | rm -rf thirdparty/tcc.original/ |
| 48 | rsync -a thirdparty/tcc/ thirdparty/tcc.original/ |
| 49 | ## rm -rf $TCC_FOLDER |
| 50 | |
| 51 | pushd . |
| 52 | |
| 53 | git clone https://repo.or.cz/tinycc.git |
| 54 | |
| 55 | cd tinycc |
| 56 | |
| 57 | git checkout $TCC_COMMIT |
| 58 | export 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 . |
| 61 | for 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 | |
| 83 | gmake |
| 84 | gmake install |
| 85 | |
| 86 | popd |
| 87 | |
| 88 | rsync -a --delete tinycc/$TCC_FOLDER/* $TCC_FOLDER/ |
| 89 | rsync -a thirdparty/tcc.original/.git/ $TCC_FOLDER/.git/ |
| 90 | rsync -a thirdparty/tcc.original/lib/libgc* $TCC_FOLDER/lib/ |
| 91 | rsync -a thirdparty/tcc.original/lib/build* $TCC_FOLDER/lib/ |
| 92 | rsync -a thirdparty/tcc.original/README.md $TCC_FOLDER/README.md |
| 93 | rsync -a $CURRENT_SCRIPT_PATH $TCC_FOLDER/build.sh |
| 94 | mv $TCC_FOLDER/tcc $TCC_FOLDER/tcc.exe |
| 95 | |
| 96 | date > $TCC_FOLDER/build_on_date.txt |
| 97 | echo $TCC_COMMIT_FULL_HASH > $TCC_FOLDER/build_source_hash.txt |
| 98 | $TCC_FOLDER/tcc.exe --version > $TCC_FOLDER/build_version.txt |
| 99 | uname -a > $TCC_FOLDER/build_machine_uname.txt |
| 100 | |
| 101 | ## needed for Big Sur |
| 102 | ln -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 | |
| 107 | pushd . |
| 108 | cd $TCC_FOLDER |
| 109 | git add . |
| 110 | git commit -m "build with \`$BUILD_CMD\`" |
| 111 | popd |
| 112 | |
| 113 | echo "tcc commit: $TCC_COMMIT , full hash: $TCC_COMMIT_FULL_HASH ." |
| 114 | echo "The tcc executable is ready in $TCC_FOLDER/tcc.exe" |
| 115 | |