# Maintainer: Maxime Gauduin <alucryd@archlinux.org>

pkgname=skia-sharp
pkgver=2.80.3
pkgrel=0
_minor=${pkgver#*.*.}
_major=${pkgver%*.*}
_major=${_major#*.*}
_release=$pkgrel
_gittag=v$pkgver
pkgdesc='The Skia 2D Graphics library from Google exposed to .NET languages and runtimes across the board'
arch="x86_64 aarch64"
options="!check" # No testsuite
url=https://github.com/mono/SkiaSharp
license="MIT"

makedepends="
  clang
  python2
  gn
  ninja
  zlib-dev
  libpng-dev
  libwebp-dev
  libjpeg-turbo-dev
  freetype-dev 
  fontconfig-dev
  expat-dev
"
source="
	$pkgname-$_gittag.tar.gz::https://github.com/mono/skia/archive/refs/tags/$_gittag.tar.gz
	0001-dng_sdk-downgrade-for-musl-build.patch
	0002-force-python2.patch
"
builddir="$srcdir"/skia-$pkgver

prepare(){
	default_prepare
	python2 tools/git-sync-deps
}	

build(){
  CFLAGS="$CFLAGS \
    -I/usr/include/freetype2 \
    -DSKIA_C_DLL"

  extra_cflags=""
  for cflag in $CFLAGS; do
    extra_cflags="$extra_cflags\"${cflag}\","
  done
  extra_ldflags=""
  for ldflag in $LDFLAGS; do
    extra_ldflags="$extra_ldflags\"${ldflag}\","
  done

  gn gen out \
    --args="target_os=\"linux-musl\" \
            target_cpu=\"x64\" \
            cc=\"clang\" \
            cxx=\"clang++\" \
            extra_cflags=[${extra_cflags}] \
            extra_ldflags=[${extra_ldflags}] \
            skia_enable_gpu=true \
            skia_enable_tools=false \
            skia_use_dng_sdk=true \
            skia_use_icu=false \
            skia_use_piex=true \
            skia_use_sfntly=false \
            is_component_build=false \
            is_debug=false \
            is_official_build=true \
            linux_soname_version=\"${_major}.${_minor}.${_release}\""
  ninja -C out
}

package() {
  install -Dm 755 "$builddir"/out/libSkiaSharp.so -t "$pkgdir"/usr/lib/
  ln -s libSkiaSharp.so.${_major} "$pkgdir"/usr/lib/libSkiaSharp.so.${_major}.${_minor}.${_release} 
  ln -s libSkiaSharp.so "$pkgdir"/usr/lib/libSkiaSharp.so.${_major} 
  install -Dm 644 "$builddir"/LICENSE -t "$pkgdir"/usr/share/licenses/skia-sharp/
}
sha512sums="
b671194e964ca38742bf48e265ec46dfbe02f1cab96a8a0f1638e905f2fe64d7d2ca79b45b3d2d5ed25c96c9b6ebdba3b723bc9976c5a2e529f4635a4d8a30e5  skia-sharp-v2.80.3.tar.gz
aeebbd95c8fb81b49fe83ce951b7b8d7aa2d2665a16c79b448cec8a6d3d6ca3e4f8aa3fb97d4614e40175d57abb29df64fb9a1173e7b126a6b5e5b6c5fa277a3  0001-dng_sdk-downgrade-for-musl-build.patch
5bd83270f068d3570ff26d0b07e7566d89e89df935e52a62359b1d53ae49e68cc4bab681ae2f65325edd96bf0f5dce6452fe4ecfd45be157fe3ac7746d81df4c  0002-force-python2.patch
"
