toybox/scripts/portability.sh
<<
>>
Prefs
   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 a pointless warning only clang produces
  26[ -n "$("$CROSS_COMPILE$CC" --version | grep -w clang)" ] &&
  27  CFLAGS+=" -Wno-string-plus-int"
  28
  29# Address Sanitizer
  30if [ -n "$ASAN" ]; then
  31  # Turn ASan on and disable most optimization to get more readable backtraces.
  32  # (Technically ASAN is just "-fsanitize=address" and the rest is optional.)
  33  export CFLAGS="$CFLAGS -fsanitize=address -O1 -g -fno-omit-frame-pointer -fno-optimize-sibling-calls"
  34  export NOSTRIP=1
  35  # Ignore leaks on exit. TODO
  36  export ASAN_OPTIONS="detect_leaks=0"
  37  # only do this once
  38  unset ASAN
  39fi
  40
  41# Probe number of available processors, and add one.
  42: ${CPUS:=$(($(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)+1))}
  43
  44# Centos 7 bug workaround, EOL June 30 2024. TODO
  45DASHN=-n; wait -n 2>/dev/null; [ $? -eq 2 ] && unset DASHN
  46
  47# If the build is using gnu tools, make them behave less randomly.
  48export LANG=c
  49export LC_ALL=C
  50