1 # Usage:
2 # source build/common.sh
3
4 # Include guard.
5 test -n "${__BUILD_COMMON_SH:-}" && return
6 readonly __BUILD_COMMON_SH=1
7
8 if test -z "${REPO_ROOT:-}"; then
9 echo 'build/common.sh: $REPO_ROOT should be set before sourcing'
10 exit 1
11 fi
12
13 set -o nounset
14 set -o errexit
15 #eval 'set -o pipefail'
16
17 # New version is slightly slower -- 13 seconds vs. 11.6 seconds on oils-for-unix
18 readonly CLANG_DIR_RELATIVE='../oil_DEPS/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04'
19
20 CLANG_DIR_1=$REPO_ROOT/$CLANG_DIR_RELATIVE
21 CLANG_DIR_FALLBACK=~/git/oilshell/oil/$CLANG_DIR_RELATIVE
22 if test -d $CLANG_DIR_1; then
23 CLANG_DIR=$CLANG_DIR_1
24 CLANG_IS_MISSING=''
25 else
26 # BUG FIX: What if we're building _deps/ovm-build or ../benchmark-data/src?
27 # Just hard-code an absolute path. (We used to use $PWD, but I think that
28 # was too fragile.)
29 CLANG_DIR=$CLANG_DIR_FALLBACK
30 CLANG_IS_MISSING='T'
31 fi
32 readonly CLANG_DIR
33
34 readonly CLANG=$CLANG_DIR/bin/clang # used by benchmarks/{id,ovm-build}.sh
35 readonly CLANGXX=$CLANG_DIR/bin/clang++
36
37 # I'm not sure if there's a GCC version of this?
38 export ASAN_SYMBOLIZER_PATH=$CLANG_DIR_RELATIVE/bin/llvm-symbolizer
39
40 # ThreadSanitizer doesn't always give us all locations, but this doesn't help
41 # export TSAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH
42
43 # equivalent of 'cc' for C++ language
44 # https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc
45 CXX=${CXX:-'c++'}
46
47 # Compiler flags we want everywhere.
48 # - -Weverything is more than -Wall, but too many errors now.
49 # - -fno-omit-frame-pointer is what Brendan Gregg says should always be on.
50 # Omitting the frame pointer might be neglibly faster, but reduces
51 # observability. It's required for the 'perf' tool and other kinds of tracing.
52 # Anecdotally the speed difference was in the noise on parsing
53 # configure-coreutils.
54 # - TODO(6/22): Disabled invalid-offsetof for now, but we should enable it after
55 # progress on the garbage collector. It could catch bugs.
56
57 BASE_CXXFLAGS='-std=c++11 -Wall -Wno-invalid-offsetof -fno-omit-frame-pointer'
58
59 readonly PY27=Python-2.7.13
60
61 readonly PREPARE_DIR=$REPO_ROOT/../oil_DEPS/cpython-full
62
63 log() {
64 echo "$@" >&2
65 }
66
67 die() {
68 log "$0: FATAL: $@"
69 exit 1
70 }
71
72 can-compile-32-bit() {
73 # Try compiling a basic file
74 c++ -m32 -o /dev/null build/detect-cc.c
75 }