#!/bin/bash
#force chromium to link against host system libs.
# got this from 'chromium.SlackBuild'

# The array of possible replacements of embedded with system libraries is
# found in 'build/linux/unbundle/replace_gn_files.py':
gn_system_libraries=(
  # 'bzip2'
  'ffmpeg'
  'flac'
  'freetype'
  'harfbuzz-ng'
  'icu'
  'libdrm'
  # 'libevent'
  'libjpeg'
  'libpng'
  'libvpx'
  'libwebp'
  'libxml'
  'libxslt'
  # 'openh264'
  # 'opus'
  're2'
  # 'snappy'
  'zlib'
  )

# Unbundle the libraries which we use from the system.
# (taken from Arch Linux:)
# This *should* do what the remove_bundled_libraries.py script does,
# with the added benefit of not having to list all the remaining libraries:
echo "-- Unbundling system libraries from $PRGNAM sources."
for ULIB in ${gn_system_libraries[@]}; do
  find -type f -path "*third_party/$ULIB/*" \
    \! -path "*third_party/$ULIB/chromium/*" \
    \! -path "*third_party/$ULIB/google/*" \
    \! -regex '.*\.\(gn\|gni\|isolate\)' \
    -delete
done

# Change bundled libraries to system ones:
echo "-- Change bundled to system libraries in $PRGNAM sources."
python3 build/linux/unbundle/replace_gn_files.py --system-libraries ${gn_system_libraries[@]}



