name: synfigstudio
title: 'Synfig Studio'
summary: Create and edit 2D animations and compositions
description: |
  Synfig Studio is a free and open-source 2D animation software, designed as
  powerful industrial-strength solution for creating film-quality animation
  using a vector and bitmap artwork. It eliminates the need to create
  animation frame-by frame, allowing you to produce 2D animation of a higher
  quality with fewer people and resources.

  Features:

  - Can manipulate vector and bitmap artwork
  - Automatic tweening (independent from FPS)
  - Multitude of layers of various types (geometry primitives, shapes,
  gradients, fractals)
  - Full-featured bone system
  - Filters and effects for compositing (blurs, distortions, color
  manipulation, masks)
  - All color operations use High Dynamic-Range Imaging (HDRI)
  - Pentablet-friendly tools
  - Sound support
  - Linking data on file- or parameter-level
  - Automatic animation using mathematical functions

base: core18
adopt-info: cleanup
confinement: strict
license: GPL-3.0

architectures:
  - build-on: amd64

apps:
  synfigstudio: &app
    command: usr/bin/synfigstudio
    common-id: org.synfig.SynfigStudio
    desktop: usr/share/applications/org.synfig.SynfigStudio.desktop
    extensions: [gnome-3-34]
    plugs: &plugs [opengl, home, removable-media, gsettings, network]
    environment: &env
      __EGL_VENDOR_LIBRARY_DIRS: $SNAP/gnome-platform/usr/share/glvnd/egl_vendor.d:$SNAP/usr/share/glvnd/egl_vendor.d
      PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

  synfig:
    command: usr/bin/synfig
    extensions: [gnome-3-34]
    plugs: *plugs
    environment: *env

layout:
  /usr/share/synfig:
    symlink: $SNAP/usr/share/synfig
  /usr/share/pixmaps/synfigstudio:
    symlink: $SNAP/usr/share/pixmaps/synfigstudio

parts:
  synfig-deps:
    plugin: nil
    build-packages:
      - g++
      - intltool
      - gettext
      - libmagickcore-dev
      - libmagick++-dev
      - libopenexr-dev
      - libsigc++-2.0-dev
      - libxml++2.6-dev
      - libfftw3-dev
      - libmlt-dev
      - libmlt++-dev
      - libmlt-data
      - libmng-dev
      - git
      - libxml2-utils # to extract version from appdata file
    stage-packages:
      - libilmbase12
      - libmagick++-6.q16-7
      - libmagic1
      - libmlt++3
      - libmlt6
      - libmng2
      - libopenexr22
      - libsigc++-2.0-0v5
      - libxml++2.6-2v5
      - libdv-bin # mod_dv
      - ffmpeg # mod_ffmpeg
      - libflite1 # ffmpeg required
      - imagemagick # mod_imagemagick
      - libglu1-mesa
      - freeglut3
      - python3-lxml # lottie exporter

  etl:
    after: [synfig-deps]
    plugin: autotools
    source: ETL
    configflags: &cfgflags
      - --prefix=/usr

  synfig-core:
    after: [etl]
    plugin: autotools
    source: synfig-core
    configflags: *cfgflags
    override-build: &build |
      set -xe
      autoreconf -i
      intltoolize --force
      snapcraftctl build

  synfig-studio:
    after: [synfig-core]
    plugin: autotools
    source: synfig-studio
    configflags: *cfgflags
    override-build: *build

  cleanup:
    after: [synfig-studio]
    plugin: nil
    build-snaps: [core18, gnome-3-34-1804]

    override-stage: |
      set -xe
      snapcraftctl stage

      appdata_file="usr/share/appdata/org.synfig.SynfigStudio.appdata.xml"
      appdata_version=$(xmllint --xpath 'string(//release[1]/@version)' "$appdata_file")

      # fix the icon path and point it to a file inside the snap
      sed -i -E "s|^Icon=(.*)|Icon=\${SNAP}/usr/share/icons/hicolor/scalable/apps/\1.svg|g" \
        usr/share/applications/org.synfig.SynfigStudio.desktop

      cd "$SNAPCRAFT_PROJECT_DIR"

      # consider grade to be stable if commit is tagged
      git describe --exact-match HEAD && grade="stable" || grade="devel"
      snapcraftctl set-grade "$grade"

      # append build date and git hash to version for untagged ("devel") builds
      if [ "$grade" = "devel" ]; then
        githash=$(git rev-parse --short=7 HEAD)
        datestring=$(date -u +%Y%m%d)
        snapcraftctl set-version "${appdata_version}-${datestring}~${githash}"
      fi

    override-prime: |
      set -eux
      for lib in "libharfbuzz" "libglibmm" "libgiomm" "libQt" "libflite" "qt5"; do
        rm -rf "usr/lib/$SNAPCRAFT_ARCH_TRIPLET/$lib"*
      done
      for cruft in "bug" "lintian" "man" "icons/Humanity"; do
        rm -rf "$SNAPCRAFT_PRIME/usr/share/$cruft"
      done
      find $SNAPCRAFT_PRIME/usr/share/doc/ -type f -not -name 'copyright' -delete
      find $SNAPCRAFT_PRIME/usr/share -type d -empty -delete
      # Remove all files from snap that are already included in the base snap or in
      # any connected content snaps
      for snap in "core18" "gnome-3-34-1804"; do  # List all content-snaps and base snaps you're using here
        cd "/snap/$snap/current" && find . -type f,l -exec rm -f "$SNAPCRAFT_PRIME/{}" \;
      done
