# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=deepin-daemon
pkgver=6.1.22
pkgrel=1
pkgdesc='Daemon handling the DDE session settings'
arch=('x86_64')
url="https://github.com/linuxdeepin/dde-daemon"
license=('GPL3')
# deepin-session-shell not added for org.deepin.dde.LockFront1, because bring in
#                      deepin-session for non-DDE users is not desirable
depends=('deepin-desktop-schemas' 'deepin-api' 'deepin-app-services' 'deepin-wloutput-daemon'
         # TODO
         'gtk3' 'libx11' 'gdk-pixbuf-xlib' 'gdk-pixbuf2' 'libxi' 'libpulse' 'glib2' 'libxcursor'
         'libxcrypt' 'libgudev' 'pam' 'iso-codes'
         # accounts
         'accountsservice' 
         # accounts/grub
         'deepin-polkit-agent' 'deepin-polkit-agent-ext-gnomekeyring'
         # accounts/keybinding/systeminfo
         'deepin-desktop-base'
         # accounts1/user
         'deepin-desktop-theme'
         # appearance
         'fontconfig' 'noto-fonts'
         # audio/session
         'pulse-native-provider' 'alsa-lib'
         # bin/backlight_helper
         'ddcutil'
         # clipboard
         'libxfixes'
         # dock
         'bamf'
         # gesture
         'deepin-widgets'
         # image_effect
         'deepin-session-ui' 'sudo'
         # inputdevices
         'imwheel' 'libxkbfile' 'procps-ng' 'psmisc'
         # iw
         'libnl'
         # keybinding
         'gvfs'
         # keybinding/default-terminal, keybinding/shortcuts/system_shortcut.go
         'deepin-application-manager'
         # misc
         'librsvg'
         # network
         'mobile-broadband-provider-info' 'org.freedesktop.secrets' 'xdg-utils'
         # network/system
         'systemd' 'systemd-libs'
         # system
         'dmidecode' 'libinput' 'lshw' 'upower'
         # systeminfo
         'lsb-release' 'udisks2' 'util-linux')
makedepends=('sqlite' 'deepin-gettext-tools' 'git' 'mercurial' 'python-gobject' 'networkmanager'
             'bluez' 'go')
optdepends=('networkmanager: for network management support'
            'bluez: for bluetooth support'
            'iw: for miracast module'
            'proxychains-ng: for proxy configuration module')
conflicts=('dde-daemon')
replaces=('dde-daemon')
groups=('deepin')
install="$pkgname.install"
source=("git+https://github.com/linuxdeepin/dde-daemon.git#tag=$pkgver"
        $pkgname-gcc-15.patch::https://github.com/linuxdeepin/dde-daemon/commit/582054f3cb14902dcf96ae6e80b1b18a22187e23.patch)
sha512sums=('e317c0f563d6b2b162ad4d9371f19f0ae8587aa1c96a115088e4006eba587ecea42da2e6a6494f0b7e3d18daf5e7a1e78a0fd0e4241f4206f0f812c1645bc442'
            '226574fd50cd3a2addcad1f67e5dbf0abcaaba4f594768195487436f26da6bf5025b087022d03db2ed18f08d0c922e057dd19ede1fc154aed9fa1224f7ef2616')

prepare() {
  cd dde-daemon
  patch -p1 -i ../$pkgname-gcc-15.patch
  go get github.com/linuxdeepin/go-gir

  # https://github.com/linuxdeepin/developer-center/discussions/3327
  sed -i 's#/usr/libexec#/usr/lib#' keybinding1/shortcuts/system_shortcut.go
  sed -i 's#${PREFIX}/libexec/#${PREFIX}/lib/#;s#${DESTDIR}/lib#${DESTDIR}${PREFIX}/lib#' Makefile

  sed -i 's|/etc/os-version|/etc/uos-version|' keybinding1/shortcuts/shortcut_manager.go
}

build() {
  cd dde-daemon

  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  
  # make -C network/nm_generator gen-nm-code
  make
}

package() {
  cd dde-daemon
  make DESTDIR="$pkgdir" PAM_MODULE_DIR=usr/lib/security install

  install -Dm644 debian/dde-daemon.sysusers "$pkgdir/usr/lib/sysusers.d/deepin-daemon.conf"
}
