# Maintainer: PktSurf <smlinux@pktsurf.in>
app=samba
version=4.18.0
build=1sml
homepage="https://www.samba.org"
download="https://download.samba.org/pub/samba/stable/samba-$version.tar.gz"
desc="CIFS file and print server, version 4"
requires="acl attr netbsd-curses readline libcap tar db popt libaio perl-modules"

prepbuilddir() {
  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/netgroup.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
}

build() {
  unset CFLAGS CXXFLAGS
  ./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 \
    --disable-fault-handling

  make
  make install DESTDIR=$pkg

  cp COPYING $pkgdocs/

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

  rmdir $pkg/bind-dns

  preprunitservice -s smbd -d
  preprunitservice -s nmbd -d

  mkfinalpkg
}

sha512sums="
969acb2ece0c34ff19eac31cdef1362ffc73c6f60abc477a5ab9cb089e13d942b222a7ad7bde8833a551d55d6b42d1cec7d7b19e6919a9a142881458e2611f27  samba-4.18.0.tar.lz
bc2df70e327fea5dfbd923600225f1448815d842c37d6937dd74eab7f7699d7f52cd7a8e28a61233974649cf86661a0107dce5019d33b71205e4b41bac73f4e2  add_missing___compar_fn_t.patch
58de5e79fdfd06e828d478e112d581d333a8bee88d2602b92204d780f0d707b27dd84f8e2e6b00fca40da81c8fe99aa5bcec70d8b393d3a0a83199c72a4aa48b  getpwent_r.patch
9642e0de5a39ab940e0f53040ae20fccdbde471bed9bcca713482f26e7c88451e405bd63d719d0548975c7c4c045b51b0006672d34ec4390c3b5a618ea6c8d85  missing-headers.patch
9bf4bbc8b03d9ea17d2f8ffeaf3a83541b171936a90bb8d75b08cc5afbdbaaec545c1b3782c90ae2ffc4568ab4e6f15fb21899d80c654a796301e16429c93b65  musl_rm_unistd_incl.patch
b7906d66fe55a980a54161ee3f311b51bcbce76b8d4c8cc1ba6d0c5bdf98232cb192b9d2c1aa7b3e2742f5b9848c6cf429347940eefe66c3e0eda1d5aac1bf93  musl_uintptr.patch
f997d0bca9de64a567bccc245bec41e4aa00bacb379d8e348678dcafcf7e723e8716608c5d2d266ad816439b8b93bb8ee28371308a01c9d9c50229f1fc8deb67  netgroup.patch
c0bbe1186b150a9bb2a0b741a8cfbd7a5109e5fed1eaa07aaa38cf026ebe054d38cc01e2496f0cab7b40f743e1b7ecfbf8a4d5820810226c4152021df65f36dc  pidl.patch
e98fd19f65d954f04f7e3b5be86e9c4bcc9ac090c40037de77bfeb266617747c514aeb42f3daf84113b2f3374480d25e368bc1fdebc1870458eda12329d2062e  samba-bgqd-include-signal-h.patch
"