xref: /aosp_15_r20/external/toybox/scripts/portability.sh (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1# sourced to find alternate names for things
2
3source ./configure
4
5if [ -z "$(command -v "$CROSS_COMPILE$CC")" ]
6then
7  echo "No $CROSS_COMPILE$CC found" >&2
8  exit 1
9fi
10
11if [ -z "$SED" ]
12then
13  [ ! -z "$(command -v gsed 2>/dev/null)" ] && SED=gsed || SED=sed
14fi
15
16# Tell linker to do dead code elimination at function level
17if [ "$(uname)" == "Darwin" ]
18then
19  CFLAGS+=" -Wno-deprecated-declarations"
20  : ${LDOPTIMIZE:=-Wl,-dead_strip} ${STRIP:=strip}
21else
22  : ${LDOPTIMIZE:=-Wl,--gc-sections -Wl,--as-needed} ${STRIP:=strip -s -R .note* -R .comment}
23fi
24
25# Disable pointless warnings only clang produces
26[ -n "$("$CROSS_COMPILE$CC" --version | grep -w clang)" ] &&
27  CFLAGS+=" -Wno-string-plus-int -Wno-invalid-source-encoding" ||
28# And ones only gcc produces
29  CFLAGS+=" -Wno-restrict -Wno-format-overflow"
30
31# Address Sanitizer
32if [ -n "$ASAN" ]; then
33  # Turn ASan on and disable most optimization to get more readable backtraces.
34  # (Technically ASAN is just "-fsanitize=address" and the rest is optional.)
35  export CFLAGS="$CFLAGS -fsanitize=address -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls -static-libasan"
36  export NOSTRIP=1
37  # Ignore leaks on exit. TODO
38  export ASAN_OPTIONS="detect_leaks=0"
39  # only do this once
40  unset ASAN
41fi
42
43# Probe number of available processors, and add one.
44: ${CPUS:=$(($(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)+1))}
45
46# If the build is using gnu tools, make them behave less randomly.
47export LANG=c
48export LC_ALL=C
49