# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Alexandre Filgueira <alexfilgueira@cinnarch.com>
# Contributor: M0Rf30
# Contributor: unifiedlinux
# Contributor: CReimer

pkgname=cinnamon
pkgver=4.2.4
pkgrel=1
pkgdesc="Linux desktop which provides advanced innovative features and a traditional user experience"
arch=('x86_64')
url="https://github.com/linuxmint/${pkgname}"
license=('GPL2')
depends=('accountsservice' 'caribou' 'cinnamon-control-center' 'cinnamon-menus' 'cinnamon-screensaver'
         'cinnamon-session' 'cinnamon-settings-daemon' 'cjs' 'gnome-backgrounds'
         'gnome-themes-extra' 'gstreamer' 'libgnomekbd' 'libkeybinder3' 'librsvg' 'muffin'
         'network-manager-applet' 'nemo' 'polkit-gnome' 'python-cairo' 'python-dbus'
         'python-gobject' 'python-pam' 'python-pexpect' 'python-pillow' 'python-pyinotify'
         'python-tinycss' 'xapps')
optdepends=('blueberry: Bluetooth support'
            'cinnamon-translations: i18n'
            'gnome-panel: fallback mode'
            'metacity: fallback mode'
            'system-config-printer: printer settings')
makedepends=('intltool' 'gtk-doc' 'gobject-introspection')
options=('!emptydirs')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz"
        "0001-cinnamon-settings-don-t-rely-on-the-presence-of-cinn.patch"
        "set_wheel.patch"
        "default-theme.patch")
sha512sums=('6ba5a760253ece582c2b6cc037d92b9d51a1ae397312d852c4e08c5ab6e64e1f01f88f58e87bb5eaffc9e26c2a3ebcddbf0292449d5b95404deed59ad48edf38'
            '77c2229d350bb1445375d206af769f1dde9329ce3575e40e9c1d5fea3ec0f49c0a7ef36d78caf895d9224147947bd102bab924b5579dc8dc5f8d3269e0c76374'
            'fd7e117054996ed1c3dfd0f968c2bf98ca4fcee9a100221f8839a232147745ec0140e1f68eeffba58a3c44f66f26e05d433648a7a28858ec669524f7266ba04c'
            '3c460141b277df61c4546cc311fa5ecc7e7ea19a7d39a92d1d0214c37a91b4e163bc91823df7098bd2cf6fb430361cdb9839ab96abe53fe82f2a735e187de563')
b2sums=('92018afef197066765c9c3ea8e82528f77519aed60b463727b845a557ac6a8990cd509891123a63384ae5e95f39b77ff66ec1a85c42877dc7209d02a9c492a96'
        '1d873efa0d17e358f834c4374f39bbf3f74340849f9c28a0950c0a064772083798aba3435e564acdf43a94665389917788e295073d4a65cc18600d71b7a9f008'
        '3becf1f40068fc629109e6e7d464c3c484296afacc9ab6328b2ccbb3c9735bcbfa9550f9f73b430ede178ae668e37c660ce322b5b4d1873526de3d3d41185160'
        '3a7515cc7b0ca1549289be62f6d5cbd79f4b076892194f4b6264555322d430a3d6474db9ec62439f3ba41d43d1017dc39a4c44add2e5e5c09f32012b772a7041')

prepare() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    # Check for the cc-panel module path, not for the irrelevant binary
    # https://github.com/linuxmint/cinnamon/pull/7382
    patch -p1 -i ../0001-cinnamon-settings-don-t-rely-on-the-presence-of-cinn.patch

    # Use wheel group instread of sudo (taken from Fedora)
    patch -Np1 -i ../set_wheel.patch

    # Set default theme to 'cinnamon'
    patch -Np1 -i ../default-theme.patch

    # Replace MintInstall with GNOME Software
    sed -i 's/mintinstall.desktop/org.gnome.Software.desktop/' data/org.cinnamon.gschema.xml.in

    # Add polkit agent to required components
    sed -i 's/RequiredComponents=\(.*\)$/RequiredComponents=\1polkit-gnome-authentication-agent-1;/' \
        files/usr/share/cinnamon-session/sessions/cinnamon*.session

    # https://github.com/linuxmint/cinnamon/issues/3575#issuecomment-374887122
    # Cinnamon has no upstream backgrounds, use GNOME backgrounds instead
    sed -i 's|/usr/share/cinnamon-background-properties|/usr/share/gnome-background-properties|' \
        files/usr/share/cinnamon/cinnamon-settings/modules/cs_backgrounds.py

    NOCONFIGURE=1 ./autogen.sh
}

build() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    ./configure --prefix=/usr \
                --sysconfdir=/etc \
                --libexecdir=/usr/lib/cinnamon \
                --localstatedir=/var \
                --disable-static \
                --disable-gtk-doc \
                --disable-schemas-compile \
                --enable-compile-warnings=yes

    # https://bugzilla.gnome.org/show_bug.cgi?id=656231
    sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

    make
}

package() {
    cd "${srcdir}"/${pkgname}-${pkgver}

    make DESTDIR="${pkgdir}" install
}
