# -*- 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           github 1.0

github.setup        pennmush pennmush 187p0
revision            0
categories          games
license             Artistic-1 BSD
maintainers         nomaintainer
description         The PennMUSH mud server
long_description \
   There are a number of flavors of MUSH server freely available to those \
   who want to run their own MUSHes: TinyMUSH 3.0, TinyMUSH 2.2, TinyMUX 1.6, \
   and PennMUSH 1.7.x. TinyMUSH uses a disk-based database, while PennMUSH \
   keeps its database in the computer's memory (TinyMUX can do either). This \
   makes PennMUSH suitable for computers which have plenty of memory or \
   little disk space. From a user standpoint they offer many similar features \
   and a very similar command parser.

homepage            https://www.pennmush.org/

checksums           rmd160  9ef170502af9b7e4e640360f80f83d6fa3744d6d \
                    sha256  674057a3abd7d8ae331a67339e43608b3cf35576e7cd90020944069b02fc35ad \
                    size    4343410

depends_lib         path:lib/libssl.dylib:openssl port:pcre path:bin/perl:perl5 port:gettext

patchfiles          patch-getentropy.diff

# work around some autoconf deficiencies and force some cflags in explicitly.
configure.env       PERL=${prefix}/bin/perl \
                    CURL_CONFIG=${prefix}/bin/curl-config CURL_CFLAGS=-I${prefix}/include CURL_LIBS=-L${prefix}/lib\ -lcurl
configure.args      --without-mysql --without-postgresql \
                    --with-openssl=${prefix} \
                    --with-pcre=${prefix}

post-build {
   system "cd ${worksrcpath}/game/txt && make clean all"
}

set pennmush_install_dir ${prefix}/libexec/${name}

# Do our own install since the Makefiles aren't quite up to snuff for
# full autoconf use yet...
destroot {
   global pennmush_install_dir
   xinstall -m 755 -d ${destroot}${pennmush_install_dir}
   copy {*}[glob ${worksrcpath}/game/*] ${destroot}${pennmush_install_dir}
   xinstall -m 755 ${worksrcpath}/src/netmud \
      ${destroot}${pennmush_install_dir}/netmush
   xinstall -m 755 ${worksrcpath}/src/info_slave \
      ${destroot}${pennmush_install_dir}
   xinstall -m 755 ${worksrcpath}/utils/ln-dir.sh \
      ${destroot}${pennmush_install_dir}
   reinplace "s|GAMEDIR=|GAMEDIR=${pennmush_install_dir}|g" \
      ${destroot}${pennmush_install_dir}/restart.dst
   delete ${destroot}${pennmush_install_dir}/mush.cnf
}

post-activate {
   global pennmush_install_dir
   if {![file exists ${pennmush_install_dir}/mush.cnf]} {
      copy ${pennmush_install_dir}/mushcnf.dst ${pennmush_install_dir}/mush.cnf
   }
}

variant mysql5 description {Use MySQL for database} {
   depends_lib-append      path:bin/mysql_config5:mysql5
   configure.args-delete   --without-mysql
   configure.args-append   --with-mysql=${prefix}/bin/mysql_config5
}

variant postgresql16 description {Use PostgreSQL for database} {
   depends_lib-append      port:postgresql16
   configure.args-delete   --without-postgresql
   configure.args-append   --with-postgresql=${prefix}/lib/postgresql16/bin/pg_config
   configure.env-append    POSTGRESQL_CPPFLAGS=-I${prefix}/include/postgresql16 \
                           POSTGRESQL_LDFLAGS=-L${prefix}/lib/postgresql16
}