# work around linker errors, see https://bbs.archlinux32.org/viewtopic.php?pid=4894#p4894
eval "$(
declare -f build | \
  sed '
    /_flags/ a _flags+=('fatal_linker_warnings=false')
  '
)"

# fix regression uintptr_t in vaapi
source+=(chromium-vaapi-uintptr.patch)
sha256sums+=('c1b2285dec2acae6108a496cba9230680cd5eedf3467d4563ec4b546fc8224aa')

eval "$(
  declare -f prepare | \
    sed '
      /chromium-vaapi-fix-the/a patch -Np1 -i ../chromium-vaapi-uintptr.patch
    '
)"

# no SAMUFLAGS, see https://www.mail-archive.com/pacman-dev@archlinux.org/msg17258.html
# going the sed-way
eval "$(
  declare -f build | \
    sed '
      s/ninja/ninja -j 1/
    '
)"

# can't create dynamic relocation R_386_32 against local symbol in readonly segment
eval "$(
  declare -f build | \
    sed '
      /gn gen/ i \
        sed -i '\''s/ldflags += [[] "-m32" []]/ldflags += [ "-m32", "-Wl,-z,notext" ]/'\'' build/config/compiler/BUILD.gn
    '
)"

# disable SSE2 for i686 (no i486 yet, flags are in the same place for MMX and SSE math, but
# we don't even have a gui yet), also disable SSE math as this is not supported with march=i686
# (at least  gcc)
if [ "$CARCH" = 'i686' ]; then
  eval "$(
    declare -f build | \
      sed '
        /gn gen/ i \
          sed -i '\''s/"-msse2"/""/'\'' build/config/compiler/BUILD.gn \
          sed -i '\''s/"-mfpmath=sse"/""/'\'' build/config/compiler/BUILD.gn
      '
  )"
fi

# disabled: not complete and completely broken, use --no-sandbox for now when running
# for for 64-bit time functions in seccomp sanbox (thanks to schnitzeltony)
# https://github.com/schnitzeltony/meta-browser/blob/master/recipes-browser/chromium/files/0003-Fix-sandbox-Aw-snap-for-syscalls-403-and-407.patch
#source+=('chromium-81.0.4044.122-Fix-sandbox-Aw-snap-for-syscalls-403-and-407.patch')
#sha256sums+=('4837f797a910795bf3161805a3302d5f3701573ca90da8af32b2f4aa62510d20')
#eval "$(
#  declare -f prepare | \
#    sed '
#      /patch.*chromium-106.*/a patch -Np1 -i "$srcdir/chromium-81.0.4044.122-Fix-sandbox-Aw-snap-for-syscalls-403-and-407.patch"
#    '
#)"

# reenable 32-bit
source+=('reenable-linux-i686-builds.patch')
sha256sums+=('f3d3702106e2307c00f1db97fa2614bbedd208ecb217052e3cc789945e17a139')
eval "$(
  declare -f prepare | \
    sed '
      /patch.*chromium-106.*/a patch -Np1 -i "$srcdir/reenable-linux-i686-builds.patch"
    '
)"