# https://snapcraft.io/docs/snapcraft-yaml-reference

name: ${PROJECT_SLUG}
title: ${PROJECT_NAME}
base: core18
#base: core20
version: '${PROJECT_VERSION}'
summary: ${PROJECT_DESCRIPTION}
description: |
  An application to create and edit animations for the web and similar.

#icon: share/${PROJECT_SLUG}/${PROJECT_SLUG}/images/logo.svg
icon: data/images/logo.svg
grade: stable
confinement: strict
passthrough:
    license: GPL-3.0

apps:
    ${PROJECT_SLUG}:
        command: bin/${PROJECT_SLUG}
        desktop: share/applications/${PROJECT_ID}.desktop
        plugs:
            - desktop
            - desktop-legacy
            - wayland
            - unity7
            - home
        extensions:
            - kde-neon
        #command-chain:
            #- snap/command-chain/snapcraft-runner
            #- snap/command-chain/desktop-launch

#assumes:
    #- command-chain
#environment:
    #SNAP_DESKTOP_RUNTIME: "$SNAP/kf5"
    #LD_LIBRARY_PATH: "$SNAP/opt:$LD_LIBRARY_PATH"
#plugs:
    #icon-themes:
        #interface: content
        #target: $SNAP/data-dir/icons
        #default-provider: gtk-common-themes
    #kde-frameworks-5-plug:
        #interface: content
        #content: kde-frameworks-5-core18-all
        #target: $SNAP/kf5
        #default-provider: kde-frameworks-5-core18
    #sound-themes:
        #interface: content
        #target: $SNAP/data-dir/sounds
        #default-provider: gtk-common-themes

parts:
    ${PROJECT_SLUG}:
        source: .
        source-type: local
        #source: https://gitlab.com/mattbas/glaxnimate.git
        #source-type: git
        #source-branch: release
        plugin: cmake
        #build-packages:
        #    - g++
        #    - cmake
        #    - qtbase5-dev
        #    - libpython3-dev
        #    - zlib1g-dev
        #    - make
        #stage-packages:
        #    - libqt5xml5
        #    - libqt5widgets5
        #    - libpython3.8
        #    - zlib1g
        #    - libgtk3-nocsd0
        ## I think there's a better way of doing this? but documentation isn't clear
        ##override-stage: snapcraftctl stage; cp -r /root/parts/glaxnimate/install/usr/local/* /root/stage
        #override-prime: |
        #    snapcraftctl prime
        #    cp -r /root/parts/glaxnimate/install/usr/local/* /root/prime
        #    #cp -r /opt /root/prime/opt
        build-packages:
           - libpython3-dev
           - zlib1g-dev
           - make
           - libpotrace-dev
           - libarchive-dev
           - libvpx-dev
           - x264
        stage-packages:
           - libpython3.6
           - zlib1g
           - libgtk3-nocsd0
           - libpotrace0
           - libarchive-dev
           - libvpx5
           - x264
        override-build: |
            # base
            apt-get update -qq
            apt-get install -y libpython3-dev python3-pip software-properties-common desktop-file-utils zlib1g-dev
            # updated packaged
            add-apt-repository ppa:beineri/opt-qt-5.15.2-bionic -y
            add-apt-repository ppa:ubuntu-toolchain-r/test -y
            apt update -qq
            apt-get install -y qt515base qt515tools qt515translations libgl1-mesa-dev g++-9 qt515svg
            pip3 install cmake
            export LD_LIBRARY_PATH=/opt/qt515/lib/
            # ffmpeg
            apt-get install -y git build-essential nasm pkg-config
            git clone https://github.com/FFmpeg/FFmpeg.git --branch release/4.4
            cd FFmpeg/
            ./configure --disable-static --enable-shared
            make -j4
            make install
            cd ..
            # build
            cmake $SNAPCRAFT_PART_SRC -DCMAKE_CXX_COMPILER=/usr/bin/g++-9 -DQt5_DIR=/opt/qt515/lib/cmake/Qt5 -DCMAKE_PREFIX_PATH=/opt/qt515/lib/cmake/Qt5LinguistTools/
            make -j4
            make translations
            make install DESTDIR=$SNAPCRAFT_PART_INSTALL
        # I think there's a better way of doing this? but documentation isn't clear
        override-stage: |
            snapcraftctl stage
            cp -r $SNAPCRAFT_PART_INSTALL/usr/local/* $SNAPCRAFT_STAGE
            cp -r /usr/local/lib/* $SNAPCRAFT_STAGE/lib
            mkdir -p $SNAPCRAFT_STAGE/lib/x86_64-linux-gnu/
            cp /usr/lib/x86_64-linux-gnu/libstdc++.so* $SNAPCRAFT_STAGE/lib/x86_64-linux-gnu/
        override-prime: |
            snapcraftctl prime
            cp -r $SNAPCRAFT_PART_INSTALL/usr/local/* $SNAPCRAFT_PRIME
            cp -r /usr/local/lib/* $SNAPCRAFT_PRIME/lib
            cp -fr /opt/qt515/* $SNAPCRAFT_PRIME
            mkdir -p $SNAPCRAFT_PRIME/lib/x86_64-linux-gnu/
            cp /usr/lib/x86_64-linux-gnu/libstdc++.so* $SNAPCRAFT_PRIME/lib/x86_64-linux-gnu/
