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

name                sqsh
version             2.4
revision            3
categories          sysutils databases
license             GPL-2+
maintainers         nomaintainer

description         A Sybase Shell
long_description    Sqsh (pronounced skwish) is short for SQshelL (pronounced s-q-shell), \
                    a replacement for the venerable 'isql' program supplied by Sybase.
homepage            http://sqsh.sourceforge.net/
platforms           darwin

master_sites        sourceforge
checksums           md5     0ad6cc9452d3257866ccde5f14ffa013 \
                    sha1    8446a3e03457489dddc9ecb79a5e88b0605edad3

depends_lib         port:readline port:freetds
extract.suffix      .tgz

patchfiles          patch-sqsh_readline.c \
                    patch-cmd_connect.diff

post-patch {
    reinplace "s|malloc.h|stdlib.h|" ${worksrcpath}/src/sqsh_parser/tsql.c
}

configure.env       SYBASE=${prefix} CPPFLAGS=-I${prefix}/include/freetds INCDIRS=${prefix}/include LIBDIRS=${prefix}/lib
configure.args      --with-readline --mandir=${prefix}/share/man

build.target        build         
use_parallel_build  yes

destroot.target-append install.man

post-destroot {
    file rename ${destroot}${prefix}/etc/sqshrc ${destroot}${prefix}/etc/sqshrc.sample
}

post-activate {
   if {![file exists ${prefix}/etc/sqshrc]} {
      file copy ${prefix}/etc/sqshrc.sample ${prefix}/etc/sqshrc
   } else {
      ui_msg "\n****************************************************************"
      ui_msg "The already existing sqshrc has been retained.  The distribution's"
      ui_msg "sqshrc has instead been installed to "
      ui_msg "    ${prefix}/etc/sqshrc.sample "
      ui_msg "****************************************************************"
   }
}