summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 7580769bf5950f6e5b2321d0409782f7a2e768b3 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# Maintainer:  Chris Severance aur.severach aATt spamgourmet dott com
# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Iacopo Isimbaldi <isiachi@rhye.it>
# Contributor: Jan Houben <jan@nexttrex.de>
# Contributor: Jesus Alvarez <jeezusjr at gmail dot com>

# todo: why is -git in the middle of linux-git-headers?

_opt_DKMS=0

_opt_UTIL=2 # default 2
# 0 - zfs-utils is a separate package
# 1 - zfs-utils is a package split here
# 2 - zfs-utils is integrated into zfs-linux

_opt_git=''
_opt_git='-git'

# Additional option: see _commit below
# Commit branches with newer version numbers have both newer and older code than master.

set -u
pkgbase="zfs-linux${_opt_git}"
pkgname=("${pkgbase}")
if [ "${_opt_DKMS}" -eq 0 ]; then
  pkgname+=("${pkgbase}-headers")
fi
if [ "${_opt_UTIL}" -eq 1 ]; then
  pkgname+=("zfs-utils${_opt_git}")
fi
pkgver=2.2.99.r537.gfd51786f86
pkgrel=1
_pkgver="${pkgver%%.r*}"
#_commit="#branch=zfs-${_pkgver%.*}-release"
arch=('x86_64')
url='https://zfsonlinux.org/'
license=('CDDL')
depends=('kmod' 'linux')
makedepends=('perl' 'python')
if [ ! -z "${_opt_git}" ]; then
  makedepends+=('git' 'linux-headers')
  _srcdir='zfs'
else
  _srcdir="zfs-${_pkgver}"
fi
options=('!strip')
source=(
  "https://github.com/zfsonlinux/zfs/releases/download/zfs-${_pkgver}/zfs-${_pkgver}.tar.gz"
  '0001-only-build-the-module-in-dkms.conf.patch'
)
if [ "$(vercmp "${_pkgver}" '0.8.3')" -eq 0 ]; then
  source+=('linux-5.5-compat-blkg_tryget.patch')
fi
source+=(
  'zfs.initcpio.install'
  'zfs.initcpio.hook'
)
md5sums=('SKIP'
         'f607f969110a7b36a7a45b28b1f4343d'
         'eca615c602740315333aedd417d83541'
         'fa15be4761c8a56ad0177d1a06a4c7f8')
sha256sums=('SKIP'
            '0b28be1e55248435739c9d68fd85acd969b150a5b6216fd63d05cf892e352dac'
            'da1cdc045d144d2109ec7b5d97c53a69823759d8ecff410e47c3a66b69e6518d'
            '9c20256093997f7cfa9e7eb5d85d4a712d528a6ff19ef35b83ad03fb1ceae3bc')
b2sums=('SKIP'
        'becb6d74105f79e41b653abe41e3666d0c67c5640de30a512a425deaed83a49113526e66930a30fb0f61d04867f7b9b5c562c8638ab095f0c1be5db46cab7950'
        '570e995bba07ea0fb424dff191180b8017b6469501964dc0b70fd51e338a4dad260f87cc313489866cbfd1583e4aac2522cf7309c067cc5314eb83c37fe14ff3'
        'e14366cbf680e3337d3d478fe759a09be224c963cc5207bee991805312afc49a49e6691f11e5b8bbe8dde60e8d855bd96e7f4f48f24a4c6d4a8c1bab7fc2bba0')

_extramodules="$(uname -r)"

# Find valid installed kernel to build for next boot after upgrading kernel
_fn_calc_extramodules() {
  local _ev="${_extramodules%%-*}"
  local _fmax=''
  local _f _fv
  for _f in /usr/lib/modules/${_ev%.*}.*/build/Makefile; do
    _f="${_f#/usr/lib/modules/}"
    _f="${_f%/build/Makefile}"
    _fv="${_f%%-*}"
    if [ -z "${_fmax}" ] || [ "$(pkgver "${_ev}" "${_fmax}")" -ge 0 ]; then
      _fmax="${_f}"
    fi
  done
  if [ ! -z "${_fmax}" ] && [ "${_extramodules}" != "${_fmax}" ]; then
    set +u; msg "Found upgraded kernel ${_fmax}"; set -u
    _extramodules="${_fmax}"
  fi
}

if [ ! -z "${_opt_git}" ]; then
  source[0]="git+https://github.com/zfsonlinux/zfs.git${_commit:-}"
  md5sums[0]='SKIP'
  sha256sums[0]='SKIP'
  b2sums[0]='SKIP'
pkgver() {
  set -u
  cd "${_srcdir}"
  git describe --long | sed -e 's/^zfs-//' -e 's/\([^-]*-g\)/r\1/' -e 's/-/./g'
  set +u
}
elif [ "${_pkgver}" != "${pkgver}" ]; then
pkgver() {
  set -u
  echo "${_pkgver}"
  set +u
}
fi

if [ ! -z "${HOME:-}" ]; then # block mksrcinfo
  _fn_calc_extramodules
  _fn_calc_extramodules() { true; }
  if [ "${_opt_DKMS}" -eq 0 ]; then
    pkgver+=".k${_extramodules%%-*}"
  fi
fi

prepare() {
  set -u
  cd "${_srcdir}"

  #From: Eli Schwartz <eschwartz@archlinux.org>
  #Date: Sun, 28 Oct 2018 15:01:58 -0400
  #Subject: [PATCH] only build the module in dkms.conf
  #cd '..'; cp -pr "${_srcdir}" 'a'; ln -s "${_srcdir}" 'b'; false
  # diff -pNaru4 'a' 'b' > '0001-only-build-the-module-in-dkms.conf.patch'
  patch -Nup1 -i "${srcdir}/0001-only-build-the-module-in-dkms.conf.patch"

  # DKMS install customized all the way back to autoconf
  local _dkmsdir="${srcdir}/dkms.Arch"
  # makepkg -i on git packages reruns prepare()
  if [ ! -z "${_opt_git}" ]; then
    rm -rf "${_dkmsdir}"
  fi
  if [ "${_opt_DKMS}" -ne 0 ] && [ ! -d "${_dkmsdir}" ]; then
    install -d "${_dkmsdir}"
    cp -rp . "${_dkmsdir}"
    pushd "${_dkmsdir}" > /dev/null
    rm -f 'configure'
    # remove unneeded sections from module build
    sed -re "/AC_CONFIG_FILES/,/]\)/{
/AC_CONFIG_FILES/n
/]\)/n
/^\s*(module\/.*)?(${pkgname%-dkms}.release|Makefile)/!d
}" -i 'configure.ac'
    popd > /dev/null
  fi
  set +u
}

build() {
  set -u
  cd "${_srcdir}"
  if [ ! -s 'configure' ]; then
    ./autogen.sh
  fi
  if [ "${_opt_DKMS}" -ne 0 ]; then
    local _dkmsdir="${srcdir}/dkms.Arch"
    pushd "${_dkmsdir}" > /dev/null
    if [ ! -s 'configure' ]; then
      ./autogen.sh
      ./scripts/dkms.mkconf -n 'zfs' -v "${_pkgver}" -f 'dkms.conf'
      if [ ! -z "${_opt_git}" ]; then
        # update metadata
        ./scripts/make_gitrev.sh
        local _meta_release="${pkgver#*.r}"
        sed -e "s/Release:[[:print:]]*/Release:      ${_meta_release/./_}/" -i 'META'
      fi
    fi
    popd > /dev/null
  fi
  if [ ! -s 'Makefile' ]; then
    _fn_calc_extramodules
    local _cf=(
      --prefix='/usr'
      --sysconfdir='/etc'
      --sbindir='/usr/bin'
      --libdir='/usr/lib'
      --datadir='/usr/share'
      --includedir='/usr/include'
      --with-udevdir='/usr/lib/udev'
      --libexecdir='/usr/lib/zfs'
      # kernel module build
      --with-config='kernel'
      --with-linux="/usr/lib/modules/${_extramodules}/build"
      --with-linux-obj="/usr/lib/modules/${_extramodules}/build"
    )
    if [ "${_opt_UTIL}" -ge 1 ]; then
      _cf+=(
      # utils build
      --with-config='user'
      --enable-pyzfs='no'
      --with-mounthelperdir='/usr/bin'
      # all build
      --with-config='all'
      )
      if [ "$(vercmp "${pkgver}" '0.8.0')" -le 0 ] && [ -z "${_opt_git}" ]; then
        # pyzfs is not built, but build system tries to check for python anyway
        # fixed in master
        ln -s '/bin/true' 'python3-fake'
        _cf+=(
          --with-python="${PWD}/python3-fake"
        )
      fi
    fi
    nice \
    ./configure "${_cf[@]}"
  fi
  nice make -s

  # make install is very slow. Much faster to do this once and copy
  rm -rf "${srcdir}/inst"
  install -d "${srcdir}/inst"
  make -s -j1 DESTDIR="${srcdir}/inst" install
  set +u
}

package_zfs-linux-git() {
  set -u
  pkgdesc='Kernel modules for the Zettabyte File System.'
  install='zfs.install'
  provides=("zfs=${_pkgver}" "zfs-linux=${_pkgver}" "spl=${_pkgver}")
  #groups=('archzfs-linux-git')
  conflicts=('zfs-dkms' 'zfs-dkms-git' 'zfs-dkms-rc' 'spl-dkms' 'spl-dkms-git' 'zfs-linux' 'spl-linux-git' 'spl-linux')
  replaces=('spl-linux-git')
  #if [ "${_opt_UTIL}" -le 1 ]; then
    depends+=("zfs-utils>=${_pkgver}")
  #fi

  cd "${_srcdir}"
  cp -rp "${srcdir}/inst"/* "${pkgdir}"

  _fix_modules
  if [ "${_opt_UTIL}" -eq 2 ]; then
    provides+=("zfs-utils=${_pkgver}")
    conflicts+=('zfs-linux' 'zfs-utils')
    _fix_utils
  else
    _del_utils
  fi
  _del_headers

  if [ "${_opt_DKMS}" -eq 0 ]; then
    # linux not maintained by severach are broken without provides
    if [ "$(vercmp "${_extramodules%%-*}" '4.19')" -lt 0 ]; then
      # I don't want Linux version info showing on AUR web. After a few months 'linux<0.0.0' makes it look like an out of date package.
      _fn_calc_extramodules
      local _kernelversionsmall="${_extramodules}"
      _kernelversionsmall="${_kernelversionsmall%%-*}"
      _kernelversionsmall="${_kernelversionsmall%.0}" # trim 4.0.0 -> 4.0, 4.1.0 -> 4.1
      # prevent the mksrcinfo bash emulator from getting these vars!
      #eval 'conf''licts+=("linux>${_kernelversionsmall}" "linux<${_kernelversionsmall}")'
      eval 'dep''ends+=("linux=${_kernelversionsmall}")'
    fi
  else
    depends+=('dkms')
    conflicts+=('zfs-linux-headers')
    #depends+=('lsb-release') # patched away
    _del_modules
    pushd "${srcdir}/dkms.Arch" > /dev/null
    local _dkmsdir="${pkgdir}/usr/src/zfs-${_pkgver}"
    install -d "${_dkmsdir}"/{config,scripts}
    cp -a configure dkms.conf Makefile.in META zfs_config.h.in zfs.release.in include/ module/ "${_dkmsdir}"/
    cp config/config.* config/missing config/*sh "${_dkmsdir}"/config/
    cp scripts/enum-extract.pl scripts/dkms.postbuild "${_dkmsdir}"/scripts/
    popd > /dev/null
  fi
  set +u
}
_z="$(declare -f package_zfs-linux-git)"; eval "${_z//-git/}"

_fix_modules() {
  pushd "${pkgdir}" > /dev/null
  install -d 'usr/lib'
  mv lib/* 'usr/lib/'
  rmdir 'lib'
  popd > /dev/null
}

_del_utils() {
  pushd "${pkgdir}" > /dev/null
  if [ -d 'usr/share' ]; then
    mv 'usr/lib/modules' .
    mv 'usr/src' .
    rm -r 'etc' 'usr'
    install -d 'usr/lib'
    mv 'src' 'usr/'
    mv 'modules' 'usr/lib/'
  fi
  popd > /dev/null
}

_del_headers() {
  pushd "${pkgdir}" > /dev/null
  rm -r 'usr/src'
  popd > /dev/null
}

_del_modules() {
  pushd "${pkgdir}" > /dev/null
  rm -r 'usr/lib/modules'
  rmdir --ignore-fail-on-non-empty -p 'usr/lib'
  popd > /dev/null
}

package_zfs-utils-git() {
  set -u
  pkgdesc='Userspace utilities for the Zettabyte File System.'
  depends=('systemd')
  optdepends=(
    'python: for arcstat/arc_summary/dbufstat'
  )
  provides=("${pkgname%-git}=${pkgver%%.r*}")
  conflicts=("${pkgname%-git}")
  cd "${_srcdir}"

  cp -rp "${srcdir}/inst"/* "${pkgdir}"

  _fix_utils
  _fix_modules
  _del_modules
  _del_headers
  set +u
}
_z="$(declare -f package_zfs-utils-git)"; eval "${_z//-git/}"

_fix_utils() {
  install -D -m644 contrib/bash_completion.d/zfs "${pkgdir}"/usr/share/bash-completion/completions/zfs
  # Remove uneeded files
  rm -r "${pkgdir}"/etc/init.d
  rm -r "${pkgdir}"/etc/sudoers.d #???
  # We're experimenting with dracut in [extra], so start installing this.
  #rm -r "${pkgdir}"/usr/lib/dracut
  rm -r "${pkgdir}"/usr/lib/modules-load.d
  rm -r "${pkgdir}"/usr/share/initramfs-tools
  rm -r "${pkgdir}"/usr/share/zfs/zfs-tests # For zpool set compatibility

  install -D -m644 "${srcdir}"/zfs.initcpio.hook "${pkgdir}"/usr/lib/initcpio/hooks/zfs
  install -D -m644 "${srcdir}"/zfs.initcpio.install "${pkgdir}"/usr/lib/initcpio/install/zfs
}

package_zfs-linux-git-headers() {
  set -u
  pkgdesc='Kernel headers for the Zettabyte File System.'
  depends=("zfs-utils=${_pkgver}")
  provides=("zfs-headers=${_pkgver}" "zfs-linux-headers=${_pkgver}" "spl-headers=${_pkgver}")
  conflicts=('zfs-headers' 'zfs-dkms' 'zfs-dkms-git' 'zfs-dkms-rc' 'spl-dkms' 'spl-dkms-git' 'spl-headers')

  cd "${_srcdir}"
  cp -rp "${srcdir}/inst"/* "${pkgdir}/"

  _fix_modules
  _del_utils
  _del_modules

  # Remove reference to ${srcdir}
  _fn_calc_extramodules
  sed -e "s+${srcdir}++" -i "${pkgdir}"/usr/src/zfs-*/${_extramodules}/Module.symvers
  set +u
}
_z="$(declare -f package_zfs-linux-git-headers)"; eval "${_z//-git/}"
unset _z

set +u