# set manually sysctl vm.mmap_min_addr=0 before building this package

# linker runs out of memory on 32-bit
eval "$(
  declare -f build | \
    sed '
      3 i LDFLAGS+=" -Wl,--no-keep-memory"
      3 i CFLAGS+=" -g1"
      3 i CXXFLAGS+=" -g1"
    '
)"  

# Parallel builds lead to "virtual memory exhausted"?
# not sure, if still needed (or in fact, working)
eval "$(
  declare -f build | \
    sed '
      \@^\s*echo @ {
        N
        \@\n\s*kmk @ d
      }
      s|kmk|kmk -j 1|
    ' | \
    sed '
      \@^\s*\./configure @ {
        s@--disable-\S\+@@g
        s@--enable-\S\+@@g
        s@configure @\0--only-additions --disable-kmods @
      }
    ';
)"

pkgname=(
  $(
    printf '%s\n' "${pkgname[@]}" \
    | grep '^virtualbox-guest-' \
    | grep -v -- '-nox$'
  )
)

# let's not use too much memory, gcc tmpfiles can in this
# case also be put on a real /tmp (instead of tmpfs) to reduce
# preasure on the RAM
eval "$(
  declare -f build | \
    sed '
      /source/ i \ sed -i 's/-pipe//g' Config.kmk
    '
)"