# Maintainer: PktSurf <smlinux@pktsurf.in>
app=postfix
version=3.4.9
build=2sml
homepage="https://www.postfix.org/"
download="https://cdn.postfix.johnriley.me/mirrors/postfix-release/official/postfix-$version.tar.gz"
desc="Fast, secure and easy-to-administer mail server"
requires="pcre openssl sqlite db icu"

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

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

build() {

  AUXLIBS="-lssl -lcrypto" \
  CCARGS="-DNO_NIS -DNO_NISPLUS -DUSE_TLS" \
    make -f Makefile.init makefiles

  make

  sh postfix-install -non-interactive \
    install_root=$pkg \
    daemon_directory=/lib/postfix \
    manpage_directory=/share/man \
    command_directory=/bin

  cp COPYRIGHT LICENSE $pkgdocs/

  (
    cd $pkg/etc/postfix
    mv master.cf.proto master.cf.proto.new
    mv aliases aliases.new
    mv access access.new
    mv main.cf main.cf.new
    mv canonical canonical.new
    mv transport transport.new
    mv makedefs.out makedefs.out.new
    mv postfix-files postfix-files.new
    mv header_checks header_checks.new
    mv master.cf master.cf.new
    mv bounce.cf.default bounce.cf.default.new
    mv virtual virtual.new
    mv generic generic.new

    cd ../../

    # unnecessary stupidity hardcoded in the Makefile
    mv usr/sbin/sendmail bin/ 
    cd bin 
    ln -s sendmail mailq
    ln -s sendmail newaliases
    rm -rv $pkg/usr
  )

  preprunitservice -s postfix -d
  preprunitservice -s postfix.ssl -d

  mkfinalpkg
}

sha512sums="
83c62f7d4f9394354a30cc3ece54f5bbfb09f33716d7a24d36493ed937f360c7eaee268562bc88b0efffd26a6077206b14baf7803853b1857334b76eb4beecf0  postfix-3.4.9.tar.lz
"
