# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           conflicts_build 1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1
PortGroup           meson 1.0

# _SC_PHYS_PAGES, openat
legacysupport.newest_darwin_requires_legacy 10

set realname        netatalk
set branch          4
name                ${realname}${branch}
conflicts           ${realname}

github.setup        Netatalk ${realname} ${branch}-5-1 ${realname}-
version             [string map {- .} ${github.version}]
revision            0
categories          net
license             GPL-2+
maintainers         {@trodemaster icloud.com:manuals-unread2u} openmaintainer
homepage            https://netatalk.io
description         Netatalk is a freely-available Open Source AFP fileserver.
long_description    {*}${description}. It allows Unix-like operating systems \
                    to serve as file servers for Macintosh computers.

distname            ${realname}-${version}
use_xz              yes
checksums           rmd160  30986ad34619e6c4cee961296c2507ba44c52057 \
                    sha256  f091de10b0c40996ebf7d6502cf947cfd87dfe1a7e62f9d96013225573938524 \
                    size    1305244
github.tarball_from releases

meson.wrap_mode     nodownload

depends_build-append \
                    port:bison \
                    port:cmark-gfm \
                    port:flex \
                    path:bin/perl:perl5 \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:avahi \
                    port:bstring \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:iniparser \
                    port:kerberos5 \
                    port:libevent \
                    port:libgcrypt \
                    port:libiconv \
                    path:lib/libldap.dylib:openldap \
                    port:sqlite3

# libtirpc is a supported and prioritized option, but the build fails with it:
# /opt/local/include/tirpc/rpc/rpcent.h:55:8: error: redefinition of 'struct rpcent'
# /opt/local/include/tirpc/rpc/rpcent.h:62:23: error: conflicting types for 'getrpcbyname'; have 'struct rpcent *(const char *)'
# nfsquota.c:131:24: error: 'rpc_uint' undeclared (first use in this function); did you mean 'rpcent'?
conflicts_build     libtirpc

# cc1: error: unrecognized command line option "-std=c11"
compiler.c_standard 2011

configure.args-append   -Dwith-cnid-backends=sqlite \
                        -Dwith-init-style=none \
                        -Dwith-libiconv-path=${prefix} \
                        -Dwith-lockfile-path=${prefix}/var/run \
                        -Dwith-pam-config-path=${prefix}/etc/pam.d \
                        -Dwith-spotlight=true \
                        -Dwith-spotlight-backends=cnid

if {[string match *gcc* ${configure.compiler}] && ${configure.build_arch} in [list arm i386 ppc]} {
    configure.ldflags-append \
                        -latomic
}

# nad_ls.c:638:39: error: passing argument 4 of 'scandir' from incompatible pointer type [-Wincompatible-pointer-types]
if {${os.platform} eq "darwin" && ${os.major} < 13} {
    configure.cflags-append \
                        -D_MACPORTS_LEGACY_COMPATIBLE_SCANDIR=1
}

startupitem.create      yes
startupitem.executable  ${prefix}/sbin/netatalk -d -F ${prefix}/etc/afp.conf
startupitem.logfile ${prefix}/var/log/${name}.log
startupitem.logfile.stderr ${prefix}/var/log/${name}-stderr.log
startupitem.logevents   yes
startupitem.debug       yes

notes "
    Configuration files can be found in:
        ${prefix}/etc/
    
    Log files can be found in:
        ${prefix}/var/log/
"
