# Maintainer: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Alexandre Filgueira <alexfilgueira@cinnarch.com>
# Based on gnome-control-center:
# Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Jan de Groot <jgc@archlinux.org>

pkgname=cinnamon-control-center
pkgver=4.2.1
pkgrel=1
pkgdesc="The Control Center for Cinnamon"
arch=('x86_64')
url="https://github.com/linuxmint/${pkgname}"
license=('GPL')
depends=('cinnamon-settings-daemon' 'cinnamon-menus' 'colord'
         'libgnomekbd' 'libmm-glib' 'nm-connection-editor')
optdepends=('cinnamon-translations: i18n'
            'gnome-color-manager: for color management tasks'
            'gnome-online-accounts: for the online accounts module')
makedepends=('gnome-online-accounts' 'intltool' 'python')
options=('!emptydirs')
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
sha256sums=('93742e071806662194951203fe4096be0fd350b8e33ae61de2571a96f1a9f841')
b2sums=('16db678f75a4c15b4f86a49213ac60a6eed6e142bac07ceee181200061c68abca7a38c017ad8cf63886aaac474d8d799d0aaf0b356d7affaeffe7b14750b3858')

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

    NOCONFIGURE=1 ./autogen.sh
}

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

    ./configure --prefix=/usr \
                --sysconfdir=/etc \
                --localstatedir=/var \
                --enable-systemd

    #https://bugzilla.gnome.org/show_bug.cgi?id=656229
    sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0 /g' -e 's/    if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then/      func_append compile_command " -Wl,-O1,--as-needed"\n      func_append finalize_command " -Wl,-O1,--as-needed"\n\0/' libtool
    make
}

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

    # https://github.com/linuxmint/Cinnamon/pull/7382#issuecomment-374894901
    # /usr/bin/cinnamon-control-center is not meant for users, it is a development troubleshooting tool.
    # Just install the shell libs/headers.
    make -C shell  DESTDIR="${pkgdir}" install-{libcinnamon_control_center_includeHEADERS,libLTLIBRARIES,pkgconfigDATA}
    make -C panels DESTDIR="${pkgdir}" install

    install -d -o root -g 102 -m 750 "${pkgdir}"/usr/share/polkit-1/rules.d
}
