app=samba
version=4.15.5
build=2sml
homepage="https://www.samba.org"
download="https://download.samba.org/pub/samba/stable/samba-4.15.5.tar.gz"
desc="CIFS file and print server, version 4"
requires="acl attr netbsd-curses readline libcap tar db popt libaio perl-modules"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions

  applypatch $srcdir/add_missing___compar_fn_t.patch
  applypatch $srcdir/getpwent_r.patch
  applypatch $srcdir/missing-headers.patch
  applypatch $srcdir/musl_rm_unistd_incl.patch
  applypatch $srcdir/musl_uintptr.patch
  applypatch $srcdir/netapp.patch
  applypatch $srcdir/netdb-defines.patch
  applypatch $srcdir/tevent.patch
  applypatch $srcdir/pidl.patch
  applypatch $srcdir/samba-bgqd-include-signal-h.patch

  SAMBAJOBS="$(echo $MAKEFLAGS | sed 's@-j@@')"

  # Enabling quotas results in "[2022/03/05 14:15:09.123806,  0] ../../source3/lib/sysquotas.c:566(sys_get_quota)
  # sys_path_to_bdev() failed for path [.]!
  # in logs, so disable them
  # https://codeberg.org/davidak/nixos-config/issues/5
  # https://lists.samba.org/archive/samba/2010-October/158650.html

  ./configure \
    --prefix="/" \
    --bindir=/bin \
    --sbindir=/bin \
    --libexecdir=/lib \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --docdir=/doc/"$app-$version" \
    --with-configdir=/etc/samba \
    --with-lockdir=/var/lock \
    --with-logfilebase=/var/log \
    --with-piddir=/var/run \
    --with-privatedir=/etc/samba \
    --without-ldap \
    --without-ads \
    --without-pam \
    --without-ad-dc \
    --without-systemd \
    --without-gettext \
    --without-gpgme \
    --disable-rpath-install \
    --disable-python \
    --without-regedit \
    --without-quotas \
    --jobs="$SAMBAJOBS" 

  make
  make install DESTDIR=$pkg

  cp COPYING $pkgdocs/

  cp examples/smb.conf.default $pkg/etc/samba/smb.conf.new

  rmdir $pkg/bind-dns

  preprunitservice smbd down
  preprunitservice nmbd down

  mkfinalpkg
}

sha512sums="
808e0f15931bab18a1e36298528a01a1250efaef9f99508dd620d6936dd4a2fc3ccc64ab9dcc94bd73460697d16d6ca0652ccbcdbe1644ffedce0137d796d3ca  samba-4.15.5.tar.gz
bc2df70e327fea5dfbd923600225f1448815d842c37d6937dd74eab7f7699d7f52cd7a8e28a61233974649cf86661a0107dce5019d33b71205e4b41bac73f4e2  add_missing___compar_fn_t.patch
58de5e79fdfd06e828d478e112d581d333a8bee88d2602b92204d780f0d707b27dd84f8e2e6b00fca40da81c8fe99aa5bcec70d8b393d3a0a83199c72a4aa48b  getpwent_r.patch
c0afe8b1dfddc5290c9aa611163d20adc3a546f54bba0081f739cda4255829f1a72bae422b6cb049aca82e58d4daf63ad5553f4c5c51671019bfbbc2781460f0  missing-headers.patch
9bf4bbc8b03d9ea17d2f8ffeaf3a83541b171936a90bb8d75b08cc5afbdbaaec545c1b3782c90ae2ffc4568ab4e6f15fb21899d80c654a796301e16429c93b65  musl_rm_unistd_incl.patch
b7906d66fe55a980a54161ee3f311b51bcbce76b8d4c8cc1ba6d0c5bdf98232cb192b9d2c1aa7b3e2742f5b9848c6cf429347940eefe66c3e0eda1d5aac1bf93  musl_uintptr.patch
3b4759dfcf6ec54f2131390c9eb7fd7dd23071e304905cdeaf7a9828fa888cb3dcb5c5bb6a07a634c51d0392ac47f6e22b937faf4354e3b07cfc0de7fdfa28e9  netapp.patch
1854577d0e4457e27da367a6c7ec0fb5cfd63cefea0a39181c9d6e78cf8d3eb50878cdddeea3daeec955d00263151c2f86ea754ff4276ef98bc52c0276d9ffe8  netdb-defines.patch
c0bbe1186b150a9bb2a0b741a8cfbd7a5109e5fed1eaa07aaa38cf026ebe054d38cc01e2496f0cab7b40f743e1b7ecfbf8a4d5820810226c4152021df65f36dc  pidl.patch
e98fd19f65d954f04f7e3b5be86e9c4bcc9ac090c40037de77bfeb266617747c514aeb42f3daf84113b2f3374480d25e368bc1fdebc1870458eda12329d2062e  samba-bgqd-include-signal-h.patch
e7441d4692c354ff265ec5b5666ebd8c02762cffd805b4af6fdcb405e9b7641e195d068b60bb0ed1ffada4db4db84492db598efd37d0a27d66b5b4c923891891  tevent.patch
"
