# -*- 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                newlisp
version             10.7.5
revision            0
categories          lang
maintainers         nomaintainer
license             GPL-3
description         newLISP is a LISP-like scripting language
long_description    newLISP is a LISP-like scripting language for doing things \
                    you typically do with scripting languages: programming \
                    for the internet, system administration, text processing, \
                    gluing other programs together, etc. newLISP is a scripting LISP \
                    for people who are fascinated by LISP's beauty and power of expression, \
                    but who need it stripped down to easy-to-learn essentials.

homepage            http://www.newlisp.org
master_sites        sourceforge
extract.suffix      .tgz
checksums           rmd160  62acd6c9fc31438689cc221cf3541de23ef0b4d3 \
                    sha256  dc2d0ff651c2b275bc4af3af8ba59851a6fb6e1eaddc20ae75fb60b1e90126ec \
                    size    1168896
                    
depends_lib         port:readline \
                    port:libffi

patchfiles          patch-darwin.diff

post-patch {
    copy -force ${filespath}/makefile_build ${worksrcpath}
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_build
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_darwinLP64_utf8_lib
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_darwin_utf8_lib
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_darwinLP64_utf8_ffi
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_darwin_utf8_leopardPPC_ffi
    reinplace "s|%COMPILER%|${configure.cc}|" ${worksrcpath}/makefile_darwin_utf8_leopardIntel_ffi
    reinplace "s|%DEVDIR%|${developer_dir}|" ${worksrcpath}/makefile_darwin_utf8_leopardPPC_ffi
    reinplace "s|%DEVDIR%|${developer_dir}|" ${worksrcpath}/makefile_darwin_utf8_leopardIntel_ffi
    reinplace "s|%VER%|${macosx_deployment_target}|" ${worksrcpath}/makefile_darwin_utf8_leopardPPC_ffi
    reinplace "s|%VER%|${macosx_deployment_target}|" ${worksrcpath}/makefile_darwin_utf8_leopardIntel_ffi
    reinplace "s|%SDK%|${macosx_sdk_version}|" ${worksrcpath}/makefile_darwin_utf8_leopardPPC_ffi
    reinplace "s|%SDK%|${macosx_sdk_version}|" ${worksrcpath}/makefile_darwin_utf8_leopardIntel_ffi
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_build
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_darwinLP64_utf8_lib
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_darwin_utf8_lib
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_darwinLP64_utf8_ffi
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_darwin_utf8_leopardPPC_ffi
    reinplace "s|%CFLAGS%|${configure.cflags} ${configure.cc_archflags}|g" ${worksrcpath}/makefile_darwin_utf8_leopardIntel_ffi

    if {${build_arch} eq "x86_64"} {
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwinLP64_utf8_ffi|" ${worksrcpath}/configure
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwinLP64_utf8_ffi|" ${worksrcpath}/makefile_build
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwinLP64_utf8_ffi|" ${worksrcpath}/Makefile
        reinplace "s|%MAKEFILE_DYLIB%|makefile_darwinLP64_utf8_lib|" ${worksrcpath}/Makefile
    }
    if {${build_arch} eq "ppc64"} {
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/configure
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/makefile_build
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/Makefile
        reinplace "s|%MAKEFILE_DYLIB%|makefile_darwinLP64_utf8_lib|" ${worksrcpath}/Makefile
    }
    if {${build_arch} eq "i386"} {
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardIntel_ffi|" ${worksrcpath}/configure
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardIntel_ffi|" ${worksrcpath}/makefile_build
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardIntel_ffi|" ${worksrcpath}/Makefile
        reinplace "s|%MAKEFILE_DYLIB%|makefile_darwin_utf8_lib|" ${worksrcpath}/Makefile
    }
    if {${build_arch} eq "ppc"} {
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/configure
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/makefile_build
        reinplace "s|%MAKEFILE_DARWIN%|makefile_darwin_utf8_leopardPPC_ffi|" ${worksrcpath}/Makefile
        reinplace "s|%MAKEFILE_DYLIB%|makefile_darwin_utf8_lib|" ${worksrcpath}/Makefile
    }
    if {${build_arch} in [list i386 ppc]} {
        reinplace "s|64-bit|32-bit|" ${worksrcpath}/configure
        # Remove 64-bit flag:
        reinplace "s|-DNEWLISP64| |" ${worksrcpath}/makefile_build
    }
    # Set NEWLISPDIR to Macports prefix:
    reinplace "s|%PREFIX%|${prefix}|" ${worksrcpath}/newlisp.h
    reinplace "s|%PREFIX%|${prefix}|" ${worksrcpath}/makefile_original_install
}

build.args-append   CC=${configure.cc}

build.target        macosall

pre-destroot {
    move ${worksrcpath}/makefile_original_install ${worksrcpath}/makefile_install
}

# newlisp's makefile don't support DESTDIR but provide an install_home target using $HOME
# remember to check makefile_install and remove the following if DESTDIR gets supported
destroot.args       HOME=${destroot}${prefix}
destroot.target     install_home

test.run            yes
test.target         check
