aboutsummaryrefslogtreecommitdiff
path: root/scripts/portability.sh
blob: 3af2be5f445408cb8bb6653e98b2680cbc41a3ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# sourced to find alternate names for things

source ./configure

if [ -z "$(command -v "${CROSS_COMPILE}${CC}")" ]
then
  echo "No ${CROSS_COMPILE}${CC} found" >&2
  exit 1
fi

if [ -z "$SED" ]
then
  [ ! -z "$(command -v gsed 2>/dev/null)" ] && SED=gsed || SED=sed
fi

# Tell linker to do dead code elimination at function level
if [ "$(uname)" == "Darwin" ]
then
  : ${LDOPTIMIZE:=-Wl,-dead_strip} ${STRIP:=strip}
else
  : ${LDOPTIMIZE:=-Wl,--gc-sections -Wl,--as-needed} ${STRIP:=strip -s -R .note* -R .comment}
fi

# Address Sanitizer
if [ ! -z "$ASAN" ]; then
  # Turn ASan on and disable most optimization to get more readable backtraces.
  # (Technically ASAN is just "-fsanitize=address" and the rest is optional.)
  ASAN_FLAGS="-fsanitize=address -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls"
  CFLAGS="$CFLAGS $ASAN_FLAGS"
  HOSTCC="$HOSTCC $ASAN_FLAGS"
  NOSTRIP=1
  # Ignore leaks on exit. TODO
  export ASAN_OPTIONS="detect_leaks=0"
  unset ASAN
fi

# Centos 7 bug workaround, EOL June 30 2024. TODO
DASHN=-n; wait -n 2>/dev/null; [ $? -eq 2 ] && unset DASHN

# If the build is using gnu tools, make them behave less randomly.
export LANG=c
export LC_ALL=C