summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 64fc7863e35e3471d94c688ce177279a03e8379b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Maintainer: bkuri <aur+nzbget-git@bkuri.com>
# Contributor: selfdenial <selfdenial@pm.me>
# Contributor: Nicola Hinssen <nicola.hinssen@gmail.com>
# Contributor: Jan Holthuis <holthuis.jan@googlemail.com>

pkgbase=nzbget-git
pkgname=(nzbget-git nzbget-git-debug)
pkgver=24.5.r2530.184834d3
pkgrel=2
pkgdesc="Download from Usenet using .nzb files (testing release)"

arch=('x86_64')
install=nzbget.install
license=('GPL')
options=('debug' '!lto')
url="https://github.com/nzbgetcom/nzbget"

depends=('libxml2' 'openssl')
makedepends=('cmake' 'boost' 'git')
optdepends=('nzbget-git-debug: Debug symbols for nzbget'
			'python: run scripts'
            'unrar: unpacking archives'
            'p7zip: unpacking archives')

conflicts=('nzbget' 'nzbget-systemd')
provides=('nzbget' 'nzbget-systemd')

source=("$pkgname::git+https://github.com/nzbgetcom/nzbget.git#branch=develop"
        "nzbget.service")

sha256sums=('SKIP'
            'e92d2d09e56930475c9f28641a3326a17aa187834e1bd6328a65b6ed7cc25e99')

prepare() {
  cd "${srcdir}/${pkgbase}"
  
  # Ensure build directory exists
  mkdir -p build
  
  # Set environment variables to control build locations
  export HOME="${srcdir}"
  export XDG_CACHE_HOME="${srcdir}/.cache"
  export XDG_DATA_HOME="${srcdir}/data"
  export XDG_CONFIG_HOME="${srcdir}/config"
}

build() {
  cd "${srcdir}/${pkgbase}/build"

  # Configure the build to generate debug symbols
  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_POLICY_DEFAULT_CMP0167=NEW \
    -DDEBUG_SYMBOLS=ON

  # Build the project
  cmake --build . -j $(nproc)
}

check() {
  cd "${srcdir}/${pkgbase}/build"
  ctest --output-on-failure
}

package_nzbget-git() {
  cd "${srcdir}/${pkgname}/build"
  DESTDIR="$pkgdir" cmake --install .
  
  # Install systemd service file
  install -Dm644 "${srcdir}/nzbget.service" "${pkgdir}/usr/lib/systemd/system/nzbget.service"
  
  # Create necessary directories
  install -dm 755 "${pkgdir}/var/lib/nzbget"
  install -dm 755 "${pkgdir}/usr/share/nzbget"
  
  # Install additional files
  cd "${srcdir}/${pkgname}"
  install -Dm 644 README.md "${pkgdir}/usr/share/nzbget/README.md"
  install -Dm 644 nzbget.conf "${pkgdir}/usr/share/nzbget/nzbget.conf"

  # Remove unnecessary build artifacts
  rm -rf "${pkgdir}/usr/src"
  rm -rf "${pkgdir}/home"
  
  # Strip binary (added back)
  cd "$pkgdir/usr/bin"
  if [[ -f nzbget && "$(file -bi nzbget)" == *"application/x-executable"* ]]; then
    strip --strip-all nzbget
  fi
}

package_nzbget-git-debug() {
  pkgdesc="Debug symbols for nzbget-git"
  depends=("nzbget-git=$pkgver")
  options=('!strip')

  # Create debug directory
  install -dm755 "${pkgdir}/usr/lib/debug"

  # Copy debug symbols
  cd "${srcdir}/${pkgbase}/build"
  find . -name "*.debug" -exec install -Dm644 {} "${pkgdir}/usr/lib/debug/{}" \;

  # Optionally, copy full debug symbols for the binary
  if [[ -f "${srcdir}/${pkgbase}/build/nzbget" ]]; then
    objcopy --only-keep-debug "${srcdir}/${pkgbase}/build/nzbget" "${pkgdir}/usr/lib/debug/usr/bin/nzbget.debug"
  fi
}

pkgver() {
  cd "${srcdir}/${pkgbase}"
  
  # Extract version from CMakeLists.txt
  local _pkgver=$(grep -oP 'set\(VERSION "\K[^"]+' CMakeLists.txt)
  
  # Get commit count and short hash
  local _rev=$(git rev-list --count HEAD)
  local _hash=$(git rev-parse --short HEAD)
  
  # Construct and print version string
  printf "%s.r%s.%s" "${_pkgver}" "${_rev}" "${_hash}"
}